Class: Forme::Serializer::PlainText
- Inherits:
-
Object
- Object
- Forme::Serializer::PlainText
- Defined in:
- lib/forme/transformers/serializer.rb
Overview
Serializer class that converts tags to plain text strings.
Registered at :text.
Instance Method Summary collapse
-
#call(tag) ⇒ Object
Serialize the tag to plain text string.
Instance Method Details
#call(tag) ⇒ Object
Serialize the tag to plain text string.
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/forme/transformers/serializer.rb', line 135 def call(tag) case tag when Tag case tag.type.to_sym when :input case tag.attr[:type].to_sym when :radio, :checkbox tag.attr[:checked] ? '_X_' : '___' when :submit, :reset, :hidden '' when :password "********\n" else "#{tag.attr[:value].to_s}\n" end when :select "\n#{call(tag.children)}" when :option "#{call([tag.attr[:selected] ? '_X_ ' : '___ ', tag.children])}\n" when :textarea, :label "#{call(tag.children)}\n" when :legend v = call(tag.children) "#{v}\n#{'-' * v.length}\n" else call(tag.children) end when Input call(tag.format) when Array tag.map{|x| call(x)}.join else tag.to_s end end |