Class: Forme::ERB::Form
Overview
Subclass used when using Forme ERB integration. Handles integrating into the view template so that methods with blocks can inject strings into the output.
Instance Attribute Summary collapse
-
#output ⇒ Object
readonly
Template output object, where serialized output gets injected.
Attributes inherited from Form
#hidden_tags, #input_defaults, #namespaces, #opts, #serializer
Instance Method Summary collapse
-
#capture(block = '') ⇒ Object
:nodoc:.
-
#emit(tag) ⇒ Object
Serialize the tag and inject it into the output.
-
#form(*a, &block) ⇒ Object
Capture the inside of the form, injecting it into the template if a block is given, or returning it as a string if not.
-
#initialize ⇒ Form
constructor
Set the template output object when initializing.
-
#inputs(*a, &block) ⇒ Object
Capture the inside of the inputs, injecting it into the template if a block is given, or returning it as a string if not.
-
#tag(type, attr = {}, children = [], &block) ⇒ Object
If a block is given, inject an opening tag into the output, inject any given children into the output, yield to the block, inject a closing tag into the output.
Methods inherited from Form
#<<, #_input, #_inputs, #_tag, #button, #close, #each_obj, form, #input, new, #obj, #open, #raw, #raw_output, #tag_, #with_obj, #with_opts
Constructor Details
#initialize ⇒ Form
Set the template output object when initializing.
31 32 33 34 |
# File 'lib/forme/erb.rb', line 31 def initialize(*) super @output = @opts[:output] ? @opts[:output] : '' end |
Instance Attribute Details
#output ⇒ Object (readonly)
Template output object, where serialized output gets injected.
28 29 30 |
# File 'lib/forme/erb.rb', line 28 def output @output end |
Instance Method Details
#capture(block = '') ⇒ Object
:nodoc:
79 80 81 82 83 84 85 |
# File 'lib/forme/erb.rb', line 79 def capture(block='') # :nodoc: buf_was, @output = @output, block.is_a?(Proc) ? (eval("@_out_buf", block.binding) || @output) : block yield ret = @output @output = buf_was ret end |
#emit(tag) ⇒ Object
Serialize the tag and inject it into the output.
37 38 39 |
# File 'lib/forme/erb.rb', line 37 def emit(tag) output << tag.to_s end |
#form(*a, &block) ⇒ Object
Capture the inside of the form, injecting it into the template if a block is given, or returning it as a string if not.
53 54 55 56 57 58 59 |
# File 'lib/forme/erb.rb', line 53 def form(*a, &block) if block capture(block){super} else super end end |
#inputs(*a, &block) ⇒ Object
Capture the inside of the inputs, injecting it into the template if a block is given, or returning it as a string if not.
43 44 45 46 47 48 49 |
# File 'lib/forme/erb.rb', line 43 def inputs(*a, &block) if block capture(block){super} else capture{super} end end |
#tag(type, attr = {}, children = [], &block) ⇒ Object
If a block is given, inject an opening tag into the output, inject any given children into the output, yield to the block, inject a closing tag into the output. If a block is not given, just return the tag created.
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/forme/erb.rb', line 65 def tag(type, attr={}, children=[], &block) tag = _tag(type, attr, children) if block capture(block) do emit(serialize_open(tag)) Array(tag.children).each{|c| emit(c)} yield self emit(serialize_close(tag)) end else tag end end |