Class: Org::Tag

Inherits:
Object
  • Object
show all
Defined in:
lib/org/to/html.rb

Overview

Extracted from Ramaze Gestalt

Instance Method Summary collapse

Constructor Details

#initialize(name, value, args = {}, &block) ⇒ Tag

Returns a new instance of Tag.



65
66
67
# File 'lib/org/to/html.rb', line 65

def initialize(name, value, args = {}, &block)
  @name, @value, @args, @block = name, value, args, block
end

Instance Method Details

#build_tag(name, attr = {}, text = []) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/org/to/html.rb', line 75

def build_tag(name, attr = {}, text = [])
  @out << "<#{name}"
  @out << attr.map{|k,v| %[ #{k}="#{Org.escape_html(v)}"] }.join
  if text != [] or block_given?
    @out << ">"
    @out << Org.escape_html([text].join)
    if block_given?
      text = yield
      @out << text.to_str if text != @out and text.respond_to?(:to_str)
    end
    @out << "</#{name}>"
  else
    @out << ' />'
  end
end

#to_sObject



69
70
71
72
73
# File 'lib/org/to/html.rb', line 69

def to_s
  @out = ''
  build_tag(@name, @args, @value, &@block)
  @out
end