fix onebox for your own site
This commit is contained in:
parent
d237e3bf3b
commit
0f88947279
|
@ -84,7 +84,7 @@ GEM
|
|||
activesupport (= 3.2.11)
|
||||
arel (~> 3.0.2)
|
||||
tzinfo (~> 0.3.29)
|
||||
activerecord-postgres-hstore (0.7.0)
|
||||
activerecord-postgres-hstore (0.7.1)
|
||||
rails
|
||||
rake
|
||||
activeresource (3.2.11)
|
||||
|
@ -100,9 +100,9 @@ GEM
|
|||
arel (3.0.2)
|
||||
barber (0.2.0)
|
||||
execjs
|
||||
better_errors (0.3.2)
|
||||
better_errors (0.5.0)
|
||||
coderay (>= 1.0.0)
|
||||
erubis (>= 2.7.0)
|
||||
erubis (>= 2.6.6)
|
||||
binding_of_caller (0.6.8)
|
||||
bourne (1.1.2)
|
||||
mocha (= 0.10.5)
|
||||
|
@ -158,7 +158,7 @@ GEM
|
|||
pry (>= 0.9.10)
|
||||
terminal-table (>= 1.4.3)
|
||||
thor (>= 0.14.6)
|
||||
guard-jasmine (1.12.1)
|
||||
guard-jasmine (1.12.2)
|
||||
childprocess
|
||||
guard (>= 1.1.0)
|
||||
multi_json
|
||||
|
|
|
@ -31,11 +31,16 @@ class SiteSetting < ActiveRecord::Base
|
|||
client_setting(:flush_timings_secs, 5)
|
||||
|
||||
|
||||
|
||||
# settings only available server side
|
||||
setting(:auto_track_topics_after, 60000)
|
||||
setting(:long_polling_interval, 15000)
|
||||
setting(:flags_required_to_hide_post, 3)
|
||||
setting(:cooldown_minutes_after_hiding_posts, 10)
|
||||
|
||||
# used mainly for dev, force hostname for Discourse.base_url
|
||||
# You would usually use multisite for this
|
||||
setting(:force_hostname, '')
|
||||
setting(:port, Rails.env.development? ? 3000 : '')
|
||||
setting(:enable_private_messages, true)
|
||||
setting(:use_ssl, false)
|
||||
|
|
|
@ -256,6 +256,7 @@ en:
|
|||
system_username: "Username that sends system messages"
|
||||
send_welcome_message: "Do new users get a welcome private message?"
|
||||
port: "If you'd like to specify a port in the URL. Useful in development mode. Leave blank for none."
|
||||
force_hostname: "If you'd like to specify a hostname in the URL. Useful in development mode. Leave blank for none."
|
||||
|
||||
invite_expiry_days: "How long (in days) that invite keys are valid."
|
||||
|
||||
|
|
|
@ -21,8 +21,12 @@ module Discourse
|
|||
def self.base_url
|
||||
protocol = "http"
|
||||
protocol = "https" if SiteSetting.use_ssl?
|
||||
result = "#{protocol}://#{current_hostname}"
|
||||
result << ":#{SiteSetting.port}" if SiteSetting.port.present?
|
||||
if SiteSetting.force_hostname.present?
|
||||
result = "#{protocol}://#{SiteSetting.force_hostname}"
|
||||
else
|
||||
result = "#{protocol}://#{current_hostname}"
|
||||
end
|
||||
result << ":#{SiteSetting.port}" if SiteSetting.port.present? && SiteSetting.port.to_i > 0
|
||||
result
|
||||
end
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ module Oneboxer
|
|||
# Return a oneboxer for a given URL
|
||||
def self.onebox_for_url(url)
|
||||
matchers.each do |regexp, oneboxer|
|
||||
regexp = regexp.call if regexp.class == Proc
|
||||
return oneboxer.new(url) if url =~ regexp
|
||||
end
|
||||
nil
|
||||
|
|
|
@ -19,7 +19,6 @@ module Oneboxer
|
|||
result['description'] = node['content'] if node
|
||||
end
|
||||
|
||||
|
||||
result
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,8 +8,8 @@ module Oneboxer
|
|||
attr_accessor :regexp
|
||||
attr_accessor :favicon_file
|
||||
|
||||
def matcher(regexp)
|
||||
self.regexp = regexp
|
||||
def matcher(regexp=nil,&blk)
|
||||
self.regexp = regexp || blk
|
||||
end
|
||||
|
||||
def favicon(favicon_file)
|
||||
|
|
|
@ -5,8 +5,9 @@ module Oneboxer
|
|||
class DiscourseOnebox < BaseOnebox
|
||||
include ActionView::Helpers::DateHelper
|
||||
|
||||
# TODO: we need to remove these hardcoded urls ASAP
|
||||
matcher /^https?\:\/\/(dev.discourse.org|localhost\:3000|l.discourse|discuss.emberjs.com)\/.*$/
|
||||
matcher do
|
||||
Regexp.new "^#{Discourse.base_url.gsub(".","\\.")}.*$", true
|
||||
end
|
||||
|
||||
def onebox
|
||||
uri = URI::parse(@url)
|
||||
|
|
|
@ -1,6 +1,40 @@
|
|||
require 'spec_helper'
|
||||
require 'oneboxer'
|
||||
|
||||
describe "Dynamic Oneboxer" do
|
||||
class DummyDynamicOnebox < Oneboxer::BaseOnebox
|
||||
matcher do
|
||||
/^https?:\/\/dummy2.localhost/
|
||||
end
|
||||
|
||||
def onebox
|
||||
"dummy2!"
|
||||
end
|
||||
end
|
||||
|
||||
before do
|
||||
Oneboxer.add_onebox DummyDynamicOnebox
|
||||
@dummy_onebox_url = "http://dummy2.localhost/dummy-object"
|
||||
end
|
||||
|
||||
context 'find onebox for url' do
|
||||
|
||||
it 'returns blank with an unknown url' do
|
||||
Oneboxer.onebox_for_url('http://asdfasdfasdfasdf.asdf').should be_blank
|
||||
end
|
||||
|
||||
it 'returns something when matched' do
|
||||
Oneboxer.onebox_for_url(@dummy_onebox_url).should be_present
|
||||
end
|
||||
|
||||
it 'returns an instance of our class when matched' do
|
||||
Oneboxer.onebox_for_url(@dummy_onebox_url).kind_of?(DummyDynamicOnebox).should be_true
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe Oneboxer do
|
||||
|
||||
# A class to help us test
|
||||
|
@ -12,6 +46,7 @@ describe Oneboxer do
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
before do
|
||||
Oneboxer.add_onebox DummyOnebox
|
||||
@dummy_onebox_url = "http://dummy.localhost/dummy-object"
|
||||
|
@ -129,4 +164,4 @@ describe Oneboxer do
|
|||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue