Module: Onebox::Engine

Included in:
AmazonOnebox, AudioOnebox, DoubanOnebox, GithubBlobOnebox, GithubCommitOnebox, GithubGistOnebox, GithubIssueOnebox, GithubPullRequestOnebox, GoogleCalendarOnebox, GoogleDocsOnebox, GoogleMapsOnebox, GooglePlayAppOnebox, ImageOnebox, ImgurOnebox, PastebinOnebox, PubmedOnebox, SlidesOnebox, SoundCloudOnebox, StackExchangeOnebox, SteamStoreWidgetOnebox, TwitterStatusOnebox, VideoOnebox, WhitelistedGenericOnebox, WikipediaOnebox, YoukuOnebox, YoutubeOnebox
Defined in:
lib/onebox/engine.rb,
lib/onebox/engine/html.rb,
lib/onebox/engine/json.rb,
lib/onebox/engine/audio_onebox.rb,
lib/onebox/engine/image_onebox.rb,
lib/onebox/engine/imgur_onebox.rb,
lib/onebox/engine/video_onebox.rb,
lib/onebox/engine/youku_onebox.rb,
lib/onebox/engine/amazon_onebox.rb,
lib/onebox/engine/douban_onebox.rb,
lib/onebox/engine/pubmed_onebox.rb,
lib/onebox/engine/slides_onebox.rb,
lib/onebox/engine/standard_embed.rb,
lib/onebox/engine/youtube_onebox.rb,
lib/onebox/engine/pastebin_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/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/google_calendar_onebox.rb,
lib/onebox/engine/google_play_app_onebox.rb,
lib/onebox/engine/github_pullrequest_onebox.rb,
lib/onebox/engine/steam_store_widget_onebox.rb,
lib/onebox/engine/whitelisted_generic_onebox.rb

Defined Under Namespace

Modules: ClassMethods, HTML, JSON, StandardEmbed Classes: AmazonOnebox, AudioOnebox, DoubanOnebox, GithubBlobOnebox, GithubCommitOnebox, GithubGistOnebox, GithubIssueOnebox, GithubPullRequestOnebox, GoogleCalendarOnebox, GoogleDocsOnebox, GoogleMapsOnebox, GooglePlayAppOnebox, ImageOnebox, ImgurOnebox, PastebinOnebox, PubmedOnebox, SlidesOnebox, SoundCloudOnebox, StackExchangeOnebox, SteamStoreWidgetOnebox, TwitterStatusOnebox, VideoOnebox, WhitelistedGenericOnebox, WikipediaOnebox, 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


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/onebox/engine.rb', line 33

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
28
29
30
# File 'lib/onebox/engine.rb', line 22

def options=(opt)
  return @options if opt.nil? #make sure options provided
  if opt.instance_of? OpenStruct
    @options = @options.merge(opt.to_h)
  else
   @options =  @options.merge(opt)
  end
  @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.


63
64
65
# File 'lib/onebox/engine.rb', line 63

def placeholder_html
  to_html
end

#to_htmlObject

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


51
52
53
# File 'lib/onebox/engine.rb', line 51

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