Class: Page
- Inherits:
-
Object
- Object
- Page
- Defined in:
- lib/page.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#content ⇒ Object
Returns the value of attribute content.
-
#directory_path ⇒ Object
Returns the value of attribute directory_path.
-
#file_basename ⇒ Object
Returns the value of attribute file_basename.
-
#file_format ⇒ Object
Returns the value of attribute file_format.
-
#level ⇒ Object
Returns the value of attribute level.
-
#output_file ⇒ Object
Returns the value of attribute output_file.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#path ⇒ Object
Returns the value of attribute path.
-
#target ⇒ Object
Returns the value of attribute target.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
- #add_child(child) ⇒ Object
- #has_children? ⇒ Boolean
- #has_parent(p) ⇒ Object
-
#initialize ⇒ Page
constructor
A new instance of Page.
- #postprocess ⇒ Object
- #relative_site_root ⇒ Object
Constructor Details
#initialize ⇒ Page
Returns a new instance of Page.
7 8 9 10 |
# File 'lib/page.rb', line 7 def initialize @level = 0 @children = Array.new end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
3 4 5 |
# File 'lib/page.rb', line 3 def children @children end |
#content ⇒ Object
Returns the value of attribute content.
5 6 7 |
# File 'lib/page.rb', line 5 def content @content end |
#directory_path ⇒ Object
Returns the value of attribute directory_path.
3 4 5 |
# File 'lib/page.rb', line 3 def directory_path @directory_path end |
#file_basename ⇒ Object
Returns the value of attribute file_basename.
3 4 5 |
# File 'lib/page.rb', line 3 def file_basename @file_basename end |
#file_format ⇒ Object
Returns the value of attribute file_format.
3 4 5 |
# File 'lib/page.rb', line 3 def file_format @file_format end |
#level ⇒ Object
Returns the value of attribute level.
3 4 5 |
# File 'lib/page.rb', line 3 def level @level end |
#output_file ⇒ Object
Returns the value of attribute output_file.
3 4 5 |
# File 'lib/page.rb', line 3 def output_file @output_file end |
#parent ⇒ Object
Returns the value of attribute parent.
3 4 5 |
# File 'lib/page.rb', line 3 def parent @parent end |
#path ⇒ Object
Returns the value of attribute path.
3 4 5 |
# File 'lib/page.rb', line 3 def path @path end |
#target ⇒ Object
Returns the value of attribute target.
3 4 5 |
# File 'lib/page.rb', line 3 def target @target end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
5 6 7 |
# File 'lib/page.rb', line 5 def title @title end |
Instance Method Details
#add_child(child) ⇒ Object
12 13 14 15 16 |
# File 'lib/page.rb', line 12 def add_child child @children.push child child.parent = self child.level = self.level + 1 end |
#has_children? ⇒ Boolean
18 19 20 |
# File 'lib/page.rb', line 18 def has_children? !@children.empty? end |
#has_parent(p) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/page.rb', line 22 def has_parent p if self.parent == p return true else if self.parent.nil? return false else return self.parent.has_parent p end end end |
#postprocess ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/page.rb', line 38 def postprocess return unless @content out = "" @content.each_line do |line| if line =~ /^#dir_toc/ if self.has_children? out += "<ul>" self.children.each do |child| out += "<li>" out += "<a href='#{self.relative_site_root}#{child.target}'>#{child.title}</a>" out += "</li>" end out += "</ul>" end else out += line end end @content = out end |
#relative_site_root ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/page.rb', line 60 def relative_site_root out = "" effective_level = self.level if self.file_basename == "index" effective_level += 1 end effective_level.times do out += "../" end out end |