class SimpleFormat::Converter
Public Class Methods
new(emoji=nil)
click to toggle source
# File lib/simple_format.rb, line 8 def initialize(emoji=nil) @emoji = emoji if emoji.is_a?(SimpleFormat::Emoji) end
Public Instance Methods
auto_link(string)
click to toggle source
# File lib/simple_format.rb, line 40 def auto_link(string) # 链接转换 @auto_link ||= AutoLink.new @auto_link.all(string) end
emoji_with(string)
click to toggle source
# File lib/simple_format.rb, line 21 def emoji_with(string) # 表情符 转 <img> emoji.replace_emoji_with_images(string) end
html_with(html, options = {})
click to toggle source
# File lib/simple_format.rb, line 25 def html_with(html, options = {}) options = { elements: sanitized_allowed_tags, attributes: { all: sanitized_allowed_attributes } } if options.empty? Sanitize.clean(html, options) end
nl2br(string)
click to toggle source
# File lib/simple_format.rb, line 34 def nl2br(string) # 回车 转 <br /> if string string.gsub("\n\r","<br />").gsub("\r", "").gsub("\n", "<br />") end end
rich_with(string)
click to toggle source
# File lib/simple_format.rb, line 12 def rich_with(string) # 转 富文本 return string unless string string = emoji_with(string) string = nl2br(string).to_str string = auto_link(string) string = html_with(string) return string end
text_with(string)
click to toggle source
# File lib/simple_format.rb, line 30 def text_with(string) # 清除 html Sanitize.clean(string, {elements: [], attributes: { all: [] }}) end
Private Instance Methods
emoji()
click to toggle source
# File lib/simple_format.rb, line 47 def emoji @emoji || Emoji.new end
sanitized_allowed_attributes()
click to toggle source
# File lib/simple_format.rb, line 55 def sanitized_allowed_attributes ['shape', 'coords', 'target', 'href', 'muted', 'volume', 'name', 'class', 'title', 'border', 'poster', 'loop', 'autoplay', 'allowfullscreen', 'fullscreen', 'align' , 'quality', 'allowscriptaccess', 'wmode', 'flashvars', 'webkit-playsinline', 'x-webkit-airplay', 'data-original', 'src', 'controls', 'preload', 'type', 'width', 'height', 'size', 'alt'] end