Class: Slimdown::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/slimdown/page.rb

Overview

The model representing a page

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(absolute_path) ⇒ Page

Get new page object

Parameters:

  • absolute_path (String)

    The absolute path to this document, including extension.



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

#templateObject (readonly)

The template from the document headers



8
9
10
# File 'lib/slimdown/page.rb', line 8

def template
  @template
end

#titleObject (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')

Parameters:

  • path (String)

    relative path to page. Doesn’t include extension.

Returns:



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

#bodyKramdown::Document

Get the parsed body

Returns:

  • (Kramdown::Document)

    the parsed Markdown body.



41
42
43
# File 'lib/slimdown/page.rb', line 41

def body
  @parsed_page.body
end

#childrenArray<Slimdown::Page>

The children of this document.

Returns:



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

#pathString

The relative path for this document.

Returns:

  • (String)

    the relative path, e.g. ‘about/contact’



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

#siblingsArray<Slimdown::Page>

The sibling pages to this document.

Returns:



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