Class: Forme::Rails::Form
Overview
Subclass used when using Forme/Rails ERB integration, handling integration with the view template.
Instance Attribute Summary collapse
-
#template ⇒ Object
readonly
The Rails template that created this form.
Attributes inherited from Form
#error_handler, #formatter, #hidden_tags, #input_defaults, #inputs_wrapper, #labeler, #obj, #opts, #serializer, #wrapper
Instance Method Summary collapse
-
#_inputs ⇒ Object
If a block is not given, emit the inputs into the current output buffer.
-
#button ⇒ Object
Return a string version of the button that is already marked as safe.
-
#emit(tag) ⇒ Object
Serialize and mark as already escaped the string version of the input.
-
#initialize ⇒ Form
constructor
Set the template object when initializing.
-
#input ⇒ Object
Return a string version of the input that is already marked as safe.
-
#inputs ⇒ Object
Capture the inputs into a new output buffer, and return the buffer if not given a block.
-
#tag(type, attr = {}, children = [], &block) ⇒ Object
If a block is given, create a new output buffer and make sure all the output of the tag goes into that buffer, and return the buffer.
- #tag_(type, attr = {}, children = []) {|_self| ... } ⇒ Object
Methods inherited from Form
#<<, #_input, #_tag, #close, #form, form, #format, #open, #serialize, #transform, #transformer
Constructor Details
#initialize ⇒ Form
Set the template object when initializing.
33 34 35 36 |
# File 'lib/forme/rails.rb', line 33 def initialize(*) super @template = @opts[:template] end |
Instance Attribute Details
#template ⇒ Object (readonly)
The Rails template that created this form.
30 31 32 |
# File 'lib/forme/rails.rb', line 30 def template @template end |
Instance Method Details
#_inputs ⇒ Object
If a block is not given, emit the inputs into the current output buffer.
56 57 58 59 60 61 62 |
# File 'lib/forme/rails.rb', line 56 def _inputs(*) if block_given? super else emit(super) end end |
#button ⇒ Object
Return a string version of the button that is already marked as safe.
70 71 72 |
# File 'lib/forme/rails.rb', line 70 def (*) template.raw(super.to_s) end |
#emit(tag) ⇒ Object
Serialize and mark as already escaped the string version of the input.
40 41 42 |
# File 'lib/forme/rails.rb', line 40 def emit(tag) template.output_buffer << template.raw(tag.to_s) end |
#input ⇒ Object
Return a string version of the input that is already marked as safe.
65 66 67 |
# File 'lib/forme/rails.rb', line 65 def input(*) template.raw(super.to_s) end |
#inputs ⇒ Object
Capture the inputs into a new output buffer, and return the buffer if not given a block
46 47 48 49 50 51 52 |
# File 'lib/forme/rails.rb', line 46 def inputs(*) if block_given? super else template.send(:with_output_buffer){super} end end |
#tag(type, attr = {}, children = [], &block) ⇒ Object
If a block is given, create a new output buffer and make sure all the output of the tag goes into that buffer, and return the buffer. Otherwise, just return a string version of the tag that is already marked as safe.
78 79 80 81 82 83 84 85 |
# File 'lib/forme/rails.rb', line 78 def tag(type, attr={}, children=[], &block) if block_given? template.send(:with_output_buffer){tag_(type, attr, children, &block)} else tag = _tag(type, attr, children) template.raw(tag.to_s) end end |
#tag_(type, attr = {}, children = []) {|_self| ... } ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/forme/rails.rb', line 87 def tag_(type, attr={}, children=[]) tag = _tag(type, attr, children) emit(serializer.serialize_open(tag)) if serializer.respond_to?(:serialize_open) Array(tag.children).each{|c| emit(c)} yield self if block_given? emit(serializer.serialize_close(tag)) if serializer.respond_to?(:serialize_close) end |