Class: PbbuilderTemplate
- Defined in:
- lib/pbbuilder/template.rb
Overview
PbbuilderTemplate is an extension of Pbbuilder to be used as a Rails template It adds support for partials.
Class Attribute Summary collapse
-
.template_lookup_options ⇒ Object
Returns the value of attribute template_lookup_options.
Instance Method Summary collapse
-
#initialize(context, message) ⇒ PbbuilderTemplate
constructor
A new instance of PbbuilderTemplate.
-
#partial!(*args) ⇒ Object
Render a partial.
- #set!(field, *args, **kwargs, &block) ⇒ Object
Methods inherited from Pbbuilder
#extract!, #method_missing, #respond_to_missing?, #target!
Constructor Details
#initialize(context, message) ⇒ PbbuilderTemplate
Returns a new instance of PbbuilderTemplate.
10 11 12 13 |
# File 'lib/pbbuilder/template.rb', line 10 def initialize(context, ) @context = context super() end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Pbbuilder
Class Attribute Details
.template_lookup_options ⇒ Object
Returns the value of attribute template_lookup_options.
5 6 7 |
# File 'lib/pbbuilder/template.rb', line 5 def @template_lookup_options end |
Instance Method Details
#partial!(*args) ⇒ Object
Render a partial. Can be called as: pb.partial! “name/of_partial”, argument: 123 pb.partial! “name/of_partial”, locals: 123 pb.partial! partial: “name/of_partial”, argument: 123 pb.partial! partial: “name/of_partial”, locals: 123 pb.partial! @model # @model is an ActiveModel value, it will use the name to look up a partial
21 22 23 24 25 26 27 |
# File 'lib/pbbuilder/template.rb', line 21 def partial!(*args) if args.one? && _is_active_model?(args.first) _render_active_model_partial args.first else _render_explicit_partial(*args) end end |
#set!(field, *args, **kwargs, &block) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/pbbuilder/template.rb', line 29 def set!(field, *args, **kwargs, &block) # If partial options are being passed, we render a submessage with a partial if kwargs.has_key?(:partial) if args.one? && kwargs.has_key?(:as) # pb.friends @friends, partial: "friend", as: :friend # Call set! on the super class, passing in a block that renders a partial for every element super(field, *args) do |element| _set_inline_partial(element, kwargs) end else # pb.best_friend partial: "person", person: @best_friend # Call set! as a submessage, passing in the kwargs as partial options super(field, *args) do (kwargs) end end else super end end |