Class: Estatic::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/estatic/resource.rb

Direct Known Subclasses

Category, Subcategory

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#localsObject

Returns the value of attribute locals.



3
4
5
# File 'lib/estatic/resource.rb', line 3

def locals
  @locals
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/estatic/resource.rb', line 3

def name
  @name
end

Instance Method Details

#directoryObject



23
24
25
# File 'lib/estatic/resource.rb', line 23

def directory
  File.join(Estatic.configuration.estatic_site_path, name)
end

#get_localsObject



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_chunksObject



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_nameObject



27
28
29
# File 'lib/estatic/resource.rb', line 27

def proper_name
  name.gsub('-', ' ').split.map(&:capitalize).join(' ')
end

#total_chunksObject



19
20
21
# File 'lib/estatic/resource.rb', line 19

def total_chunks
  products_in_chunks.size
end