Merge pull request #1439 from zvikara/master

HandlebarsOneboxes: avoid constants multiple declarations
This commit is contained in:
Sam 2013-09-15 19:14:41 -07:00
commit c2ceced747
2 changed files with 20 additions and 12 deletions

View File

@ -2,17 +2,21 @@ require_dependency 'oneboxer/handlebars_onebox'
module Oneboxer module Oneboxer
class StackExchangeOnebox < HandlebarsOnebox class StackExchangeOnebox < HandlebarsOnebox
DOMAINS = [
'stackexchange', unless defined? DOMAINS
'stackoverflow', DOMAINS = [
'superuser', 'stackexchange',
'serverfault', 'stackoverflow',
'askubuntu' 'superuser',
] 'serverfault',
'askubuntu'
]
end
# http://rubular.com/r/V3T0I1VTPn # http://rubular.com/r/V3T0I1VTPn
REGEX = unless defined? REGEX
/^http:\/\/(?:(?:(?<subsubdomain>\w*)\.)?(?<subdomain>\w*)\.)?(?<domain>#{DOMAINS.join('|')})\.com\/(?:questions|q)\/(?<question>\d*)/ REGEX = /^http:\/\/(?:(?:(?<subsubdomain>\w*)\.)?(?<subdomain>\w*)\.)?(?<domain>#{DOMAINS.join('|')})\.com\/(?:questions|q)\/(?<question>\d*)/
end
matcher REGEX matcher REGEX
favicon 'stackexchange.png' favicon 'stackexchange.png'

View File

@ -2,10 +2,14 @@ require_dependency 'oneboxer/handlebars_onebox'
module Oneboxer module Oneboxer
class TwitterOnebox < HandlebarsOnebox class TwitterOnebox < HandlebarsOnebox
BASE_URL = 'https://api.twitter.com'.freeze
REGEX = unless defined? BASE_URL
/^https?:\/\/(?:www\.)?twitter.com\/(?<user>[^\/]+)\/status\/(?<id>\d+)$/ BASE_URL = 'https://api.twitter.com'.freeze
end
unless defined? REGEX
REGEX = /^https?:\/\/(?:www\.)?twitter.com\/(?<user>[^\/]+)\/status\/(?<id>\d+)$/
end
matcher REGEX matcher REGEX