mongoid_markdown_extension 0.1.3 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -3
- data/README.md +22 -15
- data/Rakefile +1 -1
- data/lib/mongoid_markdown_extension.rb +3 -3
- data/lib/mongoid_markdown_extension/inline_renderer.rb +1 -1
- data/lib/mongoid_markdown_extension/markdown.rb +4 -3
- data/lib/mongoid_markdown_extension/version.rb +1 -1
- data/mongoid_markdown_extension.gemspec +13 -13
- data/test/mongoid_markdown_extension/markdown_test.rb +24 -1
- data/test/test_helper.rb +3 -3
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 123144dae792881275b9b36e956c437a510b2dfd
|
4
|
+
data.tar.gz: f315498dcd5199dffce976e7f594b67f4fad2d4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8696f00b293eee30fb6b21fa9a88beceb98ed4481512b19dcccc89f4f3a9ed481542c0c13d5bcdd8537ec53df3a01ff3c05cf18d0d8dbad44ede07c7d8b56bd1
|
7
|
+
data.tar.gz: 15137f9ca084cc5bc7566c020e13bbb4fd394f418113882103d09a4fc58b6d2bca9488d0b55093937f9076d3de48970f4af11b1694e6b0734a1bd233f1c838f6
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -8,28 +8,34 @@
|
|
8
8
|
|
9
9
|
Add this line to your application's Gemfile:
|
10
10
|
|
11
|
-
|
11
|
+
```ruby
|
12
|
+
gem 'mongoid_markdown_extension'
|
13
|
+
```
|
12
14
|
|
13
15
|
And then execute:
|
14
16
|
|
15
|
-
|
17
|
+
```sh
|
18
|
+
$ bundle
|
19
|
+
```
|
16
20
|
|
17
21
|
Or install it yourself as:
|
18
22
|
|
19
|
-
|
23
|
+
```sh
|
24
|
+
$ gem install mongoid_markdown_extension
|
25
|
+
```
|
20
26
|
|
21
27
|
## Configuration
|
22
28
|
|
23
29
|
The defaults are as follows:
|
24
30
|
|
25
|
-
```
|
31
|
+
```ruby
|
26
32
|
extensions = {
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
+
autolink: true
|
34
|
+
footnotes: true
|
35
|
+
highlight: true
|
36
|
+
space_after_headers: true
|
37
|
+
strikethrough: true
|
38
|
+
superscript: true
|
33
39
|
}
|
34
40
|
|
35
41
|
render_options = {}
|
@@ -37,10 +43,11 @@ render_options = {}
|
|
37
43
|
|
38
44
|
These can be overwritten with an initializer, for example `config/initializers/mongoid_markdown.rb`:
|
39
45
|
|
40
|
-
```
|
46
|
+
```ruby
|
41
47
|
MongoidMarkdownExtension::Markdown.configure do |c|
|
42
|
-
|
43
|
-
|
48
|
+
c.extensions = { autolink: true }
|
49
|
+
c.render_class = CustomRenderer
|
50
|
+
c.render_options = { filter_html: true }
|
44
51
|
end
|
45
52
|
```
|
46
53
|
|
@@ -50,13 +57,13 @@ See [Redcarpet documentation](https://github.com/vmg/redcarpet) for available ex
|
|
50
57
|
|
51
58
|
Add to a Mongoid model:
|
52
59
|
|
53
|
-
```
|
60
|
+
```ruby
|
54
61
|
class MyModel
|
55
62
|
include Mongoid::Document
|
56
63
|
field :text, type: MongoidMarkdownExtension::Markdown
|
57
64
|
end
|
58
65
|
```
|
59
|
-
|
66
|
+
|
60
67
|
Use it:
|
61
68
|
|
62
69
|
```Ruby
|
data/Rakefile
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require 'mongoid_markdown_extension/inline_renderer'
|
2
|
+
require 'mongoid_markdown_extension/markdown'
|
3
|
+
require 'mongoid_markdown_extension/version'
|
@@ -32,11 +32,12 @@ module MongoidMarkdownExtension
|
|
32
32
|
|
33
33
|
def markdown_renderer
|
34
34
|
Redcarpet::Markdown.new(
|
35
|
-
|
35
|
+
self.class.configuration.render_class.new(self.class.configuration.render_options),
|
36
36
|
self.class.configuration.extensions
|
37
37
|
)
|
38
38
|
end
|
39
39
|
|
40
|
+
# TODO: how to combine custom render class with the InlineRenderer?
|
40
41
|
def markdown_inline_renderer
|
41
42
|
Redcarpet::Markdown.new(InlineRenderer, tables: false)
|
42
43
|
end
|
@@ -83,6 +84,7 @@ module MongoidMarkdownExtension
|
|
83
84
|
|
84
85
|
class Configuration
|
85
86
|
attr_accessor :extensions
|
87
|
+
attr_accessor :render_class
|
86
88
|
attr_accessor :render_options
|
87
89
|
|
88
90
|
def initialize
|
@@ -94,9 +96,8 @@ module MongoidMarkdownExtension
|
|
94
96
|
strikethrough: true,
|
95
97
|
superscript: true
|
96
98
|
}
|
99
|
+
@render_class = Redcarpet::Render::HTML
|
97
100
|
@render_options = {}
|
98
101
|
end
|
99
102
|
end
|
100
|
-
|
101
|
-
# ---------------------------------------------------------------------
|
102
103
|
end
|
@@ -4,24 +4,24 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'mongoid_markdown_extension/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'mongoid_markdown_extension'
|
8
8
|
spec.version = MongoidMarkdownExtension::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
11
|
-
spec.description =
|
12
|
-
spec.summary =
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
9
|
+
spec.authors = ['Tomas Celizna']
|
10
|
+
spec.email = ['mail@tomascelizna.com']
|
11
|
+
spec.description = 'Custom field type for Mongoid that handles Markdown conversion via Redcarpet gem.'
|
12
|
+
spec.summary = 'Custom field type for Mongoid that handles Markdown conversion via Redcarpet gem.'
|
13
|
+
spec.homepage = 'https://github.com/tomasc/mongoid_markdown_extension'
|
14
|
+
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
19
|
+
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_dependency
|
22
|
-
spec.add_dependency
|
21
|
+
spec.add_dependency 'redcarpet', '>= 3.1.2'
|
22
|
+
spec.add_dependency 'mongoid', '>= 4.0', '< 6.0'
|
23
23
|
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
26
|
-
spec.add_development_dependency
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
25
|
+
spec.add_development_dependency 'coveralls'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
27
27
|
end
|
@@ -7,6 +7,21 @@ class MongoidMarkdownExtensionTest
|
|
7
7
|
field :body, type: MongoidMarkdownExtension::Markdown
|
8
8
|
end
|
9
9
|
|
10
|
+
class CustomRenderer < Redcarpet::Render::HTML
|
11
|
+
def preprocess(doc)
|
12
|
+
doc.gsub(/\[button:(.*)\]\((.*)\)/) do
|
13
|
+
button_label = Regexp.last_match(1)
|
14
|
+
button_link = Regexp.last_match(2)
|
15
|
+
|
16
|
+
if button_label && button_link
|
17
|
+
"<a href='#{button_link}' class='button'>#{button_label}</a>"
|
18
|
+
else
|
19
|
+
button_label
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
10
25
|
# ---------------------------------------------------------------------
|
11
26
|
|
12
27
|
module MongoidMarkdownExtension
|
@@ -22,7 +37,15 @@ module MongoidMarkdownExtension
|
|
22
37
|
end
|
23
38
|
end
|
24
39
|
it 'returns default values' do
|
25
|
-
MongoidMarkdownExtension::Markdown.configuration.extensions.must_equal(
|
40
|
+
MongoidMarkdownExtension::Markdown.configuration.extensions.must_equal(
|
41
|
+
autolink: true,
|
42
|
+
footnotes: true,
|
43
|
+
highlight: true,
|
44
|
+
space_after_headers: true,
|
45
|
+
strikethrough: true,
|
46
|
+
superscript: true
|
47
|
+
)
|
48
|
+
MongoidMarkdownExtension::Markdown.configuration.render_class.must_equal Redcarpet::Render::HTML
|
26
49
|
MongoidMarkdownExtension::Markdown.configuration.render_options.must_equal({})
|
27
50
|
end
|
28
51
|
end
|
data/test/test_helper.rb
CHANGED
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.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Tomas Celizna
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redcarpet
|
@@ -76,20 +76,20 @@ dependencies:
|
|
76
76
|
name: rake
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
|
-
- - "
|
79
|
+
- - "~>"
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version: '0'
|
81
|
+
version: '10.0'
|
82
82
|
type: :development
|
83
83
|
prerelease: false
|
84
84
|
version_requirements: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
|
-
- - "
|
86
|
+
- - "~>"
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version: '0'
|
88
|
+
version: '10.0'
|
89
89
|
description: Custom field type for Mongoid that handles Markdown conversion via Redcarpet
|
90
90
|
gem.
|
91
91
|
email:
|
92
|
-
-
|
92
|
+
- mail@tomascelizna.com
|
93
93
|
executables: []
|
94
94
|
extensions: []
|
95
95
|
extra_rdoc_files: []
|
@@ -128,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
128
|
version: '0'
|
129
129
|
requirements: []
|
130
130
|
rubyforge_project:
|
131
|
-
rubygems_version: 2.4.
|
131
|
+
rubygems_version: 2.4.5.1
|
132
132
|
signing_key:
|
133
133
|
specification_version: 4
|
134
134
|
summary: Custom field type for Mongoid that handles Markdown conversion via Redcarpet
|