mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 14:49:07 +08:00
HandlebarsOneboxes: avoid constants multiple declarations
This commit is contained in:
parent
10c4dee67c
commit
b071927ced
|
@ -2,6 +2,8 @@ require_dependency 'oneboxer/handlebars_onebox'
|
|||
|
||||
module Oneboxer
|
||||
class StackExchangeOnebox < HandlebarsOnebox
|
||||
|
||||
unless defined? DOMAINS
|
||||
DOMAINS = [
|
||||
'stackexchange',
|
||||
'stackoverflow',
|
||||
|
@ -9,10 +11,12 @@ module Oneboxer
|
|||
'serverfault',
|
||||
'askubuntu'
|
||||
]
|
||||
end
|
||||
|
||||
# http://rubular.com/r/V3T0I1VTPn
|
||||
REGEX =
|
||||
/^http:\/\/(?:(?:(?<subsubdomain>\w*)\.)?(?<subdomain>\w*)\.)?(?<domain>#{DOMAINS.join('|')})\.com\/(?:questions|q)\/(?<question>\d*)/
|
||||
unless defined? REGEX
|
||||
REGEX = /^http:\/\/(?:(?:(?<subsubdomain>\w*)\.)?(?<subdomain>\w*)\.)?(?<domain>#{DOMAINS.join('|')})\.com\/(?:questions|q)\/(?<question>\d*)/
|
||||
end
|
||||
|
||||
matcher REGEX
|
||||
favicon 'stackexchange.png'
|
||||
|
|
|
@ -2,10 +2,14 @@ require_dependency 'oneboxer/handlebars_onebox'
|
|||
|
||||
module Oneboxer
|
||||
class TwitterOnebox < HandlebarsOnebox
|
||||
BASE_URL = 'https://api.twitter.com'.freeze
|
||||
|
||||
REGEX =
|
||||
/^https?:\/\/(?:www\.)?twitter.com\/(?<user>[^\/]+)\/status\/(?<id>\d+)$/
|
||||
unless defined? BASE_URL
|
||||
BASE_URL = 'https://api.twitter.com'.freeze
|
||||
end
|
||||
|
||||
unless defined? REGEX
|
||||
REGEX = /^https?:\/\/(?:www\.)?twitter.com\/(?<user>[^\/]+)\/status\/(?<id>\d+)$/
|
||||
end
|
||||
|
||||
matcher REGEX
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user