Class: JADOF::Page
- Inherits:
-
Object
- Object
- JADOF::Page
- Extended by:
- PageAPI
- Includes:
- IndifferentVariableHash
- Defined in:
- lib/jadof/page.rb
Overview
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_DIR =
'./pages/'
- DEFAULT_FORMATTERS =
{ 'markdown' => lambda { |text| require 'maruku'; Maruku.new(text).to_html }, 'erb' => lambda { |text| require 'erb'; ERB.new(text).result }, 'haml' => lambda { |text| require 'haml'; Haml::Engine.new(text).render }, 'textile' => lambda { |text| require 'redcloth'; RedCloth.new(text).to_html } }
Instance Attribute Summary collapse
-
#body ⇒ String
the top of the file (if YAML was included).
-
#filename ⇒ String
The filename (without a directory), eg.
-
#name ⇒ String
If the filename is ‘foo.markdown`, the name will be `foo`.
-
#parent ⇒ String
in a subdirectory below ‘Page.dir`.
-
#path ⇒ String
The full system path to this file.
Attributes included from PageAPI
Instance Method Summary collapse
-
#==(other_page) ⇒ true, false
If 2 pages have the same system path, they’re the same.
-
#extensions ⇒ Array(String)
This file’s extension(s).
- #full_name ⇒ String
-
#initialize(options = nil) ⇒ Page
constructor
A page is a dumb object and doesn’t know how to load itself from a file on the filesystem.
- #render ⇒ Object (also: #to_html)
-
#to_param ⇒ String
A param representation of this page for us in web applications.
-
#to_s ⇒ String
This page as a string.
Methods included from PageAPI
[], all, cache_for, count, first, from_path, get, inherited, last, matches_conditions?, where
Constructor Details
#initialize(options = nil) ⇒ Page
A page is a dumb object and doesn’t know how to load itself from a file on the filesystem. See ‘Page.from_path` to load a JADOF::Page from a file.
229 230 231 |
# File 'lib/jadof/page.rb', line 229 def initialize = nil .each {|attribute, value| send "#{attribute}=", value } if end |
Instance Attribute Details
#body ⇒ String
the top of the file (if YAML was included).
We strip out the YAML and use it to set variables on the Page. If you need the full text from the file, you should ‘File.read(@page.path)`.
211 212 213 |
# File 'lib/jadof/page.rb', line 211 def body @body end |
#filename ⇒ String
Returns The filename (without a directory), eg. ‘foo.markdown`.
203 204 205 |
# File 'lib/jadof/page.rb', line 203 def filename @filename end |
#name ⇒ String
If the filename is ‘foo.markdown`, the name will be `foo`
If the file is in a subdirectory below ‘Page.dir`, eg. `foo/bar.markdown`, the name will be `bar` but the #full_name will be `foo/bar`.
197 198 199 |
# File 'lib/jadof/page.rb', line 197 def name @name end |
#parent ⇒ String
in a subdirectory below ‘Page.dir`. This will be `“”` if it is in `Page.dir` or it will be `“sub/directories”` if it is in subdirectories.
217 218 219 |
# File 'lib/jadof/page.rb', line 217 def parent @parent end |
#path ⇒ String
Returns The full system path to this file.
200 201 202 |
# File 'lib/jadof/page.rb', line 200 def path @path end |
Instance Method Details
#==(other_page) ⇒ true, false
Returns If 2 pages have the same system path, they’re the same.
253 254 255 256 |
# File 'lib/jadof/page.rb', line 253 def == other_page return false unless other_page.is_a? Page return other_page.path == path end |
#extensions ⇒ Array(String)
Returns This file’s extension(s).
220 221 222 |
# File 'lib/jadof/page.rb', line 220 def extensions filename.scan(/\.([^\.]+)/).flatten end |
#full_name ⇒ String
234 235 236 |
# File 'lib/jadof/page.rb', line 234 def full_name parent == '' ? name : File.join(parent, name) end |
#render ⇒ Object Also known as: to_html
Returns the formatted #body of this JADOF::Page using ‘Page.formatters`.
The file extensions from the #filename are used to match formatters.
For ‘foo.markdown`, `Page.formatters` will be used. For `foo.markdown.erb`, `Page.formatters` and `Page.formatters` will be used.
With multiple extensions, the last extension is used first, and then the second-to-last, etc.
246 247 248 |
# File 'lib/jadof/page.rb', line 246 def render self.class.render self end |
#to_param ⇒ String
Returns A param representation of this page for us in web applications. Defaults to #full_name.
264 265 266 |
# File 'lib/jadof/page.rb', line 264 def to_param full_name end |
#to_s ⇒ String
Returns This page as a string. Defaults to #full_name.
259 260 261 |
# File 'lib/jadof/page.rb', line 259 def to_s full_name end |