Module: Tuxedo::ActionView::Helpers

Defined in:
lib/tuxedo/action_view/helpers.rb

Overview

Main module for the ActionView helpers

Examples:


presenter_for(instance)

prac(instance, method, *args)

Instance Method Summary collapse

Instance Method Details

#prac(object, method, *args) ⇒ Object

Present And Call Shorthand method for using the following call

presenter_for(object).zone_label

Examples:


prac object :zone_label

Parameters:

  • object (Object)
  • method (method)

    the method we should call on the presentor

  • args (Hash)

    optional arguments for the method



42
43
44
45
# File 'lib/tuxedo/action_view/helpers.rb', line 42

def prac(object, method, *args)
  return if object.nil? || method.nil?
  presenter_for(object).send(method.to_sym, *args)
end

#presenter_for(model, klass = nil) {|presenter| ... } ⇒ Object

We can use this to give a block and wrap all the presenter methods in the block. This shows clearly that we are using a presenter without the explicit assign statement. Some magic happens to initiate a new presenter with the model and the view context

Parameters:

  • model (Object)

    any type of object that needs to be presented

  • klass (KlassName) (defaults to: nil)

    a different presenter klass

Yields:

  • (presenter)

Returns:

  • model presenter instance



21
22
23
24
25
26
27
# File 'lib/tuxedo/action_view/helpers.rb', line 21

def presenter_for(model, klass = nil)
  return if model.nil?
  klass ||= "#{model.class.name}#{Tuxedo.config.suffix}".constantize
  presenter = klass.new(model, self)
  yield presenter if block_given?
  presenter
end