wcc-contentful-app 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/app/helpers/wcc/contentful/app/section_helper.rb +2 -75
- data/{app/models → lib}/wcc/contentful/app/custom_markdown_render.rb +0 -0
- data/lib/wcc/contentful/app/markdown_renderer.rb +85 -0
- data/lib/wcc/contentful/app/version.rb +1 -1
- data/lib/wcc/contentful/app.rb +1 -1
- metadata +11 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 222d97e2c5e468eb06480abd758461d38c47cff94d3ae3b66546ca4a2dc28270
|
4
|
+
data.tar.gz: c29432ed47e73ae1be706e1aef01ccc38b74d812ce354d39fc5c8d55d34f79b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37edcae2cb5a0bb83ec1cce4f19f42965e3a95c6f47899408dfd53883641bff88c6736a3cd7fdfa0a5d6609c3f0d0824ee776dbad374a44b7e31c3c25dbafb88
|
7
|
+
data.tar.gz: fca724980ba8a2594f14b51df9f86765350520fda4baca57719df8a013d3d24fc9e1297dc4c086378e720002cc5d3c46ed37874068d3a045eec97a8c51223c12
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'redcarpet'
|
4
|
+
require '../wcc-contentful-app/lib/wcc/contentful/app/markdown_renderer'
|
4
5
|
|
5
6
|
module WCC::Contentful::App::SectionHelper
|
6
7
|
extend self
|
@@ -35,87 +36,13 @@ module WCC::Contentful::App::SectionHelper
|
|
35
36
|
end
|
36
37
|
|
37
38
|
def markdown(text)
|
38
|
-
|
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))
|
39
|
+
html_to_render = WCC::Contentful::App::MarkdownRenderer.new.markdown(text)
|
62
40
|
|
63
41
|
content_tag(:div,
|
64
42
|
CGI.unescapeHTML(html_to_render).html_safe,
|
65
43
|
class: 'formatted-content')
|
66
44
|
end
|
67
45
|
|
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
46
|
def safe_line_break(text, options = {})
|
120
47
|
return unless text.present?
|
121
48
|
|
File without changes
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './custom_markdown_render'
|
4
|
+
|
5
|
+
class WCC::Contentful::App::MarkdownRenderer
|
6
|
+
def markdown(text)
|
7
|
+
raise ArgumentError, 'markdown method requires text' unless text
|
8
|
+
|
9
|
+
markdown_links = links_within_markdown(text)
|
10
|
+
links_with_classes, raw_classes = gather_links_with_classes_data(markdown_links)
|
11
|
+
|
12
|
+
options = {
|
13
|
+
filter_html: true,
|
14
|
+
hard_wrap: true,
|
15
|
+
link_attributes: { target: '_blank' },
|
16
|
+
space_after_headers: true,
|
17
|
+
fenced_code_blocks: true,
|
18
|
+
links_with_classes: links_with_classes
|
19
|
+
}
|
20
|
+
|
21
|
+
extensions = {
|
22
|
+
autolink: true,
|
23
|
+
superscript: true,
|
24
|
+
disable_indented_code_blocks: true,
|
25
|
+
tables: true
|
26
|
+
}
|
27
|
+
|
28
|
+
renderer = ::WCC::Contentful::App::CustomMarkdownRender.new(options)
|
29
|
+
markdown = ::Redcarpet::Markdown.new(renderer, extensions)
|
30
|
+
markdown.render(remove_markdown_href_class_syntax(raw_classes, text))
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def remove_markdown_href_class_syntax(raw_classes, text)
|
36
|
+
text_without_markdown_class_syntax = text.dup
|
37
|
+
raw_classes.each { |klass| text_without_markdown_class_syntax.slice!(klass) }
|
38
|
+
text_without_markdown_class_syntax
|
39
|
+
end
|
40
|
+
|
41
|
+
def links_within_markdown(text)
|
42
|
+
text.scan(/(\[(.*?)\]\((.*?)\)(\{\:.*?\})?)/)
|
43
|
+
end
|
44
|
+
|
45
|
+
def gather_links_with_classes_data(markdown_links)
|
46
|
+
links_with_classes_arr = []
|
47
|
+
raw_classes_arr = []
|
48
|
+
markdown_links.each do |markdown_link_arr|
|
49
|
+
next unless markdown_link_arr.last.present?
|
50
|
+
|
51
|
+
raw_class = markdown_link_arr[3]
|
52
|
+
url, title = url_and_title(markdown_link_arr[2])
|
53
|
+
content = markdown_link_arr[1]
|
54
|
+
classes = capture_individual_classes(raw_class)
|
55
|
+
link_class = combine_individual_classes_to_one_string(classes)
|
56
|
+
|
57
|
+
raw_classes_arr << raw_class
|
58
|
+
links_with_classes_arr << [url, title, content, link_class]
|
59
|
+
end
|
60
|
+
|
61
|
+
[links_with_classes_arr, raw_classes_arr]
|
62
|
+
end
|
63
|
+
|
64
|
+
def url_and_title(markdown_link_and_title)
|
65
|
+
match =
|
66
|
+
markdown_link_and_title.scan(
|
67
|
+
/(\s|^)(https?:\/\/\S*|^\/\S*\/*\S*|^#\S*|mailto:\S*)(?=\s|$)|(\".*?\")/
|
68
|
+
)
|
69
|
+
url = match[0][1]
|
70
|
+
title = match[1] ? match[1][2] : nil
|
71
|
+
[url, title]
|
72
|
+
end
|
73
|
+
|
74
|
+
def capture_individual_classes(classes)
|
75
|
+
classes.scan(/\.[^\.\}\s]*/)
|
76
|
+
end
|
77
|
+
|
78
|
+
def combine_individual_classes_to_one_string(classes)
|
79
|
+
class_string = ''
|
80
|
+
classes.each do |klass|
|
81
|
+
class_string += klass.tr('.', '') + ' '
|
82
|
+
end
|
83
|
+
class_string
|
84
|
+
end
|
85
|
+
end
|
data/lib/wcc/contentful/app.rb
CHANGED
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.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Watermark Dev
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-21 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.0.6
|
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.0.6
|
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
|
@@ -458,7 +459,7 @@ licenses:
|
|
458
459
|
- MIT
|
459
460
|
metadata:
|
460
461
|
documentation_uri: https://watermarkchurch.github.io/wcc-contentful/1.0/wcc-contentful-app
|
461
|
-
post_install_message:
|
462
|
+
post_install_message:
|
462
463
|
rdoc_options: []
|
463
464
|
require_paths:
|
464
465
|
- lib
|
@@ -473,9 +474,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
473
474
|
- !ruby/object:Gem::Version
|
474
475
|
version: '0'
|
475
476
|
requirements: []
|
476
|
-
rubyforge_project:
|
477
|
-
rubygems_version: 2.6.
|
478
|
-
signing_key:
|
477
|
+
rubyforge_project:
|
478
|
+
rubygems_version: 2.7.6.2
|
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)
|
481
482
|
[![Build Status](https://circleci.com/gh/watermarkchurch/wcc-contentful.svg?style=svg)](https://circleci.com/gh/watermarkchurch/wcc-contentful)
|