diff --git a/README.md b/README.md index 9f64d7a..e6a3caf 100644 --- a/README.md +++ b/README.md @@ -37,10 +37,12 @@ Since webshims does not support fingerprinting, this will result in 404s (missin (Note that this should be run directly, not in a dom-ready block.) ```javascript - $.webshims.setOptions('basePath', '/assets/webshims/shims/') + $.webshims.setOptions('basePath', '/webshims/shims/1.15.6/') $.webshims.polyfill() ``` + The version number above should match the version of Webshims. When you update the gem change this so browser-cached files get reloaded. If you are interpolating your JavaScript, you can use the helper `webshims_path` to automatically populate the path with version number. + 4. For Turbolinks users only: you'll need to update the polyfill on page load: ```coffeescript @@ -48,6 +50,21 @@ Since webshims does not support fingerprinting, this will result in 404s (missin $(this).updatePolyfill() ``` +5. For Spork users, if you have a line to reload your routes for each spec run in your `spec_helper`: + + ```ruby + Spork.each_run do + # This code will be run each time you run your specs. + load "#{Rails.root}/config/routes.rb" + end + ``` + + Then you need to add the `mount` to your `config/routes.rb` otherwise it gets removed by Spork's reload. + + ```ruby + mount Webshims::Rails::Rewrite.new, at: '/webshims/shims' + ``` + ## Updating this gem This is only in the case this repository is not up-to-date; I try to stay current with webshims but sometimes I miss the webshims releases. diff --git a/config/routes.rb b/config/routes.rb new file mode 100644 index 0000000..5c67db7 --- /dev/null +++ b/config/routes.rb @@ -0,0 +1,3 @@ +Rails.application.routes.draw do + mount Webshims::Rails::Rewrite.new, :at => "/webshims/shims" +end diff --git a/lib/webshims-rails.rb b/lib/webshims-rails.rb index 94bffdd..0dc0ae8 100644 --- a/lib/webshims-rails.rb +++ b/lib/webshims-rails.rb @@ -1,4 +1,6 @@ require "webshims-rails/version" +require "webshims-rails/view-helpers" +require "webshims-rails/rewrite" module Webshims module Rails @@ -12,6 +14,10 @@ class Engine < ::Rails::Engine app.config.assets.precompile << /webshims/ end end + + initializer "Webshims::Rails::ViewHelpers" do + ActiveSupport.on_load(:action_view) { include Webshims::Rails::ViewHelpers } + end end end end diff --git a/lib/webshims-rails/rewrite.rb b/lib/webshims-rails/rewrite.rb new file mode 100644 index 0000000..5a469bc --- /dev/null +++ b/lib/webshims-rails/rewrite.rb @@ -0,0 +1,21 @@ +module Webshims + module Rails + class Rewrite < Rack::File + + def initialize + super(root) + end + + def call(env) + env["PATH_INFO"] = env["PATH_INFO"].gsub(%r(\A/[0-9.]+/), '') + super(env) + end + + private + + def root + File.join(Gem.loaded_specs["webshims-rails"].full_gem_path, "vendor", "assets", "javascripts", "webshims", "shims") + end + end + end +end diff --git a/lib/webshims-rails/view-helpers.rb b/lib/webshims-rails/view-helpers.rb new file mode 100644 index 0000000..085f001 --- /dev/null +++ b/lib/webshims-rails/view-helpers.rb @@ -0,0 +1,9 @@ +module Webshims + module Rails + module ViewHelpers + def webshims_path + "/webshims/shims/#{Webshims::Rails::WEBSHIMS_VERSION}/" + end + end + end +end