Class: Fierce::MasterOfCeremonies
- Inherits:
-
Object
- Object
- Fierce::MasterOfCeremonies
- Defined in:
- lib/fierce/master_of_ceremonies.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
-
#locals ⇒ Object
readonly
Returns the value of attribute locals.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Instance Method Summary collapse
- #base_presenters ⇒ Object
- #custom_presenter ⇒ Object
-
#initialize(template, path, locals, controller, context) ⇒ MasterOfCeremonies
constructor
A new instance of MasterOfCeremonies.
- #locals_presenter ⇒ Object
- #partial(name) ⇒ Object
- #presenters ⇒ Object
- #render ⇒ Object
- #view_model ⇒ Object
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
#context ⇒ Object (readonly)
Returns the value of attribute context.
3 4 5 |
# File 'lib/fierce/master_of_ceremonies.rb', line 3 def context @context end |
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
3 4 5 |
# File 'lib/fierce/master_of_ceremonies.rb', line 3 def controller @controller end |
#locals ⇒ Object (readonly)
Returns the value of attribute locals.
3 4 5 |
# File 'lib/fierce/master_of_ceremonies.rb', line 3 def locals @locals end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/fierce/master_of_ceremonies.rb', line 3 def path @path end |
#template ⇒ Object (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_presenters ⇒ Object
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_presenter ⇒ Object
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_presenter ⇒ Object
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 |
#presenters ⇒ Object
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 |