From e141c084f9ce7224f1910fb0fed9de09682715d6 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Fri, 28 Mar 2014 09:27:53 +0100 Subject: [PATCH] Dedicated DOM builder class for CDATA tags. --- lib/oga.rb | 5 +++-- lib/oga/xml/builder.rb | 4 +++- lib/oga/xml/cdata.rb | 12 ++++++++++++ lib/oga/xml/comment.rb | 4 +--- 4 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 lib/oga/xml/cdata.rb diff --git a/lib/oga.rb b/lib/oga.rb index b9eb488..6fb3972 100644 --- a/lib/oga.rb +++ b/lib/oga.rb @@ -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' diff --git a/lib/oga/xml/builder.rb b/lib/oga/xml/builder.rb index 45a024f..26801e4 100644 --- a/lib/oga/xml/builder.rb +++ b/lib/oga/xml/builder.rb @@ -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) diff --git a/lib/oga/xml/cdata.rb b/lib/oga/xml/cdata.rb new file mode 100644 index 0000000..47b1221 --- /dev/null +++ b/lib/oga/xml/cdata.rb @@ -0,0 +1,12 @@ +module Oga + module XML + ## + # + # + class Cdata < Text + def to_xml + return "" + end + end # Cdata + end # XML +end # Oga diff --git a/lib/oga/xml/comment.rb b/lib/oga/xml/comment.rb index eeb0eae..3069883 100644 --- a/lib/oga/xml/comment.rb +++ b/lib/oga/xml/comment.rb @@ -2,9 +2,7 @@ module Oga module XML ## # - class Comment < Node - attr_accessor :text - + class Comment < Text def to_xml return "" end