Class: OverpassDoc::Generator
- Inherits:
-
Object
- Object
- OverpassDoc::Generator
- Defined in:
- lib/overpass-doc/generator.rb
Instance Attribute Summary collapse
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#package ⇒ Object
readonly
Returns the value of attribute package.
-
#queries ⇒ Object
readonly
Returns the value of attribute queries.
Instance Method Summary collapse
- #copy_assets(asset_dir = @asset_dir) ⇒ Object
-
#initialize(dir, output_dir, view_dir = nil, asset_dir = nil) ⇒ Generator
constructor
A new instance of Generator.
- #read_template(name) ⇒ Object
- #run ⇒ Object
- #write_file(package, filename, content) ⇒ Object
Constructor Details
#initialize(dir, output_dir, view_dir = nil, asset_dir = nil) ⇒ Generator
Returns a new instance of Generator.
7 8 9 10 11 12 13 14 |
# File 'lib/overpass-doc/generator.rb', line 7 def initialize(dir, output_dir, view_dir=nil, asset_dir=nil) @dir = dir @output_dir = output_dir @asset_dir = asset_dir || File.join( File.dirname( __FILE__ ) , "assets") @view_dir = view_dir || File.join( File.dirname( __FILE__ ) , "views") @package = OverpassDoc::Package.new(@dir) @templates = {} end |
Instance Attribute Details
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
5 6 7 |
# File 'lib/overpass-doc/generator.rb', line 5 def dir @dir end |
#package ⇒ Object (readonly)
Returns the value of attribute package.
5 6 7 |
# File 'lib/overpass-doc/generator.rb', line 5 def package @package end |
#queries ⇒ Object (readonly)
Returns the value of attribute queries.
5 6 7 |
# File 'lib/overpass-doc/generator.rb', line 5 def queries @queries end |
Instance Method Details
#copy_assets(asset_dir = @asset_dir) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/overpass-doc/generator.rb', line 39 def copy_assets(asset_dir=@asset_dir) $stderr.puts("Copying assets"); if !File.exists?(@output_dir) FileUtils.mkdir_p(@output_dir) end FileUtils.cp_r( "#{@asset_dir}/.", @output_dir ) end |
#read_template(name) ⇒ Object
24 25 26 27 28 |
# File 'lib/overpass-doc/generator.rb', line 24 def read_template(name) return @templates[name] if @templates[name] @templates[name] = File.read(File.join(@view_dir, "#{name}.erb")) return @templates[name] end |
#run ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/overpass-doc/generator.rb', line 16 def run copy_assets @package.generate(self) rescue => e puts e puts e.backtrace end |
#write_file(package, filename, content) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/overpass-doc/generator.rb', line 30 def write_file(package, filename, content) if File.dirname(filename) != "." FileUtils.mkdir_p File.join(@output_dir, File.dirname(filename)) end File.open(File.join(@output_dir, filename), "w") do |f| f.puts(content) end end |