Class: Amanzi::HTML::Document

Inherits:
XML::Document show all
Defined in:
lib/amanzi/xml.rb

Instance Attribute Summary

Attributes inherited from XML::Element

#attributes, #children, #depth, #name, #namespace

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from XML::Document

#add_singleton_elements, #comment, #singleton_elements, #singleton_method, #to_s, #to_xml

Methods inherited from XML::Element

#<<, #[]=, #add_child, #attribute_text, camelize, #comment, #contents, #indent, #insert, #insert_child, #make_child, #ns, #tag, #to_s, #to_xml

Constructor Details

#initialize(title) ⇒ Document

Returns a new instance of Document.



123
124
125
126
127
128
# File 'lib/amanzi/xml.rb', line 123

def initialize(title)
  super 'HTML'
  add_singleton_elements ['head']
  add_singleton_elements ['body']
  head.title << title
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args, &block) ⇒ Object

Pass any unknown methods down to body



130
131
132
133
# File 'lib/amanzi/xml.rb', line 130

def method_missing(symbol,*args,&block)
  singleton_method(symbol,*args,&block) ||
  singleton_method(:body).send(symbol, *args, &block)
end

Class Method Details

.testObject



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/amanzi/xml.rb', line 134

def self.test
  doc = XML::Document.new "HTML"
  doc.head.title << "Test HTML Document"
  doc.body.h1 << "Header One"

  puts doc.to_s

  doc = HTML::Document.new 'Another test HTML Document'
  doc.body.h1 << 'Header Two'
  doc.table do |t|
    t.tr{|r| r.th << :one;r.th << :two}
    t.tr{|r| r.td << 1;r.td << 2}
  end

  puts doc.to_s
end