Sha256: f884f2a1ef35af3cbf4ed1c52c361ee930762eca01ff5ad9e85dce54cf15e7e8
Contents?: true
Size: 1.46 KB
Versions: 1
Compression:
Stored size: 1.46 KB
Contents
module Pipio # Basic message with body text (as opposed to pure status messages, which # have no body). class XMLMessage < Message def initialize(sender_screen_name, time, sender_alias, body) super(sender_screen_name, time, sender_alias) @body = normalize(body) @styled_body = %(<div><span style="font-family: Helvetica; font-size: 12pt;">#{@body}</span></div>) end attr_reader :body def to_s %(<message sender="#{@sender_screen_name}" time="#{adium_formatted_time}" alias="#{@sender_alias}">#{@styled_body}</message>\n) end private # Balances mismatched tags, normalizes body style, and fixes actions # so they are in Adium style (Pidgin uses "***Buddy waves at you", Adium uses # "*Buddy waves at you*"). def normalize(string) new_body = normalize_entities(string) # Fix mismatched tags. Yes, it's faster to do it per-message # than all at once. new_body = Pipio::TagBalancer.new(new_body).balance if @sender_alias[0,3] == '***' # "***<alias>" is what pidgin sets as the alias for a /me action @sender_alias.slice!(0,3) new_body = "*#{new_body}*" end new_body end # Escapes all entities in string except for "<", ">", "&", """, # and "'". def normalize_entities(string) # Convert '&' to '&' only if it's not followed by an entity. string.gsub(/&(?!lt|gt|amp|quot|apos)/, '&') end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
pipio-0.0.1 | lib/pipio/messages/xml_message.rb |