Skip to content

Commit

Permalink
Merge branch 'master' of github.com:kaspergrubbe/embedda
Browse files Browse the repository at this point in the history
  • Loading branch information
kaspergrubbe committed Mar 17, 2013
2 parents 78936c5 + b8c7460 commit cba0f6f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lib/embedda.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def embedda
private
def youtube_replace(compiled)
compiled.gsub!(/<a[^>]*?youtube\.com\/watch\?v=([a-zA-Z0-9\-\_]+).*?<\/a>/i, youtube_player("\\1"))
compiled.gsub!(/[http|https]+:\/\/(?:www\.)?youtube\.com\/watch\?v=([a-zA-Z0-9\-\_]+)\S*/i, youtube_player("\\1"))
compiled.gsub!(/[http|https]+:\/\/(?:www\.)?youtube\.com\/watch\?v=([a-zA-Z0-9\-\_]+)\w*/i, youtube_player("\\1"))

return compiled
end
Expand All @@ -19,7 +19,7 @@ def youtube_player(token)

def vimeo_replace(compiled)
compiled.gsub!(/<a[^>]*?vimeo\.com\/(\d+).*?<\/a>/i, vimeo_player("\\1"))
compiled.gsub!(/[http|https]+:\/\/(?:www\.)?vimeo\.com\/(\d+)\S*/i, vimeo_player("\\1"))
compiled.gsub!(/[http|https]+:\/\/(?:www\.)?vimeo\.com\/(\d+)\w*/i, vimeo_player("\\1"))

return compiled
end
Expand Down
26 changes: 18 additions & 8 deletions spec/embedda_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@
expect(story).to eq(@embed_string)
end

it "should embed when text have a link with feature_embed" do
story = "http://www.youtube.com/watch?feature=player_embedded&v=dQw4w9WgXcQ".embedda
# expect(story).to eq(@embed_string)
end

it "should embed when also other text is present around link" do
story = "Hello, my name is Kasper: http://www.youtube.com/watch?v=dQw4w9WgXcQ <br/>And I am embedding links".embedda
expect(story).to eq("Hello, my name is Kasper: #{@embed_string} <br/>And I am embedding links")
story = "Hello, my name is Kasper: http://www.youtube.com/watch?v=dQw4w9WgXcQ<br/>And I am embedding links".embedda
expect(story).to eq("Hello, my name is Kasper: #{@embed_string}<br/>And I am embedding links")
end

it "should embed when text include anchor tag to Youtube" do
Expand All @@ -23,8 +28,13 @@
end

it "should embed when also other text is present around anchor tag" do
story = "Hello, my name is Kasper: <a href=\"http://www.youtube.com/watch?v=dQw4w9WgXcQ\">Look here for HalfLife3!</a> <br/>And I am embedding links".embedda
expect(story).to eq("Hello, my name is Kasper: #{@embed_string} <br/>And I am embedding links")
story = "Hello, my name is Kasper: <b><a href=\"http://www.youtube.com/watch?v=dQw4w9WgXcQ\">Look here for HalfLife3!</a><br/></b>And I am embedding links".embedda
expect(story).to eq("Hello, my name is Kasper: <b>#{@embed_string}<br/></b>And I am embedding links")
end

it "should embed when content is around the link" do
story = "\n\nMy suggestions for getting ready for the dreadful monday we all hate:\n\nhttp://www.youtube.com/watch?v=dQw4w9WgXcQ\n\n".embedda
expect(story).to eq("\n\nMy suggestions for getting ready for the dreadful monday we all hate:\n\n#{@embed_string}\n\n")
end
end

Expand All @@ -39,8 +49,8 @@
end

it "should embed when also other text is present around link" do
story = "Hello, my name is Kasper: http://vimeo.com/20241459 <br/>And I am embedding links".embedda
expect(story).to eq("Hello, my name is Kasper: #{@embed_string} <br/>And I am embedding links")
story = "Hello, my name is Kasper: http://vimeo.com/20241459<br/>And I am embedding links".embedda
expect(story).to eq("Hello, my name is Kasper: #{@embed_string}<br/>And I am embedding links")
end

it "should embed when text include anchor tag to Youtube" do
Expand All @@ -49,8 +59,8 @@
end

it "should embed when also other text is present around anchor tag" do
story = "Hello, my name is Kasper: <a href=\"http://vimeo.com/20241459\">Look here for HalfLife3!</a> <br/>And I am embedding links".embedda
expect(story).to eq("Hello, my name is Kasper: #{@embed_string} <br/>And I am embedding links")
story = "Hello, my name is Kasper: <a href=\"http://vimeo.com/20241459\">Look here for HalfLife3!</a><br/>And I am embedding links".embedda
expect(story).to eq("Hello, my name is Kasper: #{@embed_string}<br/>And I am embedding links")
end
end
end

0 comments on commit cba0f6f

Please sign in to comment.