wcc-contentful-app 1.0.5 → 1.1.0
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 +5 -5
- data/app/helpers/wcc/contentful/app/section_helper.rb +5 -76
- data/{app/models → lib}/wcc/contentful/app/custom_markdown_render.rb +2 -0
- data/lib/wcc/contentful/app/markdown_renderer.rb +96 -0
- data/lib/wcc/contentful/app/version.rb +1 -1
- data/lib/wcc/contentful/app.rb +2 -2
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 444b08f86e21df28e755f40fe31a9c178825a96a244783876a10cf5e7dc5325e
|
4
|
+
data.tar.gz: 9405a2a26803c33773a5bce865b5404d07a60a18dc26972b1a08e9785b335d83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f480e13b3d2d6e4638137e88ff49486eda16b45af0d4a271501c5cd2e4b6c298545b44fe7472be3e37d8101c4218339856c81a0fca68c91771867f1f47efdfc6
|
7
|
+
data.tar.gz: 34c0d07fe98312d67791ce8b99b7383963e2a5e0391e7f1c32864fae4c143f7d5909fb99ee639f1193b8cbe66a877072ec9b066b2e4192477603ebb7814476a7
|
@@ -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
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
|
@@ -0,0 +1,96 @@
|
|
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
|
+
options = options&.dup
|
10
|
+
|
11
|
+
@extensions = {
|
12
|
+
autolink: true,
|
13
|
+
superscript: true,
|
14
|
+
disable_indented_code_blocks: true,
|
15
|
+
tables: true
|
16
|
+
}.merge!(options&.delete(:extensions) || {})
|
17
|
+
|
18
|
+
@options = {
|
19
|
+
filter_html: true,
|
20
|
+
hard_wrap: true,
|
21
|
+
link_attributes: { target: '_blank' },
|
22
|
+
space_after_headers: true,
|
23
|
+
fenced_code_blocks: true
|
24
|
+
}.merge!(options || {})
|
25
|
+
end
|
26
|
+
|
27
|
+
def markdown(text)
|
28
|
+
raise ArgumentError, 'markdown method requires text' unless text
|
29
|
+
|
30
|
+
markdown_links = links_within_markdown(text)
|
31
|
+
links_with_classes, raw_classes = gather_links_with_classes_data(markdown_links)
|
32
|
+
|
33
|
+
options = @options.merge({
|
34
|
+
links_with_classes: links_with_classes
|
35
|
+
})
|
36
|
+
|
37
|
+
renderer = ::WCC::Contentful::App::CustomMarkdownRender.new(options)
|
38
|
+
markdown = ::Redcarpet::Markdown.new(renderer, extensions)
|
39
|
+
markdown.render(remove_markdown_href_class_syntax(raw_classes, text))
|
40
|
+
end
|
41
|
+
|
42
|
+
alias_method :call, :markdown
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def remove_markdown_href_class_syntax(raw_classes, text)
|
47
|
+
text_without_markdown_class_syntax = text.dup
|
48
|
+
raw_classes.each { |klass| text_without_markdown_class_syntax.slice!(klass) }
|
49
|
+
text_without_markdown_class_syntax
|
50
|
+
end
|
51
|
+
|
52
|
+
def links_within_markdown(text)
|
53
|
+
text.scan(/(\[(.*?)\]\((.*?)\)(\{\:.*?\})?)/)
|
54
|
+
end
|
55
|
+
|
56
|
+
def gather_links_with_classes_data(markdown_links)
|
57
|
+
links_with_classes_arr = []
|
58
|
+
raw_classes_arr = []
|
59
|
+
markdown_links.each do |markdown_link_arr|
|
60
|
+
next unless markdown_link_arr.last.present?
|
61
|
+
|
62
|
+
raw_class = markdown_link_arr[3]
|
63
|
+
url, title = url_and_title(markdown_link_arr[2])
|
64
|
+
content = markdown_link_arr[1]
|
65
|
+
classes = capture_individual_classes(raw_class)
|
66
|
+
link_class = combine_individual_classes_to_one_string(classes)
|
67
|
+
|
68
|
+
raw_classes_arr << raw_class
|
69
|
+
links_with_classes_arr << [url, title, content, link_class]
|
70
|
+
end
|
71
|
+
|
72
|
+
[links_with_classes_arr, raw_classes_arr]
|
73
|
+
end
|
74
|
+
|
75
|
+
def url_and_title(markdown_link_and_title)
|
76
|
+
match =
|
77
|
+
markdown_link_and_title.scan(
|
78
|
+
/(\s|^)(https?:\/\/\S*|^\/\S*\/*\S*|^#\S*|mailto:\S*)(?=\s|$)|(\".*?\")/
|
79
|
+
)
|
80
|
+
url = match[0][1]
|
81
|
+
title = match[1] ? match[1][2] : nil
|
82
|
+
[url, title]
|
83
|
+
end
|
84
|
+
|
85
|
+
def capture_individual_classes(classes)
|
86
|
+
classes.scan(/\.[^\.\}\s]*/)
|
87
|
+
end
|
88
|
+
|
89
|
+
def combine_individual_classes_to_one_string(classes)
|
90
|
+
class_string = ''
|
91
|
+
classes.each do |klass|
|
92
|
+
class_string += klass.tr('.', '') + ' '
|
93
|
+
end
|
94
|
+
class_string
|
95
|
+
end
|
96
|
+
end
|
data/lib/wcc/contentful/app.rb
CHANGED
@@ -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
|
@@ -37,7 +37,7 @@ module WCC::Contentful::App
|
|
37
37
|
WCC::Contentful.init!
|
38
38
|
|
39
39
|
# Extend all model types w/ validation & extra fields
|
40
|
-
WCC::Contentful.
|
40
|
+
WCC::Contentful::Model.schema.each_value do |t|
|
41
41
|
file = File.dirname(__FILE__) + "/model/#{t.name.underscore}.rb"
|
42
42
|
require file if File.exist?(file)
|
43
43
|
end
|
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
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Watermark Dev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-02 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
|
355
|
+
version: 1.1.0
|
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
|
362
|
+
version: 1.1.0
|
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
|
@@ -457,7 +458,7 @@ homepage: https://github.com/watermarkchurch/wcc-contentful
|
|
457
458
|
licenses:
|
458
459
|
- MIT
|
459
460
|
metadata:
|
460
|
-
documentation_uri: https://watermarkchurch.github.io/wcc-contentful/1.
|
461
|
+
documentation_uri: https://watermarkchurch.github.io/wcc-contentful/1.1/wcc-contentful-app
|
461
462
|
post_install_message:
|
462
463
|
rdoc_options: []
|
463
464
|
require_paths:
|
@@ -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.
|
478
|
+
rubygems_version: 2.7.6.2
|
478
479
|
signing_key:
|
479
480
|
specification_version: 4
|
480
481
|
summary: "[](https://rubygems.org/gems/wcc-contentful-app)
|