Class: RailsWizard::Template
- Inherits:
-
Object
- Object
- RailsWizard::Template
- Defined in:
- lib/rails_wizard/template.rb
Instance Attribute Summary collapse
-
#recipes ⇒ Object
readonly
Returns the value of attribute recipes.
Class Method Summary collapse
Instance Method Summary collapse
- #args ⇒ Object
- #compile ⇒ Object
- #custom_code ⇒ Object
- #custom_code? ⇒ Boolean
-
#initialize(recipes) ⇒ Template
constructor
A new instance of Template.
- #recipe_classes ⇒ Object
- #recipes_with_dependencies ⇒ Object
- #render(template_name, binding = nil) ⇒ Object
- #resolve_recipes ⇒ Object
Constructor Details
#initialize(recipes) ⇒ Template
Returns a new instance of Template.
5 6 7 |
# File 'lib/rails_wizard/template.rb', line 5 def initialize(recipes) @recipes = recipes.map{|r| RailsWizard::Recipe.from_mongo(r)} end |
Instance Attribute Details
#recipes ⇒ Object (readonly)
Returns the value of attribute recipes.
3 4 5 |
# File 'lib/rails_wizard/template.rb', line 3 def recipes @recipes end |
Class Method Details
.render(template_name, binding = nil) ⇒ Object
13 14 15 16 |
# File 'lib/rails_wizard/template.rb', line 13 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
9 10 11 |
# File 'lib/rails_wizard/template.rb', line 9 def self.template_root File.dirname(__FILE__) + '/../../templates' end |
Instance Method Details
#args ⇒ Object
51 52 53 |
# File 'lib/rails_wizard/template.rb', line 51 def args recipes.map(&:args).uniq end |
#compile ⇒ Object
47 48 49 |
# File 'lib/rails_wizard/template.rb', line 47 def compile render 'layout', binding end |
#custom_code ⇒ Object
56 |
# File 'lib/rails_wizard/template.rb', line 56 def custom_code; nil end |
#custom_code? ⇒ Boolean
55 |
# File 'lib/rails_wizard/template.rb', line 55 def custom_code?; false end |
#recipe_classes ⇒ Object
25 26 27 |
# File 'lib/rails_wizard/template.rb', line 25 def recipe_classes @recipe_classes ||= recipes.map{|r| RailsWizard::Recipe.from_mongo(r)} end |
#recipes_with_dependencies ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rails_wizard/template.rb', line 29 def recipes_with_dependencies @recipes_with_dependencies ||= recipe_classes added_more = false for recipe in recipe_classes recipe.requires.each do |requirement| requirement = RailsWizard::Recipe.from_mongo(requirement) count = @recipes_with_dependencies.size (@recipes_with_dependencies << requirement).uniq! unless @recipes_with_dependencies.size == count added_more = true end end end added_more ? recipes_with_dependencies : @recipes_with_dependencies end |
#render(template_name, binding = nil) ⇒ Object
17 |
# File 'lib/rails_wizard/template.rb', line 17 def render(template_name, binding = nil); self.class.render(template_name, binding) end |
#resolve_recipes ⇒ Object
20 21 22 23 |
# File 'lib/rails_wizard/template.rb', line 20 def resolve_recipes # @resolve_recipes ||= recipes_with_dependencies.sort @resolve_recipes ||= recipes_with_dependencies end |