Class: Sprites::Batch

Inherits:
Object
  • Object
show all
Defined in:
lib/sprites/batch.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Batch

Returns a new instance of Batch.



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/sprites/batch.rb', line 5

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.expand_path(pair.last[:root], file_name)
      pair.last.merge!(:config_root => root)
    end
    arr.push OpenStruct.new(pair.last)
    arr
  end
end

Instance Attribute Details

#batchesObject (readonly)

Returns the value of attribute batches.



3
4
5
# File 'lib/sprites/batch.rb', line 3

def batches
  @batches
end

Instance Method Details

#generateObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/sprites/batch.rb', line 19

def generate
  @batches.each do |batch|
    generator = Sprites::Generator.new(batch.files, batch.output, batch.config_root, batch.options || {})
    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