Class: Atom::Content::Xhtml
Overview
XHTML content within an Atom document.
Constant Summary collapse
- XHTML =
'http://www.w3.org/1999/xhtml'
Instance Method Summary collapse
-
#initialize(xml) ⇒ Xhtml
constructor
A new instance of Xhtml.
- #to_xml(nodeonly = true, name = 'content', namespace = nil, namespace_map = Atom::Xml::NamespaceMap.new) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(xml) ⇒ Xhtml
Returns a new instance of Xhtml.
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/atom.rb', line 262 def initialize(xml) super("") parse(xml, :once => true) starting_depth = xml.depth # Get the next element - should be a div according to the atom spec while xml.read == 1 && xml.node_type != XML::Reader::TYPE_ELEMENT; end if xml.local_name == 'div' && xml.namespace_uri == XHTML set_content(xml.read_inner_xml.strip.gsub(/\s+/, ' ')) else set_content(xml.read_outer_xml) end # get back to the end of the element we were created with while xml.read == 1 && xml.depth > starting_depth; end end |
Instance Method Details
#to_xml(nodeonly = true, name = 'content', namespace = nil, namespace_map = Atom::Xml::NamespaceMap.new) ⇒ Object
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/atom.rb', line 280 def to_xml(nodeonly = true, name = 'content', namespace = nil, namespace_map = Atom::Xml::NamespaceMap.new) node = XML::Node.new("#{namespace_map.get(Atom::NAMESPACE)}:#{name}") node['type'] = 'xhtml' node['xml:lang'] = self.xml_lang div = XML::Node.new('div') div['xmlns'] = XHTML p = XML::Parser.string(to_s) content = p.parse.root.copy(true) div << content node << div node end |