Class: Requirejs::Rails::Config

Inherits:
ActiveSupport::OrderedOptions
  • Object
show all
Defined in:
lib/requirejs/rails/config.rb

Instance Method Summary collapse

Constructor Details

#initialize(app = Rails.application) ⇒ Config

Returns a new instance of Config.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/requirejs/rails/config.rb', line 10

def initialize(app=Rails.application)
  super
  self.manifest = nil

  self.tmp_dir = Rails.root + 'tmp'
  self.bin_dir = Pathname.new(__FILE__+'/../../../../bin').cleanpath

  self.source_dir = self.tmp_dir + 'assets'
  self.target_dir = Rails.root + 'public/assets'
  self.rjs_path   = self.bin_dir+'r.js'

  self.driver_template_path = Pathname.new(__FILE__+'/../rjs_driver.js.erb').cleanpath
  self.driver_path = self.tmp_dir + 'rjs_driver.js'

  # The user-supplied config parameters, to be merged with the default params.
  # This file must contain a single JavaScript object.
  self.user_config_file = Pathname.new(app.paths["config"].first)+'requirejs.yml'
  if self.user_config_file.exist?
    self.user_config = YAML.load(self.user_config_file.read)
  else
    self.user_config = {}
  end

  self.run_config = {
    "baseUrl" => "/assets",
    "modules" => [ { 'name' => 'application' } ]
  }
  self.run_config.merge!(self.user_config)
  self.run_config_json = self.run_config.to_json

  self.build_config = self.run_config.merge "baseUrl" => source_dir.to_s
  self.build_config.merge!(self.user_config)
end

Instance Method Details

#get_bindingObject



48
49
50
# File 'lib/requirejs/rails/config.rb', line 48

def get_binding
  return binding()
end

#module_path_for(name) ⇒ Object



44
45
46
# File 'lib/requirejs/rails/config.rb', line 44

def module_path_for(name)
  self.target_dir+(name+'.js')
end