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
#hidden_tags, #input_defaults, #opts, #serializer
Instance Method Summary collapse
-
#_inputs(inputs = [], opts = {}) ⇒ 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.
-
#raw_output(s) ⇒ Object
Use the template’s raw method to mark the given string as html safe.
-
#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
:nodoc:.
Methods inherited from Form
#<<, #_input, #_tag, #close, #each_obj, form, #form, #namespaces, new, #obj, #open, #raw, #with_obj, #with_opts
Constructor Details
#initialize ⇒ Form
Set the template object when initializing.
35 36 37 38 |
# File 'lib/forme/rails.rb', line 35 def initialize(*) super @template = @opts[:template] end |
Instance Attribute Details
#template ⇒ Object (readonly)
The Rails template that created this form.
32 33 34 |
# File 'lib/forme/rails.rb', line 32 def template @template end |
Instance Method Details
#_inputs(inputs = [], opts = {}) ⇒ Object
If a block is not given, emit the inputs into the current output buffer.
58 59 60 61 62 63 64 |
# File 'lib/forme/rails.rb', line 58 def _inputs(inputs=[], opts={}) # :nodoc: if block_given? && !opts[:subform] super else emit(super) end end |
#button ⇒ Object
Return a string version of the button that is already marked as safe.
72 73 74 |
# File 'lib/forme/rails.rb', line 72 def (*) super.to_s end |
#emit(tag) ⇒ Object
Serialize and mark as already escaped the string version of the input.
42 43 44 |
# File 'lib/forme/rails.rb', line 42 def emit(tag) template.output_buffer << tag.to_s end |
#input ⇒ Object
Return a string version of the input that is already marked as safe.
67 68 69 |
# File 'lib/forme/rails.rb', line 67 def input(*) super.to_s end |
#inputs ⇒ Object
Capture the inputs into a new output buffer, and return the buffer if not given a block
48 49 50 51 52 53 54 |
# File 'lib/forme/rails.rb', line 48 def inputs(*) if block_given? super else template.send(:with_output_buffer){super} end end |
#raw_output(s) ⇒ Object
Use the template’s raw method to mark the given string as html safe.
77 78 79 |
# File 'lib/forme/rails.rb', line 77 def raw_output(s) template.raw(s) 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.
85 86 87 88 89 90 91 |
# File 'lib/forme/rails.rb', line 85 def tag(type, attr={}, children=[], &block) if block_given? template.send(:with_output_buffer){tag_(type, attr, children, &block)} else _tag(type, attr, children).to_s end end |
#tag_(type, attr = {}, children = []) {|_self| ... } ⇒ Object
:nodoc:
93 94 95 96 97 98 99 |
# File 'lib/forme/rails.rb', line 93 def tag_(type, attr={}, children=[]) # :nodoc: tag = _tag(type, attr, children) emit(serialize_open(tag)) Array(tag.children).each{|c| emit(c)} yield self if block_given? emit(serialize_close(tag)) end |