Class: Benoit::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/benoit/page.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs) ⇒ Page

Returns a new instance of Page.



9
10
11
12
13
14
15
# File 'lib/benoit/page.rb', line 9

def initialize(attrs)
    @attr_names = @attrNames = []
    @original_path = attrs["_original_path"]
    setFileType!(attrs)
    set_permalink!(attrs)
    @metadata = methodsFromAttrs(attrs)
end

Instance Attribute Details

#attrs_hashObject (readonly)

Returns the value of attribute attrs_hash.



3
4
5
# File 'lib/benoit/page.rb', line 3

def attrs_hash
  @attrs_hash
end

Returns the value of attribute permalink.



3
4
5
# File 'lib/benoit/page.rb', line 3

def permalink
  @permalink
end

#siteContextObject (readonly)

Returns the value of attribute siteContext.



3
4
5
# File 'lib/benoit/page.rb', line 3

def siteContext
  @siteContext
end

Class Method Details

.from_hash(page_attrs) ⇒ Object



5
6
7
# File 'lib/benoit/page.rb', line 5

def self.from_hash(page_attrs)
    new(page_attrs)
end

Instance Method Details

#[](key) ⇒ Object



30
31
32
# File 'lib/benoit/page.rb', line 30

def [](key)
  @metadata[key]
end

#[]=(key, value) ⇒ Object



34
35
36
37
# File 'lib/benoit/page.rb', line 34

def []=(key, value)
  instance_variable_set("@#{key}", value)
  @metadata[key] = value
end

#has_value?(value) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/benoit/page.rb', line 22

def has_value?(value)
  @metadata.has_value?(value)
end

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/benoit/page.rb', line 26

def key?(key)
  @metadata.key?(key)
end

#keysObject



39
40
41
# File 'lib/benoit/page.rb', line 39

def keys
  @metadata.keys
end

#set_permalink!(attrs) ⇒ Object



43
44
45
46
# File 'lib/benoit/page.rb', line 43

def set_permalink!(attrs)
  @permalink = "/#{@original_path}"
  @attrNames << :permalink
end

#templateObject



17
18
19
20
# File 'lib/benoit/page.rb', line 17

def template
    # For compat with other site generators
    @template || @layout
end

#to_hash(options = {}) ⇒ Object



52
53
54
# File 'lib/benoit/page.rb', line 52

def to_hash(options={})
    attrsFromMethods(@attrNames)
end

#to_json(options = {}) ⇒ Object



48
49
50
# File 'lib/benoit/page.rb', line 48

def to_json(options={})
    attrsFromMethods(@attrNames).to_json
end