Class: Brite::Page
Overview
Models a site page.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#author ⇒ Object
Author of page.
-
#category ⇒ Object
Category (“a glorified tag”).
-
#date ⇒ Object
Publish date.
-
#draft ⇒ Object
(also: #draft?)
Is this page a draft? If so it will not be rendered.
-
#file ⇒ Object
readonly
The ‘.page` file.
-
#layout ⇒ Object
Layout to use for page.
-
#route ⇒ Object
Output route.
-
#site ⇒ Object
readonly
Instance of Site class to which this page belongs.
-
#summary ⇒ Object
Summary is the rendering of the first part.
-
#tags ⇒ Object
Tags (labels).
-
#title ⇒ Object
Title of page/post.
Instance Method Summary collapse
-
#extension ⇒ Object
Output extension (defualts to ‘html’).
-
#extension=(extname) ⇒ Object
Set output extension.
-
#initialize(site, file, copy = {}) ⇒ Page
constructor
New Page.
- #initialize_defaults ⇒ Object
- #inspect ⇒ Object
-
#name ⇒ Object
The ‘name` is same as `output` but without any file extension.
-
#output ⇒ Object
The page’s route, which is effectively the “Save As” output file.
-
#output=(path) ⇒ Object
(also: #permalink=)
Set route directly, relative to file, overriding any slug.
-
#permalink ⇒ Object
(also: #url)
Same as output but prefixed with ‘/`.
-
#root ⇒ String
Relative path difference between the route and the site’s root.
-
#to_s ⇒ Object
Renders page template.
Methods inherited from Model
#[], #[]=, #config, #method_missing, #part, #rendering_fields, #to_binding, #to_h, #update
Constructor Details
#initialize(site, file, copy = {}) ⇒ Page
New Page.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/brite/page.rb', line 9 def initialize(site, file, copy={}) @site = site @file = file initialize_defaults update(copy) @_template = Neapolitan.file(file, :stencil=>site.config.stencil) #site.page_defaults) update(@_template.) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Brite::Model
Instance Attribute Details
#author ⇒ Object
Author of page.
48 49 50 |
# File 'lib/brite/page.rb', line 48 def @author end |
#category ⇒ Object
Category (“a glorified tag”)
61 62 63 |
# File 'lib/brite/page.rb', line 61 def category @category end |
#date ⇒ Object
Publish date.
54 55 56 |
# File 'lib/brite/page.rb', line 54 def date @date end |
#draft ⇒ Object Also known as: draft?
Is this page a draft? If so it will not be rendered.
64 65 66 |
# File 'lib/brite/page.rb', line 64 def draft @draft end |
#file ⇒ Object (readonly)
The ‘.page` file.
45 46 47 |
# File 'lib/brite/page.rb', line 45 def file @file end |
#layout ⇒ Object
Layout to use for page.
73 74 75 |
# File 'lib/brite/page.rb', line 73 def layout @layout end |
#route ⇒ Object
Output route.
70 71 72 |
# File 'lib/brite/page.rb', line 70 def route @route end |
#site ⇒ Object (readonly)
Instance of Site class to which this page belongs.
42 43 44 |
# File 'lib/brite/page.rb', line 42 def site @site end |
#summary ⇒ Object
Summary is the rendering of the first part.
165 166 167 |
# File 'lib/brite/page.rb', line 165 def summary @summary end |
#tags ⇒ Object
Tags (labels)
76 77 78 |
# File 'lib/brite/page.rb', line 76 def @tags end |
#title ⇒ Object
Title of page/post.
51 52 53 |
# File 'lib/brite/page.rb', line 51 def title @title end |
Instance Method Details
#extension ⇒ Object
Output extension (defualts to ‘html’).
145 146 147 |
# File 'lib/brite/page.rb', line 145 def extension @extension #||= '.html' end |
#extension=(extname) ⇒ Object
Set output extension.
154 155 156 157 158 159 160 |
# File 'lib/brite/page.rb', line 154 def extension=(extname) @extension = ( e = (extname || 'html').to_s e = '.' + e unless e.start_with?('.') e ) end |
#initialize_defaults ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/brite/page.rb', line 23 def initialize_defaults @tags = [] @author = site.config. @route = site.config.page_route @layout = site.config.page_layout @extension = '.html' # these are filled-out as needed, but the instance variable # must define up front to ensure #to_h will pick them up. # Probably this should be done in a different way in the future. @output = nil @path = nil @name = nil @url = nil @root = nil end |
#inspect ⇒ Object
173 174 175 |
# File 'lib/brite/page.rb', line 173 def inspect "#<#{self.class} #{@file}>" end |
#name ⇒ Object
The ‘name` is same as `output` but without any file extension.
120 121 122 |
# File 'lib/brite/page.rb', line 120 def name @name ||= output.chomp(extension) end |
#output ⇒ Object
The page’s route, which is effectively the “Save As” output file.
95 96 97 |
# File 'lib/brite/page.rb', line 95 def output @output ||= calculate_output end |
#output=(path) ⇒ Object Also known as: permalink=
Set route directly, relative to file, overriding any slug.
100 101 102 |
# File 'lib/brite/page.rb', line 100 def output=(path) @output = path.sub(/^\//,'') end |
#permalink ⇒ Object Also known as: url
Same as output but prefixed with ‘/`.
108 109 110 |
# File 'lib/brite/page.rb', line 108 def permalink '/' + output end |
#root ⇒ String
Relative path difference between the route and the site’s root. The return value is a string of ‘..` paths, e.g. `“../../”`.
139 140 141 142 |
# File 'lib/brite/page.rb', line 139 def root #@root ||= '../' * file.count('/') @root ||= '../' * (output.count('/') - (output.scan('../').length*2)) end |
#to_s ⇒ Object
Renders page template.
168 169 170 |
# File 'lib/brite/page.rb', line 168 def to_s render end |