class Slimdown::Page
The model representing a page
Attributes
All the document headers
The template from the document headers
The title from the document headers
Public Class Methods
Get page object by relative path.
Example:
Slimdown::Page.find('about/contact')
@param [String] path relative path to page. Doesn't include extension. @return [Slimdown::Page] the page corresponding to this path.
# 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
Get new page object
@param [String] absolute_path The absolute path to this document,
including extension.
# 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
Public Instance Methods
Get the parsed body
@return [Kramdown::Document] the parsed Markdown body.
# File lib/slimdown/page.rb, line 42 def body @parsed_page.body end
The children of this document.
@return [Array<Slimdown::Page>] a list of child pages.
# File lib/slimdown/page.rb, line 61 def children # Check to see whether dir exists. Slimdown::Folder.new(@absolute_path.chomp('.md')).pages end
The parent of this document
@return [<Slimdown::Page>|nil] the parent, if it exists
# File lib/slimdown/page.rb, line 69 def parent parent = File.expand_path('..', @absolute_path).concat('.md') return nil unless File.file?(parent) Slimdown::Page.new(parent) end
The relative path for this document.
@return [String] the relative path, e.g. 'about/contact'
# File lib/slimdown/page.rb, line 80 def path @absolute_path.sub(%r{^#{Slimdown.config.location}/(.*)\.md}, '\1') end
The sibling pages to this document.
@return [Array<Slimdown::Page>] a list of sibling pages.
# 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
Private Instance Methods
# File lib/slimdown/page.rb, line 86 def load_headers @headers = @parsed_page.headers @title = @headers['title'] @template = @headers['template'] end