Class: SyntaxTree::Haml::Doctype
- Inherits:
-
Object
- Object
- SyntaxTree::Haml::Doctype
- Defined in:
- lib/syntax_tree/haml/doctype.rb
Overview
Constant Summary collapse
- TYPES =
{ "basic" => "Basic", "frameset" => "Frameset", "mobile" => "Mobile", "rdfa" => "RDFa", "strict" => "Strict", "xml" => "XML" }
- VERSIONS =
["1.1", "5"]
Instance Attribute Summary collapse
-
#node ⇒ Object
readonly
Returns the value of attribute node.
Instance Method Summary collapse
- #format(q) ⇒ Object
-
#initialize(node) ⇒ Doctype
constructor
A new instance of Doctype.
- #pretty_print(q) ⇒ Object
Constructor Details
#initialize(node) ⇒ Doctype
Returns a new instance of Doctype.
20 21 22 |
# File 'lib/syntax_tree/haml/doctype.rb', line 20 def initialize(node) @node = node end |
Instance Attribute Details
#node ⇒ Object (readonly)
Returns the value of attribute node.
18 19 20 |
# File 'lib/syntax_tree/haml/doctype.rb', line 18 def node @node end |
Instance Method Details
#format(q) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/syntax_tree/haml/doctype.rb', line 24 def format(q) parts = ["!!!"] parts << if TYPES.key?(node.value[:type]) TYPES[node.value[:type]] elsif VERSIONS.include?(node.value[:version]) node.value[:version] else node.value[:type] end parts << node.value[:encoding] if node.value[:encoding] q.text(parts.join(" ")) end |
#pretty_print(q) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/syntax_tree/haml/doctype.rb', line 40 def pretty_print(q) q.group(2, "(doctype", ")") do q.breakable if TYPES.key?(node.value[:type]) q.text("type=") q.pp(node.value[:type]) elsif VERSIONS.include?(node.value[:version]) q.text("version=") q.pp(node.value[:version]) else q.text("type=") q.pp(node.value[:type]) end if node.value[:encoding] q.breakable q.text("encoding=") q.pp(node.value[:encoding]) end end end |