Module: Onebox::Engine
- Included in:
- AllowlistedGenericOnebox, AmazonOnebox, AsciinemaOnebox, AudioOnebox, AudioboomOnebox, BandCampOnebox, CloudAppOnebox, CoubOnebox, FacebookMediaOnebox, FiveHundredPxOnebox, FlickrOnebox, FlickrShortenedOnebox, GfycatOnebox, GiphyOnebox, GithubCommitOnebox, GithubFolderOnebox, GithubGistOnebox, GithubIssueOnebox, GithubPullRequestOnebox, GoogleCalendarOnebox, GoogleDocsOnebox, GoogleDriveOnebox, GoogleMapsOnebox, GooglePhotosOnebox, GooglePlayAppOnebox, ImageOnebox, ImgurOnebox, InstagramOnebox, KalturaOnebox, MixcloudOnebox, PastebinOnebox, PdfOnebox, PubmedOnebox, RedditMediaOnebox, ReplitOnebox, SimplecastOnebox, SketchFabOnebox, SlidesOnebox, SoundCloudOnebox, StackExchangeOnebox, SteamStoreOnebox, TrelloOnebox, TwitterStatusOnebox, TypeformOnebox, VideoOnebox, VimeoOnebox, WikimediaOnebox, WikipediaOnebox, WistiaOnebox, 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/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/trello_onebox.rb,
lib/onebox/engine/wistia_onebox.rb,
lib/onebox/engine/kaltura_onebox.rb,
lib/onebox/engine/standard_embed.rb,
lib/onebox/engine/youtube_onebox.rb,
lib/onebox/engine/bandcamp_onebox.rb,
lib/onebox/engine/cloudapp_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/instagram_onebox.rb,
lib/onebox/engine/sketchfab_onebox.rb,
lib/onebox/engine/wikimedia_onebox.rb,
lib/onebox/engine/wikipedia_onebox.rb,
lib/onebox/engine/simplecast_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/gitlab_blob_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/google_drive_onebox.rb,
lib/onebox/engine/reddit_media_onebox.rb,
lib/onebox/engine/github_commit_onebox.rb,
lib/onebox/engine/github_folder_onebox.rb,
lib/onebox/engine/google_photos_onebox.rb,
lib/onebox/engine/facebook_media_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/allowlisted_generic_onebox.rb
Defined Under Namespace
Modules: ClassMethods, HTML, JSON, OpengraphImage, StandardEmbed Classes: AllowlistedGenericOnebox, AmazonOnebox, AsciinemaOnebox, AudioOnebox, AudioboomOnebox, BandCampOnebox, CloudAppOnebox, CoubOnebox, FacebookMediaOnebox, FiveHundredPxOnebox, FlickrOnebox, FlickrShortenedOnebox, GfycatOnebox, GiphyOnebox, GithubBlobOnebox, GithubCommitOnebox, GithubFolderOnebox, GithubGistOnebox, GithubIssueOnebox, GithubPullRequestOnebox, GitlabBlobOnebox, GoogleCalendarOnebox, GoogleDocsOnebox, GoogleDriveOnebox, GoogleMapsOnebox, GooglePhotosOnebox, GooglePlayAppOnebox, ImageOnebox, ImgurOnebox, InstagramOnebox, KalturaOnebox, MixcloudOnebox, PastebinOnebox, PdfOnebox, PubmedOnebox, RedditMediaOnebox, ReplitOnebox, SimplecastOnebox, SketchFabOnebox, SlidesOnebox, SoundCloudOnebox, StackExchangeOnebox, SteamStoreOnebox, TrelloOnebox, TwitchClipsOnebox, TwitchStreamOnebox, TwitchVideoOnebox, TwitterStatusOnebox, TypeformOnebox, VideoOnebox, VimeoOnebox, WikimediaOnebox, WikipediaOnebox, WistiaOnebox, XkcdOnebox, YoukuOnebox, YoutubeOnebox
Constant Summary collapse
- DEFAULT =
{}
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#options ⇒ Object
Returns the value of attribute options.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
- .all_iframe_origins ⇒ Object
- .engines ⇒ Object
- .included(object) ⇒ Object
- .origins_to_regexes(origins) ⇒ Object
Instance Method Summary collapse
- #initialize(url, timeout = nil) ⇒ 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
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
32 33 34 |
# File 'lib/onebox/engine.rb', line 32 def errors @errors end |
#options ⇒ Object
Returns the value of attribute options.
31 32 33 |
# File 'lib/onebox/engine.rb', line 31 def @options end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
31 32 33 |
# File 'lib/onebox/engine.rb', line 31 def timeout @timeout end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
31 32 33 |
# File 'lib/onebox/engine.rb', line 31 def uri @uri end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
31 32 33 |
# File 'lib/onebox/engine.rb', line 31 def url @url end |
Class Method Details
.all_iframe_origins ⇒ Object
15 16 17 |
# File 'lib/onebox/engine.rb', line 15 def self.all_iframe_origins engines.flat_map { |e| e.iframe_origins }.uniq.compact end |
.engines ⇒ Object
9 10 11 12 13 |
# File 'lib/onebox/engine.rb', line 9 def self.engines constants.select do |constant| constant.to_s =~ /Onebox$/ end.map(&method(:const_get)) end |
.included(object) ⇒ Object
5 6 7 |
# File 'lib/onebox/engine.rb', line 5 def self.included(object) object.extend(ClassMethods) end |
.origins_to_regexes(origins) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/onebox/engine.rb', line 19 def self.origins_to_regexes(origins) return /.*/ if origins.include?("*") origins.map do |origin| escaped_origin = Regexp.escape(origin) if origin.start_with?("*.", "https://*.", "http://*.") escaped_origin = escaped_origin.sub("\\*", '\S*') end Regexp.new("\\A#{escaped_origin}", 'i') end end |
Instance Method Details
#initialize(url, timeout = nil) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/onebox/engine.rb', line 43 def initialize(url, timeout = nil) @errors = {} @options = DEFAULT class_name = self.class.name.split("::").last.to_s # Set the engine options extracted from global options. self. = Onebox.[class_name] || {} @url = url @uri = URI(url) if always_https? @uri.scheme = 'https' @url = @uri.to_s end @timeout = timeout || Onebox..timeout 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.
74 75 76 |
# File 'lib/onebox/engine.rb', line 74 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.
62 63 64 |
# File 'lib/onebox/engine.rb', line 62 def to_html fail NoMethodError, "Engines need to implement this method" end |