Class: Benoit::SiteContext
- Inherits:
-
Object
- Object
- Benoit::SiteContext
- Defined in:
- lib/benoit/site_context.rb
Defined Under Namespace
Classes: ContextObject
Instance Attribute Summary collapse
-
#pages ⇒ Object
readonly
Returns the value of attribute pages.
-
#paths_map ⇒ Object
Returns the value of attribute paths_map.
Class Method Summary collapse
- .clear_paginated_collections! ⇒ Object
- .from_hash(context_attrs) ⇒ Object
- .paginate_collection(collection, per_page) ⇒ Object
- .paginated_collections ⇒ Object
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(pages) ⇒ SiteContext
constructor
A new instance of SiteContext.
- #page_with_path(path) ⇒ Object
- #paginated_collection?(key) ⇒ Boolean
- #paginated_collections ⇒ Object
- #to_context ⇒ Object
Constructor Details
#initialize(pages) ⇒ SiteContext
Returns a new instance of SiteContext.
82 83 84 |
# File 'lib/benoit/site_context.rb', line 82 def initialize(pages) @pages = pages end |
Instance Attribute Details
#pages ⇒ Object (readonly)
Returns the value of attribute pages.
78 79 80 |
# File 'lib/benoit/site_context.rb', line 78 def pages @pages end |
#paths_map ⇒ Object
Returns the value of attribute paths_map.
80 81 82 |
# File 'lib/benoit/site_context.rb', line 80 def paths_map @paths_map end |
Class Method Details
.clear_paginated_collections! ⇒ Object
120 121 122 |
# File 'lib/benoit/site_context.rb', line 120 def self.clear_paginated_collections! @paginated_collections.clear if @paginated_collections end |
.from_hash(context_attrs) ⇒ Object
71 72 73 74 75 76 |
# File 'lib/benoit/site_context.rb', line 71 def self.from_hash(context_attrs) page_contexts = context_attrs.values.map do |context| Page.from_hash(context) end new(page_contexts) end |
.paginate_collection(collection, per_page) ⇒ Object
111 112 113 114 |
# File 'lib/benoit/site_context.rb', line 111 def self.paginate_collection(collection, per_page) @paginated_collections ||= Hash.new([]) @paginated_collections[collection] << per_page end |
.paginated_collections ⇒ Object
116 117 118 |
# File 'lib/benoit/site_context.rb', line 116 def self.paginated_collections @paginated_collections end |
Instance Method Details
#[](key) ⇒ Object
86 87 88 89 |
# File 'lib/benoit/site_context.rb', line 86 def [](key) key = paths_map[key] if paths_map.key?(key) page_with_path(key) end |
#page_with_path(path) ⇒ Object
91 92 93 94 95 |
# File 'lib/benoit/site_context.rb', line 91 def page_with_path(path) @pages.find do |page| page.permalink == "/#{path}" end end |
#paginated_collection?(key) ⇒ Boolean
105 106 107 108 109 |
# File 'lib/benoit/site_context.rb', line 105 def paginated_collection?(key) unless self.class.paginated_collections.nil? self.class.paginated_collections.key?(key) end end |
#paginated_collections ⇒ Object
101 102 103 |
# File 'lib/benoit/site_context.rb', line 101 def paginated_collections self.class.paginated_collections end |
#to_context ⇒ Object
97 98 99 |
# File 'lib/benoit/site_context.rb', line 97 def to_context @context ||= ContextObject.new(self) end |