Sha256: 977cca48f8a6d38407d60d200b4f8c09a82788bd61d86c4e9f7a0d168ff84e93
Contents?: true
Size: 1.79 KB
Versions: 1
Compression:
Stored size: 1.79 KB
Contents
module RailsWizard class Template attr_reader :scrolls, :unknown_scroll_names def initialize(scrolls) @unknown_scroll_names = [] @scrolls = scrolls.inject([]) do |list, name| scroll = RailsWizard::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.sort.sort # why do the extra sorts to resolve nesting?! end def scroll_classes @scroll_classes ||= scrolls.map { |name| RailsWizard::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 = RailsWizard::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 |
---|---|
ey_rails_wizard-0.5.0 | lib/rails_wizard/template.rb |