Module: HtmlHandler
- Included in:
- HTML::Table, HTML::Table::Caption, HTML::Table::ColGroup, HTML::Table::TableSection, Table::ColGroup::Col, Table::Row, Table::Row::Data, Table::Row::Header
- Defined in:
- lib/html/html_handler.rb
Instance Method Summary collapse
-
#html(formatting = true) ⇒ Object
Returns the HTML text for the current object.
Instance Method Details
#html(formatting = true) ⇒ Object
Returns the HTML text for the current object. Indentation and end tag options are optional, based on the settings of the classes themselves.
If formatting
is false, then formatting and whitespace is not applied and you will get a single, very long string. Note that case is still honored.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/html/html_handler.rb', line 38 def html(formatting = true) if self.class.respond_to?(:html_case) $upper = true if self.class.html_case == "upper" end if $upper @html_begin.upcase! @html_end.upcase! end ilevel = 0 if formatting && self.class.respond_to?(:indent_level) ilevel = self.class.indent_level end html = ' ' * ilevel + @html_begin[0..-1] len = html.length html[len,len] = '>' if self.kind_of?(Array) if formatting html << self.map{ |e| "\n" + e.html(formatting).to_s }.join else html << self.map{ |e| e.html(formatting).to_s }.join end else html << @html_body end ##################################################################### # Add end tags, or not, depending on whether the class supports the # end_tags class method. Those that don't have an end_tags class # method necessarily means that the end tag must be included. # # The Table.global_end_tags method overrides the individual class # preferences with regards to end tags. ##################################################################### if self.kind_of?(Array) if HTML::Table. if self.class.respond_to?(:end_tags?) if formatting if self.class. html << "\n" + (' ' * ilevel) + @html_end end else html << (' ' * ilevel) + @html_end if self.class. end else if formatting html << "\n" + (' ' * ilevel) + @html_end else html << (' ' * ilevel) + @html_end end end else unless self.class.respond_to?(:end_tags?) if formatting html << "\n" + (' ' * ilevel) + @html_end else html << (' ' * ilevel) + @html_end end end end else if HTML::Table. if self.class.respond_to?(:end_tags?) html << @html_end if self.class. else html << @html_end end else unless self.class.respond_to?(:end_tags?) html << @html_end end end end return html end |