Sha256: 32ea3ad2b03ab22f777380f96bda282a5672cad2cb317ee14235d951077bb2a1

Contents?: true

Size: 1.5 KB

Versions: 42

Compression:

Stored size: 1.5 KB

Contents

module RailsWizard
  class Template
    attr_reader :recipes

    def initialize(recipes)
      @recipes = recipes.map{|r| RailsWizard::Recipe.from_mongo(r)}
    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_recipes
      # @resolve_recipes ||= recipes_with_dependencies.sort
      @resolve_recipes ||= recipes_with_dependencies
    end

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

    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

    def compile
      render 'layout', binding
    end

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

    def custom_code?; false end
    def custom_code; nil end
  end
end

Version data entries

42 entries across 42 versions & 2 rubygems

Version Path
rails_apps_composer-1.2.1 lib/rails_wizard/template.rb
rails_apps_composer-1.2.0 lib/rails_wizard/template.rb
rails_apps_composer-1.1.8 lib/rails_wizard/template.rb
rails_apps_composer-1.1.7 lib/rails_wizard/template.rb
rails_apps_composer-1.1.6 lib/rails_wizard/template.rb
rails_apps_composer-1.1.5 lib/rails_wizard/template.rb
rails_apps_composer-1.1.4 lib/rails_wizard/template.rb
rails_apps_composer-1.1.3 lib/rails_wizard/template.rb
rails_apps_composer-1.1.2 lib/rails_wizard/template.rb
rails_apps_composer-1.1.1 lib/rails_wizard/template.rb
rails_apps_composer-1.1.0 lib/rails_wizard/template.rb
rails_apps_composer-1.0.26 lib/rails_wizard/template.rb
rails_apps_composer-1.0.25 lib/rails_wizard/template.rb
rails_apps_composer-1.0.24 lib/rails_wizard/template.rb
rails_apps_composer-1.0.23 lib/rails_wizard/template.rb
rails_apps_composer-1.0.22 lib/rails_wizard/template.rb
rails_apps_composer-1.0.21 lib/rails_wizard/template.rb
rails_apps_composer-1.0.20 lib/rails_wizard/template.rb
rails_apps_composer-1.0.19 lib/rails_wizard/template.rb
rails_apps_composer-1.0.18 lib/rails_wizard/template.rb