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.
295 296 297 298 299 |
# File 'lib/rtfdoc.rb', line 295 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.
293 294 295 |
# File 'lib/rtfdoc.rb', line 293 def config @config end |
#renderer ⇒ Object (readonly)
Returns the value of attribute renderer.
293 294 295 |
# File 'lib/rtfdoc.rb', line 293 def renderer @renderer end |
Instance Method Details
#run ⇒ Object
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
# File 'lib/rtfdoc.rb', line 301 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).output) out.close end |