Class: Fierce::MasterOfCeremonies

Inherits:
Object
  • Object
show all
Defined in:
lib/fierce/master_of_ceremonies.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template, path, locals, controller, context) ⇒ MasterOfCeremonies

Returns a new instance of MasterOfCeremonies.



5
6
7
8
9
10
11
# File 'lib/fierce/master_of_ceremonies.rb', line 5

def initialize(template, path, locals, controller, context)
  @template =   template
  @path =       path
  @locals =     locals
  @controller = controller
  @context =    context
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



3
4
5
# File 'lib/fierce/master_of_ceremonies.rb', line 3

def context
  @context
end

#controllerObject (readonly)

Returns the value of attribute controller.



3
4
5
# File 'lib/fierce/master_of_ceremonies.rb', line 3

def controller
  @controller
end

#localsObject (readonly)

Returns the value of attribute locals.



3
4
5
# File 'lib/fierce/master_of_ceremonies.rb', line 3

def locals
  @locals
end

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/fierce/master_of_ceremonies.rb', line 3

def path
  @path
end

#templateObject (readonly)

Returns the value of attribute template.



3
4
5
# File 'lib/fierce/master_of_ceremonies.rb', line 3

def template
  @template
end

Instance Method Details

#base_presentersObject



28
29
30
31
32
33
34
35
# File 'lib/fierce/master_of_ceremonies.rb', line 28

def base_presenters
  collection = [
    DelegateGenerator::Controller.new(controller).generate,
    context
  ]
  collection.unshift(locals_presenter) if locals_presenter
  collection
end

#custom_presenterObject



17
18
19
20
21
22
23
24
25
26
# File 'lib/fierce/master_of_ceremonies.rb', line 17

def custom_presenter
  return @custom_presenter if @custom_presenter
  return unless presenter_class = PresenterFinder.new(path).perform

  @custom_presenter = if presenter_class.instance_method(:initialize).arity == 1
    presenter_class.new(ViewModel.new(*base_presenters))
  else
    presenter_class.new
  end
end

#locals_presenterObject



43
44
45
46
# File 'lib/fierce/master_of_ceremonies.rb', line 43

def locals_presenter
  return unless locals.size > 0
  Struct.new(*locals.keys.map(&:to_sym)).new(*locals.values)
end

#partial(name) ⇒ Object



52
53
54
# File 'lib/fierce/master_of_ceremonies.rb', line 52

def partial(name)
  partial = PartialFinder.new(name, path, custom_presenter, context).perform
end

#presentersObject



37
38
39
40
41
# File 'lib/fierce/master_of_ceremonies.rb', line 37

def presenters
  collection = base_presenters
  collection.unshift(custom_presenter) if custom_presenter
  collection
end

#renderObject



48
49
50
# File 'lib/fierce/master_of_ceremonies.rb', line 48

def render
  Renderer.new(self).render(template, view_model).html_safe
end

#view_modelObject



13
14
15
# File 'lib/fierce/master_of_ceremonies.rb', line 13

def view_model
  @view_model ||= ViewModel.new(*presenters)
end