class Bem
Constants
- LEVEL_ASSETS
Public Instance Methods
create()
click to toggle source
# File lib/bem-on-rails/generators/templates/thor/bem.tt.rb, line 19 def create create_level unless level_exist? ess = resolve_essence path = path_resolve(ess) name = build_def(ess) dest = File.join path, name create_essence(BEM[ess.to_s.pluralize.to_sym], path) update_assets(name, path) end
Protected Instance Methods
create_essence(essence_options, path)
click to toggle source
# File lib/bem-on-rails/generators/templates/thor/bem.tt.rb, line 55 def create_essence(essence_options, path) names = generate_klass @css_class = '.' + names[:klass] # If you need more templates. Please create them into templates # directory. Watch existing templates for example. # What is .tt? It is custom extension for finding templates in other files. if options[:tech] # Maybe recive from command line template "#{ options[:tech] }.tt", File.join(BEM[:root], path, names[:klass] + BEM[:techs][options[:tech].to_sym]) else defaults(essence_options, path, names) end end
create_level(l=options[:level])
click to toggle source
# File lib/bem-on-rails/generators/templates/thor/bem.tt.rb, line 38 def create_level(l=options[:level]) target = Rails.root.join BEM[:root], l # Make files for level assets BEM[:assets].each do |type, tech| create_file File.join target, LEVEL_ASSETS, type.to_s, "level" + tech[:ext] end # Update app assets with levels assets BEM[:assets].each do |type, tech| asset = File.join(Rails.root, "app", "assets", type.to_s, "application" + tech[:ext]) destination = [l, LEVEL_ASSETS, type.to_s, "level" + tech[:ext]] create_file asset unless File.exist?(asset) append_file asset, "\n#{ tech[:import] } #{ File.join(destination) }#{ tech[:postfix] }" end end
defaults(essence_options, path, names)
click to toggle source
# File lib/bem-on-rails/generators/templates/thor/bem.tt.rb, line 68 def defaults(essence_options, path, names) BEM[:default].each do |tech| template "#{ tech }.tt", File.join(BEM[:root], path, names[:klass] + BEM[:techs][tech]) end end
level_exist?(l=options[:level])
click to toggle source
# File lib/bem-on-rails/generators/templates/thor/bem.tt.rb, line 34 def level_exist?(l=options[:level]) File.directory? Rails.root.join BEM[:root], l end
update_assets(name, path)
click to toggle source
# File lib/bem-on-rails/generators/templates/thor/bem.tt.rb, line 74 def update_assets(name, path) level = BEM[:level] || options[:level] BEM[:assets].each do |type, tech| asset = File.join(Rails.root, BEM[:root], level, LEVEL_ASSETS, type.to_s, "level" + tech[:ext]) # BEM[:root] > level > .bem > assets # 4 ../ destination = ["../../../../", path, name + tech[:ext]].reject(&:empty?) create_file asset unless File.exist?(asset) append_file asset, "\n#{ tech[:import] } #{ File.join(destination) }#{ tech[:postfix] }" end end