Class: Slimdown::Page
- Inherits:
-
Object
- Object
- Slimdown::Page
- Defined in:
- lib/slimdown/page.rb
Overview
The model representing a page
Instance Attribute Summary collapse
-
#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.
-
#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
14 15 16 17 18 19 20 21 |
# File 'lib/slimdown/page.rb', line 14 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
#template ⇒ Object (readonly)
The template from the document headers
8 9 10 |
# File 'lib/slimdown/page.rb', line 8 def template @template end |
#title ⇒ Object (readonly)
The title from the document headers
6 7 8 |
# File 'lib/slimdown/page.rb', line 6 def title @title end |
Class Method Details
.find(path) ⇒ Slimdown::Page
Get page object by relative path.
Example:
Slimdown::Page.find('about/contact')
30 31 32 33 34 35 36 |
# File 'lib/slimdown/page.rb', line 30 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
41 42 43 |
# File 'lib/slimdown/page.rb', line 41 def body @parsed_page.body end |
#children ⇒ Array<Slimdown::Page>
The children of this document.
60 61 62 63 64 65 66 |
# File 'lib/slimdown/page.rb', line 60 def children # Check to see whether dir exists. folder = @absolute_path folder.slice! '.md' Slimdown::Folder.new(folder).pages end |
#path ⇒ String
The relative path for this document.
71 72 73 74 75 76 77 78 |
# File 'lib/slimdown/page.rb', line 71 def path loc = Slimdown.config.location relative = @absolute_path relative.slice! "#{loc}/" relative.slice! '.md' relative end |
#siblings ⇒ Array<Slimdown::Page>
The sibling pages to this document.
48 49 50 51 52 53 54 55 |
# File 'lib/slimdown/page.rb', line 48 def siblings # List other markdown files in the same folder. # Sibling folder. folder = File.dirname @absolute_path Slimdown::Folder.new(folder).pages end |