lib/atom/text.rb in atom-tools-2.0.4 vs lib/atom/text.rb in atom-tools-2.0.5
- old
+ new
@@ -39,25 +39,34 @@
REXML::XPath.each(c, './/xhtml:*', 'xhtml' => XHTML::NS) do |x|
x.name = x.name
end
end
- else
+ elsif ['text', 'html'].include?(type)
c = x[0] ? x[0].value : nil
+ else
+ c = x
end
else
c = x.to_s
end
e.instance_variable_set("@content", c)
end
on_build do |e,x|
c = e.instance_variable_get('@content')
-
if c.respond_to? :parent
- x << c.dup
+ if c.is_a?(REXML::Element) && c.name == 'content' # && !c.text.strip == ''
+ # c
+ c.children.each do |child_element|
+ x.add_element(child_element) unless child_element.is_a?(REXML::Text) && child_element.to_s.strip == ''
+ end
+ # x.add_text('') # unless child_element.to_s.strip == ''
+ else
+ x << c.dup
+ end
elsif c
x.text = c.to_s
end
end
@@ -118,12 +127,12 @@
end
fixed = Hpricot(self.to_s, :xhtml_strict => true)
xml = REXML::Document.new("<div>#{fixed}</div>").root
else
- # XXX check that @type is an XML mimetype and parse it
- raise "I haven't implemented this yet"
+ # Not XHTML, HTML, or text - return the REXML::Element, leave it up to the user to parse the content
+ xml = @content
end
xml
end
@@ -186,10 +195,10 @@
end
# Atom::Content behaves the same as an Atom::Text, but for two things:
#
# * the "type" attribute can be an arbitrary media type
- # * there is a "src" attribute which is an IRI that points to the content of the entry (in which case the content element will be empty)
+ # * there is a "src" attribute which is an URI that points to the content of the entry (in which case the content element will be empty)
class Content < Atom::Text
is_atom_element :content
atom_attrb :src