Class | Atom::Text |
In: |
lib/atom/yaml.rb
lib/atom/text.rb |
Parent: | Atom::Element |
An Atom::Element representing a text construct. It has a single attribute, "type", which accepts values "text", "html" and "xhtml"
returns a string suitable for dumping into an HTML document
# File lib/atom/text.rb, line 32 32: def html 33: if self["type"] == "xhtml" or self["type"] == "html" 34: to_s 35: elsif self["type"] == "text" 36: REXML::Text.new(to_s).to_s 37: end 38: end
# File lib/atom/text.rb, line 23 23: def to_s 24: if self["type"] == "xhtml" 25: @content.children.to_s 26: else 27: @content.to_s 28: end 29: end
attempts to parse the content of this element as XML and return it as an array of REXML::Elements.
If this self["type"] is "html" and Hpricot is installed, it will be converted to XHTML first.
# File lib/atom/text.rb, line 45 45: def xml 46: if self["type"] == "xhtml" 47: @content.children 48: elsif self["type"] == "text" 49: [self.to_s] 50: elsif self["type"] == "html" 51: begin 52: require "hpricot" 53: rescue 54: raise "Turning HTML content into XML requires Hpricot." 55: end 56: 57: fixed = Hpricot(self.to_s, :xhtml_strict => true) 58: REXML::Document.new("<div>#{fixed}</div>").root.children 59: else 60: # XXX check that @type is an XML mimetype and parse it 61: raise "I haven't implemented this yet" 62: end 63: end