Object
@group Extension API
# File lib/prawn/text/formatted/parser.rb, line 35 def self.format(string, *args) tokens = string.gsub(/<br\s*\/?>/, "\n").scan(PARSER_REGEX) self.array_from_tokens(tokens) end
# File lib/prawn/text/formatted/parser.rb, line 40 def self.to_string(array) prefixes = { :bold => "<b>", :italic => "<i>", :underline => "<u>", :strikethrough => "<strikethrough>", :subscript => "<sub>", :superscript => "<sup>" } suffixes = { :bold => "</b>", :italic => "</i>", :underline => "</u>", :strikethrough => "</strikethrough>", :subscript => "</sub>", :superscript => "</sup>" } array.collect do |hash| prefix = "" suffix = "" if hash[:styles] hash[:styles].each do |style| prefix = prefix + prefixes[style] suffix = suffixes[style] + suffix end end font = hash[:font] ? " name='#{hash[:font]}'" : nil size = hash[:size] ? " size='#{hash[:size]}'" : nil if hash[:character_spacing] character_spacing = " character_spacing='#{hash[:character_spacing]}'" else character_spacing = nil end if font || size || character_spacing prefix = prefix + "<font#{font}#{size}#{character_spacing}>" suffix = "</font>" end link = hash[:link] ? " href='#{hash[:link]}'" : nil anchor = hash[:anchor] ? " anchor='#{hash[:anchor]}'" : nil if link || anchor prefix = prefix + "<link#{link}#{anchor}>" suffix = "</link>" end if hash[:color] if hash[:color].kind_of?(Array) prefix = prefix + "<color c='#{hash[:color][0]}'" + " m='#{hash[:color][1]}'" + " y='#{hash[:color][2]}'" + " k='#{hash[:color][3]}'>" else prefix = prefix + "<color rgb='#{hash[:color]}'>" end suffix = "</color>" end string = hash[:text].gsub("&", "&").gsub(">", ">").gsub("<", "<") prefix + string + suffix end.join end
Generated with the Darkfish Rdoc Generator 2.