Skip to content

A Rails engine wrapper to include the webshims js library

Notifications You must be signed in to change notification settings

marnen/webshims-rails

 
 

Repository files navigation

Webshims-rails

Easily include the webshims library (by Alexander Farkas) in your Rails 3.1+ project with the asset pipeline.

Note on Changes in Rails 4

With the release of Rails 4 and an updated sprockets-rails gem, only digest filenames are compiled when running rake assets:precompile (non-digest filenames are no longer compiled).

Since webshims does not support fingerprinting, this will result in 404s (missing assets) in production mode. To avoid this, you have two options:

One, turn (back) on asset compiling with non-digest filenames, with, for example, this gist: https://gist.github.com/eric1234/5692456

Or two, run


$ rake webshims:update_public

which copies the webshims directory into the public/ directory. Then, alter step 3 below to re-configure your basePath from public/assets (as it was in Rails 3.X) to public/:

$.webshims.setOptions(‘basePath’, ‘/webshims/shims/’)

Usage

1. Add webshims-rails to your Gemfile for bundler: gem 'webshims-rails'
2. Require modernizr and the webshims polyfiller, eg, in your application.js:

//= require webshims/extras/modernizr-custom
//= require webshims/polyfiller

Update note: Previous webshims-rails included only the minified versions; this was incorrect, since the dev (unminified) versions should be required by Sprockets and then the Rails asset pipeline will minify as necessary in production. The unminified (‘dev’) versions have been moved up a directory to simplify the require paths.

Users of previous webshims-rails versions should update their sprockets requires and webshims options as below (though I’ll leave the minified assets in there to prevent errors).

3. In your javascript, after the polyfiller has been required, set the basePath for webshims as shown below, and then call $.webshims.polyfill(); see webshims docs for more options.
(Note that this should be run directly, not in a dom-ready block.)

  $.webshims.setOptions('basePath', '/assets/webshims/shims/')
  $.webshims.polyfill()

License

MIT licensed, like the Webshims library.

About

A Rails engine wrapper to include the webshims js library

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 100.0%