mongoid_markdown_extension 0.1.6 → 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 +5 -5
- data/.ruby-version +1 -0
- data/.travis.yml +11 -0
- data/CHANGELOG.md +20 -0
- data/Gemfile +9 -1
- data/lib/mongoid_markdown_extension.rb +2 -0
- data/lib/mongoid_markdown_extension/inline_renderer.rb +5 -2
- data/lib/mongoid_markdown_extension/markdown.rb +51 -51
- data/lib/mongoid_markdown_extension/version.rb +1 -1
- data/mongoid_markdown_extension.gemspec +3 -3
- data/test/mongoid_markdown_extension/markdown_test.rb +52 -24
- data/test/test_helper.rb +3 -2
- metadata +19 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
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
@@ -11,3 +11,14 @@ notifications:
|
|
11
11
|
- tomas.celizna@gmail.com
|
12
12
|
on_failure: change
|
13
13
|
on_success: never
|
14
|
+
|
15
|
+
matrix:
|
16
|
+
include:
|
17
|
+
- rvm: 2.3.3
|
18
|
+
env: MONGOID_VERSION=4
|
19
|
+
- rvm: 2.3.3
|
20
|
+
env: MONGOID_VERSION=5
|
21
|
+
- rvm: 2.7.2
|
22
|
+
env: MONGOID_VERSION=6
|
23
|
+
- rvm: 2.7.2
|
24
|
+
env: MONGOID_VERSION=7
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# CHANGELOG
|
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
|
+
|
10
|
+
## 0.1.10
|
11
|
+
|
12
|
+
- Fixed passing configuration to `InlineRenderer`
|
13
|
+
|
14
|
+
## 0.1.9
|
15
|
+
|
16
|
+
- `#to_stripped_s` removes leading & trailing white-space (null, horizontal tab, line feed, vertical tab, form feed, carriage return, space) using Ruby's `#strip`
|
17
|
+
|
18
|
+
## 0.1.8
|
19
|
+
|
20
|
+
- Mongoid 7 compatibility
|
data/Gemfile
CHANGED
@@ -1,4 +1,12 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
# Specify your gem's dependencies in mongoid_markdown_extension.gemspec
|
4
|
-
gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
case version = ENV['MONGOID_VERSION'] || '~> 7.0'
|
7
|
+
when /7/ then gem 'mongoid', '~> 7.0'
|
8
|
+
when /6/ then gem 'mongoid', '~> 6.0'
|
9
|
+
when /5/ then gem 'mongoid', '~> 5.1'
|
10
|
+
when /4/ then gem 'mongoid', '~> 4.0'
|
11
|
+
else gem 'mongoid', version
|
12
|
+
end
|
@@ -3,87 +3,86 @@ require 'redcarpet/render_strip'
|
|
3
3
|
|
4
4
|
module MongoidMarkdownExtension
|
5
5
|
class Markdown < String
|
6
|
-
|
7
|
-
|
8
|
-
@str = str.to_s
|
6
|
+
class << self
|
7
|
+
attr_writer :configuration
|
9
8
|
end
|
10
9
|
|
11
|
-
def
|
12
|
-
@
|
10
|
+
def self.configuration
|
11
|
+
@configuration ||= Configuration.new
|
13
12
|
end
|
14
13
|
|
15
|
-
def
|
16
|
-
|
14
|
+
def self.reset
|
15
|
+
@configuration = Configuration.new
|
17
16
|
end
|
18
17
|
|
19
|
-
def
|
20
|
-
|
18
|
+
def self.configure
|
19
|
+
yield(configuration)
|
21
20
|
end
|
22
21
|
|
23
|
-
def
|
24
|
-
|
22
|
+
def self.demongoize(value)
|
23
|
+
Markdown.new(value)
|
25
24
|
end
|
26
25
|
|
27
|
-
def mongoize
|
28
|
-
|
26
|
+
def self.mongoize(value)
|
27
|
+
case value
|
28
|
+
when Markdown then value.mongoize
|
29
|
+
else value
|
30
|
+
end
|
29
31
|
end
|
30
32
|
|
31
|
-
|
33
|
+
def self.evolve(value)
|
34
|
+
case value
|
35
|
+
when Markdown then value.mongoize
|
36
|
+
else value
|
37
|
+
end
|
38
|
+
end
|
32
39
|
|
33
|
-
def
|
34
|
-
|
35
|
-
self.class.configuration.render_class.new(self.class.configuration.render_options),
|
36
|
-
self.class.configuration.extensions
|
37
|
-
)
|
40
|
+
def initialize(str)
|
41
|
+
super(str.to_s)
|
38
42
|
end
|
39
43
|
|
40
|
-
|
41
|
-
|
42
|
-
Redcarpet::Markdown.new(InlineRenderer, tables: false)
|
44
|
+
def to_html
|
45
|
+
markdown_renderer.render(to_s).html_safe
|
43
46
|
end
|
44
47
|
|
45
|
-
def
|
46
|
-
|
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
|
47
52
|
end
|
48
53
|
|
49
|
-
|
54
|
+
def to_stripped_s
|
55
|
+
markdown_stripdown_renderer.render(to_s).try(:strip)
|
56
|
+
end
|
50
57
|
|
51
|
-
|
52
|
-
attr_accessor :configuration
|
58
|
+
private
|
53
59
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
60
|
+
def markdown_renderer
|
61
|
+
render_class = MongoidMarkdownExtension::Markdown.configuration.render_class
|
62
|
+
render_options = MongoidMarkdownExtension::Markdown.configuration.render_options
|
63
|
+
extensions = MongoidMarkdownExtension::Markdown.configuration.extensions
|
58
64
|
|
59
|
-
|
60
|
-
|
61
|
-
end
|
65
|
+
Redcarpet::Markdown.new(render_class.new(render_options), extensions)
|
66
|
+
end
|
62
67
|
|
63
|
-
|
64
|
-
|
65
|
-
|
68
|
+
# TODO: how to combine custom render class with the InlineRenderer?
|
69
|
+
def markdown_inline_renderer
|
70
|
+
inline_render_class = MongoidMarkdownExtension::Markdown.configuration.inline_render_class
|
71
|
+
render_options = MongoidMarkdownExtension::Markdown.configuration.render_options
|
72
|
+
extensions = MongoidMarkdownExtension::Markdown.configuration.extensions
|
73
|
+
extensions[:tables] = false
|
66
74
|
|
67
|
-
|
68
|
-
|
69
|
-
when Markdown then value.mongoize
|
70
|
-
else value
|
71
|
-
end
|
72
|
-
end
|
75
|
+
Redcarpet::Markdown.new(inline_render_class.new(render_options), extensions)
|
76
|
+
end
|
73
77
|
|
74
|
-
|
75
|
-
|
76
|
-
when Markdown then value.mongoize
|
77
|
-
else value
|
78
|
-
end
|
79
|
-
end
|
78
|
+
def markdown_stripdown_renderer
|
79
|
+
Redcarpet::Markdown.new(Redcarpet::Render::StripDown)
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
-
# ---------------------------------------------------------------------
|
84
|
-
|
85
83
|
class Configuration
|
86
84
|
attr_accessor :extensions
|
85
|
+
attr_accessor :inline_render_class
|
87
86
|
attr_accessor :render_class
|
88
87
|
attr_accessor :render_options
|
89
88
|
|
@@ -96,6 +95,7 @@ module MongoidMarkdownExtension
|
|
96
95
|
strikethrough: true,
|
97
96
|
superscript: true
|
98
97
|
}
|
98
|
+
@inline_render_class = MongoidMarkdownExtension::InlineRenderer
|
99
99
|
@render_class = Redcarpet::Render::HTML
|
100
100
|
@render_options = {}
|
101
101
|
end
|
@@ -18,10 +18,10 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_dependency 'redcarpet', '
|
22
|
-
spec.add_dependency 'mongoid', '>= 4.0'
|
21
|
+
spec.add_dependency 'redcarpet', '~> 3.4'
|
22
|
+
spec.add_dependency 'mongoid', '>= 4.0', '< 8'
|
23
23
|
|
24
|
-
spec.add_development_dependency 'bundler'
|
24
|
+
spec.add_development_dependency 'bundler'
|
25
25
|
spec.add_development_dependency 'coveralls'
|
26
26
|
spec.add_development_dependency 'rake', '~> 10.0'
|
27
27
|
end
|
@@ -1,7 +1,5 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
# ---------------------------------------------------------------------
|
4
|
-
|
5
3
|
class MongoidMarkdownExtensionTest
|
6
4
|
include Mongoid::Document
|
7
5
|
field :body, type: MongoidMarkdownExtension::Markdown
|
@@ -29,15 +27,20 @@ module MongoidMarkdownExtension
|
|
29
27
|
let(:string) { 'some text with _italic_' }
|
30
28
|
subject { MongoidMarkdownExtension::Markdown.new(string) }
|
31
29
|
|
30
|
+
after(:each) do
|
31
|
+
MongoidMarkdownExtension::Markdown.reset
|
32
|
+
end
|
33
|
+
|
32
34
|
describe 'configuration' do
|
33
35
|
describe 'setup block' do
|
34
36
|
it 'yields self' do
|
35
37
|
MongoidMarkdownExtension::Markdown.configure do |config|
|
36
|
-
config.must_be_kind_of Configuration
|
38
|
+
_(config).must_be_kind_of MongoidMarkdownExtension::Configuration
|
37
39
|
end
|
38
40
|
end
|
41
|
+
|
39
42
|
it 'returns default values' do
|
40
|
-
MongoidMarkdownExtension::Markdown.configuration.extensions.must_equal(
|
43
|
+
_(MongoidMarkdownExtension::Markdown.configuration.extensions).must_equal(
|
41
44
|
autolink: true,
|
42
45
|
footnotes: true,
|
43
46
|
highlight: true,
|
@@ -45,80 +48,105 @@ module MongoidMarkdownExtension
|
|
45
48
|
strikethrough: true,
|
46
49
|
superscript: true
|
47
50
|
)
|
48
|
-
MongoidMarkdownExtension::Markdown.configuration.
|
49
|
-
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({})
|
50
54
|
end
|
51
55
|
end
|
52
56
|
end
|
53
57
|
|
54
|
-
# ---------------------------------------------------------------------
|
55
|
-
|
56
58
|
describe '#to_s' do
|
57
59
|
it 'returns the original value' do
|
58
|
-
subject.to_s.must_equal string
|
60
|
+
_(subject.to_s).must_equal string
|
59
61
|
end
|
60
62
|
end
|
61
63
|
|
62
64
|
describe '#to_html' do
|
63
65
|
it 'survives nil' do
|
64
|
-
MongoidMarkdownExtension::Markdown.new(nil).to_html.must_equal ''
|
66
|
+
_(MongoidMarkdownExtension::Markdown.new(nil).to_html).must_equal ''
|
65
67
|
end
|
68
|
+
|
66
69
|
it 'converts the string to html' do
|
67
|
-
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)
|
68
71
|
end
|
69
72
|
end
|
70
73
|
|
71
74
|
describe '#to_inline_html' do
|
72
75
|
let(:string) { "some text with _italic_\n\nfoo" }
|
76
|
+
let(:string_with_line_breaks) { "some text with line break \nfoo" }
|
73
77
|
|
74
78
|
it 'survives nil' do
|
75
|
-
MongoidMarkdownExtension::Markdown.new(nil).to_inline_html.must_equal ''
|
79
|
+
_(MongoidMarkdownExtension::Markdown.new(nil).to_inline_html).must_equal ''
|
76
80
|
end
|
81
|
+
|
77
82
|
it 'converts the string to html' do
|
78
|
-
subject.to_inline_html.wont_include '<p>'
|
83
|
+
_(subject.to_inline_html).wont_include '<p>'
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'replaces <p> with <br>' do
|
87
|
+
_(subject.to_inline_html).must_equal 'some text with <em>italic</em><br><br>foo'
|
79
88
|
end
|
80
|
-
|
81
|
-
|
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"
|
82
95
|
end
|
83
96
|
end
|
84
97
|
|
85
98
|
describe '#to_stripped_s' do
|
86
99
|
it 'survives nil' do
|
87
|
-
MongoidMarkdownExtension::Markdown.new(nil).to_stripped_s.must_equal ''
|
100
|
+
_(MongoidMarkdownExtension::Markdown.new(nil).to_stripped_s).must_equal ''
|
88
101
|
end
|
102
|
+
|
89
103
|
it 'converts the markdown to stripped string' do
|
90
|
-
subject.to_stripped_s.wont_include '_'
|
104
|
+
_(subject.to_stripped_s).wont_include '_'
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'removes newlines' do
|
108
|
+
_(subject.to_stripped_s).wont_include "\n"
|
91
109
|
end
|
92
110
|
end
|
93
111
|
|
94
112
|
describe '#mongoize' do
|
95
113
|
it 'returns string' do
|
96
|
-
subject.mongoize.must_equal string
|
114
|
+
_(subject.mongoize).must_equal string
|
97
115
|
end
|
98
116
|
end
|
99
117
|
|
100
|
-
# ---------------------------------------------------------------------
|
101
|
-
|
102
118
|
describe '.mongoize' do
|
103
119
|
describe 'when passed a string' do
|
104
120
|
it 'returns it back' do
|
105
|
-
MongoidMarkdownExtension::Markdown.mongoize(string).must_equal string
|
121
|
+
_(MongoidMarkdownExtension::Markdown.mongoize(string)).must_equal string
|
106
122
|
end
|
107
123
|
end
|
124
|
+
|
108
125
|
describe 'when passed markdown object' do
|
109
126
|
it 'returns its string' do
|
110
|
-
MongoidMarkdownExtension::Markdown.mongoize(subject).must_be_kind_of String
|
127
|
+
_(MongoidMarkdownExtension::Markdown.mongoize(subject)).must_be_kind_of String
|
111
128
|
end
|
112
129
|
end
|
113
130
|
end
|
114
131
|
|
115
132
|
describe '.demongoize' do
|
116
133
|
it 'does not change the value' do
|
117
|
-
MongoidMarkdownExtension::Markdown.demongoize(string).must_equal string
|
134
|
+
_(MongoidMarkdownExtension::Markdown.demongoize(string)).must_equal string
|
118
135
|
end
|
119
136
|
|
120
137
|
it 'returns markdown object' do
|
121
|
-
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>/
|
122
150
|
end
|
123
151
|
end
|
124
152
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
require 'bundler/setup'
|
2
|
-
|
3
|
-
require 'mongoid_markdown_extension'
|
2
|
+
|
4
3
|
require 'minitest'
|
5
4
|
require 'minitest/autorun'
|
6
5
|
require 'minitest/spec'
|
7
6
|
|
7
|
+
require 'mongoid_markdown_extension'
|
8
|
+
|
8
9
|
if ENV['CI']
|
9
10
|
require 'coveralls'
|
10
11
|
Coveralls.wear!
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
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
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 3.
|
19
|
+
version: '3.4'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 3.
|
26
|
+
version: '3.4'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: mongoid
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -31,6 +31,9 @@ dependencies:
|
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '4.0'
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '8'
|
34
37
|
type: :runtime
|
35
38
|
prerelease: false
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -38,20 +41,23 @@ dependencies:
|
|
38
41
|
- - ">="
|
39
42
|
- !ruby/object:Gem::Version
|
40
43
|
version: '4.0'
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '8'
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: bundler
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
44
50
|
requirements:
|
45
|
-
- - "
|
51
|
+
- - ">="
|
46
52
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
53
|
+
version: '0'
|
48
54
|
type: :development
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
51
57
|
requirements:
|
52
|
-
- - "
|
58
|
+
- - ">="
|
53
59
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
60
|
+
version: '0'
|
55
61
|
- !ruby/object:Gem::Dependency
|
56
62
|
name: coveralls
|
57
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -90,7 +96,9 @@ extra_rdoc_files: []
|
|
90
96
|
files:
|
91
97
|
- ".coveralls.yml"
|
92
98
|
- ".gitignore"
|
99
|
+
- ".ruby-version"
|
93
100
|
- ".travis.yml"
|
101
|
+
- CHANGELOG.md
|
94
102
|
- Gemfile
|
95
103
|
- LICENSE
|
96
104
|
- README.md
|
@@ -121,8 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
129
|
- !ruby/object:Gem::Version
|
122
130
|
version: '0'
|
123
131
|
requirements: []
|
124
|
-
|
125
|
-
rubygems_version: 2.4.5.1
|
132
|
+
rubygems_version: 3.1.4
|
126
133
|
signing_key:
|
127
134
|
specification_version: 4
|
128
135
|
summary: Custom field type for Mongoid that handles Markdown conversion via Redcarpet
|