Class: Slimdown::Page
- Inherits:
-
Object
- Object
- Slimdown::Page
- Defined in:
- lib/slimdown/page.rb
Overview
The model representing a page
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
All the document headers.
-
#template ⇒ Object
readonly
The template from the document headers.
-
#title ⇒ Object
readonly
The title from the document headers.
Class Method Summary collapse
-
.find(path) ⇒ Slimdown::Page
Get page object by relative path.
Instance Method Summary collapse
-
#body ⇒ Kramdown::Document
Get the parsed body.
-
#children ⇒ Array<Slimdown::Page>
The children of this document.
-
#initialize(absolute_path) ⇒ Page
constructor
Get new page object.
-
#parent ⇒ <Slimdown::Page>|nil
The parent of this document.
-
#path ⇒ String
The relative path for this document.
-
#siblings ⇒ Array<Slimdown::Page>
The sibling pages to this document.
Constructor Details
#initialize(absolute_path) ⇒ Page
Get new page object
15 16 17 18 19 20 21 22 |
# File 'lib/slimdown/page.rb', line 15 def initialize(absolute_path) # Open the markdown file. @absolute_path = absolute_path @parsed_page = Slimdown::PageParser.new @absolute_path load_headers end |
Instance Attribute Details
#headers ⇒ Object (readonly)
All the document headers
9 10 11 |
# File 'lib/slimdown/page.rb', line 9 def headers @headers end |
#template ⇒ Object (readonly)
The template from the document headers
7 8 9 |
# File 'lib/slimdown/page.rb', line 7 def template @template end |
#title ⇒ Object (readonly)
The title from the document headers
5 6 7 |
# File 'lib/slimdown/page.rb', line 5 def title @title end |
Class Method Details
.find(path) ⇒ Slimdown::Page
31 32 33 34 35 36 37 |
# File 'lib/slimdown/page.rb', line 31 def self.find(path) # Finds the relative page. config = Slimdown.config loc = config.location self.new("#{loc}/#{path}.md") end |
Instance Method Details
#body ⇒ Kramdown::Document
Get the parsed body
42 43 44 |
# File 'lib/slimdown/page.rb', line 42 def body @parsed_page.body end |
#children ⇒ Array<Slimdown::Page>
The children of this document.
61 62 63 64 |
# File 'lib/slimdown/page.rb', line 61 def children # Check to see whether dir exists. Slimdown::Folder.new(@absolute_path.chomp('.md')).pages end |
#parent ⇒ <Slimdown::Page>|nil
The parent of this document
69 70 71 72 73 74 75 |
# File 'lib/slimdown/page.rb', line 69 def parent parent = File.('..', @absolute_path).concat('.md') return nil unless File.file?(parent) Slimdown::Page.new(parent) end |
#path ⇒ String
The relative path for this document.
80 81 82 |
# File 'lib/slimdown/page.rb', line 80 def path @absolute_path.sub(%r{^#{Slimdown.config.location}/(.*)\.md}, '\1') end |
#siblings ⇒ Array<Slimdown::Page>
The sibling pages to this document.
49 50 51 52 53 54 55 56 |
# File 'lib/slimdown/page.rb', line 49 def siblings # List other markdown files in the same folder. # Sibling folder. folder = File.dirname @absolute_path Slimdown::Folder.new(folder).pages end |