Class: RTFDoc::Generator
- Inherits:
-
Object
- Object
- RTFDoc::Generator
- Defined in:
- lib/rtfdoc.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#renderer ⇒ Object
readonly
Returns the value of attribute renderer.
Instance Method Summary collapse
-
#initialize(config_path) ⇒ Generator
constructor
A new instance of Generator.
- #run ⇒ Object
Constructor Details
#initialize(config_path) ⇒ Generator
Returns a new instance of Generator.
321 322 323 324 325 |
# File 'lib/rtfdoc.rb', line 321 def initialize(config_path) @config = YAML.load_file(config_path) @content_dir = @config['content_dir'] @parts = {} end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
319 320 321 |
# File 'lib/rtfdoc.rb', line 319 def config @config end |
#renderer ⇒ Object (readonly)
Returns the value of attribute renderer.
319 320 321 |
# File 'lib/rtfdoc.rb', line 319 def renderer @renderer end |
Instance Method Details
#run ⇒ Object
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 |
# File 'lib/rtfdoc.rb', line 327 def run tree = build_content_tree nodes = config['resources'].map do |rs| if rs.is_a?(Hash) name, endpoints = rs.each_pair.first paths = tree[name] Resource.build(name, paths, endpoints: endpoints) else paths = tree[rs] paths.is_a?(Hash) ? Resource.build(rs, paths) : Section.new(rs, File.read(paths)) end end out = File.new("#{Dir.tmpdir}/rtfdoc_output.html", 'w') out.write(Template.new(nodes, config).output) out.close end |