Class: Page

Inherits:
Object
  • Object
show all
Defined in:
lib/page.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePage

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

#childrenObject

Returns the value of attribute children.



3
4
5
# File 'lib/page.rb', line 3

def children
  @children
end

#contentObject

Returns the value of attribute content.



5
6
7
# File 'lib/page.rb', line 5

def content
  @content
end

#directory_pathObject

Returns the value of attribute directory_path.



3
4
5
# File 'lib/page.rb', line 3

def directory_path
  @directory_path
end

#file_basenameObject

Returns the value of attribute file_basename.



3
4
5
# File 'lib/page.rb', line 3

def file_basename
  @file_basename
end

#file_formatObject

Returns the value of attribute file_format.



3
4
5
# File 'lib/page.rb', line 3

def file_format
  @file_format
end

#levelObject

Returns the value of attribute level.



3
4
5
# File 'lib/page.rb', line 3

def level
  @level
end

#output_fileObject

Returns the value of attribute output_file.



3
4
5
# File 'lib/page.rb', line 3

def output_file
  @output_file
end

#parentObject

Returns the value of attribute parent.



3
4
5
# File 'lib/page.rb', line 3

def parent
  @parent
end

#pathObject

Returns the value of attribute path.



3
4
5
# File 'lib/page.rb', line 3

def path
  @path
end

#targetObject

Returns the value of attribute target.



3
4
5
# File 'lib/page.rb', line 3

def target
  @target
end

#titleObject (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

Returns:

  • (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

#postprocessObject



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_rootObject



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