Class: Requirejs::Rails::Engine

Inherits:
Rails::Engine
  • Object
show all
Defined in:
lib/requirejs/rails/engine.rb

Class Method Summary collapse

Class Method Details

.process_user_config_file(app, config) ⇒ Object

Process 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.



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/requirejs/rails/engine.rb', line 80

def self.process_user_config_file(app, config)
  config_path = Pathname.new(app.paths["config"].first)
  config.requirejs.user_config_file = config_path+'requirejs.yml'

  yaml_file_contents = nil
  if config.requirejs.user_config_file.exist?
    yaml_file_contents = config.requirejs.user_config_file.read
  else
    # if requirejs.yml doesn't exist, look for requirejs.yml.erb and process it as an erb
    config.requirejs.user_config_file = config_path+'requirejs.yml.erb'

    if config.requirejs.user_config_file.exist?
      yaml_file_contents = ERB.new(config.requirejs.user_config_file.read).result
    end
  end

  if yaml_file_contents.nil?
    # If we couldn't find any matching file contents to process, empty user config
    config.requirejs.user_config = {}
  else
    config.requirejs.user_config = YAML.load(yaml_file_contents)
  end
end