Class: PagesCore::Templates::TemplateConfiguration

Inherits:
Object
  • Object
show all
Defined in:
lib/pages_core/templates/template_configuration.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template_name) ⇒ TemplateConfiguration

Returns a new instance of TemplateConfiguration.


12
13
14
# File 'lib/pages_core/templates/template_configuration.rb', line 12

def initialize(template_name)
  @template_name = template_name.to_sym
end

Instance Attribute Details

#template_nameObject (readonly)

Returns the value of attribute template_name


4
5
6
# File 'lib/pages_core/templates/template_configuration.rb', line 4

def template_name
  @template_name
end

Class Method Details

.all_blocksObject


7
8
9
# File 'lib/pages_core/templates/template_configuration.rb', line 7

def all_blocks
  new(:index).all_blocks
end

Instance Method Details

#all_blocksObject

Returns a list of all configured blocks


62
63
64
65
66
67
# File 'lib/pages_core/templates/template_configuration.rb', line 62

def all_blocks
  (
    all_templates.map { |t| configured_block_names(t) } +
      all_templates.map { |t| enabled_block_names(t) }
  ).flatten.compact.uniq
end

#block(block_name) ⇒ Object


36
37
38
39
40
41
42
# File 'lib/pages_core/templates/template_configuration.rb', line 36

def block(block_name)
  default_block_options(block_name)
    .deep_merge(config.get(:default, :blocks, block_name) || {})
    .deep_merge(
      config.get(:templates, @template_name, :blocks, block_name) || {}
    )
end

#configObject


16
17
18
# File 'lib/pages_core/templates/template_configuration.rb', line 16

def config
  PagesCore::Templates.configuration
end

#enabled_blocksObject


44
45
46
47
48
49
50
51
# File 'lib/pages_core/templates/template_configuration.rb', line 44

def enabled_blocks
  blocks = value(:enabled_blocks)
  blocks = [:name] + blocks unless blocks.include?(:name)
  if block_given?
    blocks.each { |block_name| yield block_name, block(block_name) }
  end
  blocks
end

#metadata_blocksObject


53
54
55
56
57
58
59
# File 'lib/pages_core/templates/template_configuration.rb', line 53

def 
  blocks = PagesCore::Templates.
  if block_given?
    blocks.each { |block_name| yield block_name, block(block_name) }
  end
  blocks
end

#options(*path) ⇒ Object


28
29
30
31
32
33
34
# File 'lib/pages_core/templates/template_configuration.rb', line 28

def options(*path)
  path = [path, :options].flatten
  (config.get(*[:default, path].flatten) || {})
    .deep_merge(
      config.get(*[:templates, @template_name, path].flatten) || {}
    )
end

#value(*path) ⇒ Object


20
21
22
23
24
25
26
# File 'lib/pages_core/templates/template_configuration.rb', line 20

def value(*path)
  path = [path, :value].flatten
  value = config.get(*[:default, path].flatten)
  template_value = config.get(*[:templates, @template_name, path].flatten)
  value = template_value unless template_value.nil?
  value
end