Class: RailsWizard::Template
- Inherits:
-
Object
- Object
- RailsWizard::Template
- Defined in:
- lib/rails_wizard/template.rb
Instance Attribute Summary collapse
-
#scrolls ⇒ Object
readonly
Returns the value of attribute scrolls.
-
#unknown_scroll_names ⇒ Object
readonly
Returns the value of attribute unknown_scroll_names.
Class Method Summary collapse
Instance Method Summary collapse
- #args ⇒ Object
- #compile ⇒ Object
- #custom_code ⇒ Object
- #custom_code? ⇒ Boolean
-
#initialize(scrolls) ⇒ Template
constructor
A new instance of Template.
- #render(template_name, binding = nil) ⇒ Object
- #resolve_scrolls ⇒ Object
- #scroll_classes ⇒ Object
- #scrolls_with_dependencies ⇒ Object
Constructor Details
#initialize(scrolls) ⇒ Template
Returns a new instance of Template.
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/rails_wizard/template.rb', line 5 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 |
Instance Attribute Details
#scrolls ⇒ Object (readonly)
Returns the value of attribute scrolls.
3 4 5 |
# File 'lib/rails_wizard/template.rb', line 3 def scrolls @scrolls end |
#unknown_scroll_names ⇒ Object (readonly)
Returns the value of attribute unknown_scroll_names.
3 4 5 |
# File 'lib/rails_wizard/template.rb', line 3 def unknown_scroll_names @unknown_scroll_names end |
Class Method Details
.render(template_name, binding = nil) ⇒ Object
23 24 25 26 |
# File 'lib/rails_wizard/template.rb', line 23 def self.render(template_name, binding = nil) erb = ERB.new(File.open(template_root + '/' + template_name + '.erb').read) erb.result(binding) end |
.template_root ⇒ Object
19 20 21 |
# File 'lib/rails_wizard/template.rb', line 19 def self.template_root File.dirname(__FILE__) + '/../../templates' end |
Instance Method Details
#args ⇒ Object
60 61 62 |
# File 'lib/rails_wizard/template.rb', line 60 def args scrolls.map(&:args).uniq end |
#compile ⇒ Object
56 57 58 |
# File 'lib/rails_wizard/template.rb', line 56 def compile render 'layout', binding end |
#custom_code ⇒ Object
65 |
# File 'lib/rails_wizard/template.rb', line 65 def custom_code; nil end |
#custom_code? ⇒ Boolean
64 |
# File 'lib/rails_wizard/template.rb', line 64 def custom_code?; false end |
#render(template_name, binding = nil) ⇒ Object
27 |
# File 'lib/rails_wizard/template.rb', line 27 def render(template_name, binding = nil); self.class.render(template_name, binding) end |
#resolve_scrolls ⇒ Object
30 31 32 |
# File 'lib/rails_wizard/template.rb', line 30 def resolve_scrolls @resolve_scrolls ||= scrolls_with_dependencies.sort end |
#scroll_classes ⇒ Object
34 35 36 |
# File 'lib/rails_wizard/template.rb', line 34 def scroll_classes @scroll_classes ||= scrolls.map { |name| RailsWizard::Scroll.from_mongo(name) } end |
#scrolls_with_dependencies ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rails_wizard/template.rb', line 38 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 |