### Home Classes Methods

### In Files

- lib/xmpp4r/xhtml/html.rb

### Parent

XMPPElement

### Methods

- ::new
- #body
- #body=
- #contents=
- #set_body
- #set_contents
- #to_text

### Files

- CHANGELOG
- COPYING
- LICENSE
- README.rdoc
- README_ruby19.txt

### Class/Module Index

Quicksearch

- Jabber
- Jabber::ArgumentError
- Jabber::Bytestreams
- Jabber::Bytestreams::IBB
- Jabber::Bytestreams::IBBInitiator
- Jabber::Bytestreams::IBBQueueItem
- Jabber::Bytestreams::IBBTarget
- Jabber::Bytestreams::IqQueryBytestreams
- Jabber::Bytestreams::IqSi
- Jabber::Bytestreams::IqSiFile
- Jabber::Bytestreams::IqSiFileRange
- Jabber::Bytestreams::SOCKS5Bytestreams
- Jabber::Bytestreams::SOCKS5BytestreamsInitiator
- Jabber::Bytestreams::SOCKS5BytestreamsPeer
- Jabber::Bytestreams::SOCKS5BytestreamsServer
- Jabber::Bytestreams::SOCKS5BytestreamsServerStreamHost
- Jabber::Bytestreams::SOCKS5BytestreamsTarget
- Jabber::Bytestreams::SOCKS5Socket
- Jabber::Bytestreams::StreamHost
- Jabber::Bytestreams::StreamHostUsed
- Jabber::Callback
- Jabber::CallbackList
- Jabber::Caps
- Jabber::Caps::C
- Jabber::Caps::Helper
- Jabber::Client
- Jabber::ClientAuthenticationFailure
- Jabber::Command
- Jabber::Command::IqCommand
- Jabber::Command::Responder
- Jabber::Component
- Jabber::ComponentAuthenticationFailure
- Jabber::Connection
- Jabber::Connection::SSLSocketUTF8
- Jabber::Dataforms
- Jabber::Dataforms::XData
- Jabber::Dataforms::XDataField
- Jabber::Dataforms::XDataInstructions
- Jabber::Dataforms::XDataReported
- Jabber::Dataforms::XDataTitle
- Jabber::Delay
- Jabber::Delay::XDelay
- Jabber::Discovery
- Jabber::Discovery::Feature
- Jabber::Discovery::Helper
- Jabber::Discovery::Identity
- Jabber::Discovery::IqQueryDiscoInfo
- Jabber::Discovery::IqQueryDiscoItems
- Jabber::Discovery::Item
- Jabber::Discovery::Responder
- Jabber::EntityTime
- Jabber::EntityTime::IqTime
- Jabber::EntityTime::Responder
- Jabber::ErrorResponse
- Jabber::FeatureNegotiation
- Jabber::FeatureNegotiation::IqFeature
- Jabber::FileTransfer
- Jabber::FileTransfer::FileSource
- Jabber::FileTransfer::Helper
- Jabber::FileTransfer::TransferSource
- Jabber::Framework
- Jabber::Framework::Base
- Jabber::Framework::Bot
- Jabber::HTTPBinding
- Jabber::HTTPBinding::Client
- Jabber::IdGenerator
- Jabber::InvalidChatState
- Jabber::Iq
- Jabber::IqQuery
- Jabber::JID
- Jabber::JabberError
- Jabber::LastActivity
- Jabber::LastActivity::Helper
- Jabber::LastActivity::IqQueryLastActivity
- Jabber::MUC
- Jabber::MUC::IqQueryMUCAdmin
- Jabber::MUC::IqQueryMUCAdminItem
- Jabber::MUC::IqQueryMUCOwner
- Jabber::MUC::MUCBrowser
- Jabber::MUC::MUCClient
- Jabber::MUC::SimpleMUCClient
- Jabber::MUC::UserItem
- Jabber::MUC::XMUC
- Jabber::MUC::XMUCUser
- Jabber::MUC::XMUCUserInvite
- Jabber::MUC::XMUCUserItem
- Jabber::Message
- Jabber::NoNameXmlnsRegistered
- Jabber::NotConnected
- Jabber::Observable
- Jabber::Observable::Contact
- Jabber::Observable::PubSub
- Jabber::Observable::PubSub::AlreadySet
- Jabber::Observable::PubSub::NoService
- Jabber::Observable::Subscriptions
- Jabber::Presence
- Jabber::PubSub
- Jabber::PubSub::Configuration
- Jabber::PubSub::Event
- Jabber::PubSub::EventItem
- Jabber::PubSub::EventItems
- Jabber::PubSub::IqPubSub
- Jabber::PubSub::IqPubSubOwner
- Jabber::PubSub::Item
- Jabber::PubSub::Items
- Jabber::PubSub::NodeBrowser
- Jabber::PubSub::NodeConfig
- Jabber::PubSub::NodeHelper
- Jabber::PubSub::OAuthPubSubStreamHelper
- Jabber::PubSub::OAuthServiceHelper
- Jabber::PubSub::OwnerNodeConfig
- Jabber::PubSub::Publish
- Jabber::PubSub::Retract
- Jabber::PubSub::ServiceHelper
- Jabber::PubSub::Subscription
- Jabber::PubSub::SubscriptionConfig
- Jabber::PubSub::Unsubscribe
- Jabber::RPC
- Jabber::RPC::Client
- Jabber::RPC::IqQueryRPC
- Jabber::RPC::Server
- Jabber::Reliable
- Jabber::Reliable::Connection
- Jabber::Reliable::Listener
- Jabber::Roster
- Jabber::Roster::Helper
- Jabber::Roster::Helper::RosterItem
- Jabber::Roster::IqQueryRoster
- Jabber::Roster::RosterItem
- Jabber::Roster::RosterX
- Jabber::Roster::RosterXItem
- Jabber::Roster::XRoster
- Jabber::Roster::XRosterItem
- Jabber::SASL
- Jabber::SASL::Anonymous
- Jabber::SASL::Base
- Jabber::SASL::DigestMD5
- Jabber::SASL::Plain
- Jabber::SOCKS5Error
- Jabber::Semaphore
- Jabber::ServerDisconnected
- Jabber::Stream
- Jabber::Stream::ThreadBlock
- Jabber::StreamParser
- Jabber::Test
- Jabber::Test::ListenerMocker
- Jabber::UserLocation
- Jabber::UserLocation::Helper
- Jabber::UserLocation::Location
- Jabber::UserTune
- Jabber::UserTune::Helper
- Jabber::UserTune::Tune
- Jabber::Vcard
- Jabber::Vcard::Helper
- Jabber::Vcard::IqVcard
- Jabber::Version
- Jabber::Version::IqQueryVersion
- Jabber::Version::Responder
- Jabber::Version::SimpleResponder
- Jabber::X
- Jabber::XHTML
- Jabber::XHTML::Body
- Jabber::XHTML::HTML
- Jabber::XMPPElement
- Jabber::XMPPStanza
- Jabber::XParent
- REXML
- REXML::Element
- REXML::IOSource
- XMLRPC
- XMLRPC::Create
- Base64
- ObservableThing
- QObserver
- ThreadStore

No matching classes.

# Jabber::XHTML::HTML

XHTML-IM (XEP-0071) container

The important methods are:

- HTML#contents=

- HTML#to_text

### Public Class Methods

new(contents=[]) click to toggle source

Initialize element with HTML contents (see HTML#contents=)

    # File lib/xmpp4r/xhtml/html.rb, line 20
    def initialize(contents=[])
      super()
      self.contents = contents
    end

### Public Instance Methods

body() click to toggle source

Get first XHTML::Body child

    # File lib/xmpp4r/xhtml/html.rb, line 27
    def body
      first_element('body') || add(Body.new)
    end

body=(body) click to toggle source

Replace first XHTML::Body child

    # File lib/xmpp4r/xhtml/html.rb, line 33
    def body=(body)
      delete_elements('body')
      add(body)
    end

contents=(contents) click to toggle source

Set contents of this HTML document. The "contents" parameter can be:

- An Array of REXML::Element and Strings which will replace the current children of the body

- A single REXML::Element which will replace all other children of the body

- An instance of XHTML::Body which will replace the current body

- A String comprising an HTML fragment. This will be parsed, which could raise an Exception. We must never send invalid XML over an XMPP stream. If you intend to put variable data in your HTML, use something like Rails' Builder::XmlMarkup or Ramaze::Gestalt

    # File lib/xmpp4r/xhtml/html.rb, line 53
    def contents=(contents)
      if contents.kind_of? String
        self.body = REXML::Document.new("<body xmlns='#{NS_XHTML}'>#{contents}</body>").root
      elsif contents.kind_of? Body
        self.body = contents
      elsif contents.kind_of? Array
        self.body = Body.new
        contents.each do |element|
          if element.kind_of? String
            body.add_text(element)
          else
            body.add(element)
          end
        end
      else
        self.body = Body.new
        body.add(contents)
      end
    end

set_body(body) click to toggle source

Replace first XHTML::Body child (chainable)

    # File lib/xmpp4r/xhtml/html.rb, line 40
    def set_body(body)
      self.body = body
      self
    end

set_contents(contents) click to toggle source

HTML#contents= chainable

    # File lib/xmpp4r/xhtml/html.rb, line 75
    def set_contents(contents)
      self.contents = contents
      self
    end

to_text() click to toggle source

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
    def to_text
      text_getter = nil # Create binding so that the following lambda can work recursively

      text_getter = lambda do |element|
        if element.kind_of? REXML::Text
          element.value
        elsif element.kind_of? REXML::Element
          element.children.collect { |child|
            text_getter.call(child)
          }.join
        end
      end

      text_getter.call(self) # Finally, execute and return results
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.