class Thamble::Tag

Tags represent an individual HTML tag.

Constants

CGI

Attributes

type[R]

The type of the tag

Public Class Methods

new(type, content='', attr=nil) click to toggle source

Create a new instance. Usually not called directly, but through Tag.tag.

    # File lib/thamble.rb
167 def initialize(type, content='', attr=nil)
168   @type, @content, @attr = type, content, attr||OPTS
169 end
tag(type, content='', attr=nil) click to toggle source

If the given content is already a Tag instance with the same type, return it directly, otherwise create a new Tag instance with the given arguments.

    # File lib/thamble.rb
157 def self.tag(type, content='', attr=nil)
158   if content.is_a?(Tag) && content.type.to_s == type.to_s 
159     content
160   else
161     new(type, content, attr)
162   end
163 end

Public Instance Methods

close() click to toggle source

A string for the closing HTML for the tag.

    # File lib/thamble.rb
187 def close
188   "</#{@type}>\n"
189 end
content() click to toggle source

A string for the inner HTML for the tag.

    # File lib/thamble.rb
182 def content
183   h @content
184 end
open() click to toggle source

A string for the opening HTML for the tag.

    # File lib/thamble.rb
177 def open
178   "<#{@type}#{' ' unless @attr.empty?}#{attr}>"
179 end
to_s() click to toggle source

A string for the HTML to use for this tag.

    # File lib/thamble.rb
172 def to_s
173   "#{open}#{content}#{close}"
174 end

Private Instance Methods

attr() click to toggle source

A string for the html attributes for the tag.

    # File lib/thamble.rb
194 def attr
195   @attr.map{|k,v| "#{k}=\"#{h v}\""}.sort.join(' ')
196 end
escape_html(value) click to toggle source
    # File lib/thamble.rb
204 def escape_html(value)
205   CGI.escapeHTML(value.to_s)
206 end
h(s) click to toggle source

A HTML-escaped version of the given argument.

    # File lib/thamble.rb
215 def h(s)
216   case s
217   when Raw
218     s
219   when Tag
220     s.to_s
221   else
222     escape_html(s)
223   end
224 end