mato 1.2.3 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +11 -5
- data/CHANGELOG.md +8 -1
- data/README.md +23 -1
- data/lib/mato.rb +2 -0
- data/lib/mato/config.rb +18 -19
- data/lib/mato/rescue.rb +20 -0
- data/lib/mato/timeout.rb +30 -0
- data/lib/mato/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 195f9886598ddf1a08ec46a3b9bb30dfa21a943c
|
4
|
+
data.tar.gz: ee6f5a7eeb28141a9b0a3fd63c9c4867e8bbb8bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d094d454579750f042c6fc586233f9f94172efc490969b8e2d55b9c7ec9f3d5ad2efb59e881fba36e802cef7aee51e35ccc89fc80cde024b047e7a563447fc67
|
7
|
+
data.tar.gz: 57481242dfab44c1c3718ba1a36d917ecf4af9da1722d8c29479e41ce58153dd27e869820c5075b1852e16dd078943c642cba77cead030308da8df6106e9b73a
|
data/.rubocop.yml
CHANGED
@@ -15,6 +15,9 @@ Lint/AmbiguousBlockAssociation:
|
|
15
15
|
Lint/ScriptPermission:
|
16
16
|
Enabled: false
|
17
17
|
|
18
|
+
Lint/RescueWithoutErrorClass:
|
19
|
+
Enabled: false
|
20
|
+
|
18
21
|
Layout/MultilineMethodCallIndentation:
|
19
22
|
Enabled: false
|
20
23
|
|
@@ -22,7 +25,7 @@ Layout/EmptyLinesAroundClassBody:
|
|
22
25
|
Enabled: false
|
23
26
|
|
24
27
|
Metrics/AbcSize:
|
25
|
-
Max:
|
28
|
+
Max: 35
|
26
29
|
|
27
30
|
Metrics/PerceivedComplexity:
|
28
31
|
Max: 10
|
@@ -57,7 +60,7 @@ Style/CommentAnnotation:
|
|
57
60
|
Style/Documentation:
|
58
61
|
Enabled: false
|
59
62
|
|
60
|
-
|
63
|
+
Naming/FileName:
|
61
64
|
Enabled: false
|
62
65
|
|
63
66
|
Style/GuardClause:
|
@@ -114,13 +117,13 @@ Style/AsciiComments:
|
|
114
117
|
Style/EmptyMethod:
|
115
118
|
EnforcedStyle: expanded
|
116
119
|
|
117
|
-
|
120
|
+
Naming/VariableNumber:
|
118
121
|
Enabled: false
|
119
122
|
|
120
|
-
|
123
|
+
Naming/PredicateName:
|
121
124
|
Enabled: false
|
122
125
|
|
123
|
-
|
126
|
+
Naming/AccessorMethodName:
|
124
127
|
Enabled: false
|
125
128
|
|
126
129
|
Style/YodaCondition:
|
@@ -135,5 +138,8 @@ Style/MultipleComparison:
|
|
135
138
|
Style/StructInheritance:
|
136
139
|
Enabled: false
|
137
140
|
|
141
|
+
Style/NonNilCheck:
|
142
|
+
Enabled: false
|
143
|
+
|
138
144
|
Performance/RedundantBlockCall:
|
139
145
|
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
# The revision history of Mato
|
2
2
|
|
3
|
-
## v1.3.
|
3
|
+
## v1.3.0 - 2017/09/26
|
4
|
+
|
5
|
+
https://github.com/bitjourney/mato/compare/v1.2.3...1.3.0
|
6
|
+
|
7
|
+
* Added `timeout:`, `on_timeout:` and `on_error:` options to `append_*_filter` [#10](https://github.com/bitjourney/mato/pull/10)
|
8
|
+
|
9
|
+
|
10
|
+
## v1.2.3 - 2017/09/22
|
4
11
|
|
5
12
|
https://github.com/bitjourney/mato/compare/v1.2.2...1.2.3
|
6
13
|
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Mato [![Build Status](https://travis-ci.org/bitjourney/mato.svg?branch=master)](https://travis-ci.org/bitjourney/mato)
|
1
|
+
# Mato [![Build Status](https://travis-ci.org/bitjourney/mato.svg?branch=master)](https://travis-ci.org/bitjourney/mato) [![Gem Version](https://badge.fury.io/rb/mato.svg)](https://badge.fury.io/rb/mato)
|
2
2
|
|
3
3
|
**Mato**, standing for **Ma**rkdown **To**oolkit, is an extensible, pipeline-based markdown processing toolkit, inspired by [HTML::Pipeline](https://github.com/jch/html-pipeline).
|
4
4
|
|
@@ -122,6 +122,28 @@ end
|
|
122
122
|
mato.process("Hello!").render_html # "<p>HELLO!</p>\n"
|
123
123
|
```
|
124
124
|
|
125
|
+
### Timeout
|
126
|
+
|
127
|
+
There is `timeout` option to kill filters in a specified time in seconds:
|
128
|
+
|
129
|
+
```ruby
|
130
|
+
mato = Mato.define do |config|
|
131
|
+
config.append_html_filter(FooFilter, timeout: timeout_in_sec, on_timeout: callback)
|
132
|
+
end
|
133
|
+
```
|
134
|
+
|
135
|
+
If you set `on_error` callback, you can omit `on_timeout` callback.
|
136
|
+
|
137
|
+
### Errors in Filters
|
138
|
+
|
139
|
+
There is `on_error` callback to rescue errors in filters:
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
mato = Mato.define do |config|
|
143
|
+
config.append_html_filter(FooFilter, on_error: callback)
|
144
|
+
end
|
145
|
+
```
|
146
|
+
|
125
147
|
## Installation
|
126
148
|
|
127
149
|
Add this line to your application's Gemfile:
|
data/lib/mato.rb
CHANGED
@@ -5,6 +5,8 @@ require_relative "./mato/version"
|
|
5
5
|
require_relative "./mato/config"
|
6
6
|
require_relative "./mato/processor"
|
7
7
|
require_relative "./mato/converter"
|
8
|
+
require_relative "./mato/rescue"
|
9
|
+
require_relative "./mato/timeout"
|
8
10
|
|
9
11
|
# filter classes
|
10
12
|
require_relative "./mato/html_filters/token_link"
|
data/lib/mato/config.rb
CHANGED
@@ -75,34 +75,33 @@ module Mato
|
|
75
75
|
block.call(self)
|
76
76
|
end
|
77
77
|
|
78
|
-
def append_text_filter(text_filter)
|
78
|
+
def append_text_filter(text_filter, timeout: nil, on_timeout: nil, on_error: nil)
|
79
79
|
raise "text_filter must respond to call()" unless text_filter.respond_to?(:call)
|
80
|
-
text_filters.push(text_filter)
|
80
|
+
text_filters.push(wrap(text_filter, timeout: timeout, on_timeout: on_timeout, on_error: on_error))
|
81
81
|
end
|
82
82
|
|
83
|
-
def
|
84
|
-
raise "text_filter must respond to call()" unless text_filter.respond_to?(:call)
|
85
|
-
text_filters.unshift(text_filter)
|
86
|
-
end
|
87
|
-
|
88
|
-
def append_markdown_filter(markdown_filter)
|
89
|
-
raise "markdown_filter must respond to call()" unless markdown_filter.respond_to?(:call)
|
90
|
-
markdown_filters.push(markdown_filter)
|
91
|
-
end
|
92
|
-
|
93
|
-
def prepend_markdown_filter(markdown_filter)
|
83
|
+
def append_markdown_filter(markdown_filter, timeout: nil, on_timeout: nil, on_error: nil)
|
94
84
|
raise "markdown_filter must respond to call()" unless markdown_filter.respond_to?(:call)
|
95
|
-
markdown_filters.
|
85
|
+
markdown_filters.push(wrap(markdown_filter, timeout: timeout, on_timeout: on_timeout, on_error: on_error))
|
96
86
|
end
|
97
87
|
|
98
|
-
def append_html_filter(html_filter)
|
88
|
+
def append_html_filter(html_filter, timeout: nil, on_timeout: nil, on_error: nil)
|
99
89
|
raise "html_filter must respond to call()" unless html_filter.respond_to?(:call)
|
100
|
-
html_filters.push(html_filter)
|
90
|
+
html_filters.push(wrap(html_filter, timeout: timeout, on_timeout: on_timeout, on_error: on_error))
|
101
91
|
end
|
102
92
|
|
103
|
-
|
104
|
-
|
105
|
-
|
93
|
+
private
|
94
|
+
|
95
|
+
def wrap(filter, timeout:, on_timeout:, on_error:)
|
96
|
+
if timeout
|
97
|
+
filter = Mato::Timeout.new(filter, timeout: timeout, on_timeout: on_timeout || on_error)
|
98
|
+
end
|
99
|
+
|
100
|
+
if on_error
|
101
|
+
filter = Mato::Rescue.new(filter, on_error: on_error)
|
102
|
+
end
|
103
|
+
|
104
|
+
filter
|
106
105
|
end
|
107
106
|
end
|
108
107
|
end
|
data/lib/mato/rescue.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mato
|
4
|
+
class Rescue
|
5
|
+
attr_reader :filter
|
6
|
+
attr_reader :on_error
|
7
|
+
|
8
|
+
def initialize(filter, on_error:)
|
9
|
+
@filter = filter
|
10
|
+
@on_error = on_error
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(content)
|
14
|
+
filter.call(content)
|
15
|
+
rescue => e
|
16
|
+
on_error.call(e)
|
17
|
+
content
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/mato/timeout.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'timeout'
|
4
|
+
|
5
|
+
module Mato
|
6
|
+
class Timeout
|
7
|
+
attr_reader :filter
|
8
|
+
attr_reader :duration_sec
|
9
|
+
attr_reader :on_timeout
|
10
|
+
|
11
|
+
def initialize(filter, timeout:, on_timeout:)
|
12
|
+
@filter = filter
|
13
|
+
@duration_sec = timeout
|
14
|
+
@on_timeout = on_timeout
|
15
|
+
|
16
|
+
unless on_timeout
|
17
|
+
raise ArgumentError, "Missing on_timeout callback"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def call(content)
|
22
|
+
::Timeout.timeout(duration_sec) do
|
23
|
+
filter.call(content)
|
24
|
+
end
|
25
|
+
rescue ::Timeout::Error => e
|
26
|
+
on_timeout.call(e)
|
27
|
+
content
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
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: 1.
|
4
|
+
version: 1.3.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-09-
|
11
|
+
date: 2017-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -87,6 +87,8 @@ files:
|
|
87
87
|
- lib/mato/processor.rb
|
88
88
|
- lib/mato/renderers/html_renderer.rb
|
89
89
|
- lib/mato/renderers/html_toc_renderer.rb
|
90
|
+
- lib/mato/rescue.rb
|
91
|
+
- lib/mato/timeout.rb
|
90
92
|
- lib/mato/version.rb
|
91
93
|
- mato.gemspec
|
92
94
|
homepage: https://github.com/bitjourney/mato
|