Class: Geri::Page

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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_indexObject (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

Parameters:

  • path (string|NilClass)

    the url path for which to look for the page

Returns:

  • (Page)

    a page object



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

#contentObject



39
40
41
# File 'app/models/geri/page.rb', line 39

def content
  @content ||= raw.gsub(META_CAPTURE, '')
end

#fileObject



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

#metadataHash

Returns the metadata found in the metadata section of the page as a symbolized hash

Returns:

  • (Hash)

    the page metadata



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