Class: Hpricot::DocType

Inherits:
Object show all
Defined in:
lib/gems/haml-2.0.4/lib/haml/html.rb

Instance Method Summary collapse

Instance Method Details

#to_haml(tabs = 0) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/gems/haml-2.0.4/lib/haml/html.rb', line 94

def to_haml(tabs = 0)
  attrs = public_id.scan(/DTD\s+([^\s]+)\s*([^\s]*)\s*([^\s]*)\s*\/\//)[0]
  if attrs == nil
    raise Exception.new("Invalid doctype")
  end

  type, version, strictness = attrs.map { |a| a.downcase }
  if type == "html"
    version = "1.0"
    strictness = "transitional"
  end

  if version == "1.0" || version.empty?
    version = nil
  end

  if strictness == 'transitional' || strictness.empty?
    strictness = nil
  end

  version = " #{version}" if version
  if strictness
    strictness[0] = strictness[0] - 32
    strictness = " #{strictness}"
  end

  "#{tabulate(tabs)}!!!#{version}#{strictness}\n"
end