Module: Onebox::Engine
- Included in:
- AllowlistedGenericOnebox, AmazonOnebox, AnimatedImageOnebox, AsciinemaOnebox, AudioComOnebox, AudioOnebox, AudioboomOnebox, BandCampOnebox, CloudAppOnebox, CoubOnebox, DiscourseTopicOnebox, FacebookMediaOnebox, FiveHundredPxOnebox, FlickrOnebox, FlickrShortenedOnebox, GfycatOnebox, GithubActionsOnebox, GithubCommitOnebox, GithubFolderOnebox, GithubGistOnebox, GithubIssueOnebox, GithubPullRequestOnebox, GoogleCalendarOnebox, GoogleDocsOnebox, GoogleDriveOnebox, GoogleMapsOnebox, GooglePhotosOnebox, GooglePlayAppOnebox, HackernewsOnebox, ImageOnebox, ImgurOnebox, InstagramOnebox, KalturaOnebox, MixcloudOnebox, MotokoOnebox, PastebinOnebox, PdfOnebox, PubmedOnebox, RedditMediaOnebox, ReplitOnebox, SimplecastOnebox, SketchFabOnebox, SlidesOnebox, SoundCloudOnebox, StackExchangeOnebox, SteamStoreOnebox, ThreadsStatusOnebox, TiktokOnebox, 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/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/motoko_onebox.rb,
lib/onebox/engine/pubmed_onebox.rb,
lib/onebox/engine/replit_onebox.rb,
lib/onebox/engine/slides_onebox.rb,
lib/onebox/engine/tiktok_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/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/audio_com_onebox.rb,
lib/onebox/engine/audioboom_onebox.rb,
lib/onebox/engine/band_camp_onebox.rb,
lib/onebox/engine/cloud_app_onebox.rb,
lib/onebox/engine/instagram_onebox.rb,
lib/onebox/engine/wikimedia_onebox.rb,
lib/onebox/engine/wikipedia_onebox.rb,
lib/onebox/engine/hackernews_onebox.rb,
lib/onebox/engine/simplecast_onebox.rb,
lib/onebox/engine/sketch_fab_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/sound_cloud_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/animated_image_onebox.rb,
lib/onebox/engine/facebook_media_onebox.rb,
lib/onebox/engine/github_actions_onebox.rb,
lib/onebox/engine/stack_exchange_onebox.rb,
lib/onebox/engine/threads_status_onebox.rb,
lib/onebox/engine/twitter_status_onebox.rb,
lib/onebox/engine/discourse_topic_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/allowlisted_generic_onebox.rb,
lib/onebox/engine/github_pull_request_onebox.rb
Defined Under Namespace
Modules: ClassMethods, HTML, JSON, OpengraphImage, StandardEmbed Classes: AllowlistedGenericOnebox, AmazonOnebox, AnimatedImageOnebox, AsciinemaOnebox, AudioComOnebox, AudioOnebox, AudioboomOnebox, BandCampOnebox, CloudAppOnebox, CoubOnebox, DiscourseTopicOnebox, FacebookMediaOnebox, FiveHundredPxOnebox, FlickrOnebox, FlickrShortenedOnebox, GfycatOnebox, GithubActionsOnebox, GithubBlobOnebox, GithubCommitOnebox, GithubFolderOnebox, GithubGistOnebox, GithubIssueOnebox, GithubPullRequestOnebox, GitlabBlobOnebox, GoogleCalendarOnebox, GoogleDocsOnebox, GoogleDriveOnebox, GoogleMapsOnebox, GooglePhotosOnebox, GooglePlayAppOnebox, HackernewsOnebox, ImageOnebox, ImgurOnebox, InstagramOnebox, KalturaOnebox, MixcloudOnebox, MotokoOnebox, PastebinOnebox, PdfOnebox, PubmedOnebox, RedditMediaOnebox, ReplitOnebox, SimplecastOnebox, SketchFabOnebox, SlidesOnebox, SoundCloudOnebox, StackExchangeOnebox, SteamStoreOnebox, ThreadsStatusOnebox, TiktokOnebox, TrelloOnebox, TwitchClipsOnebox, TwitchStreamOnebox, TwitchVideoOnebox, TwitterStatusOnebox, TypeformOnebox, VideoOnebox, VimeoOnebox, WikimediaOnebox, WikipediaOnebox, WistiaOnebox, XkcdOnebox, YoukuOnebox, YoutubeOnebox
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.
31 32 33 |
# File 'lib/onebox/engine.rb', line 31 def errors @errors end |
#options ⇒ Object
Returns the value of attribute options.
30 31 32 |
# File 'lib/onebox/engine.rb', line 30 def @options end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
30 31 32 |
# File 'lib/onebox/engine.rb', line 30 def timeout @timeout end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
30 31 32 |
# File 'lib/onebox/engine.rb', line 30 def uri @uri end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
30 31 32 |
# File 'lib/onebox/engine.rb', line 30 def url @url end |
Class Method Details
.all_iframe_origins ⇒ Object
13 14 15 |
# File 'lib/onebox/engine.rb', line 13 def self.all_iframe_origins engines.flat_map { |e| e.iframe_origins }.uniq.compact end |
.engines ⇒ Object
9 10 11 |
# File 'lib/onebox/engine.rb', line 9 def self.engines constants.select { |constant| constant.to_s =~ /Onebox\z/ }.sort.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
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/onebox/engine.rb', line 17 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
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/onebox/engine.rb', line 40 def initialize(url, timeout = nil) @errors = {} @options = {} 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.
71 72 73 |
# File 'lib/onebox/engine.rb', line 71 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.
59 60 61 |
# File 'lib/onebox/engine.rb', line 59 def to_html fail NoMethodError, "Engines need to implement this method" end |