mongoid_markdown_extension 0.1.10 → 0.2.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 +4 -4
- data/.ruby-version +1 -0
- data/.travis.yml +2 -2
- data/CHANGELOG.md +8 -1
- data/lib/mongoid_markdown_extension/inline_renderer.rb +5 -2
- data/lib/mongoid_markdown_extension/markdown.rb +11 -15
- data/lib/mongoid_markdown_extension/version.rb +1 -1
- data/test/mongoid_markdown_extension/markdown_test.rb +39 -19
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec8e015b5cfba63e62b5e27e5291363427d405becf26f9b8b798c61e42dcb080
|
4
|
+
data.tar.gz: 535cd7396fb5267661ad155a7f3037d80a03a87fb36db3e1209c097d82609310
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2180a3997703c5a2a84624b754a29ffc59a233c82d1ffb328ba5cfd2a70d6e3463958cea22af745071958c95320a50cf4ee40459a39ebd4debe031f895b17599
|
7
|
+
data.tar.gz: f2cf2ea23f98fc0a576c7f9b4d99e3ae97a99a801ac8727358b6668b8ad255239292caf7eb7f70680df4ca7cb8b20dd8278a3b7e6265ed3cd3f0b3df0562d553
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7.2
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,15 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 0.2.0
|
4
|
+
|
5
|
+
- Added `linebreaks` option to `to_inline_html`
|
6
|
+
- Added `inline_render_class` configuration option
|
7
|
+
- Fixed `to_inline_html`
|
8
|
+
- Fixed usage of String methods
|
9
|
+
|
3
10
|
## 0.1.10
|
4
11
|
|
5
|
-
-
|
12
|
+
- Fixed passing configuration to `InlineRenderer`
|
6
13
|
|
7
14
|
## 0.1.9
|
8
15
|
|
@@ -38,28 +38,21 @@ module MongoidMarkdownExtension
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def initialize(str)
|
41
|
-
super
|
42
|
-
@str = str.to_s
|
43
|
-
end
|
44
|
-
|
45
|
-
def to_s
|
46
|
-
@str
|
41
|
+
super(str.to_s)
|
47
42
|
end
|
48
43
|
|
49
44
|
def to_html
|
50
|
-
markdown_renderer.render(
|
45
|
+
markdown_renderer.render(to_s).html_safe
|
51
46
|
end
|
52
47
|
|
53
|
-
def to_inline_html
|
54
|
-
markdown_inline_renderer.render(
|
48
|
+
def to_inline_html(line_breaks: false)
|
49
|
+
rendered = markdown_inline_renderer.render(to_s).gsub(/(<br\s?\/?>)+?\z/, '')
|
50
|
+
rendered.gsub!(/(<br\s?\/?>)+?\Z/, '') if !line_breaks
|
51
|
+
rendered.html_safe
|
55
52
|
end
|
56
53
|
|
57
54
|
def to_stripped_s
|
58
|
-
markdown_stripdown_renderer.render(
|
59
|
-
end
|
60
|
-
|
61
|
-
def mongoize
|
62
|
-
@str
|
55
|
+
markdown_stripdown_renderer.render(to_s).try(:strip)
|
63
56
|
end
|
64
57
|
|
65
58
|
private
|
@@ -74,11 +67,12 @@ module MongoidMarkdownExtension
|
|
74
67
|
|
75
68
|
# TODO: how to combine custom render class with the InlineRenderer?
|
76
69
|
def markdown_inline_renderer
|
70
|
+
inline_render_class = MongoidMarkdownExtension::Markdown.configuration.inline_render_class
|
77
71
|
render_options = MongoidMarkdownExtension::Markdown.configuration.render_options
|
78
72
|
extensions = MongoidMarkdownExtension::Markdown.configuration.extensions
|
79
73
|
extensions[:tables] = false
|
80
74
|
|
81
|
-
Redcarpet::Markdown.new(
|
75
|
+
Redcarpet::Markdown.new(inline_render_class.new(render_options), extensions)
|
82
76
|
end
|
83
77
|
|
84
78
|
def markdown_stripdown_renderer
|
@@ -88,6 +82,7 @@ module MongoidMarkdownExtension
|
|
88
82
|
|
89
83
|
class Configuration
|
90
84
|
attr_accessor :extensions
|
85
|
+
attr_accessor :inline_render_class
|
91
86
|
attr_accessor :render_class
|
92
87
|
attr_accessor :render_options
|
93
88
|
|
@@ -100,6 +95,7 @@ module MongoidMarkdownExtension
|
|
100
95
|
strikethrough: true,
|
101
96
|
superscript: true
|
102
97
|
}
|
98
|
+
@inline_render_class = MongoidMarkdownExtension::InlineRenderer
|
103
99
|
@render_class = Redcarpet::Render::HTML
|
104
100
|
@render_options = {}
|
105
101
|
end
|
@@ -35,12 +35,12 @@ module MongoidMarkdownExtension
|
|
35
35
|
describe 'setup block' do
|
36
36
|
it 'yields self' do
|
37
37
|
MongoidMarkdownExtension::Markdown.configure do |config|
|
38
|
-
config.must_be_kind_of MongoidMarkdownExtension::Configuration
|
38
|
+
_(config).must_be_kind_of MongoidMarkdownExtension::Configuration
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'returns default values' do
|
43
|
-
MongoidMarkdownExtension::Markdown.configuration.extensions.must_equal(
|
43
|
+
_(MongoidMarkdownExtension::Markdown.configuration.extensions).must_equal(
|
44
44
|
autolink: true,
|
45
45
|
footnotes: true,
|
46
46
|
highlight: true,
|
@@ -48,85 +48,105 @@ module MongoidMarkdownExtension
|
|
48
48
|
strikethrough: true,
|
49
49
|
superscript: true
|
50
50
|
)
|
51
|
-
MongoidMarkdownExtension::Markdown.configuration.
|
52
|
-
MongoidMarkdownExtension::Markdown.configuration.
|
51
|
+
_(MongoidMarkdownExtension::Markdown.configuration.inline_render_class).must_equal MongoidMarkdownExtension::InlineRenderer
|
52
|
+
_(MongoidMarkdownExtension::Markdown.configuration.render_class).must_equal Redcarpet::Render::HTML
|
53
|
+
_(MongoidMarkdownExtension::Markdown.configuration.render_options).must_equal({})
|
53
54
|
end
|
54
55
|
end
|
55
56
|
end
|
56
57
|
|
57
58
|
describe '#to_s' do
|
58
59
|
it 'returns the original value' do
|
59
|
-
subject.to_s.must_equal string
|
60
|
+
_(subject.to_s).must_equal string
|
60
61
|
end
|
61
62
|
end
|
62
63
|
|
63
64
|
describe '#to_html' do
|
64
65
|
it 'survives nil' do
|
65
|
-
MongoidMarkdownExtension::Markdown.new(nil).to_html.must_equal ''
|
66
|
+
_(MongoidMarkdownExtension::Markdown.new(nil).to_html).must_equal ''
|
66
67
|
end
|
67
68
|
|
68
69
|
it 'converts the string to html' do
|
69
|
-
subject.to_html.must_equal Redcarpet::Markdown.new(Redcarpet::Render::HTML).render(string)
|
70
|
+
_(subject.to_html).must_equal Redcarpet::Markdown.new(Redcarpet::Render::HTML).render(string)
|
70
71
|
end
|
71
72
|
end
|
72
73
|
|
73
74
|
describe '#to_inline_html' do
|
74
75
|
let(:string) { "some text with _italic_\n\nfoo" }
|
76
|
+
let(:string_with_line_breaks) { "some text with line break \nfoo" }
|
75
77
|
|
76
78
|
it 'survives nil' do
|
77
|
-
MongoidMarkdownExtension::Markdown.new(nil).to_inline_html.must_equal ''
|
79
|
+
_(MongoidMarkdownExtension::Markdown.new(nil).to_inline_html).must_equal ''
|
78
80
|
end
|
79
81
|
|
80
82
|
it 'converts the string to html' do
|
81
|
-
subject.to_inline_html.wont_include '<p>'
|
83
|
+
_(subject.to_inline_html).wont_include '<p>'
|
82
84
|
end
|
83
85
|
|
84
|
-
it 'replaces <p> with <br
|
85
|
-
subject.to_inline_html.must_equal 'some text with <em>italic</em><br
|
86
|
+
it 'replaces <p> with <br>' do
|
87
|
+
_(subject.to_inline_html).must_equal 'some text with <em>italic</em><br><br>foo'
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'allows line breaks' do
|
91
|
+
inline_html = MongoidMarkdownExtension::Markdown
|
92
|
+
.new(string_with_line_breaks)
|
93
|
+
.to_inline_html(line_breaks: true)
|
94
|
+
_(inline_html).must_equal "some text with line break<br>\nfoo"
|
86
95
|
end
|
87
96
|
end
|
88
97
|
|
89
98
|
describe '#to_stripped_s' do
|
90
99
|
it 'survives nil' do
|
91
|
-
MongoidMarkdownExtension::Markdown.new(nil).to_stripped_s.must_equal ''
|
100
|
+
_(MongoidMarkdownExtension::Markdown.new(nil).to_stripped_s).must_equal ''
|
92
101
|
end
|
93
102
|
|
94
103
|
it 'converts the markdown to stripped string' do
|
95
|
-
subject.to_stripped_s.wont_include '_'
|
104
|
+
_(subject.to_stripped_s).wont_include '_'
|
96
105
|
end
|
97
106
|
|
98
107
|
it 'removes newlines' do
|
99
|
-
subject.to_stripped_s.wont_include "\n"
|
108
|
+
_(subject.to_stripped_s).wont_include "\n"
|
100
109
|
end
|
101
110
|
end
|
102
111
|
|
103
112
|
describe '#mongoize' do
|
104
113
|
it 'returns string' do
|
105
|
-
subject.mongoize.must_equal string
|
114
|
+
_(subject.mongoize).must_equal string
|
106
115
|
end
|
107
116
|
end
|
108
117
|
|
109
118
|
describe '.mongoize' do
|
110
119
|
describe 'when passed a string' do
|
111
120
|
it 'returns it back' do
|
112
|
-
MongoidMarkdownExtension::Markdown.mongoize(string).must_equal string
|
121
|
+
_(MongoidMarkdownExtension::Markdown.mongoize(string)).must_equal string
|
113
122
|
end
|
114
123
|
end
|
115
124
|
|
116
125
|
describe 'when passed markdown object' do
|
117
126
|
it 'returns its string' do
|
118
|
-
MongoidMarkdownExtension::Markdown.mongoize(subject).must_be_kind_of String
|
127
|
+
_(MongoidMarkdownExtension::Markdown.mongoize(subject)).must_be_kind_of String
|
119
128
|
end
|
120
129
|
end
|
121
130
|
end
|
122
131
|
|
123
132
|
describe '.demongoize' do
|
124
133
|
it 'does not change the value' do
|
125
|
-
MongoidMarkdownExtension::Markdown.demongoize(string).must_equal string
|
134
|
+
_(MongoidMarkdownExtension::Markdown.demongoize(string)).must_equal string
|
126
135
|
end
|
127
136
|
|
128
137
|
it 'returns markdown object' do
|
129
|
-
MongoidMarkdownExtension::Markdown.demongoize(string).must_be_kind_of MongoidMarkdownExtension::Markdown
|
138
|
+
_(MongoidMarkdownExtension::Markdown.demongoize(string)).must_be_kind_of MongoidMarkdownExtension::Markdown
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe "splitting" do
|
143
|
+
it "returns correctly instantiated markdown objects" do
|
144
|
+
markdown = MongoidMarkdownExtension::Markdown.new("foo\nbar\nfar\nboo")
|
145
|
+
split_markdown = markdown.split("\n")
|
146
|
+
|
147
|
+
_(split_markdown.first).must_be_kind_of MongoidMarkdownExtension::Markdown
|
148
|
+
_(split_markdown.first.to_s).must_equal "foo"
|
149
|
+
_(split_markdown.first.to_html).must_match /<p>foo<\/p>/
|
130
150
|
end
|
131
151
|
end
|
132
152
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid_markdown_extension
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomas Celizna
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redcarpet
|
@@ -96,6 +96,7 @@ extra_rdoc_files: []
|
|
96
96
|
files:
|
97
97
|
- ".coveralls.yml"
|
98
98
|
- ".gitignore"
|
99
|
+
- ".ruby-version"
|
99
100
|
- ".travis.yml"
|
100
101
|
- CHANGELOG.md
|
101
102
|
- Gemfile
|
@@ -128,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
129
|
- !ruby/object:Gem::Version
|
129
130
|
version: '0'
|
130
131
|
requirements: []
|
131
|
-
rubygems_version: 3.
|
132
|
+
rubygems_version: 3.1.4
|
132
133
|
signing_key:
|
133
134
|
specification_version: 4
|
134
135
|
summary: Custom field type for Mongoid that handles Markdown conversion via Redcarpet
|