class Forme::Serializer::PlainText

  1. lib/forme/transformers/serializer.rb
Superclass: Object

Serializer class that converts tags to plain text strings.

Registered at :text.

Methods

Public Instance

  1. call

Public Instance methods

call (tag)

Serialize the tag to plain text string.

[show source]
    # File lib/forme/transformers/serializer.rb
126 def call(tag)
127   case tag
128   when Tag
129     case tag.type.to_sym
130     when :input
131       case tag.attr[:type].to_sym
132       when :radio, :checkbox
133         tag.attr[:checked] ? '_X_' : '___'
134       when :submit, :reset, :hidden
135         ''
136       when :password
137         "********\n"
138       else
139         "#{tag.attr[:value].to_s}\n"
140       end
141     when :select
142       "\n#{call(tag.children)}"
143     when :option
144       "#{call([tag.attr[:selected] ? '_X_ ' : '___ ', tag.children])}\n"
145     when :textarea, :label
146       "#{call(tag.children)}\n"
147     when :legend
148       v = call(tag.children)
149       "#{v}\n#{'-' * v.length}\n"
150     else
151       call(tag.children)
152     end
153   when Input
154     call(tag.format)
155   when Array
156     tag.map{|x| call(x)}.join
157   else
158     tag.to_s
159   end
160 end