netshade-oembed_links 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +6 -0
- data/Rakefile +1 -1
- data/lib/oembed_links.rb +3 -1
- data/lib/oembed_links/response.rb +9 -1
- data/oembed_links.gemspec +1 -1
- data/spec/oembed_links_spec.rb +13 -0
- metadata +1 -1
data/History.txt
CHANGED
data/Rakefile
CHANGED
data/lib/oembed_links.rb
CHANGED
@@ -7,7 +7,7 @@ class OEmbed
|
|
7
7
|
def initialize(provider, url, response_object)
|
8
8
|
@provider = provider
|
9
9
|
@url = url
|
10
|
-
@response = response_object
|
10
|
+
@response = response_object || {}
|
11
11
|
@rendered_via_provider = @rendered_via_regex = @rendered_via_type = false
|
12
12
|
@rendered = nil
|
13
13
|
end
|
@@ -22,6 +22,14 @@ class OEmbed
|
|
22
22
|
@rendered || self.to_s
|
23
23
|
end
|
24
24
|
|
25
|
+
|
26
|
+
# Case where url has not matched at all
|
27
|
+
def none?(*args, &block)
|
28
|
+
if @response.keys.empty? && !has_rendered?
|
29
|
+
return render_content(*args, &block)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
25
33
|
# Test if this response has been returned from
|
26
34
|
# the given provider_name.
|
27
35
|
def from?(provider_name, *args, &block)
|
data/oembed_links.gemspec
CHANGED
data/spec/oembed_links_spec.rb
CHANGED
@@ -122,6 +122,7 @@ describe OEmbed, "transforming functions" do
|
|
122
122
|
|
123
123
|
it "should always give priority to provider conditional blocks" do
|
124
124
|
OEmbed.transform("http://test1.net/foo") do |r, url|
|
125
|
+
r.none? { "none" }
|
125
126
|
r.any? { |a| "any" }
|
126
127
|
r.video? { |v| "video" }
|
127
128
|
r.from?(:test1) { |t| "test1" }
|
@@ -131,6 +132,7 @@ describe OEmbed, "transforming functions" do
|
|
131
132
|
|
132
133
|
it "should always give priority regex conditional blocks over all others except provider" do
|
133
134
|
OEmbed.transform("http://test1.net/foo") do |r, url|
|
135
|
+
r.none? { "none" }
|
134
136
|
r.any? { |a| "any" }
|
135
137
|
r.video? { |v| "video" }
|
136
138
|
r.matches?(/./) { |m| "regex" }
|
@@ -144,6 +146,7 @@ describe OEmbed, "transforming functions" do
|
|
144
146
|
|
145
147
|
it "should recognize the type of content and handle the conditional block appropriately" do
|
146
148
|
OEmbed.transform("http://test1.net/foo") do |r, url|
|
149
|
+
r.none? { "none" }
|
147
150
|
r.any? { |a| "any" }
|
148
151
|
r.video? { |v| "video" }
|
149
152
|
end.should == "video"
|
@@ -166,6 +169,16 @@ describe OEmbed, "transforming functions" do
|
|
166
169
|
end.should == "foo"
|
167
170
|
end
|
168
171
|
|
172
|
+
it "should pass control to the .none? block if no scheme matched" do
|
173
|
+
OEmbed.transform("http://not.a.valid.url.host/fake") do |r, url|
|
174
|
+
r.none? { "nomatch" }
|
175
|
+
r.audio? { |a| "audio" }
|
176
|
+
r.hedgehog? { |v| "hedgey"}
|
177
|
+
r.from?(:test2) { |t| "test2" }
|
178
|
+
r.matches?(/baz/) { |m| "regex" }
|
179
|
+
end.should == "nomatch"
|
180
|
+
end
|
181
|
+
|
169
182
|
it "should allow templates to be used to process the output" do
|
170
183
|
url_provides({
|
171
184
|
"url" => "template!"
|