Class: Atom::Content::Html
Overview
Html content within an Atom document.
Instance Method Summary collapse
-
#initialize(o) ⇒ Html
constructor
Creates a new Content::Html.
-
#to_xml(nodeonly = true, name = 'content', namespace = nil, namespace_map = Atom::Xml::NamespaceMap.new) ⇒ Object
:nodoc:.
Methods inherited from Base
Methods included from Xml::Parseable
#==, #accessor_name, #current_node_is?, included, #next_node_is?, #parse
Methods inherited from String
#constantize, #demodulize, #singularize
Constructor Details
#initialize(o) ⇒ Html
Creates a new Content::Html.
o
-
An XML::Reader or a HTML string.
269 270 271 272 273 274 275 276 277 278 279 280 |
# File 'lib/atom.rb', line 269 def initialize(o) case o when XML::Reader super(o.read_string) parse(o, :once => true) when String super(o) @type = 'html' else raise ArgumentError, "Got #{o} which isn't a String or XML::Reader" end end |
Instance Method Details
#to_xml(nodeonly = true, name = 'content', namespace = nil, namespace_map = Atom::Xml::NamespaceMap.new) ⇒ Object
:nodoc:
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
# File 'lib/atom.rb', line 282 def to_xml(nodeonly = true, name = 'content', namespace = nil, namespace_map = Atom::Xml::NamespaceMap.new) # :nodoc: require 'iconv' # Convert from utf-8 to utf-8 as a way of making sure the content is UTF-8. # # This is a pretty crappy way to do it but if we don't check libxml just # fails silently and outputs the content element without any content. At # least checking here and raising an exception gives the caller a chance # to try and recitfy the situation. # begin node = XML::Node.new("#{namespace_map.prefix(Atom::NAMESPACE, name)}") node << Iconv.iconv('utf-8', 'utf-8', self.to_s).first node['type'] = 'html' node['xml:lang'] = self.xml_lang if self.xml_lang node rescue Iconv::IllegalSequence => e raise SerializationError, "Content must be converted to UTF-8 before attempting to serialize to XML: #{e.}." end end |