class Slimdown::Page

The model representing a page

Attributes

headers[R]

All the document headers

template[R]

The template from the document headers

title[R]

The title from the document headers

Public Class Methods

find(path) click to toggle source

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
new(absolute_path) click to toggle source

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

body() click to toggle source

Get the parsed body

@return [Kramdown::Document] the parsed Markdown body.

# File lib/slimdown/page.rb, line 42
def body
  @parsed_page.body
end
children() click to toggle source

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
parent() click to toggle source

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
path() click to toggle source

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
siblings() click to toggle source

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

load_headers() click to toggle source
# File lib/slimdown/page.rb, line 86
def load_headers
  @headers = @parsed_page.headers
  @title = @headers['title']
  @template = @headers['template']
end