lib/architecture-js/generator.rb in architecture-js-0.1.17 vs lib/architecture-js/generator.rb in architecture-js-0.2.0
- old
+ new
@@ -1,14 +1,16 @@
module ArchitectureJS
class Generator
attr_accessor :template_paths,
:templates,
+ :blueprint,
:project
- def initialize(project)
- @project = project
+ def initialize(blueprint)
+ @project = blueprint
+ @blueprint = @project.config
@template_paths = @project.template_directories
@templates = Hash.new
find_templates @template_paths
end
@@ -32,19 +34,21 @@
def read_template(file)
ERB.new File.read(file)
end
def generate(template, filename, options)
+ raise "There is no template named #{template} in the #{@blueprint[:name]} project" if @templates[template].nil?
filename = "#{filename}#{@templates[template][:ext]}"
- generate_file(filename, render_template(template, options), path)
+ generate_file(filename, render_template(template, options))
end
def generate_file(filename, template, path = nil)
path ||= File.expand_path(Dir.getwd)
File.open("#{path}/#{filename}", "w+") { |f| f.write template }
end
def render_template(template, options = nil)
+ blueprint = @blueprint
project = @project
@templates[template][:erb].result(binding)
end
end
end
\ No newline at end of file