Sha256: b625cc75cb03ecd06817164d334e4c1553f491a0a6f7d7fdef3a23bfa55d1620
Contents?: true
Size: 1.16 KB
Versions: 4
Compression:
Stored size: 1.16 KB
Contents
require 'uri' require 'open-uri' module BuildMaster class Each def initialize(site_spec) @site_spec = site_spec end 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') count.to_i.times do |i| element_source = SourceContent.new(source.path, matched_element[i]) template_runner = TemplateRunner.new(target, template, element_source) template_runner.templatelets = @site_spec.load_templatelets template_runner.process end end private def load_source_xml(template) path = template.attribute_value!('source') if (URI.parse(path).scheme.nil?) return @site_spec.load_document(path) end return load_content_through_uri(path) end def load_content_through_uri(uri) buffer = StringIO.new begin open(uri) do |file| buffer.puts file.gets end return REXML::Document.new(buffer.string) rescue Exception => exception raise RuntimeError, "Error loading uri: #{uri}", caller end end end end
Version data entries
4 entries across 4 versions & 1 rubygems