| Class | Jabber::XHTML::HTML |
| In: |
lib/xmpp4r/xhtml/html.rb
|
| Parent: | XMPPElement |
Get first XHTML::Body child
# File lib/xmpp4r/xhtml/html.rb, line 27
27: def body
28: first_element('body') || add(Body.new)
29: end
Replace first XHTML::Body child
# File lib/xmpp4r/xhtml/html.rb, line 33
33: def body=(body)
34: delete_elements('body')
35: add(body)
36: end
Set contents of this HTML document. The "contents" parameter can be:
# File lib/xmpp4r/xhtml/html.rb, line 53
53: def contents=(contents)
54: if contents.kind_of? String
55: self.body = REXML::Document.new("<body xmlns='#{NS_XHTML}'>#{contents}</body>").root
56: elsif contents.kind_of? Body
57: self.body = contents
58: elsif contents.kind_of? Array
59: self.body = Body.new
60: contents.each do |element|
61: if element.kind_of? String
62: body.add_text(element)
63: else
64: body.add(element)
65: end
66: end
67: else
68: self.body = Body.new
69: body.add(contents)
70: end
71: end
Replace first XHTML::Body child (chainable)
# File lib/xmpp4r/xhtml/html.rb, line 40
40: def set_body(body)
41: self.body = body
42: self
43: end
HTML#contents= chainable
# File lib/xmpp4r/xhtml/html.rb, line 75
75: def set_contents(contents)
76: self.contents = contents
77: self
78: end
Convert contents of this XHTML container to plain text for easy usage with an additional fall-back <body/> in message stanzas
The resulting string is recursively composed of the text nodes of all children. This works because of the design criteria of HTML/XHTML: readable content is not being put into attributes but as text children.
If you require clickable links and proper information representation then compose the text yourself!
# File lib/xmpp4r/xhtml/html.rb, line 91
91: def to_text
92: text_getter = nil # Create binding so that the following lambda can work recursively
93:
94: text_getter = lambda do |element|
95: if element.kind_of? REXML::Text
96: element.value
97: elsif element.kind_of? REXML::Element
98: element.children.collect { |child|
99: text_getter.call(child)
100: }.join
101: end
102: end
103:
104: text_getter.call(self) # Finally, execute and return results
105: end