darkmouun 2.3.1 → 3.1.1
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/README.md +18 -21
- data/lib/darkmouun/main.rb +13 -17
- data/lib/darkmouun/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1f747aca75fc9d719bba0a265cb00e2f0553ca97036911220e16034d670d6e1
|
4
|
+
data.tar.gz: 9b724d1ede773105c88e8743fd2e8d21f9143518a051badfbaa8d5479e1c9d92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a4ea8e3cf385d928031a8c102830d35f32c3a05781124e7d3dfa239d6f177180f91a0f2d0f2779ff35a3a722c4f50ad18e6a4386a068b57f79c0e79f64ecdc1
|
7
|
+
data.tar.gz: 8a3b41bafe2be12d659a69286e33df1c2584293ffbad412f568a592a8f4e81845fe93212f6a7f468f376f745c0a8831683dfeaf05310ed5cbde5349bca0c8492
|
data/README.md
CHANGED
@@ -28,40 +28,40 @@ Or install it yourself as:
|
|
28
28
|
|
29
29
|
## Usage
|
30
30
|
|
31
|
-
Darkmouun.document.new
|
31
|
+
Darkmouun instance is made by `Darkmouun.document.new` with no arguments.
|
32
32
|
|
33
|
-
|
34
|
-
* 2nd arg: Kramdown's parser option (cf. [kramdown's usage](https://kramdown.gettalong.org/documentation.html#usage))
|
35
|
-
* 3rd arg: Kramdown's converter name(ex. if converter class name is ItlHtml, converter name is to_itl_html.)
|
33
|
+
(Darkmouun instance)`.convert` makes a HTML document from the markdown text and takes 3 arguments.
|
36
34
|
|
37
|
-
|
35
|
+
* 1st arg: Markdown text (String)
|
36
|
+
* 2nd arg: Kramdown's parser option (Hash) (cf. [kramdown's usage](https://kramdown.gettalong.org/documentation.html#usage))
|
37
|
+
* 3rd arg: Kramdown's converter name (Symbol)
|
38
38
|
|
39
|
-
|
40
|
-
* 3rd arg: to_html
|
39
|
+
2nd and 3rd argument have default values.
|
41
40
|
|
42
|
-
|
41
|
+
* 2nd arg: `{}`
|
42
|
+
* 3rd arg: `:to_html`
|
43
43
|
|
44
|
-
You can define pre_process and post_process as
|
44
|
+
You can define pre_process and post_process as Proc object.
|
45
45
|
|
46
46
|
```
|
47
|
-
dkmn = Darkmouun.document.new
|
47
|
+
dkmn = Darkmouun.document.new
|
48
48
|
dkmn.pre_process = lambda do |i|
|
49
49
|
i.gsub!(/MARKDOWN/, "Markdown")
|
50
50
|
end
|
51
51
|
dkmn.post_process = lambda do |i|
|
52
52
|
i.gsub!(/DOCUMENT/, "Document")
|
53
53
|
end
|
54
|
-
dkmn.convert #=> "<p>Markdown Document</p>
|
54
|
+
dkmn.convert("MARKDOWN DOCUMENT") #=> "<p>Markdown Document</p>
|
55
55
|
```
|
56
56
|
|
57
57
|
You can write the parts that Mustache extracts with templates in your markdown document.
|
58
58
|
Template is written as Ruby script, and it is made to define as the subclass of Mustache class.
|
59
59
|
|
60
|
-
The part of template extacting in the markdown document starts
|
60
|
+
The part of template extacting in the markdown document starts `<<template_name>>`.
|
61
61
|
Parameters of the template are written below with YAML format.
|
62
62
|
|
63
63
|
```
|
64
|
-
# Template file 'template_a.rb'
|
64
|
+
# Template file 'templates/template_a.rb'
|
65
65
|
|
66
66
|
class Template_A < Mustache
|
67
67
|
Template = <<EOS
|
@@ -76,19 +76,16 @@ end
|
|
76
76
|
```
|
77
77
|
# converting code
|
78
78
|
|
79
|
-
dkmn = Darkmouun.document.new
|
79
|
+
dkmn = Darkmouun.document.new
|
80
|
+
dkmn.add_template("#{__dir__}/templates/template_a.rb")
|
81
|
+
dkmn.convert(<<BODY)
|
80
82
|
The calculation:
|
81
83
|
|
82
84
|
<<Template_A>>
|
83
85
|
fig1: 1
|
84
86
|
fig2: 2
|
85
|
-
BODY
|
86
|
-
|
87
|
-
dkmn.add_templates "#{__dir__}/templates/", # 1st arg is the directory of templates.
|
88
|
-
'template_a.rb' # 2nd or later args are the files of templates.
|
89
|
-
|
90
|
-
dkmn.convert #=> <p>The Calculation:</p>
|
91
|
-
<p>1 + 2 is 3.</p>
|
87
|
+
BODY #=> <p>The Calculation:</p>
|
88
|
+
#=> <p>1 + 2 is 3.</p>
|
92
89
|
```
|
93
90
|
|
94
91
|
## kramdown extensions
|
data/lib/darkmouun/main.rb
CHANGED
@@ -16,31 +16,27 @@ module Darkmouun
|
|
16
16
|
class Darkmouun
|
17
17
|
attr_accessor :pre_process, :post_process
|
18
18
|
|
19
|
-
def initialize
|
20
|
-
@source, @options = source, options
|
19
|
+
def initialize
|
21
20
|
@templates = {}
|
22
|
-
@converter = ('to_' + (converter.to_s)).intern
|
23
21
|
end
|
24
22
|
|
25
|
-
def
|
23
|
+
def add_template(tmpl)
|
26
24
|
# for Mustache
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
tmpl_module.
|
31
|
-
|
32
|
-
|
33
|
-
if c.is_a?(Class) && c.superclass == Mustache
|
34
|
-
@templates[i] = c
|
35
|
-
end
|
25
|
+
tmpl_module = Module.new
|
26
|
+
tmpl_module.module_eval(File.read(tmpl), tmpl)
|
27
|
+
tmpl_module.constants.each do |i|
|
28
|
+
c = tmpl_module.const_get(i)
|
29
|
+
if c.is_a?(Class) && c.superclass == Mustache
|
30
|
+
@templates[i] = c
|
36
31
|
end
|
37
32
|
end
|
38
33
|
end
|
39
34
|
|
40
|
-
def convert
|
35
|
+
def convert(source, options = {}, converter = :to_html)
|
36
|
+
@source = source
|
41
37
|
do_pre_process
|
42
38
|
apply_mustache
|
43
|
-
apply_kramdown
|
39
|
+
apply_kramdown(options, converter)
|
44
40
|
do_post_process
|
45
41
|
beautify
|
46
42
|
end
|
@@ -69,9 +65,9 @@ module Darkmouun
|
|
69
65
|
end
|
70
66
|
end
|
71
67
|
|
72
|
-
def apply_kramdown
|
68
|
+
def apply_kramdown(options, converter)
|
73
69
|
begin
|
74
|
-
@result = Kramdown::Document.new(@source,
|
70
|
+
@result = Kramdown::Document.new(@source, options).send(converter)
|
75
71
|
rescue => e
|
76
72
|
raise e.class.new("\n#{e.message}\n\n>>> ERROR in \"kramdown-process\" <<<\n")
|
77
73
|
end
|
data/lib/darkmouun/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: darkmouun
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akinori Ichigo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-03-
|
11
|
+
date: 2023-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|