Dedicated DOM builder class for CDATA tags.

This commit is contained in:
Yorick Peterse 2014-03-28 09:27:53 +01:00
parent 2b250bbf42
commit e141c084f9
4 changed files with 19 additions and 6 deletions

View File

@ -6,9 +6,10 @@ require_relative 'oga/xml/lexer'
require_relative 'oga/xml/parser'
require_relative 'oga/xml/node'
require_relative 'oga/xml/element'
require_relative 'oga/xml/comment'
require_relative 'oga/xml/text'
require_relative 'oga/xml/document'
require_relative 'oga/xml/text'
require_relative 'oga/xml/comment'
require_relative 'oga/xml/cdata'
require_relative 'oga/xml/builder'
require_relative 'oga/html/parser'

View File

@ -61,7 +61,9 @@ module Oga
return Text.new(:text => node.children[0])
end
alias_method :on_cdata, :on_text
def on_cdata(node)
return Cdata.new(:text => node.children[0])
end
def on_attributes(node)
pairs = process_all(node)

12
lib/oga/xml/cdata.rb Normal file
View File

@ -0,0 +1,12 @@
module Oga
module XML
##
#
#
class Cdata < Text
def to_xml
return "<![CDATA[#{text}]]>"
end
end # Cdata
end # XML
end # Oga

View File

@ -2,9 +2,7 @@ module Oga
module XML
##
#
class Comment < Node
attr_accessor :text
class Comment < Text
def to_xml
return "<!--#{text}-->"
end