Sha256: 56fa51892ad69d5a6132dc89516525ae803ed06ad7fd4b6051ec3ec9b2a67f79
Contents?: true
Size: 1.24 KB
Versions: 31
Compression:
Stored size: 1.24 KB
Contents
# This file is part of the "Utopia Framework" project, and is licensed under the GNU AGPLv3. # Copyright 2010 Samuel Williams. All rights reserved. # See <utopia.rb> for licensing details. module Utopia class Tag def initialize(name, attributes = {}) @name = name @attributes = attributes @closed = false end attr :name attr :attributes attr :closed, true def [](key) @attributes[key] end def append(text) @content ||= StringIO.new @content.write text end def to_html(content = nil, buf = StringIO.new) write_full_html(buf, content) return buf.string end def to_hash @attributes end def to_s buf = StringIO.new write_open_html(buf) return buf.string end def write_open_html(buf, terminate = false) buf ||= StringIO.new buf.write "<#{name}" @attributes.each do |key, value| buf.write " #{key}=\"#{value}\"" end if terminate buf.write "/>" else buf.write ">" end end def write_close_html(buf) buf.write "</#{name}>" end def write_full_html(buf, content = nil) if @closed && content == nil write_open_html(buf, true) else write_open_html(buf) buf.write(content) write_close_html(buf) end end end end
Version data entries
31 entries across 31 versions & 1 rubygems