Class: Estatic::Resource
- Inherits:
-
Object
- Object
- Estatic::Resource
- Defined in:
- lib/estatic/resource.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#locals ⇒ Object
Returns the value of attribute locals.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #directory ⇒ Object
- #get_locals ⇒ Object
-
#initialize(name) ⇒ Resource
constructor
A new instance of Resource.
- #products_in_chunks ⇒ Object
- #proper_name ⇒ Object
- #total_chunks ⇒ Object
Constructor Details
#initialize(name) ⇒ Resource
Returns a new instance of Resource.
5 6 7 8 |
# File 'lib/estatic/resource.rb', line 5 def initialize(name) @name = name @locals = get_locals end |
Instance Attribute Details
#locals ⇒ Object
Returns the value of attribute locals.
3 4 5 |
# File 'lib/estatic/resource.rb', line 3 def locals @locals end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/estatic/resource.rb', line 3 def name @name end |
Instance Method Details
#directory ⇒ Object
23 24 25 |
# File 'lib/estatic/resource.rb', line 23 def directory File.join(Estatic.configuration.estatic_site_path, name) end |
#get_locals ⇒ Object
10 11 12 13 |
# File 'lib/estatic/resource.rb', line 10 def get_locals locals = Estatic.configuration.locals.detect { |e| e.keys.first == name }&.values&.first || [] locals.map { |local| [local.keys.first, local.values.first] }.to_h end |
#products_in_chunks ⇒ Object
15 16 17 |
# File 'lib/estatic/resource.rb', line 15 def products_in_chunks @chunks ||= products.each_slice(Estatic.configuration.chunk).to_a end |
#proper_name ⇒ Object
27 28 29 |
# File 'lib/estatic/resource.rb', line 27 def proper_name name.gsub('-', ' ').split.map(&:capitalize).join(' ') end |
#total_chunks ⇒ Object
19 20 21 |
# File 'lib/estatic/resource.rb', line 19 def total_chunks products_in_chunks.size end |