Class: DOWL::Generator
- Inherits:
-
Object
- Object
- DOWL::Generator
- Defined in:
- lib/dowl/generator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #copy_assets ⇒ Object
-
#initialize(schema, template = Generator.default_template()) ⇒ Generator
constructor
A new instance of Generator.
- #run ⇒ Object
Constructor Details
#initialize(schema, template = Generator.default_template()) ⇒ Generator
Returns a new instance of Generator.
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/dowl/generator.rb', line 5 def initialize(schema, template=Generator.default_template()) @template = ERB.new(File.read(template)) @schema = schema if schema.introduction @introduction = File.read(schema.introduction) if schema.introduction.end_with?(".md") renderer = Redcarpet::Render::HTML.new({}) markdown = Redcarpet::Markdown.new(renderer, {}) @introduction = markdown.render(@introduction) end end end |
Class Method Details
.default_template ⇒ Object
18 19 20 21 |
# File 'lib/dowl/generator.rb', line 18 def Generator.default_template() dir = File.dirname( __FILE__ ) return default_template_file = File.join(dir, "default.erb") end |
Instance Method Details
#copy_assets ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/dowl/generator.rb', line 23 def copy_assets asset_dir = File.join( File.dirname( __FILE__ ), "assets" ) Dir.new(asset_dir).each() do |file| if file != "." and file != ".." FileUtils.cp( File.join(asset_dir, file), Dir.pwd ) end end end |
#run ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/dowl/generator.rb', line 32 def run() copy_assets() b = binding schema = @schema introduction = @introduction return @template.result(b) end |