mato 0.2.0 → 1.0.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/CHANGELOG.md +5 -0
- data/README.md +62 -2
- data/lib/mato/processor.rb +4 -1
- data/lib/mato/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee2da8ff1a51b08c0831e7c493a6b3061b967996
|
4
|
+
data.tar.gz: 718d69d428ba169fb9038620e7d8237fdceb6486
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f2e0cdf40756e8d89cca2acc9c8a8bf294bcc35badac57dfeb07f9f986b6488fd5ea6bcc0e059f230c0f539ec1b20450a2ebd147741e13ddcd544aaf2fe33af
|
7
|
+
data.tar.gz: 335c587327afdb1c7642c0141b65db49f93ffc644c61b5ef45592c9804808846dc6befc0e50b9e059e7eedd7ae59a785c3097d701a1db04b06f32fe9bb59b5e6
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
This gem is built on [commonmarker](https://github.com/gjtorikian/commonmarker), a [CommonMark](https://github.com/jgm/CommonMark) implementation,
|
7
7
|
which can parse markdown documents.
|
8
8
|
|
9
|
-
##
|
9
|
+
## Usage
|
10
10
|
|
11
11
|
```ruby
|
12
12
|
require 'mato'
|
@@ -58,10 +58,70 @@ end
|
|
58
58
|
# Because Mato::Document is serializable, you can cache the base doc and then apply extra filters on demaond.
|
59
59
|
new_doc = doc.apply_html_filters(
|
60
60
|
-> (fragment) { modify_fragment!(fragment) },
|
61
|
-
SomeHtmlFilter.new, # anything that has #call(node) method
|
61
|
+
SomeHtmlFilter.new(some_context), # anything that has #call(node) method
|
62
62
|
)
|
63
63
|
```
|
64
64
|
|
65
|
+
## Filters
|
66
|
+
|
67
|
+
There are three kinds of filters to mutate input texts in Mato:
|
68
|
+
|
69
|
+
* Text Filters
|
70
|
+
* Markdown Filters
|
71
|
+
* HTML Filters
|
72
|
+
|
73
|
+
### Text Filters
|
74
|
+
|
75
|
+
A text filter is a callable instance that takes a `String`
|
76
|
+
and returns a mutated arg.
|
77
|
+
|
78
|
+
For example:
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
mato = Mato.define do |config|
|
82
|
+
config.append_text_filter(->(text) {
|
83
|
+
text.upcase
|
84
|
+
})
|
85
|
+
end
|
86
|
+
|
87
|
+
mato.process("Hello!").render_html # "<p>HELLO!</p>\n"
|
88
|
+
```
|
89
|
+
|
90
|
+
### Markdown Filters
|
91
|
+
|
92
|
+
A markdown filter is a callable instance that takes a ``CommonMarker::Node`
|
93
|
+
and mutate it in the method. The return value is ignored.
|
94
|
+
|
95
|
+
For example:
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
mato = Mato.define do |config|
|
99
|
+
config.append_markdown_filter(->(doc) {
|
100
|
+
paragraph = doc.first_child
|
101
|
+
text_node = paragraph.first_child
|
102
|
+
text_node.string_content = text_node.string_content.upcase
|
103
|
+
})
|
104
|
+
end
|
105
|
+
|
106
|
+
mato.process("Hello!").render_html # "<p>HELLO!</p>\n"
|
107
|
+
```
|
108
|
+
|
109
|
+
### HTML Filters
|
110
|
+
|
111
|
+
An HTML filter is a callable object that takes a ``Nokogiri::HTML::DocumentFragment`
|
112
|
+
and mutate it in the method. The return value is ignored.
|
113
|
+
|
114
|
+
```ruby
|
115
|
+
mato = Mato.define do |config|
|
116
|
+
config.append_html_filter(->(doc) {
|
117
|
+
text_node = doc.xpath('.//text()').first
|
118
|
+
text_node.content = text_node.content.upcase
|
119
|
+
})
|
120
|
+
end
|
121
|
+
|
122
|
+
mato.process("Hello!").render_html # "<p>HELLO!</p>\n"
|
123
|
+
```
|
124
|
+
|
65
125
|
## Installation
|
66
126
|
|
67
127
|
Add this line to your application's Gemfile:
|
data/lib/mato/processor.rb
CHANGED
@@ -20,12 +20,14 @@ module Mato
|
|
20
20
|
text = input.dup
|
21
21
|
|
22
22
|
config.text_filters.each do |filter|
|
23
|
-
filter
|
23
|
+
# A text filter returns a mutated text
|
24
|
+
text = filter.call(text)
|
24
25
|
end
|
25
26
|
|
26
27
|
markdown_node = parse_markdown(text)
|
27
28
|
|
28
29
|
config.markdown_filters.each do |filter|
|
30
|
+
# A markdown filter mutates the argument
|
29
31
|
filter.call(markdown_node)
|
30
32
|
end
|
31
33
|
|
@@ -33,6 +35,7 @@ module Mato
|
|
33
35
|
doc = parse_html(html)
|
34
36
|
|
35
37
|
config.html_filters.each do |filter|
|
38
|
+
# An HTML filter mutates the argument
|
36
39
|
filter.call(doc)
|
37
40
|
end
|
38
41
|
|
data/lib/mato/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mato
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- FUJI Goro
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -76,6 +76,7 @@ files:
|
|
76
76
|
- ".gitignore"
|
77
77
|
- ".rubocop.yml"
|
78
78
|
- ".travis.yml"
|
79
|
+
- CHANGELOG.md
|
79
80
|
- Gemfile
|
80
81
|
- LICENSE.txt
|
81
82
|
- README.md
|