Class: Giblish::SubtreeInfoBuilder
- Inherits:
-
Object
- Object
- Giblish::SubtreeInfoBuilder
- Defined in:
- lib/giblish/subtreeinfobuilder.rb
Constant Summary collapse
- DEFAULT_BASENAME =
"index"
Instance Attribute Summary collapse
-
#docattr_provider ⇒ Object
Returns the value of attribute docattr_provider.
Instance Method Summary collapse
- #adoc_source(src_node, dst_node, dst_top) ⇒ Object
- #api_options(src_node, dst_node, dst_top) ⇒ Object
- #document_attributes(src_node, dst_node, dst_top) ⇒ Object
-
#initialize(docattr_provider = nil, api_opt_provider = nil, adoc_src_provider = nil, basename = DEFAULT_BASENAME) ⇒ SubtreeInfoBuilder
constructor
- docattr_provider
- an object implementing the DocAttributesBase interface api_opt_provider
- an object implementing the api_options(dst_top) interface adoc_src_provider
- a Class or object implementing the SubtreeSrcItf interface basename
-
the name of the output file that is generated in each directory.
-
#on_postbuild(src_tree, dst_tree, converter) ⇒ Object
Called from TreeConverter during post build phase.
Constructor Details
#initialize(docattr_provider = nil, api_opt_provider = nil, adoc_src_provider = nil, basename = DEFAULT_BASENAME) ⇒ SubtreeInfoBuilder
- docattr_provider
-
an object implementing the DocAttributesBase interface
- api_opt_provider
-
an object implementing the api_options(dst_top) interface
- adoc_src_provider
-
a Class or object implementing the SubtreeSrcItf interface
- basename
-
the name of the output file that is generated in each directory
21 22 23 24 25 26 27 |
# File 'lib/giblish/subtreeinfobuilder.rb', line 21 def initialize(docattr_provider = nil, api_opt_provider = nil, adoc_src_provider = nil, basename = DEFAULT_BASENAME) @docattr_provider = docattr_provider @api_opt_provider = api_opt_provider @adoc_src_provider = adoc_src_provider || SubtreeIndexBase @basename = basename @adoc_source = nil end |
Instance Attribute Details
#docattr_provider ⇒ Object
Returns the value of attribute docattr_provider.
13 14 15 |
# File 'lib/giblish/subtreeinfobuilder.rb', line 13 def docattr_provider @docattr_provider end |
Instance Method Details
#adoc_source(src_node, dst_node, dst_top) ⇒ Object
37 38 39 |
# File 'lib/giblish/subtreeinfobuilder.rb', line 37 def adoc_source(src_node, dst_node, dst_top) @adoc_source end |
#api_options(src_node, dst_node, dst_top) ⇒ Object
33 34 35 |
# File 'lib/giblish/subtreeinfobuilder.rb', line 33 def (src_node, dst_node, dst_top) @api_opt_provider.nil? ? {} : @api_opt_provider.(dst_top) end |
#document_attributes(src_node, dst_node, dst_top) ⇒ Object
29 30 31 |
# File 'lib/giblish/subtreeinfobuilder.rb', line 29 def document_attributes(src_node, dst_node, dst_top) @docattr_provider.nil? ? {} : @docattr_provider.document_attributes(src_node, dst_node, dst_top) end |
#on_postbuild(src_tree, dst_tree, converter) ⇒ Object
Called from TreeConverter during post build phase
adds a ‘index’ node for each directory in the source tree and convert that index using the options from the provider objects given at instantiation of this object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/giblish/subtreeinfobuilder.rb', line 46 def on_postbuild(src_tree, dst_tree, converter) dst_tree.traverse_preorder do |level, dst_node| # we only care about directories next if dst_node.leaf? # get the relative path to the index dir from the top dir index_dir = dst_node.pathname.relative_path_from(dst_tree.pathname).cleanpath Giblog.logger.debug { "Creating #{@basename} under #{index_dir}" } # get the adoc source from the provider (Class or instance) @adoc_source = if @adoc_src_provider.is_a?(Class) @adoc_src_provider.new(dst_node, @basename).adoc_source else @adoc_src_provider.adoc_source end # add a virtual 'index.adoc' node as the only node in a source tree # with this object as source for conversion options # and adoc_source v_path = Pathname.new("/virtual") / index_dir / "#{@basename}.adoc" v_tree = PathTree.new(v_path, self) src_node = v_tree.node(v_path, from_root: true) # add the destination node where the converted file will be stored i_node = dst_node.add_descendants(@basename) # do the conversion converter.convert(src_node, i_node, dst_tree) end end |