Class: Slippers::TemplateGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/engine/template_group.rb

Direct Known Subclasses

TemplateGroupDirectory

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ TemplateGroup

Returns a new instance of TemplateGroup.



3
4
5
6
7
8
# File 'lib/engine/template_group.rb', line 3

def initialize(params={})
  @templates = params[:templates]
  @super_group = params[:super_group]
  @missing_handler = params[:missing_template_handler] || Slippers::Engine::MISSING_HANDLER
  @default_string = params[:default_string] || Slippers::Engine::DEFAULT_STRING
end

Instance Attribute Details

#default_stringObject (readonly)

Returns the value of attribute default_string.



10
11
12
# File 'lib/engine/template_group.rb', line 10

def default_string
  @default_string
end

#missing_handlerObject (readonly)

Returns the value of attribute missing_handler.



10
11
12
# File 'lib/engine/template_group.rb', line 10

def missing_handler
  @missing_handler
end

Instance Method Details

#find(subtemplate) ⇒ Object



12
13
14
15
16
# File 'lib/engine/template_group.rb', line 12

def find(subtemplate)
  return nil unless @templates
  return create_template(subtemplate.to_sym) if @templates.include?(subtemplate.to_sym)
  find_in_super_group(subtemplate)
end

#has_registered?(class_name) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
# File 'lib/engine/template_group.rb', line 18

def has_registered?(class_name)
   return false unless @templates
   return true if @templates.include?(class_name) 
   return false unless @super_group
   @super_group.has_registered?(class_name)  
end

#render(item) ⇒ Object



25
26
27
28
29
30
# File 'lib/engine/template_group.rb', line 25

def render(item)
  return '' unless @templates
  return @templates[item.class].render(item) if has_registered?(item.class)
  return '' unless @super_group
  @super_group.render(item)
end