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.
1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 |
# File 'lib/forme.rb', line 1441 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 |