Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opening template name to public #145

Merged
merged 8 commits into from
Oct 1, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/onebox/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def initialize(link, cache = nil, timeout = nil)
@url = link
@cache = cache || Onebox.defaults.cache
@timeout = timeout || Onebox.defaults.timeout
@view = View.new(template_name, true)
@view = View.new(self.class.template_name, true)
end

def to_html
Expand All @@ -42,11 +42,6 @@ def raw
raise NoMethodError, "Engines need to implement this method"
end

# calculates handlebars template name for onebox using name of engine
def template_name
self.class.name.split("::").last.downcase.gsub(/onebox/, "")
end

# raises error if not defined in onebox engine
# in each onebox, returns hash of desired onebox content
def data
Expand All @@ -65,6 +60,11 @@ def ===(object)
def matches(&block)
class_variable_set :@@matcher, Hexpress.new(&block).to_r
end

# calculates handlebars template name for onebox using name of engine
def template_name
name.split("::").last.downcase.gsub(/onebox/, "")
end
end
end
end
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion spec/lib/onebox/engine/amazon_onebox_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe Onebox::Engine::AmazonOnebox do
before(:all) do
@link = "http://www.amazon.com/Knit-Noro-Accessories-Colorful-Little/dp/193609620X"
fake(@link, response("amazon"))
fake(@link, response(described_class.template_name))
end
before(:each) { Onebox.defaults.cache.clear }

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/onebox/engine/bliptv_onebox_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe Onebox::Engine::BliptvOnebox do
before(:all) do
@link = "http://blip.tv"
fake(@link, response("bliptv"))
fake(@link, response(described_class.template_name))
end
before(:each) { Onebox.defaults.cache.clear }

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/onebox/engine/clikthrough_onebox_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe Onebox::Engine::ClikThroughOnebox do
before(:all) do
@link = "http://www.clikthrough.com/theater/video/49/en-US"
fake(@link, response("clikthrough"))
fake(@link, response(described_class.template_name))
end
before(:each) { Onebox.defaults.cache.clear }

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/onebox/engine/college_humor_onebox_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe Onebox::Engine::CollegeHumorOnebox do
before(:all) do
@link = "http://collegehumor.com"
fake(@link, response("collegehumor"))
fake(@link, response(described_class.template_name))
end
before(:each) { Onebox.defaults.cache.clear }

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/onebox/engine/dailymotion_onebox_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe Onebox::Engine::DailymotionOnebox do
before(:all) do
@link = "http://dailymotion.com"
fake(@link, response("dailymotion"))
fake(@link, response(described_class.template_name))
end
before(:each) { Onebox.defaults.cache.clear }

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/onebox/engine/dotsub_onebox_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe Onebox::Engine::DotsubOnebox do
before(:all) do
@link = "http://dotsub.com/view/665bd0d5-a9f4-4a07-9d9e-b31ba926ca78"
fake(@link, response("dotsub"))
fake(@link, response(described_class.template_name))
end
before(:each) { Onebox.defaults.cache.clear }

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/onebox/engine/example_onebox_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe Onebox::Engine::ExampleOnebox do
before(:all) do
@link = "http://example.com"
fake(@link, response("example"))
fake(@link, response(described_class.template_name))
end
before(:each) { Onebox.defaults.cache.clear }

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/onebox/engine/flickr_onebox_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe Onebox::Engine::FlickrOnebox do
before(:all) do
@link = "http://flickr.com"
fake(@link, response("flickr"))
fake(@link, response(described_class.template_name))
end
before(:each) { Onebox.defaults.cache.clear }

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/onebox/engine/funny_or_die_onebox_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe Onebox::Engine::FunnyOrDieOnebox do
before(:all) do
@link = "http://funnyordie.com"
fake(@link, response("funnyordie"))
fake(@link, response(described_class.template_name))
end
before(:each) { Onebox.defaults.cache.clear }

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/onebox/engine/github_commit_onebox_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe Onebox::Engine::GithubCommitOnebox do
before(:all) do
@link = "https://github.com/discourse/discourse/commit/803d023e2307309f8b776ab3b8b7e38ba91c0919"
fake(@link, response("github_commit"))
fake(@link, response(described_class.template_name))
end
before(:each) { Onebox.defaults.cache.clear }

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/onebox/engine/github_gist_onebox_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe Onebox::Engine::GithubGistOnebox do
before(:all) do
@link = "https://gist.github.com/anikalindtner/153044e9bea3331cc103"
fake(@link, response("github_gist"))
fake(@link, response(described_class.template_name))
end
before(:each) { Onebox.defaults.cache.clear }

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/onebox/engine/github_pullrequest_onebox_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe Onebox::Engine::GithubPullRequestOnebox do
let(:link) { "https://github.com/discourse/discourse/pull/1253/" }
before do
fake(link, response("github_pullrequest"))
fake(link, response("githubpullrequest"))
end

it_behaves_like "an engine"
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/onebox/engine/hulu_onebox_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe Onebox::Engine::HuluOnebox do
before(:all) do
@link = "http://www.hulu.com/watch/515146"
fake(@link, response("hulu"))
fake(@link, response(described_class.template_name))
end
before(:each) { Onebox.defaults.cache.clear }

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/onebox/engine/imgur_image_onebox_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe Onebox::Engine::ImgurImageOnebox do
before(:all) do
@link = "http://imgur.com/gallery/twoDTCU"
fake(@link, response("imgur_image"))
fake(@link, response(described_class.template_name))
end
before(:each) { Onebox.defaults.cache.clear }

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/onebox/engine/json_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe Onebox::Engine::JSON do
before(:all) do
@link = "http://gist.github.com"
fake(@link, response("github_gist"))
fake(@link, response("githubgist"))
end
before(:each) { Onebox.defaults.cache.clear }

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/onebox/engine/nfb_onebox_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe Onebox::Engine::NFBOnebox do
before(:all) do
@link = "http://www.nfb.ca/film/overdose"
fake(@link, response("nfb"))
fake(@link, response(described_class.template_name))
end
before(:each) { Onebox.defaults.cache.clear }

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/onebox/engine/qik_onebox_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe Onebox::Engine::QikOnebox do
before(:all) do
@link = "http://qik.com/video/13430626"
fake(@link, response("qik"))
fake(@link, response(described_class.template_name))
end
before(:each) { Onebox.defaults.cache.clear }

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/onebox/engine/revision3_onebox_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe Onebox::Engine::Revision3Onebox do
before(:all) do
@link = "http://revision3.com/discoverysharks/blue-sharks"
fake(@link, response("revision3"))
fake(@link, response(described_class.template_name))
end
before(:each) { Onebox.defaults.cache.clear }

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/onebox/engine/slideshare_onebox_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe Onebox::Engine::SlideshareOnebox do
before(:all) do
@link = "http://www.slideshare.net/TravelWorldPassport/12-local-traditions"
fake(@link, response("slideshare"))
fake(@link, response(described_class.template_name))
end
before(:each) { Onebox.defaults.cache.clear }

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/onebox/engine/sound_cloud_onebox_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe Onebox::Engine::SoundCloudOnebox do
before(:all) do
@link = "https://soundcloud.com/rac/penguin-prison-worse-it-gets-rac-mix"
fake(@link, response("soundcloud"))
fake(@link, response(described_class.template_name))
end
before(:each) { Onebox.defaults.cache.clear }

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/onebox/engine/spotify_onebox_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe Onebox::Engine::SpotifyOnebox do
before(:all) do
@link = "http://open.spotify.com/album/3eEtlM70GU40OyHMotY15N"
fake(@link, response("spotify"))
fake(@link, response(described_class.template_name))
end
before(:each) { Onebox.defaults.cache.clear }

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/onebox/engine/stack_exchange_onebox_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe Onebox::Engine::StackExchangeOnebox do
before(:all) do
@link = "http://stackoverflow.com/questions/17992553/concept-behind-these-four-lines-of-tricky-c-code"
fake(@link, response("stackexchange"))
fake(@link, response(described_class.template_name))
end
before(:each) { Onebox.defaults.cache.clear }

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/onebox/engine/ted_onebox_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe Onebox::Engine::TedOnebox do
before(:all) do
@link = "http://www.ted.com/talks/eli_beer_the_fastest_ambulance_a_motorcycle.html"
fake(@link, response("ted"))
fake(@link, response(described_class.template_name))
end
before(:each) { Onebox.defaults.cache.clear }

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/onebox/engine/viddler_onebox_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe Onebox::Engine::ViddlerOnebox do
before(:all) do
@link = "http://www.viddler.com/v/7164f749"
fake(@link, response("viddler"))
fake(@link, response(described_class.template_name))
end
before(:each) { Onebox.defaults.cache.clear }

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/onebox/engine/vimeo_onebox_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe Onebox::Engine::VimeoOnebox do
before(:all) do
@link = "http://vimeo.com/70437049"
fake(@link, response("vimeo"))
fake(@link, response(described_class.template_name))
end
before(:each) { Onebox.defaults.cache.clear }

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/onebox/engine/wikipedia_onebox_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe Onebox::Engine::WikipediaOnebox do
before(:all) do
@link = "http://en.wikipedia.org/wiki/Kevin_Bacon"
fake(@link, response("wikipedia"))
fake(@link, response(described_class.template_name))
end
before(:each) { Onebox.defaults.cache.clear }

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/onebox/engine/yfrog_onebox_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
before(:each) { Onebox.defaults.cache.clear }
before(:all) do
@link = "http://twitter.yfrog.com/h0jjdobj?sa=0"
fake(@link, response("yfrog"))
fake(@link, response(described_class.template_name))
end

let(:link) { @link }
Expand Down
49 changes: 34 additions & 15 deletions spec/lib/onebox/engine_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def view
end

describe "#record" do
class OneboxEngineBar
class OneboxEngineRecord
include Onebox::Engine

def data
Expand All @@ -42,39 +42,58 @@ def data

it "returns cached value for given url if its url is already in cache" do
cache = { "http://example.com" => "old content" }
result = OneboxEngineBar.new("http://example.com", cache).send(:record)
result = OneboxEngineRecord.new("http://example.com", cache).send(:record)
expect(result).to eq("old content")
end

it "stores cache value for given url if cache key doesn't exist" do
cache = { "http://example.com1" => "old content" }
result = OneboxEngineBar.new("http://example.com", cache).send(:record)
result = OneboxEngineRecord.new("http://example.com", cache).send(:record)
expect(result).to eq("new content")
end
end

describe ".===" do
class OneboxEngineTripleEqual
include Onebox::Engine
@@matcher = /example/
end
it "returns true if argument matches the matcher" do
class OneboxEngineFoo
include Onebox::Engine
@@matcher = /example/
end
result = OneboxEngineFoo === "http://www.example.com/product/5?var=foo&bar=5"
result = OneboxEngineTripleEqual === "http://www.example.com/product/5?var=foo&bar=5"
expect(result).to eq(true)
end
end

describe ".matches" do
it "sets @@matcher to a regular expression" do
class OneboxEngineFar
include Onebox::Engine
class OneboxEngineMatches
include Onebox::Engine

matches do
find "foo.com"
end
matches do
find "foo.com"
end
regex = OneboxEngineFar.class_variable_get(:@@matcher)
end

it "sets @@matcher to a regular expression" do
regex = OneboxEngineMatches.class_variable_get(:@@matcher)
expect(regex).to be_a(Regexp)
end
end

describe ".template_name" do
module ScopeForTemplateName
class TemplateNameOnebox
include Onebox::Engine
end
end

let(:template_name) { ScopeForTemplateName::TemplateNameOnebox.template_name }

it "should not include the scope" do
expect(template_name).not_to include("ScopeForTemplateName", "scopefortemplatename")
end

it "should not include the word Onebox" do
expect(template_name).not_to include("onebox", "Onebox")
end
end
end