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
#==, #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.
245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/atom.rb', line 245 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:
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/atom.rb', line 258 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) 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 |