Class: Doculab::TableOfContents::Page

Inherits:
Object
  • Object
show all
Defined in:
app/models/doculab/table_of_contents.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, parent = nil, options = {}) ⇒ Page

Returns a new instance of Page.



55
56
57
58
59
60
61
62
63
64
# File 'app/models/doculab/table_of_contents.rb', line 55

def initialize(title, parent = nil, options = {})
  @parent = parent
  @title = title
  @permalink = options[:permalink] || title.parameterize
  @doc = begin
    Doc.find(permalink)
  rescue
    nil
  end
end

Instance Attribute Details

#docObject (readonly)

Returns the value of attribute doc.



53
54
55
# File 'app/models/doculab/table_of_contents.rb', line 53

def doc
  @doc
end

#parentObject (readonly)

Returns the value of attribute parent.



53
54
55
# File 'app/models/doculab/table_of_contents.rb', line 53

def parent
  @parent
end

Returns the value of attribute permalink.



53
54
55
# File 'app/models/doculab/table_of_contents.rb', line 53

def permalink
  @permalink
end

#titleObject (readonly)

Returns the value of attribute title.



53
54
55
# File 'app/models/doculab/table_of_contents.rb', line 53

def title
  @title
end

Instance Method Details

#filename(extension = "textile") ⇒ Object



66
67
68
# File 'app/models/doculab/table_of_contents.rb', line 66

def filename(extension = "textile")
  Doc.directory.join("#{permalink}.#{extension}")
end

#next_pageObject



70
71
72
73
# File 'app/models/doculab/table_of_contents.rb', line 70

def next_page
  return nil if index.nil?
  TableOfContents.pages[index+1]
end

#previous_pageObject



75
76
77
78
79
# File 'app/models/doculab/table_of_contents.rb', line 75

def previous_page
  fetch_index = (index || 0)-1
  return nil if fetch_index < 0
  TableOfContents.pages[fetch_index]
end