Class: Forme::Serializer::PlainText
- Inherits:
-
Object
- Object
- Forme::Serializer::PlainText
- Defined in:
- lib/forme.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.
1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 |
# File 'lib/forme.rb', line 1279 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 |