Module: Onebox::Engine

Included in:
AmazonOnebox, AsciinemaOnebox, AudioOnebox, AudioboomOnebox, BandCampOnebox, CoubOnebox, DoubanOnebox, FiveHundredPxOnebox, FlickrOnebox, FlickrShortenedOnebox, GfycatOnebox, GiphyOnebox, GithubBlobOnebox, GithubCommitOnebox, GithubGistOnebox, GithubIssueOnebox, GithubPullRequestOnebox, GoogleCalendarOnebox, GoogleDocsOnebox, GoogleMapsOnebox, GooglePlayAppOnebox, ImageOnebox, ImgurOnebox, MixcloudOnebox, PastebinOnebox, PdfOnebox, PubmedOnebox, ReplitOnebox, SketchFabOnebox, SlidesOnebox, SoundCloudOnebox, StackExchangeOnebox, SteamStoreOnebox, TwitterStatusOnebox, TypeformOnebox, VideoOnebox, VimeoOnebox, WhitelistedGenericOnebox, WikimediaOnebox, WikipediaOnebox, XkcdOnebox, YoukuOnebox, YoutubeOnebox
Defined in:
lib/onebox/engine.rb,
lib/onebox/engine/html.rb,
lib/onebox/engine/json.rb,
lib/onebox/engine/pdf_onebox.rb,
lib/onebox/engine/coub_onebox.rb,
lib/onebox/engine/xkcd_onebox.rb,
lib/onebox/engine/audio_onebox.rb,
lib/onebox/engine/giphy_onebox.rb,
lib/onebox/engine/image_onebox.rb,
lib/onebox/engine/imgur_onebox.rb,
lib/onebox/engine/video_onebox.rb,
lib/onebox/engine/vimeo_onebox.rb,
lib/onebox/engine/youku_onebox.rb,
lib/onebox/engine/amazon_onebox.rb,
lib/onebox/engine/douban_onebox.rb,
lib/onebox/engine/flickr_onebox.rb,
lib/onebox/engine/gfycat_onebox.rb,
lib/onebox/engine/pubmed_onebox.rb,
lib/onebox/engine/replit_onebox.rb,
lib/onebox/engine/slides_onebox.rb,
lib/onebox/engine/standard_embed.rb,
lib/onebox/engine/youtube_onebox.rb,
lib/onebox/engine/bandcamp_onebox.rb,
lib/onebox/engine/mixcloud_onebox.rb,
lib/onebox/engine/opengraph_image.rb,
lib/onebox/engine/pastebin_onebox.rb,
lib/onebox/engine/typeform_onebox.rb,
lib/onebox/engine/asciinema_onebox.rb,
lib/onebox/engine/audioboom_onebox.rb,
lib/onebox/engine/sketchfab_onebox.rb,
lib/onebox/engine/wikimedia_onebox.rb,
lib/onebox/engine/wikipedia_onebox.rb,
lib/onebox/engine/soundcloud_onebox.rb,
lib/onebox/engine/github_blob_onebox.rb,
lib/onebox/engine/github_gist_onebox.rb,
lib/onebox/engine/google_docs_onebox.rb,
lib/onebox/engine/google_maps_onebox.rb,
lib/onebox/engine/steam_store_onebox.rb,
lib/onebox/engine/github_issue_onebox.rb,
lib/onebox/engine/github_commit_onebox.rb,
lib/onebox/engine/stack_exchange_onebox.rb,
lib/onebox/engine/twitter_status_onebox.rb,
lib/onebox/engine/five_hundred_px_onebox.rb,
lib/onebox/engine/google_calendar_onebox.rb,
lib/onebox/engine/google_play_app_onebox.rb,
lib/onebox/engine/flickr_shortened_onebox.rb,
lib/onebox/engine/github_pullrequest_onebox.rb,
lib/onebox/engine/whitelisted_generic_onebox.rb

Defined Under Namespace

Modules: ClassMethods, HTML, JSON, OpengraphImage, StandardEmbed Classes: AmazonOnebox, AsciinemaOnebox, AudioOnebox, AudioboomOnebox, BandCampOnebox, CoubOnebox, DoubanOnebox, FiveHundredPxOnebox, FlickrOnebox, FlickrShortenedOnebox, GfycatOnebox, GiphyOnebox, GithubBlobOnebox, GithubCommitOnebox, GithubGistOnebox, GithubIssueOnebox, GithubPullRequestOnebox, GoogleCalendarOnebox, GoogleDocsOnebox, GoogleMapsOnebox, GooglePlayAppOnebox, ImageOnebox, ImgurOnebox, MixcloudOnebox, PastebinOnebox, PdfOnebox, PubmedOnebox, ReplitOnebox, SketchFabOnebox, SlidesOnebox, SoundCloudOnebox, StackExchangeOnebox, SteamStoreOnebox, TwitchClipsOnebox, TwitchStreamOnebox, TwitchVideoOnebox, TwitterStatusOnebox, TypeformOnebox, VideoOnebox, VimeoOnebox, WhitelistedGenericOnebox, WikimediaOnebox, WikipediaOnebox, XkcdOnebox, YoukuOnebox, YoutubeOnebox

Constant Summary collapse

DEFAULT =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache


14
15
16
# File 'lib/onebox/engine.rb', line 14

def cache
  @cache
end

#timeoutObject (readonly)

Returns the value of attribute timeout


15
16
17
# File 'lib/onebox/engine.rb', line 15

def timeout
  @timeout
end

#uriObject (readonly)

Returns the value of attribute uri


13
14
15
# File 'lib/onebox/engine.rb', line 13

def uri
  @uri
end

#urlObject (readonly)

Returns the value of attribute url


13
14
15
# File 'lib/onebox/engine.rb', line 13

def url
  @url
end

Class Method Details

.enginesObject


7
8
9
10
11
# File 'lib/onebox/engine.rb', line 7

def self.engines
  constants.select do |constant|
    constant.to_s =~ /Onebox$/
  end.map(&method(:const_get))
end

.included(object) ⇒ Object


3
4
5
# File 'lib/onebox/engine.rb', line 3

def self.included(object)
  object.extend(ClassMethods)
end

Instance Method Details

#initialize(link, cache = nil, timeout = nil) ⇒ Object


30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/onebox/engine.rb', line 30

def initialize(link, cache = nil, timeout = nil)
  @options = DEFAULT
  class_name = self.class.name.split("::").last.to_s
  self.options = Onebox.options[class_name] || {} #Set the engine options extracted from global options.

  @url = link
  @uri = URI(link)
  if always_https?
    @uri.scheme = 'https'
    @url = @uri.to_s
  end
  @cache = cache || Onebox.options.cache
  @timeout = timeout || Onebox.options.timeout
end

#optionsObject


18
19
20
# File 'lib/onebox/engine.rb', line 18

def options
  @options
end

#options=(opt) ⇒ Object


22
23
24
25
26
27
# File 'lib/onebox/engine.rb', line 22

def options=(opt)
  return @options if opt.nil? #make sure options provided
  opt = opt.to_h  if opt.instance_of?(OpenStruct)
  @options.merge!(opt)
  @options
end

#placeholder_htmlObject

Some oneboxes create iframes or other complicated controls. If you're using a live editor with HTML preview, rendering those complicated controls can be slow or cause flickering.

This method allows engines to produce a placeholder such as static image frame of a video.

By default it just calls `to_html` unless implemented.


59
60
61
# File 'lib/onebox/engine.rb', line 59

def placeholder_html
  to_html
end

#to_htmlObject

raises error if not defined in onebox engine. This is the output method for an engine.


47
48
49
# File 'lib/onebox/engine.rb', line 47

def to_html
  fail NoMethodError, "Engines need to implement this method"
end