mongoid_markdown_extension 0.1.6 → 0.1.7
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/lib/mongoid_markdown_extension.rb +2 -0
- data/lib/mongoid_markdown_extension/markdown.rb +41 -41
- data/lib/mongoid_markdown_extension/version.rb +1 -1
- data/mongoid_markdown_extension.gemspec +1 -1
- data/test/mongoid_markdown_extension/markdown_test.rb +11 -7
- data/test/test_helper.rb +3 -2
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0205fc66b7a8adf5cac5d95156cdae75feb5ae39
|
4
|
+
data.tar.gz: 9909e3b390ef53daa70be54acbef2bedb5388b03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15a411be7ebb7b02c9e98b05933f83f79b81dbc7599b79ab2b3a80d114ac8cd025b95e911caefdde351b29eafafbf42fcd7e2bc48ef9a51311f62db7c32b30f3
|
7
|
+
data.tar.gz: f612112f8f502ee35031b745a14ba55ae05ac7428706ea5abd35344d840b959b45399e61875c6479a402d2f295af6792de33f22d9c2a66a9e9bebf76648d68e7
|
@@ -3,6 +3,40 @@ require 'redcarpet/render_strip'
|
|
3
3
|
|
4
4
|
module MongoidMarkdownExtension
|
5
5
|
class Markdown < String
|
6
|
+
class << self
|
7
|
+
attr_writer :configuration
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.configuration
|
11
|
+
@configuration ||= Configuration.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.reset
|
15
|
+
@configuration = Configuration.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.configure
|
19
|
+
yield(configuration)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.demongoize(value)
|
23
|
+
Markdown.new(value)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.mongoize(value)
|
27
|
+
case value
|
28
|
+
when Markdown then value.mongoize
|
29
|
+
else value
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.evolve(value)
|
34
|
+
case value
|
35
|
+
when Markdown then value.mongoize
|
36
|
+
else value
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
6
40
|
def initialize(str)
|
7
41
|
super str.to_s
|
8
42
|
@str = str.to_s
|
@@ -28,13 +62,14 @@ module MongoidMarkdownExtension
|
|
28
62
|
@str
|
29
63
|
end
|
30
64
|
|
31
|
-
private
|
65
|
+
private
|
32
66
|
|
33
67
|
def markdown_renderer
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
68
|
+
render_class = MongoidMarkdownExtension::Markdown.configuration.render_class
|
69
|
+
render_options = MongoidMarkdownExtension::Markdown.configuration.render_options
|
70
|
+
extensions = MongoidMarkdownExtension::Markdown.configuration.extensions
|
71
|
+
|
72
|
+
Redcarpet::Markdown.new(render_class.new(render_options), extensions)
|
38
73
|
end
|
39
74
|
|
40
75
|
# TODO: how to combine custom render class with the InlineRenderer?
|
@@ -43,45 +78,10 @@ module MongoidMarkdownExtension
|
|
43
78
|
end
|
44
79
|
|
45
80
|
def markdown_stripdown_renderer
|
46
|
-
Redcarpet::Markdown.new(Redcarpet::Render::StripDown
|
47
|
-
end
|
48
|
-
|
49
|
-
# ---------------------------------------------------------------------
|
50
|
-
|
51
|
-
class << self
|
52
|
-
attr_accessor :configuration
|
53
|
-
|
54
|
-
def configure
|
55
|
-
@configuration ||= Configuration.new
|
56
|
-
yield @configuration
|
57
|
-
end
|
58
|
-
|
59
|
-
def configuration
|
60
|
-
@configuration ||= Configuration.new
|
61
|
-
end
|
62
|
-
|
63
|
-
def demongoize(value)
|
64
|
-
Markdown.new(value)
|
65
|
-
end
|
66
|
-
|
67
|
-
def mongoize(value)
|
68
|
-
case value
|
69
|
-
when Markdown then value.mongoize
|
70
|
-
else value
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def evolve(value)
|
75
|
-
case value
|
76
|
-
when Markdown then value.mongoize
|
77
|
-
else value
|
78
|
-
end
|
79
|
-
end
|
81
|
+
Redcarpet::Markdown.new(Redcarpet::Render::StripDown)
|
80
82
|
end
|
81
83
|
end
|
82
84
|
|
83
|
-
# ---------------------------------------------------------------------
|
84
|
-
|
85
85
|
class Configuration
|
86
86
|
attr_accessor :extensions
|
87
87
|
attr_accessor :render_class
|
@@ -18,7 +18,7 @@ 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', '
|
21
|
+
spec.add_dependency 'redcarpet', '~> 3.4'
|
22
22
|
spec.add_dependency 'mongoid', '>= 4.0'
|
23
23
|
|
24
24
|
spec.add_development_dependency 'bundler', '~> 1.6'
|
@@ -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,13 +27,18 @@ 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
43
|
MongoidMarkdownExtension::Markdown.configuration.extensions.must_equal(
|
41
44
|
autolink: true,
|
@@ -51,8 +54,6 @@ module MongoidMarkdownExtension
|
|
51
54
|
end
|
52
55
|
end
|
53
56
|
|
54
|
-
# ---------------------------------------------------------------------
|
55
|
-
|
56
57
|
describe '#to_s' do
|
57
58
|
it 'returns the original value' do
|
58
59
|
subject.to_s.must_equal string
|
@@ -63,6 +64,7 @@ module MongoidMarkdownExtension
|
|
63
64
|
it 'survives nil' do
|
64
65
|
MongoidMarkdownExtension::Markdown.new(nil).to_html.must_equal ''
|
65
66
|
end
|
67
|
+
|
66
68
|
it 'converts the string to html' do
|
67
69
|
subject.to_html.must_equal Redcarpet::Markdown.new(Redcarpet::Render::HTML).render(string)
|
68
70
|
end
|
@@ -74,9 +76,11 @@ module MongoidMarkdownExtension
|
|
74
76
|
it 'survives nil' do
|
75
77
|
MongoidMarkdownExtension::Markdown.new(nil).to_inline_html.must_equal ''
|
76
78
|
end
|
79
|
+
|
77
80
|
it 'converts the string to html' do
|
78
81
|
subject.to_inline_html.wont_include '<p>'
|
79
82
|
end
|
83
|
+
|
80
84
|
it 'replaces <p> with <br />' do
|
81
85
|
subject.to_inline_html.must_equal 'some text with <em>italic</em><br /><br />foo'
|
82
86
|
end
|
@@ -86,6 +90,7 @@ module MongoidMarkdownExtension
|
|
86
90
|
it 'survives nil' do
|
87
91
|
MongoidMarkdownExtension::Markdown.new(nil).to_stripped_s.must_equal ''
|
88
92
|
end
|
93
|
+
|
89
94
|
it 'converts the markdown to stripped string' do
|
90
95
|
subject.to_stripped_s.wont_include '_'
|
91
96
|
end
|
@@ -97,14 +102,13 @@ module MongoidMarkdownExtension
|
|
97
102
|
end
|
98
103
|
end
|
99
104
|
|
100
|
-
# ---------------------------------------------------------------------
|
101
|
-
|
102
105
|
describe '.mongoize' do
|
103
106
|
describe 'when passed a string' do
|
104
107
|
it 'returns it back' do
|
105
108
|
MongoidMarkdownExtension::Markdown.mongoize(string).must_equal string
|
106
109
|
end
|
107
110
|
end
|
111
|
+
|
108
112
|
describe 'when passed markdown object' do
|
109
113
|
it 'returns its string' do
|
110
114
|
MongoidMarkdownExtension::Markdown.mongoize(subject).must_be_kind_of String
|
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.1.
|
4
|
+
version: 0.1.7
|
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: 2018-01-15 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
|
@@ -122,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
122
|
version: '0'
|
123
123
|
requirements: []
|
124
124
|
rubyforge_project:
|
125
|
-
rubygems_version: 2.
|
125
|
+
rubygems_version: 2.5.2
|
126
126
|
signing_key:
|
127
127
|
specification_version: 4
|
128
128
|
summary: Custom field type for Mongoid that handles Markdown conversion via Redcarpet
|