Class: Nanoc2::PageProxy

Inherits:
Proxy
  • Object
show all
Defined in:
lib/nanoc2/base/proxies/page_proxy.rb

Overview

Nanoc2::PageProxy is a proxy object for a page (Nanoc2::Page).

Instance Method Summary collapse

Methods inherited from Proxy

#[]=, #initialize, #method_missing

Constructor Details

This class inherits a constructor from Nanoc2::Proxy

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Nanoc2::Proxy

Instance Method Details

#[](key) ⇒ Object

Requests the page attribute with the given name. key can be a string or a symbol, and it can contain a trailing question mark (which will be stripped).



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/nanoc2/base/proxies/page_proxy.rb', line 9

def [](key)
  real_key = key.to_s.sub(/\?$/, '').to_sym

  if real_key == :mtime
    @obj.mtime
  elsif real_key == :parent
    @obj.parent.nil? ? nil : @obj.parent.to_proxy
  elsif real_key == :children
    @obj.children.map { |page| page.to_proxy }
  elsif real_key == :content # backward compatibility
    @obj.reps.find { |r| r.name == :default }.content
  elsif real_key == :path # backward compatibility
    @obj.reps.find { |r| r.name == :default }.web_path
  else
    super(key)
  end
end

#reps(name) ⇒ Object

Returns the page representation with the given name.



28
29
30
31
# File 'lib/nanoc2/base/proxies/page_proxy.rb', line 28

def reps(name)
  rep = @obj.reps.find { |r| r.name == name }
  rep.nil? ? nil : rep.to_proxy
end