mongoid_markdown_extension 0.1.10 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7931a4b45d301e84a32199bdeb55c8b88354ab100e03343b471f133f67703efd
4
- data.tar.gz: 8add6626be35350d1fb4017baf8239c9d60d31f8ffb9c5218d6f3caebe52d9ff
3
+ metadata.gz: ec8e015b5cfba63e62b5e27e5291363427d405becf26f9b8b798c61e42dcb080
4
+ data.tar.gz: 535cd7396fb5267661ad155a7f3037d80a03a87fb36db3e1209c097d82609310
5
5
  SHA512:
6
- metadata.gz: 9ccc13b39c9a1fba48b6e5fb5baf136702dc0f1b9171206389b869be6fbfbc103e4f25c677ac3caefa945e6e28ed16adde1f12248a02f8f95500df49a996728c
7
- data.tar.gz: 706bf6154f6c2833bf6da66a7bce54715167593f65e30e8432ff6a4b5194947d529b641e2bc299c41ed6406ecb10c9b07a332572f8e034f1b11efc45394b9a21
6
+ metadata.gz: 2180a3997703c5a2a84624b754a29ffc59a233c82d1ffb328ba5cfd2a70d6e3463958cea22af745071958c95320a50cf4ee40459a39ebd4debe031f895b17599
7
+ data.tar.gz: f2cf2ea23f98fc0a576c7f9b4d99e3ae97a99a801ac8727358b6668b8ad255239292caf7eb7f70680df4ca7cb8b20dd8278a3b7e6265ed3cd3f0b3df0562d553
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.7.2
data/.travis.yml CHANGED
@@ -18,7 +18,7 @@ matrix:
18
18
  env: MONGOID_VERSION=4
19
19
  - rvm: 2.3.3
20
20
  env: MONGOID_VERSION=5
21
- - rvm: 2.3.3
21
+ - rvm: 2.7.2
22
22
  env: MONGOID_VERSION=6
23
- - rvm: 2.5.0
23
+ - rvm: 2.7.2
24
24
  env: MONGOID_VERSION=7
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
- - FIX: pass configuration to `InlineRenderer` as well
12
+ - Fixed passing configuration to `InlineRenderer`
6
13
 
7
14
  ## 0.1.9
8
15
 
@@ -40,8 +40,11 @@ module MongoidMarkdownExtension
40
40
  nil
41
41
  end
42
42
 
43
- def paragraph(text)
44
- text + '<br /><br />'
43
+ def postprocess(full_document)
44
+ full_document
45
+ .gsub(/(<\/p>\s*<p>)+?/, '<br><br>')
46
+ .gsub(/(<\/?p>)+?/, '')
47
+ .chop
45
48
  end
46
49
  end
47
50
  end
@@ -38,28 +38,21 @@ module MongoidMarkdownExtension
38
38
  end
39
39
 
40
40
  def initialize(str)
41
- super str.to_s
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(@str).html_safe
45
+ markdown_renderer.render(to_s).html_safe
51
46
  end
52
47
 
53
- def to_inline_html
54
- markdown_inline_renderer.render(@str).gsub(/(<br\s?\/?>)+?\Z/, '').html_safe
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(@str).try(:strip)
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(InlineRenderer.new(render_options), extensions)
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
@@ -1,3 +1,3 @@
1
1
  module MongoidMarkdownExtension
2
- VERSION = '0.1.10'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  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.render_class.must_equal Redcarpet::Render::HTML
52
- MongoidMarkdownExtension::Markdown.configuration.render_options.must_equal({})
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 />' do
85
- subject.to_inline_html.must_equal 'some text with <em>italic</em><br /><br />foo'
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.1.10
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: 2020-03-02 00:00:00.000000000 Z
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.0.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