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, line 136
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