Class: RailsWizard::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_wizard/template.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#recipesObject (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_rootObject



9
10
11
# File 'lib/rails_wizard/template.rb', line 9

def self.template_root
  File.dirname(__FILE__) + '/../../templates'
end

Instance Method Details

#argsObject



50
51
52
# File 'lib/rails_wizard/template.rb', line 50

def args
  recipes.map(&:args).uniq
end

#compileObject



46
47
48
# File 'lib/rails_wizard/template.rb', line 46

def compile
  render 'layout', binding
end

#custom_codeObject



55
# File 'lib/rails_wizard/template.rb', line 55

def custom_code; nil end

#custom_code?Boolean

Returns:

  • (Boolean)


54
# File 'lib/rails_wizard/template.rb', line 54

def custom_code?; false end

#recipe_classesObject



24
25
26
# File 'lib/rails_wizard/template.rb', line 24

def recipe_classes
  @recipe_classes ||= recipes.map{|r| RailsWizard::Recipe.from_mongo(r)}
end

#recipes_with_dependenciesObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rails_wizard/template.rb', line 28

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_recipesObject



20
21
22
# File 'lib/rails_wizard/template.rb', line 20

def resolve_recipes
  @resolve_recipes ||= recipes_with_dependencies.sort
end