Class: Bookpress::Book
- Inherits:
-
Object
- Object
- Bookpress::Book
- Defined in:
- lib/bookpress.rb
Instance Attribute Summary collapse
-
#pages ⇒ Object
Returns the value of attribute pages.
-
#title ⇒ Object
Returns the value of attribute title.
-
#tree ⇒ Object
Returns the value of attribute tree.
Instance Method Summary collapse
-
#initialize(directory) ⇒ Book
constructor
A new instance of Book.
- #to_html ⇒ Object
Constructor Details
#initialize(directory) ⇒ Book
Returns a new instance of Book.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/bookpress.rb', line 24 def initialize(directory) # Get all markdown files @pages = Pathname.glob("#{directory}/" "**/*.{md,markdown}") # Create a Hash to store the book tree structure @tree = Hash.new { |h, k| h[k] = Hash.new &h.default_proc } @pages.each do |page| subdirectory = @tree page_name = page.basename page.cleanpath.each_filename do |segment| subdirectory[segment] if segment.to_s == page_name.to_s subdirectory[segment] = Utility.markdown_renderer.render(page.read) end subdirectory = subdirectory[segment] end end # Sort the structure by key @tree = @tree.sort_by_key(true) { |x, y| Utility.orderify(x.to_s) <=> Utility.orderify(y.to_s) } end |
Instance Attribute Details
#pages ⇒ Object
Returns the value of attribute pages.
22 23 24 |
# File 'lib/bookpress.rb', line 22 def pages @pages end |
#title ⇒ Object
Returns the value of attribute title.
22 23 24 |
# File 'lib/bookpress.rb', line 22 def title @title end |
#tree ⇒ Object
Returns the value of attribute tree.
22 23 24 |
# File 'lib/bookpress.rb', line 22 def tree @tree end |