class Forme::Serializer

  1. lib/forme/bs3.rb
  2. lib/forme/transformers/serializer.rb
  3. show all
Superclass: Object

Default serializer class used by the library. Any other serializer classes that want to produce html should probably subclass this class.

Registered as :default.


Public Instance

  1. call
  2. serialize_close
  3. serialize_open


SELF_CLOSING = [:img, :input]  

Which tags are self closing (such tags ignore children).

Public Instance methods

call (tag)

Serialize the tag object to an html string. Supports Tag instances, Input instances (recursing into call with the result of formatting the input), arrays (recurses into call for each entry and joins the result), and (html escapes the string version of them, unless they include the Raw module, in which case no escaping is done).

[show source]
   # File lib/forme/transformers/serializer.rb
19 def call(tag)
20   case tag
21   when Tag
22     if SELF_CLOSING.include?(tag.type)
23       "<#{tag.type}#{attr_html(tag.attr)}/>"
24     else
25       "#{serialize_open(tag)}#{call(tag.children)}#{serialize_close(tag)}"
26     end
27   when Input
28     call(tag.format)
29   when Array
30{|x| call(x)}.join
31   when DateTime, Time
32     format_time(tag)
33   when Date
34     format_date(tag)
35   when BigDecimal
36     tag.to_s('F')
37   when Raw
38     tag.to_s
39   else
40     Forme.h(tag)
41   end
42 end
serialize_close (tag)

Returns the closing part of the given tag.

[show source]
   # File lib/forme/transformers/serializer.rb
50 def serialize_close(tag)
51   "</#{tag.type}>"
52 end
serialize_open (tag)

Returns the opening part of the given tag.

[show source]
   # File lib/forme/transformers/serializer.rb
45 def serialize_open(tag)
46   "<#{tag.type}#{attr_html(tag.attr)}>"
47 end