Class: Geri::Page
- Inherits:
-
Object
- Object
- Geri::Page
- Defined in:
- app/models/geri/page.rb
Overview
Page encapsulates a site page and it’s metadata
Defined Under Namespace
Classes: PageNotFoundError
Constant Summary collapse
- META_CAPTURE =
/\A---(.*)\n---\B/m
Instance Attribute Summary collapse
-
#page_index ⇒ Object
readonly
Returns the value of attribute page_index.
Class Method Summary collapse
-
.find(path, current_site, lookup_context) ⇒ Page
Finds a page within the site and returns a new Page instance.
Instance Method Summary collapse
- #content ⇒ Object
- #file ⇒ Object
-
#initialize(path, current_site, lookup_context) ⇒ Page
constructor
A new instance of Page.
-
#metadata ⇒ Hash
Returns the metadata found in the metadata section of the page as a symbolized hash.
Constructor Details
#initialize(path, current_site, lookup_context) ⇒ Page
Returns a new instance of Page.
22 23 24 25 26 |
# File 'app/models/geri/page.rb', line 22 def initialize(path, current_site, lookup_context) @path = path @current_site = current_site @lookup_context = lookup_context end |
Instance Attribute Details
#page_index ⇒ Object (readonly)
Returns the value of attribute page_index.
8 9 10 |
# File 'app/models/geri/page.rb', line 8 def page_index @page_index end |
Class Method Details
.find(path, current_site, lookup_context) ⇒ Page
Finds a page within the site and returns a new Page instance
16 17 18 19 |
# File 'app/models/geri/page.rb', line 16 def self.find(path, current_site, lookup_context) path = '' unless path new(path, current_site, lookup_context) end |
Instance Method Details
#content ⇒ Object
39 40 41 |
# File 'app/models/geri/page.rb', line 39 def content @content ||= raw.gsub(META_CAPTURE, '') end |
#file ⇒ Object
43 44 45 46 47 48 49 |
# File 'app/models/geri/page.rb', line 43 def file @file ||= (@lookup_context.find(@path + '.html.erb') rescue false) || (@lookup_context.find(@path + '/' + 'index.html.erb') rescue false) raise PageNotFoundError.new "Page not found '/#{@path}'" unless @file @file end |
#metadata ⇒ Hash
Returns the metadata found in the metadata section of the page as a symbolized hash
31 32 33 34 35 36 37 |
# File 'app/models/geri/page.rb', line 31 def if !@metadata && @metadata ||= YAML.load() @metadata.symbolize_keys! end @metadata || {} end |