Class: SpriteBatchGenerator
- Inherits:
-
Object
- Object
- SpriteBatchGenerator
- Defined in:
- lib/sprite_batch_generator.rb
Instance Attribute Summary collapse
-
#batches ⇒ Object
readonly
Returns the value of attribute batches.
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(filename) ⇒ SpriteBatchGenerator
constructor
A new instance of SpriteBatchGenerator.
Constructor Details
#initialize(filename) ⇒ SpriteBatchGenerator
Returns a new instance of SpriteBatchGenerator.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/sprite_batch_generator.rb', line 9 def initialize(filename) config = YAML.load(File.read(filename)) @batches = config.inject([]) do |arr, pair| if !!defined?(RAILS_ROOT) pair.last.merge!(:config_root => RAILS_ROOT) elsif pair.last[:root] root = File.(pair.last[:root], file_name) pair.last.merge!(:config_root => root) end arr.push OpenStruct.new(pair.last) arr end end |
Instance Attribute Details
#batches ⇒ Object (readonly)
Returns the value of attribute batches.
7 8 9 |
# File 'lib/sprite_batch_generator.rb', line 7 def batches @batches end |
Instance Method Details
#generate ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/sprite_batch_generator.rb', line 24 def generate @batches.each do |batch| generator = SpriteGenerator.new(batch.files, batch.output, batch.config_root, batch. || {}) css = generator.create # only write output if css_output is specified unless css.nil? || css.empty? || batch.css_output.nil? output = batch.css_template.nil? ? css : Liquid::Template.parse(File.open(batch.css_template).read).render('css' => css) File.open(batch.css_output, 'w+'){|f| f.puts output } end end end |