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



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

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

#compileObject



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

def compile
  render 'layout', binding
end

#custom_codeObject



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

def custom_code; nil end

#custom_code?Boolean

Returns:

  • (Boolean)


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

def custom_code?; false end

#recipe_classesObject



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_dependenciesObject



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_recipesObject



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