Class: Onebox::Engine::PastebinOnebox
- Inherits:
-
Object
- Object
- Onebox::Engine::PastebinOnebox
- Includes:
- Onebox::Engine, StandardEmbed
- Defined in:
- lib/onebox/engine/pastebin_onebox.rb
Constant Summary
Constants included from Onebox::Engine
Instance Attribute Summary
Attributes included from Onebox::Engine
Instance Method Summary collapse
Methods included from StandardEmbed
add_oembed_provider, add_opengraph_provider, #always_https?, oembed_providers, opengraph_providers, #raw
Methods included from Onebox::Engine
engines, included, #initialize, #options, #options=, #placeholder_html
Instance Method Details
#paste_key ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/onebox/engine/pastebin_onebox.rb', line 9 def paste_key if uri.path =~ /\/raw\// match = uri.path.match(/\/raw\/([^\/]+)/) return match[1] if match && match[1] elsif uri.path =~ /\/download\// match = uri.path.match(/\/download\/([^\/]+)/) return match[1] if match && match[1] elsif uri.path =~ /\/embed\// match = uri.path.match(/\/embed\/([^\/]+)/) return match[1] if match && match[1] else match = uri.path.match(/\/([^\/]+)/) return match[1] if match && match[1] end nil rescue return nil end |
#to_html ⇒ Object
29 30 31 32 33 34 |
# File 'lib/onebox/engine/pastebin_onebox.rb', line 29 def to_html return nil unless paste_key response = Onebox::Helpers.fetch_response("http://pastebin.com/raw/#{paste_key}", 1) return nil unless response && response.code.to_i == 200 return "<iframe src='//pastebin.com/embed_iframe/#{paste_key}' style='border:none;width:100%;max-height:100px;'></iframe>" end |