Module: Onebox::Engine
- Included in:
- AmazonOnebox, AudioOnebox, ClassicGoogleMapsOnebox, GithubBlobOnebox, GithubCommitOnebox, GithubGistOnebox, GithubIssueOnebox, GithubPullRequestOnebox, GooglePlayAppOnebox, ImageOnebox, PubmedOnebox, StackExchangeOnebox, TwitterStatusOnebox, VideoOnebox, WhitelistedGenericOnebox, WikipediaOnebox, 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/video_onebox.rb,
lib/onebox/engine/amazon_onebox.rb,
lib/onebox/engine/pubmed_onebox.rb,
lib/onebox/engine/standard_embed.rb,
lib/onebox/engine/youtube_onebox.rb,
lib/onebox/engine/wikipedia_onebox.rb,
lib/onebox/engine/github_blob_onebox.rb,
lib/onebox/engine/github_gist_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_play_app_onebox.rb,
lib/onebox/engine/github_pullrequest_onebox.rb,
lib/onebox/engine/classic_google_maps_onebox.rb,
lib/onebox/engine/whitelisted_generic_onebox.rb
Defined Under Namespace
Modules: ClassMethods, HTML, JSON, StandardEmbed Classes: AmazonOnebox, AudioOnebox, ClassicGoogleMapsOnebox, GithubBlobOnebox, GithubCommitOnebox, GithubGistOnebox, GithubIssueOnebox, GithubPullRequestOnebox, GooglePlayAppOnebox, ImageOnebox, PubmedOnebox, StackExchangeOnebox, TwitterStatusOnebox, VideoOnebox, WhitelistedGenericOnebox, WikipediaOnebox, YoutubeOnebox
Constant Summary collapse
- DEFUALT =
{}
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #initialize(link, cache = nil, timeout = nil) ⇒ Object
- #options ⇒ Object
- #options=(opt) ⇒ Object
-
#placeholder_html ⇒ Object
Some oneboxes create iframes or other complicated controls.
-
#to_html ⇒ Object
raises error if not defined in onebox engine.
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
14 15 16 |
# File 'lib/onebox/engine.rb', line 14 def cache @cache end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
15 16 17 |
# File 'lib/onebox/engine.rb', line 15 def timeout @timeout end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
13 14 15 |
# File 'lib/onebox/engine.rb', line 13 def url @url end |
Class Method Details
.engines ⇒ Object
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 |
# File 'lib/onebox/engine.rb', line 33 def initialize(link, cache = nil, timeout = nil) @options = DEFUALT class_name = self.class.name.split("::").last.to_s self. = Onebox.[class_name] || {} #Set the engine options extracted from global options. @url = link @cache = cache || Onebox..cache @timeout = timeout || Onebox..timeout end |
#options ⇒ Object
18 19 20 |
# File 'lib/onebox/engine.rb', line 18 def @options end |
#options=(opt) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/onebox/engine.rb', line 22 def (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_html ⇒ Object
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.
58 59 60 |
# File 'lib/onebox/engine.rb', line 58 def placeholder_html to_html end |
#to_html ⇒ Object
raises error if not defined in onebox engine. This is the output method for an engine.
46 47 48 |
# File 'lib/onebox/engine.rb', line 46 def to_html fail NoMethodError, "Engines need to implement this method" end |