Skip to content
This repository has been archived by the owner on Mar 20, 2018. It is now read-only.

Commit

Permalink
Add auto-embedding of, well, all sorts of stuff through the magic of …
Browse files Browse the repository at this point in the history
…oEmbed.
  • Loading branch information
hmans committed Feb 20, 2012
1 parent 290569c commit 194a3e7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/schnitzelpress/post.rb
@@ -1,5 +1,11 @@
require 'tilt'
require 'coderay'
require 'oembed'

OEmbed::Providers.register_all
SoundCloundProvider = OEmbed::Provider.new("http://soundcloud.com/oembed")
SoundCloundProvider << "http://*.soundcloud.com/*"
OEmbed::Providers.register(SoundCloundProvider)

module SchnitzelPress
class MarkdownRenderer < Redcarpet::Render::HTML
Expand All @@ -10,12 +16,9 @@ def block_code(code, language)
end

def autolink(link, type)
if link =~ %r{youtube.com\/watch\?v=(.+)$}
youtube_id = $1
%q(<iframe width="600" height="335" src="http://www.youtube.com/embed/%s"></iframe>) % youtube_id
else
%q(<a href="%s">%s</a>) % [link, link]
end
OEmbed::Providers.get(link).html
rescue OEmbed::NotFound
%q(<a href="%s">%s</a>) % [link, link]
end
end

Expand Down
1 change: 1 addition & 0 deletions schnitzelpress.gemspec
Expand Up @@ -37,6 +37,7 @@ Gem::Specification.new do |gem|
gem.add_dependency 'schnitzelstyle', '~> 0.0.4'
gem.add_dependency 'i18n'
gem.add_dependency 'tilt', '~> 1.3.0'
gem.add_dependency 'ruby-oembed'

# CLI related
gem.add_dependency 'thor'
Expand Down

0 comments on commit 194a3e7

Please sign in to comment.