Class: BuildMaster::Each

Inherits:
Object
  • Object
show all
Defined in:
lib/buildmaster/site/templatelets/each.rb

Instance Method Summary collapse

Constructor Details

#initialize(site_spec) ⇒ Each

Returns a new instance of Each.



6
7
8
# File 'lib/buildmaster/site/templatelets/each.rb', line 6

def initialize(site_spec)
  @site_spec = site_spec
end

Instance Method Details

#process(target, template, source) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/buildmaster/site/templatelets/each.rb', line 10

def process(target, template, source)
    source_xml = load_source_xml(template)
    matched_element = REXML::XPath.match(source_xml, template.attribute_value!('select'))
    count = template.attribute_value!('count').to_i
    if (count > matched_element.size)
      count = matched_element.size
    end
    count.to_i.times do |i|
      element_source = SourceContent.new(source.path, matched_element[i], source.file)
      template_runner = TemplateRunner.new(target, @site_spec.load_element_processor, element_source)
      template_runner.process template
    end
end