Sha256: 82699f9c3b4c36979af9d4a757d685422fd2746c289baf95da7224f3befd9ce6
Contents?: true
Size: 1.8 KB
Versions: 2
Compression:
Stored size: 1.8 KB
Contents
require 'yaml' require 'fileutils' module Tree class Node attr_reader :children, :content, :page, :title, :root def initialize(title, page, content, root) @children = [] @root = root @page = page @title = title @content = content end def add_content(content) @content << "\n" @content << content end def add_child(child) @children << child end def traverse_subtree(&block) node_queue = [self] # Step 1 until node_queue.empty? # Step 2 node = node_queue.shift # Step 3 yield node # Step 4 node_queue = node.children.concat(node_queue) # Step 5 end end end def self.updateContent(tree, temp_dir) content = '' if tree.page.length > 0 file = File.join(temp_dir, tree.page + '.adoc') tree.add_content(File.read(file)) else if not tree.root tree.add_content("= " + tree.title) end end if not tree.root tree.add_content(":leveloffset: +1 \n") end if tree.children.length > 0 tree.children.map { |child| tree.add_content(updateContent(child, temp_dir)) } end if not tree.root tree.add_content(":leveloffset: -1 \n") end return tree.content end def self.printTree(tree, level) puts str = ("-" * level) + tree.title if tree.children.length > 0 tree.children.map { |child| printTree(child, level + 1) } end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rake_jekyll_asciidoctor_pdf-0.0.13 | lib/rake_jekyll_asciidoctor_pdf/tree.rb |
rake_jekyll_asciidoctor_pdf-0.0.12 | lib/rake_jekyll_asciidoctor_pdf/tree.rb |