mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 07:33:36 +08:00
49 lines
861 B
Ruby
49 lines
861 B
Ruby
require 'open-uri'
|
|
|
|
module Oneboxer
|
|
|
|
class BaseOnebox
|
|
|
|
class << self
|
|
attr_accessor :regexp
|
|
attr_accessor :favicon_file
|
|
|
|
def matcher(regexp=nil,&blk)
|
|
self.regexp = regexp || blk
|
|
end
|
|
|
|
def favicon(favicon_file)
|
|
self.favicon_file = "favicons/#{favicon_file}"
|
|
end
|
|
|
|
def remove_whitespace(s)
|
|
s.gsub /\n/, ''
|
|
end
|
|
|
|
def image_html(url, title, page_url)
|
|
"<a href='#{page_url}' target='_blank'><img src='#{url}' alt='#{title}'></a>"
|
|
end
|
|
|
|
def replace_tags_with_spaces(s)
|
|
s.gsub /<[^>]+>/, ' '
|
|
end
|
|
|
|
def uriencode(val)
|
|
return URI.escape(val, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
|
end
|
|
|
|
end
|
|
|
|
def initialize(url, opts={})
|
|
@url = url
|
|
@opts = opts
|
|
end
|
|
|
|
def translate_url
|
|
@url
|
|
end
|
|
|
|
end
|
|
|
|
end
|