darkmouun 2.3.1 → 3.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 18e60e63115fa16c943c12ab684572fbdadcf8087975a7be15d422fd1abab503
4
- data.tar.gz: 79410c4037b034be36ccee577e96ad0a5180341ef92987d6e536f18f214cd4e5
3
+ metadata.gz: f1f747aca75fc9d719bba0a265cb00e2f0553ca97036911220e16034d670d6e1
4
+ data.tar.gz: 9b724d1ede773105c88e8743fd2e8d21f9143518a051badfbaa8d5479e1c9d92
5
5
  SHA512:
6
- metadata.gz: 6c30cc898f302d5a7bc056995e4d23c971381ae42e6970248e01b09dd884d0dc5dd764c22121d7d450bbc393c9a66d07678ca96dabaa61ffd5d5a881ba83a1ac
7
- data.tar.gz: 71e422c0a231683e1a129d89576dce4fddd9351b25372cb28708d05dbb80300893f201c50820637615b64222030a77eb1e0720bd68b47e75bcd540eb19613e30
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 takes 3 arguments.
31
+ Darkmouun instance is made by `Darkmouun.document.new` with no arguments.
32
32
 
33
- * 1st arg: Target Markdown file name
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
- 2nd and 3rd argument has default value.
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
- * 2nd arg: {}
40
- * 3rd arg: to_html
39
+ 2nd and 3rd argument have default values.
41
40
 
42
- (Darkmouun instance).convert makes a HTML document from the target markdown document.
41
+ * 2nd arg: `{}`
42
+ * 3rd arg: `:to_html`
43
43
 
44
- You can define pre_process and post_process as a Proc object.
44
+ You can define pre_process and post_process as Proc object.
45
45
 
46
46
  ```
47
- dkmn = Darkmouun.document.new("MARKDOWN DOCUMENT", {:auto_ids => false})
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 '<<template_name>>'.
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(<<BODY, {:auto_ids => false, :input => 'sekd'}, :se_html)
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
@@ -16,31 +16,27 @@ module Darkmouun
16
16
  class Darkmouun
17
17
  attr_accessor :pre_process, :post_process
18
18
 
19
- def initialize(source, options ={}, converter = :html)
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 add_templates(dir, *tmpls)
23
+ def add_template(tmpl)
26
24
  # for Mustache
27
- tmpls.each do |tmpl|
28
- abs_path = dir + tmpl
29
- tmpl_module = Module.new
30
- tmpl_module.module_eval(File.read(abs_path), abs_path)
31
- tmpl_module.constants.each do |i|
32
- c = tmpl_module.const_get(i)
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, @options).send(@converter)
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
@@ -1,3 +1,3 @@
1
1
  module Darkmouun
2
- VERSION = "2.3.1"
2
+ VERSION = "3.1.1"
3
3
  end
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: 2.3.1
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 00:00:00.000000000 Z
11
+ date: 2023-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler