2013-02-05 14:16:51 -05:00
|
|
|
require_dependency 'oneboxer/handlebars_onebox'
|
|
|
|
|
|
|
|
module Oneboxer
|
|
|
|
class OpenGraphOnebox < HandlebarsOnebox
|
|
|
|
|
|
|
|
def template
|
|
|
|
template_path('simple_onebox')
|
|
|
|
end
|
|
|
|
|
|
|
|
def onebox
|
|
|
|
# We expect to have the options we need already
|
|
|
|
return nil unless @opts.present?
|
|
|
|
|
|
|
|
# A site is supposed to supply all the basic og attributes, but some don't (like deviant art)
|
|
|
|
# If it just has image and no title, embed it as an image.
|
2013-03-04 19:42:44 -05:00
|
|
|
return BaseOnebox.image_html(@opts['image'], nil, @url) if @opts['image'].present? && @opts['title'].blank?
|
2013-02-05 14:16:51 -05:00
|
|
|
|
|
|
|
@opts['title'] ||= @opts['description']
|
|
|
|
return nil if @opts['title'].blank?
|
|
|
|
|
|
|
|
@opts[:original_url] = @url
|
|
|
|
@opts[:text] = @opts['description']
|
2013-02-19 12:06:35 -05:00
|
|
|
@opts[:unsafe] = true
|
2013-03-01 18:46:55 -05:00
|
|
|
@opts[:host] = nice_host
|
2013-02-05 14:16:51 -05:00
|
|
|
|
|
|
|
Mustache.render(File.read(template), @opts)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|