onebox 1.8.81 → 1.8.82

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -0
  3. data/.rspec +0 -0
  4. data/.rubocop.yml +0 -0
  5. data/.ruby-gemset +0 -0
  6. data/.travis.yml +0 -0
  7. data/CHANGELOG.md +26 -26
  8. data/Gemfile +0 -0
  9. data/Gemfile.lock +154 -154
  10. data/Guardfile +0 -0
  11. data/LICENSE.txt +0 -0
  12. data/README.md +223 -223
  13. data/Rakefile +0 -0
  14. data/lib/onebox.rb +0 -0
  15. data/lib/onebox/engine.rb +188 -188
  16. data/lib/onebox/engine/amazon_onebox.rb +167 -167
  17. data/lib/onebox/engine/asciinema_onebox.rb +0 -0
  18. data/lib/onebox/engine/audio_onebox.rb +0 -0
  19. data/lib/onebox/engine/audioboom_onebox.rb +24 -24
  20. data/lib/onebox/engine/bandcamp_onebox.rb +32 -32
  21. data/lib/onebox/engine/cloudapp_onebox.rb +51 -51
  22. data/lib/onebox/engine/coub_onebox.rb +21 -21
  23. data/lib/onebox/engine/douban_onebox.rb +0 -0
  24. data/lib/onebox/engine/five_hundred_px_onebox.rb +17 -17
  25. data/lib/onebox/engine/flickr_onebox.rb +0 -0
  26. data/lib/onebox/engine/flickr_shortened_onebox.rb +0 -0
  27. data/lib/onebox/engine/gfycat_onebox.rb +0 -0
  28. data/lib/onebox/engine/giphy_onebox.rb +22 -22
  29. data/lib/onebox/engine/github_blob_onebox.rb +0 -0
  30. data/lib/onebox/engine/github_commit_onebox.rb +0 -0
  31. data/lib/onebox/engine/github_gist_onebox.rb +0 -0
  32. data/lib/onebox/engine/github_issue_onebox.rb +0 -0
  33. data/lib/onebox/engine/github_pullrequest_onebox.rb +0 -0
  34. data/lib/onebox/engine/gitlab_blob_onebox.rb +0 -0
  35. data/lib/onebox/engine/google_calendar_onebox.rb +0 -0
  36. data/lib/onebox/engine/google_docs_onebox.rb +0 -0
  37. data/lib/onebox/engine/google_maps_onebox.rb +0 -0
  38. data/lib/onebox/engine/google_photos_onebox.rb +57 -57
  39. data/lib/onebox/engine/google_play_app_onebox.rb +0 -0
  40. data/lib/onebox/engine/html.rb +0 -0
  41. data/lib/onebox/engine/image_onebox.rb +0 -0
  42. data/lib/onebox/engine/imgur_onebox.rb +65 -65
  43. data/lib/onebox/engine/instagram_onebox.rb +32 -32
  44. data/lib/onebox/engine/json.rb +0 -0
  45. data/lib/onebox/engine/kaltura_onebox.rb +31 -31
  46. data/lib/onebox/engine/mixcloud_onebox.rb +20 -20
  47. data/lib/onebox/engine/opengraph_image.rb +12 -12
  48. data/lib/onebox/engine/pastebin_onebox.rb +0 -0
  49. data/lib/onebox/engine/pdf_onebox.rb +0 -0
  50. data/lib/onebox/engine/pubmed_onebox.rb +0 -0
  51. data/lib/onebox/engine/replit_onebox.rb +24 -24
  52. data/lib/onebox/engine/sketchfab_onebox.rb +31 -31
  53. data/lib/onebox/engine/slides_onebox.rb +0 -0
  54. data/lib/onebox/engine/soundcloud_onebox.rb +31 -31
  55. data/lib/onebox/engine/stack_exchange_onebox.rb +0 -0
  56. data/lib/onebox/engine/standard_embed.rb +145 -145
  57. data/lib/onebox/engine/steam_store_onebox.rb +37 -37
  58. data/lib/onebox/engine/trello_onebox.rb +0 -0
  59. data/lib/onebox/engine/twitch_clips_onebox.rb +0 -0
  60. data/lib/onebox/engine/twitch_stream_onebox.rb +0 -0
  61. data/lib/onebox/engine/twitch_video_onebox.rb +0 -0
  62. data/lib/onebox/engine/twitter_status_onebox.rb +0 -0
  63. data/lib/onebox/engine/typeform_onebox.rb +41 -41
  64. data/lib/onebox/engine/video_onebox.rb +0 -0
  65. data/lib/onebox/engine/vimeo_onebox.rb +20 -20
  66. data/lib/onebox/engine/wechat_mp_onebox.rb +0 -0
  67. data/lib/onebox/engine/whitelisted_generic_onebox.rb +366 -366
  68. data/lib/onebox/engine/wikimedia_onebox.rb +0 -0
  69. data/lib/onebox/engine/wikipedia_onebox.rb +0 -0
  70. data/lib/onebox/engine/wistia_onebox.rb +27 -27
  71. data/lib/onebox/engine/xkcd_onebox.rb +0 -0
  72. data/lib/onebox/engine/youku_onebox.rb +0 -0
  73. data/lib/onebox/engine/youtube_onebox.rb +163 -163
  74. data/lib/onebox/file_type_finder.rb +0 -0
  75. data/lib/onebox/helpers.rb +188 -188
  76. data/lib/onebox/layout.rb +0 -0
  77. data/lib/onebox/layout_support.rb +0 -0
  78. data/lib/onebox/matcher.rb +0 -0
  79. data/lib/onebox/mixins/git_blob_onebox.rb +1 -1
  80. data/lib/onebox/mixins/twitch_onebox.rb +0 -0
  81. data/lib/onebox/oembed.rb +15 -15
  82. data/lib/onebox/open_graph.rb +90 -90
  83. data/lib/onebox/preview.rb +0 -0
  84. data/lib/onebox/sanitize_config.rb +0 -0
  85. data/lib/onebox/status_check.rb +0 -0
  86. data/lib/onebox/template_support.rb +0 -0
  87. data/lib/onebox/version.rb +5 -5
  88. data/lib/onebox/view.rb +0 -0
  89. data/lib/onebox/web.rb +0 -0
  90. data/lib/onebox/web_helpers.rb +0 -0
  91. data/onebox.gemspec +0 -0
  92. data/templates/_layout.mustache +0 -0
  93. data/templates/amazon.mustache +0 -0
  94. data/templates/douban.mustache +0 -0
  95. data/templates/githubblob.mustache +1 -1
  96. data/templates/githubcommit.mustache +0 -0
  97. data/templates/githubgist.mustache +0 -0
  98. data/templates/githubissue.mustache +0 -0
  99. data/templates/githubpullrequest.mustache +0 -0
  100. data/templates/gitlabblob.mustache +0 -0
  101. data/templates/googledocs.mustache +0 -0
  102. data/templates/googleplayapp.mustache +0 -0
  103. data/templates/instagram.mustache +0 -0
  104. data/templates/pastebin.mustache +0 -0
  105. data/templates/pdf.mustache +0 -0
  106. data/templates/pubmed.mustache +0 -0
  107. data/templates/stackexchange.mustache +0 -0
  108. data/templates/twitterstatus.mustache +0 -0
  109. data/templates/wechatmp.mustache +0 -0
  110. data/templates/whitelistedgeneric.mustache +0 -0
  111. data/templates/wikimedia.mustache +0 -0
  112. data/templates/wikipedia.mustache +0 -0
  113. data/templates/xkcd.mustache +0 -0
  114. metadata +3 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 79ca1005a313aaac0d6ca21f616e2b0c12ae6f698f412df6397545788fa0693c
4
- data.tar.gz: 2783afdc4693634f7c4a941c61c8b4d361028c966f78fef3c65cf86c39ba7800
3
+ metadata.gz: 02dde152acf886fd61f163cf5b484ac8a90b0041190566b77510e019710d190b
4
+ data.tar.gz: 13070cca8bb8b9e821b9217b46aa5a067950f201d514bc0e53368b1d75b1d7e6
5
5
  SHA512:
6
- metadata.gz: d609a2a64828733b261fdfd05b5ba12e4b1776f56fd67be13ddb2f2b638a29ee8f63f16d6aed932c3b0f0b656670592810589a4391c99d2d34d43950da1ea027
7
- data.tar.gz: bbc06c238ffbb465989e30b3de82227f2c92fefca30e0db9c0c7ead87ce14d97b1eda3aca56de64eeef11bb627f12fa71930025e301cd226497b859d6da868ac
6
+ metadata.gz: b83742da55beb7f0c2ea45b832287f1ccaead85c38ddccc4e5be6f34c1cd7174404d30533b84b10e4c61aaa2ca42088c7a09d6ec45cd59dad297720ddc22eb13
7
+ data.tar.gz: 359a0ec20cf87962124b001bb2e8b2e5c93be573dbae88578e63a43c854509e61b909f85e90ad9faa5116a5b046a41c4a4b1f278347d142c3443ad71adc59dd9
data/.gitignore CHANGED
File without changes
data/.rspec CHANGED
File without changes
data/.rubocop.yml CHANGED
File without changes
data/.ruby-gemset CHANGED
File without changes
data/.travis.yml CHANGED
File without changes
data/CHANGELOG.md CHANGED
@@ -1,26 +1,26 @@
1
- ## 1.8.78
2
-
3
- * Kaltura onebox support
4
- * Typeform onebox support
5
-
6
- ## 1.8.40
7
-
8
- * remove explicit dependency on fast blank
9
-
10
- ## 1.8.33
11
-
12
- * add support for private vimeo links
13
-
14
- ## 1.8.23
15
-
16
- * added public message about ruby support (2.2 and above)
17
- * mark all avatars being returned as onebox-avatar
18
- * twitter returns larger avatars for retina
19
-
20
- ## 1.6.6
21
-
22
- * SECURITY: normalize url for audio/video oneboxes
23
-
24
- ## 1.5.64
25
-
26
- * Escape HTML entities in text when oneboxing Amazon URLs.
1
+ ## 1.8.78
2
+
3
+ * Kaltura onebox support
4
+ * Typeform onebox support
5
+
6
+ ## 1.8.40
7
+
8
+ * remove explicit dependency on fast blank
9
+
10
+ ## 1.8.33
11
+
12
+ * add support for private vimeo links
13
+
14
+ ## 1.8.23
15
+
16
+ * added public message about ruby support (2.2 and above)
17
+ * mark all avatars being returned as onebox-avatar
18
+ * twitter returns larger avatars for retina
19
+
20
+ ## 1.6.6
21
+
22
+ * SECURITY: normalize url for audio/video oneboxes
23
+
24
+ ## 1.5.64
25
+
26
+ * Escape HTML entities in text when oneboxing Amazon URLs.
data/Gemfile CHANGED
File without changes
data/Gemfile.lock CHANGED
@@ -1,154 +1,154 @@
1
- PATH
2
- remote: .
3
- specs:
4
- onebox (1.8.80)
5
- htmlentities (~> 4.3)
6
- moneta (~> 1.0)
7
- multi_json (~> 1.11)
8
- mustache
9
- nokogiri (~> 1.7)
10
- sanitize
11
-
12
- GEM
13
- remote: https://rubygems.org/
14
- specs:
15
- ast (2.4.0)
16
- backports (3.12.0)
17
- celluloid (0.16.0)
18
- timers (~> 4.0.0)
19
- coderay (1.1.2)
20
- crass (1.0.4)
21
- diff-lcs (1.3)
22
- fakeweb (1.3.0)
23
- faraday (0.9.2)
24
- multipart-post (>= 1.2, < 3)
25
- ffi (1.10.0)
26
- formatador (0.2.5)
27
- guard (2.15.0)
28
- formatador (>= 0.2.4)
29
- listen (>= 2.7, < 4.0)
30
- lumberjack (>= 1.0.12, < 2.0)
31
- nenv (~> 0.1)
32
- notiffany (~> 0.0)
33
- pry (>= 0.9.12)
34
- shellany (~> 0.0)
35
- thor (>= 0.18.1)
36
- guard-rspec (4.2.10)
37
- guard (~> 2.1)
38
- rspec (>= 2.14, < 4.0)
39
- haml (4.0.7)
40
- tilt
41
- hitimes (1.3.1)
42
- htmlentities (4.3.4)
43
- jaro_winkler (1.5.2)
44
- listen (2.10.1)
45
- celluloid (~> 0.16.0)
46
- rb-fsevent (>= 0.9.3)
47
- rb-inotify (>= 0.9)
48
- lumberjack (1.0.13)
49
- metaclass (0.0.4)
50
- method_source (0.9.2)
51
- mini_portile2 (2.4.0)
52
- mocha (1.8.0)
53
- metaclass (~> 0.0.1)
54
- moneta (1.0.0)
55
- multi_json (1.13.1)
56
- multipart-post (2.0.0)
57
- mustache (1.1.0)
58
- nenv (0.3.0)
59
- nokogiri (1.10.1)
60
- mini_portile2 (~> 2.4.0)
61
- nokogumbo (2.0.1)
62
- nokogiri (~> 1.8, >= 1.8.4)
63
- notiffany (0.1.1)
64
- nenv (~> 0.1)
65
- shellany (~> 0.0)
66
- parallel (1.14.0)
67
- parser (2.6.0.0)
68
- ast (~> 2.4.0)
69
- powerpack (0.1.2)
70
- pry (0.12.2)
71
- coderay (~> 1.1.0)
72
- method_source (~> 0.9.0)
73
- psych (3.1.0)
74
- rack (1.6.11)
75
- rack-protection (1.5.5)
76
- rack
77
- rack-test (1.1.0)
78
- rack (>= 1.0, < 3)
79
- rainbow (3.0.0)
80
- rake (10.5.0)
81
- rb-fsevent (0.10.3)
82
- rb-inotify (0.10.0)
83
- ffi (~> 1.0)
84
- rspec (3.8.0)
85
- rspec-core (~> 3.8.0)
86
- rspec-expectations (~> 3.8.0)
87
- rspec-mocks (~> 3.8.0)
88
- rspec-core (3.8.0)
89
- rspec-support (~> 3.8.0)
90
- rspec-expectations (3.8.2)
91
- diff-lcs (>= 1.2.0, < 2.0)
92
- rspec-support (~> 3.8.0)
93
- rspec-mocks (3.8.0)
94
- diff-lcs (>= 1.2.0, < 2.0)
95
- rspec-support (~> 3.8.0)
96
- rspec-support (3.8.0)
97
- rubocop (0.65.0)
98
- jaro_winkler (~> 1.5.1)
99
- parallel (~> 1.10)
100
- parser (>= 2.5, != 2.5.1.1)
101
- powerpack (~> 0.1)
102
- psych (>= 3.1.0)
103
- rainbow (>= 2.2.2, < 4.0)
104
- ruby-progressbar (~> 1.7)
105
- unicode-display_width (~> 1.4.0)
106
- ruby-progressbar (1.10.0)
107
- sanitize (5.0.0)
108
- crass (~> 1.0.2)
109
- nokogiri (>= 1.8.0)
110
- nokogumbo (~> 2.0)
111
- shellany (0.0.1)
112
- simple_oauth (0.3.1)
113
- sinatra (1.4.8)
114
- rack (~> 1.5)
115
- rack-protection (~> 1.4)
116
- tilt (>= 1.3, < 3)
117
- sinatra-contrib (1.4.7)
118
- backports (>= 2.0)
119
- multi_json
120
- rack-protection
121
- rack-test
122
- sinatra (~> 1.4.0)
123
- tilt (>= 1.3, < 3)
124
- thor (0.20.3)
125
- tilt (2.0.9)
126
- timers (4.0.4)
127
- hitimes
128
- twitter (4.8.1)
129
- faraday (~> 0.8, < 0.10)
130
- multi_json (~> 1.0)
131
- simple_oauth (~> 0.2)
132
- unicode-display_width (1.4.1)
133
-
134
- PLATFORMS
135
- ruby
136
-
137
- DEPENDENCIES
138
- bundler (~> 2.0)
139
- fakeweb (~> 1.3)
140
- guard-rspec (~> 4.2.8)
141
- haml (~> 4.0)
142
- listen (~> 2.10.0)
143
- mocha (~> 1.1)
144
- onebox!
145
- pry (~> 0.10)
146
- rake (~> 10.4)
147
- rspec (~> 3.2)
148
- rubocop (~> 0.50)
149
- sinatra (~> 1.4)
150
- sinatra-contrib (~> 1.4)
151
- twitter (~> 4.8)
152
-
153
- BUNDLED WITH
154
- 2.0.1
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ onebox (1.8.81)
5
+ htmlentities (~> 4.3)
6
+ moneta (~> 1.0)
7
+ multi_json (~> 1.11)
8
+ mustache
9
+ nokogiri (~> 1.7)
10
+ sanitize
11
+
12
+ GEM
13
+ remote: https://rubygems.org/
14
+ specs:
15
+ ast (2.4.0)
16
+ backports (3.12.0)
17
+ celluloid (0.16.0)
18
+ timers (~> 4.0.0)
19
+ coderay (1.1.2)
20
+ crass (1.0.4)
21
+ diff-lcs (1.3)
22
+ fakeweb (1.3.0)
23
+ faraday (0.9.2)
24
+ multipart-post (>= 1.2, < 3)
25
+ ffi (1.10.0)
26
+ formatador (0.2.5)
27
+ guard (2.15.0)
28
+ formatador (>= 0.2.4)
29
+ listen (>= 2.7, < 4.0)
30
+ lumberjack (>= 1.0.12, < 2.0)
31
+ nenv (~> 0.1)
32
+ notiffany (~> 0.0)
33
+ pry (>= 0.9.12)
34
+ shellany (~> 0.0)
35
+ thor (>= 0.18.1)
36
+ guard-rspec (4.2.10)
37
+ guard (~> 2.1)
38
+ rspec (>= 2.14, < 4.0)
39
+ haml (4.0.7)
40
+ tilt
41
+ hitimes (1.3.1)
42
+ htmlentities (4.3.4)
43
+ jaro_winkler (1.5.2)
44
+ listen (2.10.1)
45
+ celluloid (~> 0.16.0)
46
+ rb-fsevent (>= 0.9.3)
47
+ rb-inotify (>= 0.9)
48
+ lumberjack (1.0.13)
49
+ metaclass (0.0.4)
50
+ method_source (0.9.2)
51
+ mini_portile2 (2.4.0)
52
+ mocha (1.8.0)
53
+ metaclass (~> 0.0.1)
54
+ moneta (1.0.0)
55
+ multi_json (1.13.1)
56
+ multipart-post (2.0.0)
57
+ mustache (1.1.0)
58
+ nenv (0.3.0)
59
+ nokogiri (1.10.1)
60
+ mini_portile2 (~> 2.4.0)
61
+ nokogumbo (2.0.1)
62
+ nokogiri (~> 1.8, >= 1.8.4)
63
+ notiffany (0.1.1)
64
+ nenv (~> 0.1)
65
+ shellany (~> 0.0)
66
+ parallel (1.14.0)
67
+ parser (2.6.0.0)
68
+ ast (~> 2.4.0)
69
+ powerpack (0.1.2)
70
+ pry (0.12.2)
71
+ coderay (~> 1.1.0)
72
+ method_source (~> 0.9.0)
73
+ psych (3.1.0)
74
+ rack (1.6.11)
75
+ rack-protection (1.5.5)
76
+ rack
77
+ rack-test (1.1.0)
78
+ rack (>= 1.0, < 3)
79
+ rainbow (3.0.0)
80
+ rake (10.5.0)
81
+ rb-fsevent (0.10.3)
82
+ rb-inotify (0.10.0)
83
+ ffi (~> 1.0)
84
+ rspec (3.8.0)
85
+ rspec-core (~> 3.8.0)
86
+ rspec-expectations (~> 3.8.0)
87
+ rspec-mocks (~> 3.8.0)
88
+ rspec-core (3.8.0)
89
+ rspec-support (~> 3.8.0)
90
+ rspec-expectations (3.8.2)
91
+ diff-lcs (>= 1.2.0, < 2.0)
92
+ rspec-support (~> 3.8.0)
93
+ rspec-mocks (3.8.0)
94
+ diff-lcs (>= 1.2.0, < 2.0)
95
+ rspec-support (~> 3.8.0)
96
+ rspec-support (3.8.0)
97
+ rubocop (0.65.0)
98
+ jaro_winkler (~> 1.5.1)
99
+ parallel (~> 1.10)
100
+ parser (>= 2.5, != 2.5.1.1)
101
+ powerpack (~> 0.1)
102
+ psych (>= 3.1.0)
103
+ rainbow (>= 2.2.2, < 4.0)
104
+ ruby-progressbar (~> 1.7)
105
+ unicode-display_width (~> 1.4.0)
106
+ ruby-progressbar (1.10.0)
107
+ sanitize (5.0.0)
108
+ crass (~> 1.0.2)
109
+ nokogiri (>= 1.8.0)
110
+ nokogumbo (~> 2.0)
111
+ shellany (0.0.1)
112
+ simple_oauth (0.3.1)
113
+ sinatra (1.4.8)
114
+ rack (~> 1.5)
115
+ rack-protection (~> 1.4)
116
+ tilt (>= 1.3, < 3)
117
+ sinatra-contrib (1.4.7)
118
+ backports (>= 2.0)
119
+ multi_json
120
+ rack-protection
121
+ rack-test
122
+ sinatra (~> 1.4.0)
123
+ tilt (>= 1.3, < 3)
124
+ thor (0.20.3)
125
+ tilt (2.0.9)
126
+ timers (4.0.4)
127
+ hitimes
128
+ twitter (4.8.1)
129
+ faraday (~> 0.8, < 0.10)
130
+ multi_json (~> 1.0)
131
+ simple_oauth (~> 0.2)
132
+ unicode-display_width (1.4.1)
133
+
134
+ PLATFORMS
135
+ ruby
136
+
137
+ DEPENDENCIES
138
+ bundler (~> 2.0)
139
+ fakeweb (~> 1.3)
140
+ guard-rspec (~> 4.2.8)
141
+ haml (~> 4.0)
142
+ listen (~> 2.10.0)
143
+ mocha (~> 1.1)
144
+ onebox!
145
+ pry (~> 0.10)
146
+ rake (~> 10.4)
147
+ rspec (~> 3.2)
148
+ rubocop (~> 0.50)
149
+ sinatra (~> 1.4)
150
+ sinatra-contrib (~> 1.4)
151
+ twitter (~> 4.8)
152
+
153
+ BUNDLED WITH
154
+ 2.0.1
data/Guardfile CHANGED
File without changes
data/LICENSE.txt CHANGED
File without changes
data/README.md CHANGED
@@ -1,223 +1,223 @@
1
- onebox
2
- ======
3
-
4
- [![Gem Version](https://badge.fury.io/rb/onebox.png)](https://rubygems.org/gems/onebox)
5
- [![Code Climate](https://codeclimate.com/github/dysania/onebox.png)](https://codeclimate.com/github/dysania/onebox)
6
- [![Build Status](https://travis-ci.org/discourse/onebox.png)](https://travis-ci.org/discourse/onebox)
7
-
8
- Onebox is a library for turning media URLs into simple HTML previews of the resource.
9
-
10
- Onebox currently has support for page, image, and video URLs for many popular sites.
11
-
12
- It's great if you want users to input URLs and have your application convert them into
13
- rich previews for display. For example, a link to a YouTube video would be automatically
14
- converted into a video player.
15
-
16
- It was originally created for [Discourse](http://discourse.org) but has since been
17
- extracted into this convenient gem for all to use!
18
-
19
- Usage
20
- -----
21
-
22
- Using onebox is fairly simple!
23
- First, make sure the library is required:
24
-
25
- ``` ruby
26
- require "onebox"
27
- ```
28
-
29
- Then pass a link to the library's interface:
30
-
31
- ``` ruby
32
- require "onebox"
33
-
34
- url = "http://www.amazon.com/gp/product/B005T3GRNW/ref=s9_simh_gw_p147_d0_i2"
35
- preview = Onebox.preview(url)
36
- ```
37
-
38
- This will contain a simple Onebox::Preview object that handles all the transformation.
39
- From here you either call `Onebox::Preview#to_s` or just pass the object to a string:
40
-
41
- ``` ruby
42
- require "onebox"
43
-
44
- url = "http://www.amazon.com/gp/product/B005T3GRNW/ref=s9_simh_gw_p147_d0_i2"
45
- preview = Onebox.preview(url)
46
- "#{preview}" == preview.to_s #=> true
47
- ```
48
-
49
- Onebox has its own caching system but you can also provide (or turn off) your own system:
50
-
51
- ``` ruby
52
- require "onebox"
53
-
54
- url = "http://www.amazon.com/gp/product/B005T3GRNW/ref=s9_simh_gw_p147_d0_i2"
55
- preview = Onebox.preview(url, cache: Rails.cache)
56
- "#{preview}" == preview.to_s #=> true
57
- ```
58
-
59
- In addition you can set your own options with this handy interface:
60
-
61
- ``` ruby
62
- require "onebox"
63
-
64
- Onebox.options = {
65
- cache: Rails.cache
66
- }
67
-
68
- url = "http://www.amazon.com/gp/product/B005T3GRNW/ref=s9_simh_gw_p147_d0_i2"
69
- preview = Onebox.preview(url)
70
- "#{preview}" == preview.to_s #=> true
71
- ```
72
-
73
- Ruby Support
74
- ------------
75
-
76
- The onebox library is supported on all "officially" supported versions of Ruby.
77
-
78
- This means you must be on Ruby 2.3 or above for it to work.
79
-
80
- Development Preview Interface
81
- -----------------------------
82
-
83
- The onebox gem comes with a development server for previewing the results
84
- of your changes. You can run it by running `bundle exec rake server` after checking
85
- out the project. You can then try out URLs.
86
-
87
- The server doesn't reload code changes automatically (PRs accepted!) so
88
- make sure to hit CTRL-C and restart the server to try a code change out.
89
-
90
-
91
- Adding Support for a new URL
92
- ----------------------------
93
-
94
- 1. Check if the site supports [oEmbed](http://oembed.com/) or [Open Graph](https://developers.facebook.com/docs/opengraph/).
95
- If it does, you can probably get away with just whitelisting the URL in `Onebox::Engine::WhitelistedGenericOnebox` (see: [Whitelisted Generic Onebox caveats](#user-content-whitelisted-generic-onebox-caveats)).
96
- If the site does not support open standards, you can create a new engine.
97
-
98
- 2. Create new onebox engine
99
-
100
- ``` ruby
101
- # in lib/onebox/engine/name_onebox.rb
102
-
103
- module Onebox
104
- module Engine
105
- class NameOnebox
106
- include LayoutSupport
107
- include HTML
108
-
109
- private
110
-
111
- def data
112
- {
113
- url: @url,
114
- name: raw.css("h1").inner_text,
115
- image: raw.css("#main-image").first["src"],
116
- description: raw.css("#postBodyPS").inner_text
117
- }
118
- end
119
- end
120
- end
121
- end
122
- ```
123
-
124
- 3. Create new onebox spec using [FakeWeb](https://github.com/chrisk/fakeweb)
125
-
126
- ``` ruby
127
- # in spec/lib/onebox/engine/name_spec.rb
128
- require "spec_helper"
129
-
130
- describe Onebox::Engine::NameOnebox do
131
- let(:link) { "http://example.com" }
132
- let(:html) { described_class.new(link).to_html }
133
-
134
- before do
135
- fake(link, response("name"))
136
- end
137
-
138
- it "has the video's title" do
139
- expect(html).to include("title")
140
- end
141
-
142
- it "has the video's still shot" do
143
- expect(html).to include("photo.jpg")
144
- end
145
-
146
- it "has the video's description" do
147
- expect(html).to include("description")
148
- end
149
-
150
- it "has the URL to the resource" do
151
- expect(html).to include(link)
152
- end
153
- end
154
- ```
155
-
156
- 4. Create new mustache template
157
-
158
- ``` html
159
- # in templates/name.mustache
160
- <div class="onebox">
161
- <a href="{{url}}">
162
- <h1>{{name}}</h1>
163
- <h2 class="host">example.com</h2>
164
- <img src="{{image}}" />
165
- <p>{{description}}</p>
166
- </a>
167
- </div>
168
- ```
169
-
170
- 5. Create new fixture from HTML response for your FakeWeb request(s)
171
-
172
- ``` bash
173
- curl --output spec/fixtures/oneboxname.response -L -X GET http://example.com
174
- ```
175
-
176
- 6. Require in Engine module
177
-
178
- ``` ruby
179
- # in lib/onebox/engine.rb
180
- require_relative "engine/name_onebox"
181
- ```
182
-
183
-
184
- Whitelisted Generic Onebox caveats
185
- ----------------------------------
186
-
187
- The Whitelisted Generic Onebox has some caveats for it's use, beyond simply whitelisting the domain.
188
-
189
- 1. The domain must be whitelisted
190
- 2. The URL you're oneboxing cannot be a root url (e.g. `http://example.com` won't work, but `http://example.com/page` will)
191
- 3. If the oneboxed URL responds with oEmbed and has a `rich` type: the `html` content must contain an `<iframe>`. Responses without an iframe will not be oneboxed.
192
-
193
-
194
- Installing
195
- ----------
196
-
197
- Add this line to your application's Gemfile:
198
-
199
- gem "onebox"
200
-
201
- And then execute:
202
-
203
- $ bundle
204
-
205
- Or install it yourself as:
206
-
207
- $ gem install onebox
208
-
209
-
210
- Issues / Discussion
211
- -------------------
212
-
213
- Discussion of the Onebox gem, its development and features should be done on
214
- [Discourse Meta](https://meta.discourse.org).
215
-
216
- Contributing
217
- ------------
218
-
219
- 1. Fork it
220
- 2. Create your feature branch (`git checkout -b my-new-feature`)
221
- 3. Commit your changes (`git commit -am 'Add some feature'`)
222
- 4. Push to the branch (`git push origin my-new-feature`)
223
- 5. Create new Pull Request
1
+ onebox
2
+ ======
3
+
4
+ [![Gem Version](https://badge.fury.io/rb/onebox.png)](https://rubygems.org/gems/onebox)
5
+ [![Code Climate](https://codeclimate.com/github/dysania/onebox.png)](https://codeclimate.com/github/dysania/onebox)
6
+ [![Build Status](https://travis-ci.org/discourse/onebox.png)](https://travis-ci.org/discourse/onebox)
7
+
8
+ Onebox is a library for turning media URLs into simple HTML previews of the resource.
9
+
10
+ Onebox currently has support for page, image, and video URLs for many popular sites.
11
+
12
+ It's great if you want users to input URLs and have your application convert them into
13
+ rich previews for display. For example, a link to a YouTube video would be automatically
14
+ converted into a video player.
15
+
16
+ It was originally created for [Discourse](http://discourse.org) but has since been
17
+ extracted into this convenient gem for all to use!
18
+
19
+ Usage
20
+ -----
21
+
22
+ Using onebox is fairly simple!
23
+ First, make sure the library is required:
24
+
25
+ ``` ruby
26
+ require "onebox"
27
+ ```
28
+
29
+ Then pass a link to the library's interface:
30
+
31
+ ``` ruby
32
+ require "onebox"
33
+
34
+ url = "http://www.amazon.com/gp/product/B005T3GRNW/ref=s9_simh_gw_p147_d0_i2"
35
+ preview = Onebox.preview(url)
36
+ ```
37
+
38
+ This will contain a simple Onebox::Preview object that handles all the transformation.
39
+ From here you either call `Onebox::Preview#to_s` or just pass the object to a string:
40
+
41
+ ``` ruby
42
+ require "onebox"
43
+
44
+ url = "http://www.amazon.com/gp/product/B005T3GRNW/ref=s9_simh_gw_p147_d0_i2"
45
+ preview = Onebox.preview(url)
46
+ "#{preview}" == preview.to_s #=> true
47
+ ```
48
+
49
+ Onebox has its own caching system but you can also provide (or turn off) your own system:
50
+
51
+ ``` ruby
52
+ require "onebox"
53
+
54
+ url = "http://www.amazon.com/gp/product/B005T3GRNW/ref=s9_simh_gw_p147_d0_i2"
55
+ preview = Onebox.preview(url, cache: Rails.cache)
56
+ "#{preview}" == preview.to_s #=> true
57
+ ```
58
+
59
+ In addition you can set your own options with this handy interface:
60
+
61
+ ``` ruby
62
+ require "onebox"
63
+
64
+ Onebox.options = {
65
+ cache: Rails.cache
66
+ }
67
+
68
+ url = "http://www.amazon.com/gp/product/B005T3GRNW/ref=s9_simh_gw_p147_d0_i2"
69
+ preview = Onebox.preview(url)
70
+ "#{preview}" == preview.to_s #=> true
71
+ ```
72
+
73
+ Ruby Support
74
+ ------------
75
+
76
+ The onebox library is supported on all "officially" supported versions of Ruby.
77
+
78
+ This means you must be on Ruby 2.3 or above for it to work.
79
+
80
+ Development Preview Interface
81
+ -----------------------------
82
+
83
+ The onebox gem comes with a development server for previewing the results
84
+ of your changes. You can run it by running `bundle exec rake server` after checking
85
+ out the project. You can then try out URLs.
86
+
87
+ The server doesn't reload code changes automatically (PRs accepted!) so
88
+ make sure to hit CTRL-C and restart the server to try a code change out.
89
+
90
+
91
+ Adding Support for a new URL
92
+ ----------------------------
93
+
94
+ 1. Check if the site supports [oEmbed](http://oembed.com/) or [Open Graph](https://developers.facebook.com/docs/opengraph/).
95
+ If it does, you can probably get away with just whitelisting the URL in `Onebox::Engine::WhitelistedGenericOnebox` (see: [Whitelisted Generic Onebox caveats](#user-content-whitelisted-generic-onebox-caveats)).
96
+ If the site does not support open standards, you can create a new engine.
97
+
98
+ 2. Create new onebox engine
99
+
100
+ ``` ruby
101
+ # in lib/onebox/engine/name_onebox.rb
102
+
103
+ module Onebox
104
+ module Engine
105
+ class NameOnebox
106
+ include LayoutSupport
107
+ include HTML
108
+
109
+ private
110
+
111
+ def data
112
+ {
113
+ url: @url,
114
+ name: raw.css("h1").inner_text,
115
+ image: raw.css("#main-image").first["src"],
116
+ description: raw.css("#postBodyPS").inner_text
117
+ }
118
+ end
119
+ end
120
+ end
121
+ end
122
+ ```
123
+
124
+ 3. Create new onebox spec using [FakeWeb](https://github.com/chrisk/fakeweb)
125
+
126
+ ``` ruby
127
+ # in spec/lib/onebox/engine/name_spec.rb
128
+ require "spec_helper"
129
+
130
+ describe Onebox::Engine::NameOnebox do
131
+ let(:link) { "http://example.com" }
132
+ let(:html) { described_class.new(link).to_html }
133
+
134
+ before do
135
+ fake(link, response("name"))
136
+ end
137
+
138
+ it "has the video's title" do
139
+ expect(html).to include("title")
140
+ end
141
+
142
+ it "has the video's still shot" do
143
+ expect(html).to include("photo.jpg")
144
+ end
145
+
146
+ it "has the video's description" do
147
+ expect(html).to include("description")
148
+ end
149
+
150
+ it "has the URL to the resource" do
151
+ expect(html).to include(link)
152
+ end
153
+ end
154
+ ```
155
+
156
+ 4. Create new mustache template
157
+
158
+ ``` html
159
+ # in templates/name.mustache
160
+ <div class="onebox">
161
+ <a href="{{url}}">
162
+ <h1>{{name}}</h1>
163
+ <h2 class="host">example.com</h2>
164
+ <img src="{{image}}" />
165
+ <p>{{description}}</p>
166
+ </a>
167
+ </div>
168
+ ```
169
+
170
+ 5. Create new fixture from HTML response for your FakeWeb request(s)
171
+
172
+ ``` bash
173
+ curl --output spec/fixtures/oneboxname.response -L -X GET http://example.com
174
+ ```
175
+
176
+ 6. Require in Engine module
177
+
178
+ ``` ruby
179
+ # in lib/onebox/engine.rb
180
+ require_relative "engine/name_onebox"
181
+ ```
182
+
183
+
184
+ Whitelisted Generic Onebox caveats
185
+ ----------------------------------
186
+
187
+ The Whitelisted Generic Onebox has some caveats for it's use, beyond simply whitelisting the domain.
188
+
189
+ 1. The domain must be whitelisted
190
+ 2. The URL you're oneboxing cannot be a root url (e.g. `http://example.com` won't work, but `http://example.com/page` will)
191
+ 3. If the oneboxed URL responds with oEmbed and has a `rich` type: the `html` content must contain an `<iframe>`. Responses without an iframe will not be oneboxed.
192
+
193
+
194
+ Installing
195
+ ----------
196
+
197
+ Add this line to your application's Gemfile:
198
+
199
+ gem "onebox"
200
+
201
+ And then execute:
202
+
203
+ $ bundle
204
+
205
+ Or install it yourself as:
206
+
207
+ $ gem install onebox
208
+
209
+
210
+ Issues / Discussion
211
+ -------------------
212
+
213
+ Discussion of the Onebox gem, its development and features should be done on
214
+ [Discourse Meta](https://meta.discourse.org).
215
+
216
+ Contributing
217
+ ------------
218
+
219
+ 1. Fork it
220
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
221
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
222
+ 4. Push to the branch (`git push origin my-new-feature`)
223
+ 5. Create new Pull Request