class TaskJuggler::HTMLDocument
HTMLDocument
objects are a specialized form of XMLDocument
objects. All mandatory elements of a proper HTML document will be added automatically upon object creation.
Attributes
html[R]
Public Class Methods
new(docType = :html5, &block)
click to toggle source
When creating a HTMLDocument
the caller can specify the type of HTML that will be used. The constructor then generates the proper XML declaration for it. :strict, :transitional and :frameset are supported for docType.
Calls superclass method
# File lib/taskjuggler/HTMLDocument.rb, line 31 def initialize(docType = :html5, &block) super(&block) unless docType == :html5 @elements << XMLBlob.new('<?xml version="1.0" encoding="UTF-8"?>') case docType when :strict dtdRef = 'Strict' url = 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd' when :transitional dtdRef = 'Transitional' url = 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd' when :frameset dtdRef = 'Frameset' url = 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd' else raise "Unsupported docType" end @elements << XMLBlob.new( '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 ' + "#{dtdRef}//EN\" \"#{url}\">") else @elements << XMLBlob.new('<!DOCTYPE html>') end @elements << XMLComment.new('This file has been generated by ' + "#{AppConfig.appName} v#{AppConfig.version}") attrs = { 'xml:lang' => 'en', 'lang' => 'en' } attrs['xmlns'] ='http://www.w3.org/1999/xhtml' unless docType == :html5 @elements << (@html = HTML.new(attrs)) end
Public Instance Methods
generateHead(title, metaTags = {}, blob = nil)
click to toggle source
Generate the ‘head’ section of an HTML page.
# File lib/taskjuggler/HTMLDocument.rb, line 63 def generateHead(title, metaTags = {}, blob = nil) @html << HEAD.new { e = [ TITLE.new { title }, META.new({ 'http-equiv' => 'Content-Type', 'content' => 'text/html; charset=utf-8' }), # Ugly hack to force IE into IE-9 mode. META.new({ 'http-equiv' => 'X-UA-Compatible', 'content' => 'IE=9' }) ] # Include optional meta tags. metaTags.each do |name, content| e << META.new({ 'name' => name, 'content' => content }) end # Add a raw HTML blob into the header if provided. e << XMLBlob.new(blob) if blob e } end