wcc-contentful-app 1.0.4 → 1.0.8

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e5a7b3e4f339c5c41851ed567148325b2050345b
4
- data.tar.gz: 21e326e43a9acafacd50b09f6b56fb384e84dc00
2
+ SHA256:
3
+ metadata.gz: 90e14d9120bf9e13feaac1b38d6de53374798a9b384bcc6b4acf099ffd83b183
4
+ data.tar.gz: f4276cdb1f6f466dd8252a5316ca0bb0a86310cabdf96e889a66bc68b8084194
5
5
  SHA512:
6
- metadata.gz: e61db702889193b0b9bbf89b0b0513ef95bf95e79abf63e620204f642e382b8e4a9a759ae568d159bbf96b680c10d7a17a476331082a55d3f005f8e5da7488ca
7
- data.tar.gz: 4104285fc476c42faed8f78a889cac82f373ec944623458f62d2e716dbfb26a785fa38de9d2364f3b2174ba1d9f53a777eba67c75387642833151c6ab1b2ad94
6
+ metadata.gz: c14a98f65f94a006d19b36b9ffd731ae0973190e12ef78be4188da0bc9429975a6657e04c7548ee3950d70d2d41105ceed703815754e87fc32abee2a90d19583
7
+ data.tar.gz: '09e349ec2bf158a6c6c5dbc7cf281e6850d35397c85bd9fd99bdfdb7acbca7bac28a7e83945bb2543f186e1f1ac388c00abf697ad9fd54615d7337a19f2dc4d3'
@@ -34,88 +34,17 @@ module WCC::Contentful::App::SectionHelper
34
34
  CGI.escape(title.gsub(/\W+/, '-')) if title.present?
35
35
  end
36
36
 
37
- def markdown(text)
38
- raise ArgumentError, 'markdown method requires text' unless text
39
-
40
- markdown_links = links_within_markdown(text)
41
- links_with_classes, raw_classes = gather_links_with_classes_data(markdown_links)
42
-
43
- options = {
44
- filter_html: true,
45
- hard_wrap: true,
46
- link_attributes: { target: '_blank' },
47
- space_after_headers: true,
48
- fenced_code_blocks: true,
49
- links_with_classes: links_with_classes
50
- }
51
-
52
- extensions = {
53
- autolink: true,
54
- superscript: true,
55
- disable_indented_code_blocks: true,
56
- tables: true
57
- }
58
-
59
- renderer = ::WCC::Contentful::App::CustomMarkdownRender.new(options)
60
- markdown = ::Redcarpet::Markdown.new(renderer, extensions)
61
- html_to_render = markdown.render(remove_markdown_href_class_syntax(raw_classes, text))
37
+ def markdown(text, options = {})
38
+ renderer = WCC::Contentful::App::MarkdownRenderer.new(
39
+ options
40
+ )
41
+ html_to_render = renderer.markdown(text)
62
42
 
63
43
  content_tag(:div,
64
44
  CGI.unescapeHTML(html_to_render).html_safe,
65
45
  class: 'formatted-content')
66
46
  end
67
47
 
68
- def links_within_markdown(text)
69
- text.scan(/(\[(.*?)\]\((.*?)\)(\{\:.*?\})?)/)
70
- end
71
-
72
- def gather_links_with_classes_data(markdown_links)
73
- links_with_classes_arr = []
74
- raw_classes_arr = []
75
- markdown_links.each do |markdown_link_arr|
76
- next unless markdown_link_arr.last.present?
77
-
78
- raw_class = markdown_link_arr[3]
79
- url, title = url_and_title(markdown_link_arr[2])
80
- content = markdown_link_arr[1]
81
- classes = capture_individual_classes(raw_class)
82
- link_class = combine_individual_classes_to_one_string(classes)
83
-
84
- raw_classes_arr << raw_class
85
- links_with_classes_arr << [url, title, content, link_class]
86
- end
87
-
88
- [links_with_classes_arr, raw_classes_arr]
89
- end
90
-
91
- def remove_markdown_href_class_syntax(raw_classes, text)
92
- text_without_markdown_class_syntax = text.dup
93
- raw_classes.each { |klass| text_without_markdown_class_syntax.slice!(klass) }
94
- text_without_markdown_class_syntax
95
- end
96
-
97
- def url_and_title(markdown_link_and_title)
98
- match =
99
- markdown_link_and_title.scan(
100
- /(\s|^)(https?:\/\/\S*|^\/\S*\/*\S*|^#\S*|mailto:\S*)(?=\s|$)|(\".*?\")/
101
- )
102
- url = match[0][1]
103
- title = match[1] ? match[1][2] : nil
104
- [url, title]
105
- end
106
-
107
- def capture_individual_classes(classes)
108
- classes.scan(/\.[^\.\}\s]*/)
109
- end
110
-
111
- def combine_individual_classes_to_one_string(classes)
112
- class_string = ''
113
- classes.each do |klass|
114
- class_string += klass.tr('.', '') + ' '
115
- end
116
- class_string
117
- end
118
-
119
48
  def safe_line_break(text, options = {})
120
49
  return unless text.present?
121
50
 
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'redcarpet'
4
+
3
5
  module WCC::Contentful::App
4
6
  class CustomMarkdownRender < Redcarpet::Render::HTML
5
7
  def initialize(options)
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './custom_markdown_render'
4
+
5
+ class WCC::Contentful::App::MarkdownRenderer
6
+ attr_reader :options, :extensions
7
+
8
+ def initialize(options = nil)
9
+ @extensions = {
10
+ autolink: true,
11
+ superscript: true,
12
+ disable_indented_code_blocks: true,
13
+ tables: true
14
+ }.merge!(options&.delete(:extensions) || {})
15
+
16
+ @options = {
17
+ filter_html: true,
18
+ hard_wrap: true,
19
+ link_attributes: { target: '_blank' },
20
+ space_after_headers: true,
21
+ fenced_code_blocks: true
22
+ }.merge!(options || {})
23
+ end
24
+
25
+ def markdown(text)
26
+ raise ArgumentError, 'markdown method requires text' unless text
27
+
28
+ markdown_links = links_within_markdown(text)
29
+ links_with_classes, raw_classes = gather_links_with_classes_data(markdown_links)
30
+
31
+ options = @options.merge({
32
+ links_with_classes: links_with_classes
33
+ })
34
+
35
+ renderer = ::WCC::Contentful::App::CustomMarkdownRender.new(options)
36
+ markdown = ::Redcarpet::Markdown.new(renderer, extensions)
37
+ markdown.render(remove_markdown_href_class_syntax(raw_classes, text))
38
+ end
39
+
40
+ alias_method :call, :markdown
41
+
42
+ private
43
+
44
+ def remove_markdown_href_class_syntax(raw_classes, text)
45
+ text_without_markdown_class_syntax = text.dup
46
+ raw_classes.each { |klass| text_without_markdown_class_syntax.slice!(klass) }
47
+ text_without_markdown_class_syntax
48
+ end
49
+
50
+ def links_within_markdown(text)
51
+ text.scan(/(\[(.*?)\]\((.*?)\)(\{\:.*?\})?)/)
52
+ end
53
+
54
+ def gather_links_with_classes_data(markdown_links)
55
+ links_with_classes_arr = []
56
+ raw_classes_arr = []
57
+ markdown_links.each do |markdown_link_arr|
58
+ next unless markdown_link_arr.last.present?
59
+
60
+ raw_class = markdown_link_arr[3]
61
+ url, title = url_and_title(markdown_link_arr[2])
62
+ content = markdown_link_arr[1]
63
+ classes = capture_individual_classes(raw_class)
64
+ link_class = combine_individual_classes_to_one_string(classes)
65
+
66
+ raw_classes_arr << raw_class
67
+ links_with_classes_arr << [url, title, content, link_class]
68
+ end
69
+
70
+ [links_with_classes_arr, raw_classes_arr]
71
+ end
72
+
73
+ def url_and_title(markdown_link_and_title)
74
+ match =
75
+ markdown_link_and_title.scan(
76
+ /(\s|^)(https?:\/\/\S*|^\/\S*\/*\S*|^#\S*|mailto:\S*)(?=\s|$)|(\".*?\")/
77
+ )
78
+ url = match[0][1]
79
+ title = match[1] ? match[1][2] : nil
80
+ [url, title]
81
+ end
82
+
83
+ def capture_individual_classes(classes)
84
+ classes.scan(/\.[^\.\}\s]*/)
85
+ end
86
+
87
+ def combine_individual_classes_to_one_string(classes)
88
+ class_string = ''
89
+ classes.each do |klass|
90
+ class_string += klass.tr('.', '') + ' '
91
+ end
92
+ class_string
93
+ end
94
+ end
@@ -3,7 +3,7 @@
3
3
  module WCC
4
4
  module Contentful
5
5
  module App
6
- VERSION = '1.0.4'
6
+ VERSION = '1.0.8'
7
7
  end
8
8
  end
9
9
  end
@@ -2,9 +2,9 @@
2
2
 
3
3
  require 'wcc/contentful/rails'
4
4
 
5
- require_relative './app/rails'
6
5
  require_relative './app/exceptions'
7
6
  require_relative './app/configuration'
7
+ require_relative './app/markdown_renderer'
8
8
 
9
9
  module WCC::Contentful::App
10
10
  class << self
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wcc-contentful-app
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Watermark Dev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-17 00:00:00.000000000 Z
11
+ date: 2022-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capybara
@@ -352,14 +352,14 @@ dependencies:
352
352
  requirements:
353
353
  - - "~>"
354
354
  - !ruby/object:Gem::Version
355
- version: 1.0.4
355
+ version: 1.0.8
356
356
  type: :runtime
357
357
  prerelease: false
358
358
  version_requirements: !ruby/object:Gem::Requirement
359
359
  requirements:
360
360
  - - "~>"
361
361
  - !ruby/object:Gem::Version
362
- version: 1.0.4
362
+ version: 1.0.8
363
363
  description: Models, Controllers, and Views common to Watermark Church apps
364
364
  email:
365
365
  - dev@watermark.org
@@ -384,7 +384,6 @@ files:
384
384
  - app/mailers/wcc/contentful/app/contact_mailer.rb
385
385
  - app/models/concerns/wcc/contentful/app/preview_password.rb
386
386
  - app/models/wcc/contentful/app/contact_form_submission.rb
387
- - app/models/wcc/contentful/app/custom_markdown_render.rb
388
387
  - app/views/components/_faq_row.html.erb
389
388
  - app/views/components/_menu-item.html.erb
390
389
  - app/views/components/_other-menu-item.html.erb
@@ -440,8 +439,10 @@ files:
440
439
  - lib/generators/wcc/templates/wcc_contentful.rb
441
440
  - lib/wcc/contentful/app.rb
442
441
  - lib/wcc/contentful/app/configuration.rb
442
+ - lib/wcc/contentful/app/custom_markdown_render.rb
443
443
  - lib/wcc/contentful/app/engine.rb
444
444
  - lib/wcc/contentful/app/exceptions.rb
445
+ - lib/wcc/contentful/app/markdown_renderer.rb
445
446
  - lib/wcc/contentful/app/rails.rb
446
447
  - lib/wcc/contentful/app/version.rb
447
448
  - lib/wcc/contentful/model/dropdown_menu.rb
@@ -474,7 +475,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
474
475
  version: '0'
475
476
  requirements: []
476
477
  rubyforge_project:
477
- rubygems_version: 2.6.11
478
+ rubygems_version: 2.7.6.2
478
479
  signing_key:
479
480
  specification_version: 4
480
481
  summary: "[![Gem Version](https://badge.fury.io/rb/wcc-contentful-app.svg)](https://rubygems.org/gems/wcc-contentful-app)