Sha256: c7b1d84157ff0c77e75f3143ac0460fde17f77c9b120c34a3b6e627decbc7984
Contents?: true
Size: 1.34 KB
Versions: 1
Compression:
Stored size: 1.34 KB
Contents
module JsRoutes class Railtie < ::Rails::Railtie config.before_configuration do config.action_view.javascript_expansions[:defaults] |= %w{ js_routes jquery.pathBuilder.js } end config.after_initialize do JsRoutes.generate_routes_file FileUtils.cp File.expand_path('../../assets/javascripts/jquery.pathBuilder.js', __FILE__), File.join(Rails.root, 'public', 'javascripts') if Rails.env.development? ApplicationController.class_eval do before_filter do JsRoutes.generate_routes_file end end end end end def self.generate_routes_file puts 'GENERATING ROUTES FILE' filename = File.join(Rails.root, 'public', 'javascripts', 'js_routes.js') FileUtils.rm filename, :force => true File.open(filename, 'w') do |f| f << 'window.Routes = {};' Rails.application.reload_routes! Rails.application.routes.routes.each do |route| defaults = route.defaults unless defaults.present? && defaults.has_key?(:exclude_from_js) && defaults[:exclude_from_js] f << <<-JS.strip Routes.#{route.name}_path = function() { Array.prototype.unshift.call(arguments, '#{route.path}'); return $.buildPath.apply($, arguments); }; JS end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
js_routes-0.1.9 | lib/js_routes/railtie.rb |