article_json 0.3.2 → 0.3.3

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
  SHA1:
3
- metadata.gz: 0f9222cb3d5c6c6c17776ac0c2ac71a1201367c6
4
- data.tar.gz: 0f474e416aed216896f2d2dbb5230670c73efc44
3
+ metadata.gz: cb77fa8003fe6ff04b110471104c7f21c96f731c
4
+ data.tar.gz: 5ae20ac88f04384394cd27707fdabc98be653171
5
5
  SHA512:
6
- metadata.gz: ebf75ee9a5d5e5c23a348efaa550c0f96dc29ad97d96e2d4792737d27c6816b0abbb1fa4945bbf1297493b4c2f30ff1aa465663d0be197b274378707c2bf3a49
7
- data.tar.gz: 3ce371166ea56f2e474abfafd0d1d03ce040fc21f00c73d506166031d82825859459c83ce075ea60a10009ce079da284e64e8a1e603c5aa10155eca5a0061418
6
+ metadata.gz: 8fbbd7e0de9d4632cc4f491358b1f1c16edb2f0ad63c2be91899636ab6548473f51f35b63dd773f0c5ad0ceb9ea61d4cc5af9712c039cfa6b105cdfa1b55d6f1
7
+ data.tar.gz: 04be4accfb46e6c035252ca2be7154f7d2cc6794c1d0b24d09ce5ac1c3ac53ee47e79eca9fb1680dee27ee724a4fde76ee8c03846267d7523ec71f18dcbe2998
data/CHANGELOG.md CHANGED
@@ -1,4 +1,6 @@
1
1
  # Changelog
2
+ ## 0.3.3 - 2018/4/12
3
+ - Support embedding SoundCloud
2
4
 
3
5
  ## 0.3.2 - 2017/12/06
4
6
  - Another **fix** to prevent `nil` elements when placing additional elements on articles that end with empty paragraphs
@@ -43,7 +45,7 @@ One potentially **breaking change** was added:
43
45
 
44
46
  ## 0.1.0 - 2017/09/20
45
47
  This is the very first release, with the following functionality:
46
- - article-json format that supports several basic elements; like headings,
48
+ - article-json format that supports several basic elements; like headings,
47
49
  paragraphs, images or lists
48
50
  - Resolving of embedded elements like videos or tweets via OEmbed standard
49
51
  - Conversion from and to JSON (or ruby hashes)
data/lib/article_json.rb CHANGED
@@ -37,6 +37,7 @@ require_relative 'article_json/import/google_doc/html/embedded_vimeo_video_parse
37
37
  require_relative 'article_json/import/google_doc/html/embedded_youtube_video_parser'
38
38
  require_relative 'article_json/import/google_doc/html/embedded_slideshare_parser'
39
39
  require_relative 'article_json/import/google_doc/html/embedded_tweet_parser'
40
+ require_relative 'article_json/import/google_doc/html/embedded_soundcloud_parser'
40
41
  require_relative 'article_json/import/google_doc/html/parser'
41
42
 
42
43
  require_relative 'article_json/export/common/elements/base'
@@ -26,8 +26,8 @@ module ArticleJSON
26
26
  def script_tags
27
27
  sources.map do |custom_element_tag, src|
28
28
  <<-HTML.gsub(/\s+/, ' ').strip
29
- <script async
30
- custom-element="#{custom_element_tag}"
29
+ <script async
30
+ custom-element="#{custom_element_tag}"
31
31
  src="#{src}"></script>
32
32
  HTML
33
33
  end
@@ -46,6 +46,8 @@ module ArticleJSON
46
46
  'amp-vimeo': 'https://cdn.ampproject.org/v0/amp-vimeo-0.1.js',
47
47
  'amp-facebook':
48
48
  'https://cdn.ampproject.org/v0/amp-facebook-0.1.js',
49
+ 'amp-soundcloud':
50
+ 'https://cdn.ampproject.org/v0/amp-soundcloud-0.1.js',
49
51
  }[custom_element_tag]
50
52
  end
51
53
  end
@@ -14,6 +14,7 @@ module ArticleJSON
14
14
  when :facebook_video then %i(amp-facebook)
15
15
  when :tweet then %i(amp-twitter)
16
16
  when :slideshare then %i(amp-iframe)
17
+ when :soundcloud then %i(amp-soundcloud)
17
18
  else []
18
19
  end
19
20
  end
@@ -33,7 +34,9 @@ module ArticleJSON
33
34
  when :tweet
34
35
  tweet_node
35
36
  when :slideshare
36
- slideshare_node
37
+ iframe_node
38
+ when :soundcloud
39
+ soundcloud_node
37
40
  end
38
41
  end
39
42
 
@@ -74,8 +77,20 @@ module ArticleJSON
74
77
  height: default_height)
75
78
  end
76
79
 
80
+ def soundcloud_node
81
+ src = Nokogiri::HTML(@element.oembed_data[:html])
82
+ .xpath('//iframe/@src').first.value
83
+ track_id = src.match(/tracks%2F(\d+)/)[1]
84
+ create_element('amp-soundcloud',
85
+ layout: 'fixed-height',
86
+ 'data-trackid': track_id,
87
+ 'data-visual': true,
88
+ width: 'auto',
89
+ height: default_height)
90
+ end
91
+
77
92
  # @return [Nokogiri::XML::Element]
78
- def slideshare_node
93
+ def iframe_node
79
94
  node = Nokogiri::HTML(@element.oembed_data[:html]).xpath('//iframe')
80
95
  create_element('amp-iframe',
81
96
  src: node.attribute('src').value,
@@ -94,6 +94,7 @@ module ArticleJSON
94
94
  EmbeddedYoutubeVideoParser,
95
95
  EmbeddedTweetParser,
96
96
  EmbeddedSlideshareParser,
97
+ EmbeddedSoundcloudParser,
97
98
  ]
98
99
  end
99
100
 
@@ -0,0 +1,28 @@
1
+ module ArticleJSON
2
+ module Import
3
+ module GoogleDoc
4
+ module HTML
5
+ class EmbeddedSoundcloudParser < EmbeddedParser
6
+ # The type of this embedded element
7
+ # @return [Symbol]
8
+ def embed_type
9
+ :soundcloud
10
+ end
11
+
12
+ class << self
13
+ # Regular expression to check if a given string is a Soundcloud URL
14
+ # Also used to extract the ID from the URL.
15
+ # @return [Regexp]
16
+ def url_regexp
17
+ %r{
18
+ ^\S* # all protocols & sub domains
19
+ soundcloud\.com/ # domain
20
+ (?<id>.+) # the slug of the user / track
21
+ }xi
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -9,4 +9,5 @@ require_relative 'utils/o_embed_resolver/slideshare'
9
9
  require_relative 'utils/o_embed_resolver/tweet'
10
10
  require_relative 'utils/o_embed_resolver/vimeo_video'
11
11
  require_relative 'utils/o_embed_resolver/youtube_video'
12
+ require_relative 'utils/o_embed_resolver/soundcloud'
12
13
  require_relative 'utils/additional_element_placer'
@@ -85,6 +85,7 @@ module ArticleJSON
85
85
  tweet: Tweet,
86
86
  vimeo_video: VimeoVideo,
87
87
  youtube_video: YoutubeVideo,
88
+ soundcloud: Soundcloud,
88
89
  }[type.to_sym]
89
90
  end
90
91
  end
@@ -0,0 +1,25 @@
1
+ module ArticleJSON
2
+ module Utils
3
+ module OEmbedResolver
4
+ class Soundcloud < Base
5
+ # Human readable name of the resolver
6
+ # @return [String]
7
+ def name
8
+ 'Soundcloud'
9
+ end
10
+
11
+ # The URL for the oembed API call
12
+ # @return [String]
13
+ def oembed_url
14
+ "http://soundcloud.com/oembed?url=#{source_url}&format=json"
15
+ end
16
+
17
+ # The URL of the element
18
+ # @return [String]
19
+ def source_url
20
+ "https://soundcloud.com/#{@element.embed_id}"
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,3 +1,3 @@
1
1
  module ArticleJSON
2
- VERSION = '0.3.2'
2
+ VERSION = '0.3.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: article_json
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Sager
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-12-07 00:00:00.000000000 Z
13
+ date: 2018-04-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: nokogiri
@@ -185,6 +185,7 @@ files:
185
185
  - lib/article_json/import/google_doc/html/embedded_facebook_video_parser.rb
186
186
  - lib/article_json/import/google_doc/html/embedded_parser.rb
187
187
  - lib/article_json/import/google_doc/html/embedded_slideshare_parser.rb
188
+ - lib/article_json/import/google_doc/html/embedded_soundcloud_parser.rb
188
189
  - lib/article_json/import/google_doc/html/embedded_tweet_parser.rb
189
190
  - lib/article_json/import/google_doc/html/embedded_vimeo_video_parser.rb
190
191
  - lib/article_json/import/google_doc/html/embedded_youtube_video_parser.rb
@@ -204,6 +205,7 @@ files:
204
205
  - lib/article_json/utils/o_embed_resolver/base.rb
205
206
  - lib/article_json/utils/o_embed_resolver/facebook_video.rb
206
207
  - lib/article_json/utils/o_embed_resolver/slideshare.rb
208
+ - lib/article_json/utils/o_embed_resolver/soundcloud.rb
207
209
  - lib/article_json/utils/o_embed_resolver/tweet.rb
208
210
  - lib/article_json/utils/o_embed_resolver/vimeo_video.rb
209
211
  - lib/article_json/utils/o_embed_resolver/youtube_video.rb
@@ -228,7 +230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
228
230
  version: '0'
229
231
  requirements: []
230
232
  rubyforge_project:
231
- rubygems_version: 2.6.12
233
+ rubygems_version: 2.6.14
232
234
  signing_key:
233
235
  specification_version: 4
234
236
  summary: JSON Format for News Articles & Ruby Gem