lib/requirejs/rails/engine.rb in requirejs-rails-0.6.1 vs lib/requirejs/rails/engine.rb in requirejs-rails-0.7.0
- old
+ new
@@ -4,34 +4,45 @@
module Requirejs
module Rails
class Engine < ::Rails::Engine
- initializer "requirejs.tag_included_state" do |app|
- ActiveSupport.on_load(:action_controller) do
- ::ActionController::Base.class_eval do
- attr_accessor :requirejs_included
- end
- end
- end
+ ### Configuration setup
+ config.before_configuration do |app|
+ config.requirejs = Requirejs::Rails::Config.new
+ config.requirejs.precompile = [/require\.js$/]
- initializer "requirejs.config" do |app|
- config = app.config
- config.requirejs = Requirejs::Rails::Config.new(app)
- if config.requirejs.manifest
- path = File.join(config.assets.manifest, "rjs_manifest.yml")
+ # Location of the user-supplied config parameters, which will be
+ # merged with the default params. It should be a YAML file with
+ # a single top-level hash, keys/values corresponding to require.js
+ # config parameters.
+ config.requirejs.user_config_file = Pathname.new(app.paths["config"].first)+'requirejs.yml'
+ if config.requirejs.user_config_file.exist?
+ config.requirejs.user_config = YAML.load(config.requirejs.user_config_file.read)
else
- path = File.join(::Rails.public_path, config.assets.prefix, "rjs_manifest.yml")
+ config.requirejs.user_config = {}
end
- config.requirejs.manifest_path = Pathname.new(path)
-
- config.requirejs.precompile = [/require\.js$/]
+ end
+ config.before_initialize do |app|
+ config = app.config
if ::Rails.env == "production"
config.assets.precompile += config.requirejs.precompile
end
+
+ manifest_path = File.join(::Rails.public_path, config.assets.prefix, "rjs_manifest.yml")
+ config.requirejs.manifest_path = Pathname.new(manifest_path)
end
-
+
+ ### Initializers
+ initializer "requirejs.tag_included_state" do |app|
+ ActiveSupport.on_load(:action_controller) do
+ ::ActionController::Base.class_eval do
+ attr_accessor :requirejs_included
+ end
+ end
+ end
+
initializer "requirejs.manifest", :after => "sprockets.environment" do |app|
config = app.config
if config.requirejs.manifest_path.exist? && config.assets.digests
rjs_digests = YAML.load_file(config.requirejs.manifest_path)
config.assets.digests.merge!(rjs_digests)