parliament-utils 0.7.3 → 0.8.0

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: 47e6ded2c67344e025266b6e20656e2175d9923b
4
- data.tar.gz: 4a76564a1c8350b01c7e12e9697ccac84c68a5cb
3
+ metadata.gz: b173f819cf1d473df8cb3e8bdbe2f7baa1c07d77
4
+ data.tar.gz: 31fec4b9ad307c3da159a8a32067f5448ceb259a
5
5
  SHA512:
6
- metadata.gz: 698da1551e3038c7bf4796fc9f74733cdd909e9bf44cd4eb741361ca6426aa543f2b90b7302216a2f34234b2ac75bf79df91d881e462553376a1b9148c7b2e86
7
- data.tar.gz: d367656e31ff77254bc8182a72a1422b7a1401f673cffb1881f5b8254e43e4ecef8d84146c47e381cffe47384a4c39c884ee63152fb158a723997f87d59b9d10
6
+ metadata.gz: 7fa9ac42aa1f5e817e4136637030c231b902d723a1bb168fd42993391c50283d3ca63d8fdc8dd252a56d87e33a6edf106c655e43a60d6c45fc87f8a7e129d1b2
7
+ data.tar.gz: e7ca04377b71a343146b21324f94c7ca50b02eb54727fb99d95cbbc2d814d2d263ee2e3ec880f6ef00d28942a62d445365155ca1fe5469a637ccb6e559c158f6
@@ -2,7 +2,6 @@
2
2
 
3
3
  # Add new mime types for use in respond_to blocks:
4
4
  # Mime::Type.register "text/richtext", :rtf
5
-
6
5
  Parliament::Utils::Helpers::ApplicationHelper::API_MIME_TYPE_CONFIG.each do |mime_type|
7
6
  primary = mime_type.shift
8
7
  alternatives = mime_type
@@ -12,5 +12,5 @@ require 'parliament/utils/config/initializers/filter_parameter_logging'
12
12
  require 'parliament/utils/config/initializers/inflections'
13
13
  require 'parliament/utils/config/initializers/mime_types'
14
14
  require 'parliament/utils/config/initializers/session_store'
15
- require 'parliament/utils/config/initializers/timeout'
15
+ require 'parliament/utils/config/initializers/timeout' if defined?(Rack::Timeout)
16
16
  require 'parliament/utils/config/initializers/wrap_parameters'
@@ -0,0 +1,25 @@
1
+ require_relative '../services/markdown_converter'
2
+ require_relative '../services/markdown_scrubber'
3
+ require 'redcarpet'
4
+
5
+ module Parliament
6
+ module Utils
7
+ module Helpers
8
+ module MarkdownHelper
9
+ # Uses redcarpet gem to convert markdown into HTML, with chosen HTML extensions
10
+ # Uses custom Parliament::Utils::Services::ParliamentMarkdownRenderer to override default autolink behaviour of redcarpet gem
11
+ # Uses custom Parliament::Utils::Services::ParliamentMarkdownScrubber to allow additional HTML tags and attributes
12
+ #
13
+ # @return template [String] Template as HTML
14
+ def self.markdown(template)
15
+ parliament_renderer = Parliament::Utils::Services::ParliamentMarkdownRenderer
16
+ parliament_scrubber = Parliament::Utils::Services::ParliamentMarkdownScrubber.new
17
+
18
+ markdown = Redcarpet::Markdown.new(parliament_renderer, tables: true, autolink: true)
19
+ html = markdown.render(ActionController::Base.helpers.sanitize(template, scrubber: parliament_scrubber))
20
+ ActionController::Base.helpers.sanitize(html, scrubber: parliament_scrubber).html_safe
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,5 +1,5 @@
1
1
  require 'i18n'
2
- require 'parliament/utils/helpers/translation_helper' unless defined?(::Rails)
2
+ require 'parliament/utils/helpers/translation_helper'
3
3
 
4
4
  # attr [String] previous_path the path to redirect back to in the case of an error.
5
5
  module Parliament
@@ -7,7 +7,7 @@ module Parliament
7
7
  module Helpers
8
8
  module PostcodeHelper
9
9
 
10
- include Parliament::Utils::Helpers::TranslationHelper unless defined?(::Rails)
10
+ include Parliament::Utils::Helpers::TranslationHelper
11
11
 
12
12
  attr_accessor :previous_path
13
13
 
@@ -1,18 +1,18 @@
1
1
  require_relative './helpers/application_helper'
2
+ require_relative './helpers/filter_helper'
2
3
  require_relative './helpers/flag_helper'
3
4
  require_relative './helpers/houses_helper'
5
+ require_relative './helpers/markdown_helper' if defined?(Rails)
4
6
  require_relative './helpers/parliament_helper'
5
7
  require_relative './helpers/postcode_helper'
6
8
  require_relative './helpers/request_helper'
7
9
  require_relative './helpers/v_card_helper'
8
- require_relative './helpers/filter_helper'
9
10
 
10
11
  require 'parliament/grom/decorator'
11
12
 
12
13
  module Parliament
13
14
  module Utils
14
15
  module Helpers
15
-
16
16
  end
17
17
  end
18
18
  end
@@ -0,0 +1,52 @@
1
+ require 'uri'
2
+ require 'redcarpet'
3
+
4
+ module Parliament
5
+ module Utils
6
+ module Services
7
+ class ParliamentMarkdownRenderer < Redcarpet::Render::HTML
8
+ # Overrides default autolink behaviour of redcarpet gem for instances such as video embeds
9
+ #
10
+ # @param link [String] The link
11
+ # @param link_type [Symbol] The link type
12
+ # @return template [String] Original link text or HTML string replacement
13
+ #
14
+ def autolink(link, link_type)
15
+ if link_type == :url
16
+ return parliament_live_video_embed(link) if link.match(/parliamentlive.tv\/event\/index\/[a-z0-9-]{36}/i)
17
+ end
18
+
19
+ link # call super instead if we actually want autolinking
20
+ end
21
+
22
+ private
23
+
24
+ # Takes a parliamentlive.tv embed or video link and returns HTML for video embed
25
+ #
26
+ # @private
27
+ #
28
+ # @param link [String] The URL for a parliamentlive.tv embed or video
29
+ # @return template [String] The parliamentlive.tv video embed code
30
+ #
31
+ def parliament_live_video_embed(link)
32
+ uri = URI.parse(link)
33
+
34
+ # Generate video URL
35
+ video_url = 'https://videoplayback.parliamentlive.tv/Player/Index'.tap do |url|
36
+ # Add video ID
37
+ url << "/#{uri.path.split('/').last}?"
38
+ # Add original query if present, and not an empty string
39
+ url << "#{uri.query}&" if uri.query&.size
40
+ # Add player options
41
+ url << 'audioOnly=False&amp;autoStart=False&amp;statsEnabled=False'
42
+ end
43
+
44
+ # Return the video player
45
+ %(<div class="video-wrap">
46
+ <iframe src="#{video_url}" name="UKPPlayer" title="UK Parliament Player" seamless="seamless" frameborder="0" allowfullscreen style="width: 100%; height: 100%"></iframe>
47
+ </div>)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,18 @@
1
+ module Parliament
2
+ module Utils
3
+ module Services
4
+ class ParliamentMarkdownScrubber < Rails::Html::PermitScrubber
5
+ # Overrides default sanitization allowing Parliament tags and/or attributes
6
+ def initialize
7
+ super
8
+ self.tags = %w(p div h1 h2 h3 h4 h5 h6 span a ol li ul strong em i itag strike del u sup sub blockquote cite table thead tbody tfoot tr th td iframe image pre code dl dt dd hr br)
9
+ self.attributes = %w(class href src name title allowfullscreen seamless frameborder style)
10
+ end
11
+
12
+ def skip_node?(node)
13
+ node.text?
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,9 @@
1
+ require_relative './services/markdown_converter'
2
+ require_relative './services/markdown_scrubber'
3
+
4
+ module Parliament
5
+ module Utils
6
+ module Services
7
+ end
8
+ end
9
+ end
@@ -1,4 +1,4 @@
1
- require_relative './test_helpers/rails_helper' if defined?(::Rails)
1
+ require_relative './test_helpers/rails_helper' if defined?(Rails)
2
2
  require_relative './test_helpers/rspec_helper'
3
3
  require_relative './test_helpers/simplecov_helper'
4
4
  require_relative './test_helpers/vcr_helper'
@@ -8,7 +8,7 @@ require_relative './test_helpers/bandiera_helper'
8
8
  module Parliament
9
9
  module Utils
10
10
  module TestHelpers
11
- include Parliament::Utils::TestHelpers::RailsHelper if defined?(::Rails)
11
+ include Parliament::Utils::TestHelpers::RailsHelper if defined?(Rails)
12
12
  include Parliament::Utils::TestHelpers::RSpecHelper
13
13
  include Parliament::Utils::TestHelpers::SimpleCovHelper
14
14
  include Parliament::Utils::TestHelpers::VCRHelper
@@ -1,5 +1,5 @@
1
1
  module Parliament
2
2
  module Utils
3
- VERSION = '0.7.3'.freeze
3
+ VERSION = '0.8.0'.freeze
4
4
  end
5
5
  end
@@ -1,5 +1,6 @@
1
1
  require 'parliament/utils/version'
2
2
  require 'parliament/utils/helpers'
3
+ require 'parliament/utils/services'
3
4
  require 'parliament/utils/config/initializers/bandiera'
4
5
  require 'parliament/utils/test_helpers'
5
6
  require 'parliament/utils/railtie' if defined?(Rails)
@@ -31,12 +31,15 @@ Gem::Specification.new do |spec|
31
31
  spec.add_dependency 'bandiera-client'
32
32
  spec.add_dependency 'pugin'
33
33
  spec.add_dependency 'haml'
34
+ spec.add_dependency 'redcarpet', '~> 3.0'
34
35
 
35
36
  spec.add_development_dependency 'parliament-ruby', '~> 0.10'
36
37
  spec.add_development_dependency 'bundler', '~> 1.15'
37
38
  spec.add_development_dependency 'rake', '~> 10.0'
38
- spec.add_development_dependency 'rspec', '~> 3.0'
39
+ spec.add_development_dependency 'rails', '~> 5.1'
40
+ spec.add_development_dependency 'rspec-rails', '~> 3.6'
39
41
  spec.add_development_dependency 'vcr', '~> 3.0'
40
42
  spec.add_development_dependency 'simplecov', '~> 0.12'
43
+ spec.add_development_dependency 'sqlite3', '~> 1.3'
41
44
  spec.add_development_dependency 'webmock', '~> 2.3'
42
45
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parliament-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.3
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rebecca Appleyard
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-04 00:00:00.000000000 Z
11
+ date: 2018-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parliament-ruby
@@ -150,6 +150,20 @@ dependencies:
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: redcarpet
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '3.0'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '3.0'
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: parliament-ruby
155
169
  requirement: !ruby/object:Gem::Requirement
@@ -193,19 +207,33 @@ dependencies:
193
207
  - !ruby/object:Gem::Version
194
208
  version: '10.0'
195
209
  - !ruby/object:Gem::Dependency
196
- name: rspec
210
+ name: rails
197
211
  requirement: !ruby/object:Gem::Requirement
198
212
  requirements:
199
213
  - - "~>"
200
214
  - !ruby/object:Gem::Version
201
- version: '3.0'
215
+ version: '5.1'
202
216
  type: :development
203
217
  prerelease: false
204
218
  version_requirements: !ruby/object:Gem::Requirement
205
219
  requirements:
206
220
  - - "~>"
207
221
  - !ruby/object:Gem::Version
208
- version: '3.0'
222
+ version: '5.1'
223
+ - !ruby/object:Gem::Dependency
224
+ name: rspec-rails
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - "~>"
228
+ - !ruby/object:Gem::Version
229
+ version: '3.6'
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - "~>"
235
+ - !ruby/object:Gem::Version
236
+ version: '3.6'
209
237
  - !ruby/object:Gem::Dependency
210
238
  name: vcr
211
239
  requirement: !ruby/object:Gem::Requirement
@@ -234,6 +262,20 @@ dependencies:
234
262
  - - "~>"
235
263
  - !ruby/object:Gem::Version
236
264
  version: '0.12'
265
+ - !ruby/object:Gem::Dependency
266
+ name: sqlite3
267
+ requirement: !ruby/object:Gem::Requirement
268
+ requirements:
269
+ - - "~>"
270
+ - !ruby/object:Gem::Version
271
+ version: '1.3'
272
+ type: :development
273
+ prerelease: false
274
+ version_requirements: !ruby/object:Gem::Requirement
275
+ requirements:
276
+ - - "~>"
277
+ - !ruby/object:Gem::Version
278
+ version: '1.3'
237
279
  - !ruby/object:Gem::Dependency
238
280
  name: webmock
239
281
  requirement: !ruby/object:Gem::Requirement
@@ -293,12 +335,16 @@ files:
293
335
  - lib/parliament/utils/helpers/filter_helper.rb
294
336
  - lib/parliament/utils/helpers/flag_helper.rb
295
337
  - lib/parliament/utils/helpers/houses_helper.rb
338
+ - lib/parliament/utils/helpers/markdown_helper.rb
296
339
  - lib/parliament/utils/helpers/parliament_helper.rb
297
340
  - lib/parliament/utils/helpers/postcode_helper.rb
298
341
  - lib/parliament/utils/helpers/request_helper.rb
299
342
  - lib/parliament/utils/helpers/translation_helper.rb
300
343
  - lib/parliament/utils/helpers/v_card_helper.rb
301
344
  - lib/parliament/utils/railtie.rb
345
+ - lib/parliament/utils/services.rb
346
+ - lib/parliament/utils/services/markdown_converter.rb
347
+ - lib/parliament/utils/services/markdown_scrubber.rb
302
348
  - lib/parliament/utils/test_helpers.rb
303
349
  - lib/parliament/utils/test_helpers/bandiera_helper.rb
304
350
  - lib/parliament/utils/test_helpers/rails_helper.rb