Sha256: 919dc10444c68ebc2b96b28080d58b5db64b071757985949c3f5b0bfce743016
Contents?: true
Size: 1.74 KB
Versions: 1
Compression:
Stored size: 1.74 KB
Contents
module EldarScrolls class Template attr_reader :scrolls, :unknown_scroll_names def initialize(scrolls) @unknown_scroll_names = [] @scrolls = scrolls.inject([]) do |list, name| scroll = EldarScrolls::Scroll.from_mongo(name) if scroll list << scroll else @unknown_scroll_names << name $stderr.puts "Unknown scroll '#{name}'. Skipping." end list end end def self.template_root File.dirname(__FILE__) + '/../../templates' end def self.render(template_name, binding = nil) erb = ERB.new(File.open(template_root + '/' + template_name + '.erb').read) erb.result(binding) end def render(template_name, binding = nil); self.class.render(template_name, binding) end def resolve_scrolls @resolve_scrolls ||= scrolls_with_dependencies.sort end def scroll_classes @scroll_classes ||= scrolls.map { |name| EldarScrolls::Scroll.from_mongo(name) } end def scrolls_with_dependencies @scrolls_with_dependencies ||= scroll_classes added_more = false for scroll in scroll_classes scroll.requires.each do |requirement| requirement = EldarScrolls::Scroll.from_mongo(requirement) count = @scrolls_with_dependencies.size (@scrolls_with_dependencies << requirement).uniq! unless @scrolls_with_dependencies.size == count added_more = true end end end added_more ? scrolls_with_dependencies : @scrolls_with_dependencies end def compile render 'layout', binding end def args scrolls.map(&:args).uniq end def custom_code?; false end def custom_code; nil end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
eldarscrolls-0.7.0 | lib/eldarscrolls/template.rb |