Class: Calamum::DocGenerator
- Inherits:
-
Object
- Object
- Calamum::DocGenerator
- Defined in:
- lib/calamum/doc_generator.rb
Instance Attribute Summary collapse
-
#template ⇒ Object
Returns the value of attribute template.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(tpl_name) ⇒ DocGenerator
constructor
A new instance of DocGenerator.
- #save_template(filename, values) ⇒ Object
Constructor Details
#initialize(tpl_name) ⇒ DocGenerator
Returns a new instance of DocGenerator.
4 5 6 7 8 9 |
# File 'lib/calamum/doc_generator.rb', line 4 def initialize(tpl_name) tpl_path = Calamum::Config[:tpl_path] filename = "#{tpl_path}/#{tpl_name}.html.erb" @template = ERB.new(File.read(filename)) end |
Instance Attribute Details
#template ⇒ Object
Returns the value of attribute template.
2 3 4 |
# File 'lib/calamum/doc_generator.rb', line 2 def template @template end |
Class Method Details
.init_base_dir ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/calamum/doc_generator.rb', line 11 def self.init_base_dir tpl_path = Calamum::Config[:tpl_path] doc_path = Calamum::Config[:doc_path] FileUtils.rm_r(doc_path, :force => true) Dir.mkdir(doc_path) # copy assets from template directory source = File.join(tpl_path, 'assets') target = File.join(doc_path, 'assets') FileUtils.copy_entry(source, target) end |
Instance Method Details
#save_template(filename, values) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/calamum/doc_generator.rb', line 23 def save_template(filename, values) values.each do |k, v| instance_variable_set("@#{k}", v) end html_data = @template.result(binding) filename = File.join(Calamum::Config[:doc_path], filename) File.open(filename, 'w+') { |file| file.write(html_data) } end |