Class: BowerRails::Dsl
- Inherits:
-
Object
- Object
- BowerRails::Dsl
- Defined in:
- lib/bower-rails/dsl.rb
Instance Attribute Summary collapse
-
#dependencies ⇒ Object
readonly
Returns the value of attribute dependencies.
-
#root_path ⇒ Object
readonly
Returns the value of attribute root_path.
Class Method Summary collapse
Instance Method Summary collapse
- #asset(name, version = "latest") ⇒ Object
- #directories ⇒ Object
- #eval_file(file) ⇒ Object
- #final_assets_path ⇒ Object
- #group(name, options = {}, &block) ⇒ Object
- #group_assets_path(group) ⇒ Object
-
#initialize ⇒ Dsl
constructor
A new instance of Dsl.
- #to_json(location) ⇒ Object
- #write_bower_json ⇒ Object
- #write_dotbowerrc ⇒ Object
Constructor Details
#initialize ⇒ Dsl
Returns a new instance of Dsl.
13 14 15 16 17 |
# File 'lib/bower-rails/dsl.rb', line 13 def initialize @dependencies = {} @root_path ||= defined?(Rails) ? Rails.root : Dir.pwd @assets_path ||= "assets" end |
Instance Attribute Details
#dependencies ⇒ Object (readonly)
Returns the value of attribute dependencies.
11 12 13 |
# File 'lib/bower-rails/dsl.rb', line 11 def dependencies @dependencies end |
#root_path ⇒ Object (readonly)
Returns the value of attribute root_path.
11 12 13 |
# File 'lib/bower-rails/dsl.rb', line 11 def root_path @root_path end |
Class Method Details
.evalute(filename) ⇒ Object
7 8 9 |
# File 'lib/bower-rails/dsl.rb', line 7 def self.evalute(filename) new.tap { |dsl| dsl.eval_file(File.join(dsl.root_path, filename)) } end |
Instance Method Details
#asset(name, version = "latest") ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/bower-rails/dsl.rb', line 35 def asset(name, version = "latest") groups.each do |g| g_norm = normalize_location_path(g.first, group_assets_path(g)) @dependencies[g_norm] ||= {} @dependencies[g_norm][name] = version end end |
#directories ⇒ Object
23 24 25 |
# File 'lib/bower-rails/dsl.rb', line 23 def directories @dependencies.keys end |
#eval_file(file) ⇒ Object
19 20 21 |
# File 'lib/bower-rails/dsl.rb', line 19 def eval_file(file) instance_eval(File.open(file, "rb") { |f| f.read }, file.to_s) end |
#final_assets_path ⇒ Object
65 66 67 68 69 |
# File 'lib/bower-rails/dsl.rb', line 65 def final_assets_path groups.map do |g| [g.first.to_s, group_assets_path(g)] end end |
#group(name, options = {}, &block) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/bower-rails/dsl.rb', line 27 def group(name, = {}, &block) if custom_assets_path = [:assets_path] assert_asset_path custom_assets_path end add_group(name, ) yield if block_given? end |
#group_assets_path(group) ⇒ Object
71 72 73 74 |
# File 'lib/bower-rails/dsl.rb', line 71 def group_assets_path group = Hash === group.last ? group.last : {:assets_path => @assets_path} [:assets_path] end |
#to_json(location) ⇒ Object
43 44 45 |
# File 'lib/bower-rails/dsl.rb', line 43 def to_json(location) dependencies_to_json @dependencies[normalize_location_path(location)] end |
#write_bower_json ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/bower-rails/dsl.rb', line 47 def write_bower_json @dependencies.each do |dir,data| FileUtils.mkdir_p dir unless File.directory? dir File.open(File.join(dir,"bower.json"), "w") do |f| f.write(dependencies_to_json(data)) end end end |
#write_dotbowerrc ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/bower-rails/dsl.rb', line 56 def write_dotbowerrc groups.map do |g| g_norm = normalize_location_path(g.first, group_assets_path(g)) File.open(File.join(g_norm, ".bowerrc"), "w") do |f| f.write(JSON.pretty_generate({:directory => "bower_components/pt"})) end end end |