onebox 1.8.85 → 1.8.86

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 292475b14d190bdb60b037b4a31cb613dd4e7380a68a3498082a78db162dd149
4
- data.tar.gz: f6c171120798bea4d9d3151b50787dae070e0b9fdfc1861310fbd308cc48b76f
3
+ metadata.gz: 631c22d7ba52fd8d88052176bc42a74bfec14409ec65da82c9b8bf8eb64bae79
4
+ data.tar.gz: '09d424a57ca87f9dd5c3be877c9b8ad0bd3cf4101536d3bbcf158f9ef9fef7de'
5
5
  SHA512:
6
- metadata.gz: e994b15b1b413515c7bcc5e5969e901bad6afd8165a9000727bb13afc395b4e4c74cdadc545ceddab55eea5bad7b7c80677906debbcdf8f706488271c8ce9771
7
- data.tar.gz: aeaea261b44ff47529dcbf500f44b8a5324f356f51dd3691c39a5d37bf6fd0812b0f7a7a1a1e131a98e4416154101e5cc476ec5d792d1666e372d09a981696cb
6
+ metadata.gz: 65cd19cd9e45693343c0cc470f9511d53eb7c43829a56591f18df1bd72583847c29533074ccc366916a45545a7824849298e7ed3d4bb42031f76d431a1824c6e
7
+ data.tar.gz: 00f273d8ba17d3d4a5046bed67bccba703bd02d3f3ea96d727685fab1b4406dab017650872e8fdc329ffe6ad50f5d683884b37c7367200d5f7f29d387c5a6d1e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- onebox (1.8.85)
4
+ onebox (1.8.86)
5
5
  htmlentities (~> 4.3)
6
6
  moneta (~> 1.0)
7
7
  multi_json (~> 1.11)
@@ -15,7 +15,7 @@ module Onebox
15
15
  /github\.com\/(?<user>[^\/]+)\/(?<repo>[^\/]+)\/blob\/(?<sha1>[^\/]+)\/(?<file>[^#]+)(#(L(?<from>[^-]*)(-L(?<to>.*))?))?/mi
16
16
  end
17
17
  def raw_template(m)
18
- "https://raw.github.com/#{m[:user]}/#{m[:repo]}/#{m[:sha1]}/#{m[:file]}"
18
+ "https://raw.githubusercontent.com/#{m[:user]}/#{m[:repo]}/#{m[:sha1]}/#{m[:file]}"
19
19
  end
20
20
  def title
21
21
  Sanitize.fragment(URI.unescape(link).sub(/^https?\:\/\/github\.com\//, ''))
@@ -7,13 +7,32 @@ module Onebox
7
7
  matches_regexp(/^https?:\/\/(www\.)?vimeo\.com\/\d+(\/[^\/]+)?$/)
8
8
  always_https
9
9
 
10
+ WIDTH ||= 640
11
+ HEIGHT ||= 360
12
+
10
13
  def placeholder_html
11
- oembed = get_oembed
12
- "<img src='#{oembed.thumbnail_url}' width='#{oembed.thumbnail_width}' height='#{oembed.thumbnail_height}' #{oembed.title_attr}>"
14
+ image_src = og_data.image_secure_url || og_data.image_url
15
+ "<img src='#{image_src}' width='#{WIDTH}' height='#{HEIGHT}' #{og_data.title_attr}>"
13
16
  end
14
17
 
15
18
  def to_html
16
- get_oembed.html
19
+ video_src = og_data.video_secure_url || og_data.video_url
20
+ video_src = video_src.gsub('autoplay=1', '').chomp("?")
21
+ <<-HTML
22
+ <iframe width="#{WIDTH}"
23
+ height="#{HEIGHT}"
24
+ src="#{video_src}"
25
+ data-original-href="#{link}"
26
+ frameborder="0"
27
+ allowfullscreen>
28
+ </iframe>
29
+ HTML
30
+ end
31
+
32
+ private
33
+
34
+ def og_data
35
+ @og_data = get_opengraph
17
36
  end
18
37
  end
19
38
  end
@@ -336,15 +336,17 @@ module Onebox
336
336
  end
337
337
 
338
338
  def video_html
339
- escaped_src = ::Onebox::Helpers.normalize_url_for_output(data[:video])
339
+ escaped_video_src = ::Onebox::Helpers.normalize_url_for_output(data[:video])
340
+ escaped_image_src = ::Onebox::Helpers.normalize_url_for_output(data[:image])
340
341
 
341
342
  <<-HTML
342
343
  <video title='#{data[:title]}'
343
344
  width='#{data[:video_width]}'
344
345
  height='#{data[:video_height]}'
345
346
  style='max-width:100%'
347
+ poster='#{escaped_image_src}'
346
348
  controls=''>
347
- <source src='#{escaped_src}'>
349
+ <source src='#{escaped_video_src}'>
348
350
  </video>
349
351
  HTML
350
352
  end
@@ -158,38 +158,46 @@ module Onebox
158
158
 
159
159
  @file = m[:file]
160
160
  @lang = Onebox::FileTypeFinder.from_file_name(m[:file])
161
- contents = open(self.raw_template(m), read_timeout: timeout).read
162
-
163
- contents_lines = contents.lines #get contents lines
164
- contents_lines_size = contents_lines.size #get number of lines
165
-
166
- cr = calc_range(m, contents_lines_size) #calculate the range of lines for output
167
- selected_one_liner = cr[:selected_one_liner] #if url is a one-liner calc_range will return it
168
- from = cr[:from]
169
- to = cr[:to]
170
- @truncated = cr[:truncated]
171
- range_provided = cr[:range_provided]
172
- @cr_results = cr
173
-
174
- if range_provided #if a range provided (single line or more)
175
- if SHOW_LINE_NUMBER
176
- lines_result = line_number_helper(contents_lines[(from - 1)..(to - 1)], from, selected_one_liner) #print code with prefix line numbers in case range provided
177
- contents = lines_result[:output]
178
- @selected_lines_array = lines_result[:array]
161
+
162
+ if @lang == "stl" && link.match(/^https?:\/\/(www\.)?github\.com.*\/blob\//)
163
+
164
+ @model_file = @lang.dup
165
+ @raw = "https://render.githubusercontent.com/view/solid?url=" + self.raw_template(m)
166
+
167
+ else
168
+ contents = open(self.raw_template(m), read_timeout: timeout).read
169
+
170
+ contents_lines = contents.lines #get contents lines
171
+ contents_lines_size = contents_lines.size #get number of lines
172
+
173
+ cr = calc_range(m, contents_lines_size) #calculate the range of lines for output
174
+ selected_one_liner = cr[:selected_one_liner] #if url is a one-liner calc_range will return it
175
+ from = cr[:from]
176
+ to = cr[:to]
177
+ @truncated = cr[:truncated]
178
+ range_provided = cr[:range_provided]
179
+ @cr_results = cr
180
+
181
+ if range_provided #if a range provided (single line or more)
182
+ if SHOW_LINE_NUMBER
183
+ lines_result = line_number_helper(contents_lines[(from - 1)..(to - 1)], from, selected_one_liner) #print code with prefix line numbers in case range provided
184
+ contents = lines_result[:output]
185
+ @selected_lines_array = lines_result[:array]
186
+ else
187
+ contents = contents_lines[(from - 1)..(to - 1)].join()
188
+ end
189
+
179
190
  else
180
191
  contents = contents_lines[(from - 1)..(to - 1)].join()
181
192
  end
182
193
 
183
- else
184
- contents = contents_lines[(from - 1)..(to - 1)].join()
185
- end
194
+ if contents.length > MAX_CHARS #truncate content chars to limits
195
+ contents = contents[0..MAX_CHARS]
196
+ @truncated = true
197
+ end
186
198
 
187
- if contents.length > MAX_CHARS #truncate content chars to limits
188
- contents = contents[0..MAX_CHARS]
189
- @truncated = true
199
+ @raw = contents
190
200
  end
191
-
192
- @raw = contents
193
201
  end
194
202
  end
195
203
 
@@ -206,7 +214,10 @@ module Onebox
206
214
  has_lines: !@selected_lines_array.nil?,
207
215
  selected_one_liner: @selected_one_liner,
208
216
  cr_results: @cr_results,
209
- truncated: @truncated
217
+ truncated: @truncated,
218
+ model_file: @model_file,
219
+ width: 480,
220
+ height: 360
210
221
  }
211
222
  end
212
223
  end
@@ -10,7 +10,7 @@ class Sanitize
10
10
  'a' => RELAXED[:attributes]['a'] + %w(target),
11
11
  'audio' => %w[controls],
12
12
  'embed' => %w[height src type width],
13
- 'iframe' => %w[allowfullscreen frameborder height scrolling src width],
13
+ 'iframe' => %w[allowfullscreen frameborder height scrolling src width data-original-href],
14
14
  'source' => %w[src type],
15
15
  'video' => %w[controls height loop width autoplay muted poster],
16
16
  'path' => %w[d],
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Onebox
4
- VERSION = "1.8.85"
4
+ VERSION = "1.8.86"
5
5
  end
@@ -1,6 +1,13 @@
1
1
  <h4><a href="{{link}}" target="_blank">{{title}}</a></h4>
2
2
  {{^has_lines}}
3
+ {{#model_file}}
4
+ <iframe class="render-viewer" width="{{width}}" height="{{height}}" src="{{content}}" sandbox="allow-scripts allow-same-origin allow-top-navigation ">
5
+ Viewer requires iframe.
6
+ </iframe>
7
+ {{/model_file}}
8
+ {{^model_file}}
3
9
  <pre><code class='{{lang}}'>{{content}}</code></pre>
10
+ {{/model_file}}
4
11
  {{/has_lines}}
5
12
  {{#has_lines}}
6
13
  {{! This is a template comment | Sample rules for this box
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onebox
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.85
4
+ version: 1.8.86
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joanna Zeta
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2019-04-12 00:00:00.000000000 Z
13
+ date: 2019-04-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: multi_json