Module: HTML5::TreeWalkers::TokenConstructor
- Included in:
- Base
- Defined in:
- lib/html5/treewalkers/base.rb
Instance Method Summary collapse
- #_(str) ⇒ Object
- #comment(data) ⇒ Object
- #doctype(name, public_id, system_id, correct = nil) ⇒ Object
- #empty_tag(name, attrs, has_children = false) ⇒ Object
- #end_tag(name) ⇒ Object
- #error(msg) ⇒ Object
- #normalize_attrs(attrs) ⇒ Object
- #start_tag(name, attrs) ⇒ Object
- #text(data) ⇒ Object
- #unknown(nodeType) ⇒ Object
Instance Method Details
#_(str) ⇒ Object
54 55 56 |
# File 'lib/html5/treewalkers/base.rb', line 54 def _(str) str end |
#comment(data) ⇒ Object
42 43 44 |
# File 'lib/html5/treewalkers/base.rb', line 42 def comment(data) {:type => :Comment, :data => data} end |
#doctype(name, public_id, system_id, correct = nil) ⇒ Object
46 47 48 |
# File 'lib/html5/treewalkers/base.rb', line 46 def doctype(name, public_id, system_id, correct=nil) {:type => :Doctype, :name => name, :public_id => public_id, :system_id => system_id, :correct => correct} end |
#empty_tag(name, attrs, has_children = false) ⇒ Object
14 15 16 17 |
# File 'lib/html5/treewalkers/base.rb', line 14 def empty_tag(name, attrs, has_children=false) error(_("Void element has children")) if has_children {:type => :EmptyTag, :name => name, :data => normalize_attrs(attrs)} end |
#end_tag(name) ⇒ Object
23 24 25 |
# File 'lib/html5/treewalkers/base.rb', line 23 def end_tag(name) {:type => :EndTag, :name => name, :data => []} end |
#error(msg) ⇒ Object
6 7 8 |
# File 'lib/html5/treewalkers/base.rb', line 6 def error(msg) {:type => "SerializeError", :data => msg} end |
#normalize_attrs(attrs) ⇒ Object
10 11 12 |
# File 'lib/html5/treewalkers/base.rb', line 10 def normalize_attrs(attrs) attrs.to_a end |
#start_tag(name, attrs) ⇒ Object
19 20 21 |
# File 'lib/html5/treewalkers/base.rb', line 19 def start_tag(name, attrs) {:type => :StartTag, :name => name, :data => normalize_attrs(attrs)} end |
#text(data) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/html5/treewalkers/base.rb', line 27 def text(data) if data =~ /\A([#{SPACE_CHARACTERS.join('')}]+)/m yield({:type => :SpaceCharacters, :data => $1}) data = data[$1.length .. -1] return if data.empty? end if data =~ /([#{SPACE_CHARACTERS.join('')}]+)\Z/m yield({:type => :Characters, :data => data[0 ... -$1.length]}) yield({:type => :SpaceCharacters, :data => $1}) else yield({:type => :Characters, :data => data}) end end |
#unknown(nodeType) ⇒ Object
50 51 52 |
# File 'lib/html5/treewalkers/base.rb', line 50 def unknown(nodeType) error(_("Unknown node type: ") + nodeType.to_s) end |