pbsimply 3.6.2 → 3.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9f6eba39306e8a547d2dc0cec4cafb7c683c47dcaf54a075101c144667135c03
4
- data.tar.gz: 905f46a0b0cb44921d20e8c6a88459943f8c49245b06983e64738c1655445bc1
3
+ metadata.gz: 5d2819cbfc7057533e6c680ba3ee1b8dc30117eb532e7061a778437b2a5f3433
4
+ data.tar.gz: fe9e02ca45a41d2a7649ea4b47be2230f52bf516b8b03722a4c6448be75d99b1
5
5
  SHA512:
6
- metadata.gz: ac06410f8bb7de354a978ff9011096e1532db1bbaf797b0c59651f91714bbf1a3d6e01138fbb5c14e8ca715c118d9f4f904844b34dfa51998b4aee8589941f1d
7
- data.tar.gz: b9524c4a55b20615f81de41542e4808ab42d81baa53b7650fbd8f4b4af87052c54ebf2403d6d6b1de796fb8c152c1da4025ef3a3606a13dc3f1bcf39402773a4
6
+ metadata.gz: 20eefe2e45fb693831c91fda93007f64782d7ebcc37fc8a964709f506771a0e7b60b03612b16fdc5edd1f59c0e6ac0c51065c51447074bca1c3ca36727a4642b
7
+ data.tar.gz: 673a659f5af31b89441e048e1896e3773d385404a9dcc9055fcc93ec85f95d2945e7daef92c6d0fd86ed23c39e73767949a5f66da732a450e97a613e08c24557
data/lib/pbsimply/accs.rb CHANGED
@@ -82,7 +82,7 @@ EOF
82
82
 
83
83
  @hooks.accs.run({index: @index, indexes: @indexes})
84
84
 
85
- doc = ERB.new(erbtemplate, trim_mode: "%<>").result(binding)
85
+ doc = str_and_render(erbtemplate, binding)
86
86
  File.open(File.join(@dir, ".index.md"), "w") do |f|
87
87
  f.write doc
88
88
  end
@@ -24,8 +24,7 @@ class PBSimply
24
24
  article_body = markdown.render(File.read procdoc)
25
25
 
26
26
  # Process with eRuby temaplte.
27
- erb_template = ERB.new(File.read(@config["template"]), trim_mode: '%<>')
28
- doc = erb_template.result(binding)
27
+ doc = expand_template binding
29
28
 
30
29
  doc
31
30
  end
@@ -51,8 +50,7 @@ class PBSimply
51
50
  article_body = markdown.to_html
52
51
 
53
52
  # Process with eRuby temaplte.
54
- erb_template = ERB.new(File.read(@config["template"]), trim_mode: '%<>')
55
- doc = erb_template.result(binding)
53
+ doc = expand_template binding
56
54
 
57
55
  doc
58
56
  end
@@ -71,13 +69,15 @@ class PBSimply
71
69
 
72
70
  def process_document(dir, filename, frontmatter, orig_filepath, ext, procdoc)
73
71
  options = @config["commonmarker_options"] ? @config["commonmarker_options"].transform_keys(&:to_sym) : {}
72
+ options.each do |k,v|
73
+ options[k] = v.transform_keys(&:to_sym)
74
+ end
74
75
 
75
76
  # Getting HTML string.
76
- article_body = Commonmarker.parse(File.read(procdoc), options: options).to_html
77
+ article_body = Commonmarker.to_html(File.read(procdoc), options: options)
77
78
 
78
79
  # Process with eRuby temaplte.
79
- erb_template = ERB.new(File.read(@config["template"]), trim_mode: '%<>')
80
- doc = erb_template.result(binding)
80
+ doc = expand_template binding
81
81
 
82
82
  doc
83
83
  end
@@ -20,8 +20,7 @@ class PBSimply
20
20
  article_body = rdoc.convert(get_markup_document(procdoc))
21
21
 
22
22
  # Process with eRuby temaplte.
23
- erb_template = ERB.new(File.read(@config["template"]), trim_mode: '%<>')
24
- doc = erb_template.result(binding)
23
+ doc = expand_template binding
25
24
 
26
25
  doc
27
26
  end
@@ -0,0 +1,112 @@
1
+ #!/bin/env ruby
2
+ require 'time'
3
+ require 'erb'
4
+
5
+ module PBSimply::ERuby
6
+ include ::ERB::Util
7
+
8
+ class WrapErubi
9
+ def initialize
10
+ require 'erubi'
11
+ end
12
+
13
+ def load_doc str
14
+ @processor = ::Erubi::Engine.new(str)
15
+ self
16
+ end
17
+
18
+ def generate bounded
19
+ eval(@processor.src, bounded)
20
+ end
21
+ end
22
+
23
+ class WrapErubis
24
+ def initialize
25
+ require 'erubis'
26
+ end
27
+
28
+ def load_doc str
29
+ @processor = ::Erubis::Eruby.new(str)
30
+ self
31
+ end
32
+
33
+ def generate bounded
34
+ @processor.result(bounded)
35
+ end
36
+ end
37
+
38
+ class WrapErb
39
+ def initialize config
40
+ @config = config
41
+ end
42
+
43
+ def load_doc str
44
+ @processor = ::ERB.new(str, trim_mode: (@config["erb_trm_mode"] || "%<>"))
45
+ self
46
+ end
47
+
48
+ def generate bounded
49
+ @processor.result(bounded)
50
+ end
51
+ end
52
+
53
+ def erblib
54
+ return @eruby_lib if @eruby_lib
55
+ case @config["eruby_lib"]
56
+ when "erubis"
57
+ @eruby_lib = WrapErubis.new
58
+ when "erubi"
59
+ @eruby_lib = WrapErubi.new
60
+ else
61
+ @eruby_lib = WrapErb.new @config
62
+ end
63
+
64
+ @eruby_lib
65
+ end
66
+
67
+ def file_and_render fp, bounded
68
+ erblib.load_doc(File.read(fp)).generate(bounded)
69
+ end
70
+
71
+ def str_and_render str, bounded
72
+ erblib.load_doc(str).generate(bounded)
73
+ end
74
+
75
+ private
76
+
77
+ def parse_time
78
+ if (Numeric === time_elem && time_elem > 1000000000000)
79
+ # JavaScript milliseconds
80
+ Time.at(time_elem / 1000)
81
+ elsif Numeric === time_elem
82
+ # Unix
83
+ Time.at(time_elem)
84
+ elsif String === time_elem
85
+ # Generic String
86
+ Time.parse(time_elem)
87
+ elsif Array === time_elem
88
+ # #local arguments array
89
+ Time.local(*time_elem)
90
+ else
91
+ Time.now
92
+ end
93
+ end
94
+
95
+ def iso8601 time_elem
96
+ parse_time(time_elem).iso8601
97
+ end
98
+
99
+ def httpdate time_elem
100
+ parse_time(time_elem).httpdate
101
+ end
102
+
103
+ def rfc822 time_elem
104
+ parse_time(time_elem).rfc822
105
+ end
106
+
107
+ alias rfc2822 rfc822
108
+
109
+ def xmldate time_elem
110
+ parse_time(time_elem).xmlschema
111
+ end
112
+ end
@@ -0,0 +1,46 @@
1
+ #!/bin/env ruby
2
+
3
+ module PBSimply::TemplateEngine
4
+ class TplEngineLiquid
5
+ def initialize template
6
+ require 'liquid'
7
+ @template = template
8
+ end
9
+
10
+ def generate frontmatter, article_body
11
+ Liquid::Template.parse(@template).render(
12
+ "frontmatter" => frontmatter,
13
+ "article_body" => body
14
+ )
15
+ end
16
+ end
17
+
18
+ class TplEngineMustache
19
+ def initialize template
20
+ require 'mustache'
21
+ @template = template
22
+ end
23
+
24
+ def generate frontmatter, article_body
25
+ Mustache.render(@template, {
26
+ frontmatter: frontmatter,
27
+ article_body: article_body
28
+ })
29
+ end
30
+ end
31
+
32
+ def expand_template binding
33
+ $stderr.puts @config["template_format"]
34
+ case @config["template_format"]
35
+ when "liquid"
36
+ tpl = TplEngineLiquid.new(File.read(@config["template"]))
37
+ tpl.generate(binding.local_variable_get(:frontmatter), binding.local_variable_get(:article_body))
38
+ when "mustache"
39
+ $stderr.puts "mustache"
40
+ tpl = TplEngineMustache.new(File.read(@config["template"]))
41
+ tpl.generate(binding.local_variable_get(:frontmatter), binding.local_variable_get(:article_body))
42
+ else
43
+ file_and_render(@config["template"], binding)
44
+ end
45
+ end
46
+ end
data/lib/pbsimply.rb CHANGED
@@ -17,13 +17,17 @@ require 'pbsimply/prayer'
17
17
  require 'pbsimply/plugger'
18
18
  require 'pbsimply/hooks'
19
19
  require 'pbsimply/accs'
20
- require 'pbsimply/config-checker.rb'
20
+ require 'pbsimply/config-checker'
21
21
  require 'pbsimply/document'
22
+ require 'pbsimply/eruby'
23
+ require 'pbsimply/template-engine'
22
24
 
23
25
  class PBSimply
24
26
  include Prayer
25
27
  include Plugger
26
28
  include ACCS
29
+ include ERuby
30
+ include TemplateEngine
27
31
 
28
32
  # Custom exception
29
33
  class PBSimplyError < StandardError
@@ -442,7 +446,7 @@ class PBSimply
442
446
  ##### Post eRuby
443
447
  if @config["post_eruby"]
444
448
  $stderr.puts "Porcessing with eRuby."
445
- doc = ERB.new(doc, nil, "%<>").result(binding)
449
+ doc = str_and_render(dov, binding)
446
450
  end
447
451
 
448
452
  # Write out
@@ -16,35 +16,32 @@ else
16
16
  @indexes.each {|filename, index| articles[(index["category"] || "default")].push index }
17
17
  end
18
18
 
19
- %>
19
+ articles.keys.sort.each do |catname|
20
+ cat = articles[catname]
20
21
 
21
- % articles.keys.sort.each do |catname|
22
- % cat = articles[catname]
23
-
24
- % unless articles.length == 1
22
+ unless articles.length == 1
25
23
  # <%= catname %>
26
- % end
24
+ <% end
25
+
26
+ sort_method = case @config["accs_sort_by"]
27
+ when "title"
28
+ lambda {|i| [i["title"].to_s, i["date"]] }
29
+ when "name"
30
+ lambda {|i| [i["_filename"].to_s, i["title"].to_s, i["date"]] }
31
+ when "serial"
32
+ lambda {|i| [i["serial"].to_s, i["date"], i["_filename"].to_s] }
33
+ else
34
+ lambda {|i| [i["date"], i["title"].to_s, i["_last_update"].to_i] }
35
+ end
27
36
 
28
- <%
29
- sort_method = case @config["accs_sort_by"]
30
- when "title"
31
- lambda {|i| [i["title"].to_s, i["date"]] }
32
- when "name"
33
- lambda {|i| [i["_filename"].to_s, i["title"].to_s, i["date"]] }
34
- when "serial"
35
- lambda {|i| [i["serial"].to_s, i["date"], i["_filename"].to_s] }
36
- else
37
- lambda {|i| [i["date"], i["title"].to_s, i["_last_update"].to_i] }
38
- end
39
-
40
- list = if @config["accs_order"] == "desc"
41
- cat.sort_by(&sort_method).reverse
42
- else
43
- cat.sort_by(&sort_method)
44
- end
45
-
46
- list.each do |i|
37
+ list = if @config["accs_order"] == "desc"
38
+ cat.sort_by(&sort_method).reverse
39
+ else
40
+ cat.sort_by(&sort_method)
41
+ end
42
+
43
+ list.each do |i|
47
44
  %>* [<%= i["title"] %>](<%= i["page_url"] %>)
48
- <% end %>
45
+ <% end
49
46
 
50
- % end
47
+ end %>
@@ -7,6 +7,9 @@ outdir: ../Build
7
7
  # Template file path.
8
8
  # ./template.html by default.
9
9
  template: template.html
10
+ # Configure the template engine/template format. The default is eruby, and liquid and mustache can be specified.
11
+ # This setting is only effective when using a document processor that defaults to eRuby. It does not function when using a document processor that employs a different dedicated template engine (e.g., Pandoc).
12
+ # template_format: eruby
10
13
  #
11
14
  # Loading CSS files (userd by Pandoc's default template.)
12
15
  # This values must be *server's URL*.
@@ -23,6 +26,13 @@ toc: true
23
26
  # Enable eRuby template expansion. true or false. false by default.
24
27
  # This settings is not avilable on rdoc, rdoc_markdown, kramdown, redcarpet or cmark engine.
25
28
  post_eruby: false
29
+ # Specify the eRuby processor library.
30
+ # The default is erb; erubis and erubi can be specified.
31
+ # Since these libraries are not fully compatible with each other, specifying one may change behavior or cause it to fail to function properly.
32
+ # eruby_lib: erb
33
+ # Specifies the value for the `trim_mode` parameter passed to the ERB constructor. The default is `%<>`.
34
+ # Specifying this value may cause .erb files used by the theme to malfunction.
35
+ # erb_trim_mode: "%<>"
26
36
  # Default metadata. If same key exists in document's frontmatter, document's frontmatter is given priority to this settings.
27
37
  default_meta:
28
38
  author: "John Doe"
@@ -16,35 +16,32 @@ else
16
16
  @indexes.each {|filename, index| articles[(index["category"] || "default")].push index }
17
17
  end
18
18
 
19
- %>
19
+ articles.keys.sort.each do |catname|
20
+ cat = articles[catname]
20
21
 
21
- % articles.keys.sort.each do |catname|
22
- % cat = articles[catname]
23
-
24
- % unless articles.length == 1
22
+ unless articles.length == 1 %>
25
23
  # <%= catname %>
26
- % end
24
+ <% end
25
+
26
+ sort_method = case @config["accs_sort_by"]
27
+ when "title"
28
+ lambda {|i| [i["title"].to_s, i["date"]] }
29
+ when "name"
30
+ lambda {|i| [i["_filename"].to_s, i["title"].to_s, i["date"]] }
31
+ when "serial"
32
+ lambda {|i| [i["serial"].to_s, i["date"], i["_filename"].to_s] }
33
+ else
34
+ lambda {|i| [i["date"], i["title"].to_s, i["_last_update"].to_i] }
35
+ end
27
36
 
28
- <%
29
- sort_method = case @config["accs_sort_by"]
30
- when "title"
31
- lambda {|i| [i["title"].to_s, i["date"]] }
32
- when "name"
33
- lambda {|i| [i["_filename"].to_s, i["title"].to_s, i["date"]] }
34
- when "serial"
35
- lambda {|i| [i["serial"].to_s, i["date"], i["_filename"].to_s] }
36
- else
37
- lambda {|i| [i["date"], i["title"].to_s, i["_last_update"].to_i] }
38
- end
39
-
40
- list = if @config["accs_order"] == "desc"
41
- cat.sort_by(&sort_method).reverse
42
- else
43
- cat.sort_by(&sort_method)
44
- end
45
-
46
- list.each do |i|
37
+ list = if @config["accs_order"] == "desc"
38
+ cat.sort_by(&sort_method).reverse
39
+ else
40
+ cat.sort_by(&sort_method)
41
+ end
42
+
43
+ list.each do |i|
47
44
  %>* [<%= i["title"] %>](<%= i["page_url"] %>)
48
- <% end %>
45
+ <% end
49
46
 
50
- % end
47
+ end %>
@@ -7,6 +7,9 @@ outdir: ../Build
7
7
  # Template file path.
8
8
  # ./template.html by default.
9
9
  template: template.html
10
+ # Configure the template engine/template format. The default is eruby, and liquid and mustache can be specified.
11
+ # This setting is only effective when using a document processor that defaults to eRuby. It does not function when using a document processor that employs a different dedicated template engine (e.g., Pandoc).
12
+ # template_format: eruby
10
13
  #
11
14
  # Loading CSS files (userd by Pandoc's default template.)
12
15
  # This values must be *server's URL*.
@@ -20,6 +23,13 @@ toc: true
20
23
  # Enable eRuby template expansion. true or false. false by default.
21
24
  # This settings is not avilable on rdoc, rdoc_markdown, kramdown, redcarpet or cmark engine.
22
25
  post_eruby: false
26
+ # Specify the eRuby processor library.
27
+ # The default is erb; erubis and erubi can be specified.
28
+ # Since these libraries are not fully compatible with each other, specifying one may change behavior or cause it to fail to function properly.
29
+ # eruby_lib: erb
30
+ # Specifies the value for the `trim_mode` parameter passed to the ERB constructor. The default is `%<>`.
31
+ # Specifying this value may cause .erb files used by the theme to malfunction.
32
+ # erb_trim_mode: "%<>"
23
33
  # Default metadata. If same key exists in document's frontmatter, document's frontmatter is given priority to this settings.
24
34
  default_meta:
25
35
  author: "John Doe"
@@ -11,25 +11,22 @@ articles = Hash.new {|h,k| h[k] = Array.new }
11
11
  articles[(index["category"] || "default")].push index
12
12
  end
13
13
 
14
- %>
14
+ artkeys = articles.keys.sort
15
+ artkeys.each do |catname|
16
+ cat = articles[catname]
15
17
 
16
- % artkeys = articles.keys.sort
17
- % artkeys.each do |catname|
18
- % cat = articles[catname]
19
-
20
- % if articles.length > 1
18
+ if articles.length > 1 %>
21
19
  # <%= catname %>
22
- % end
20
+ <% end
23
21
 
24
- <%
25
- list = if @config["accs_order"] == "desc" || @index["accs_order"] == "desc" || @index["blogmode"]
26
- cat.sort_by {|i| [i["date"].to_s, i["title"].to_s, i["_last_update"].to_i] }.reverse
27
- else
28
- cat.sort_by {|i| [i["date"].to_s, i["title"].to_s, i["_last_update"].to_i] }
29
- end
22
+ list = if @config["accs_order"] == "desc" || @index["accs_order"] == "desc" || @index["blogmode"]
23
+ cat.sort_by {|i| [i["date"].to_s, i["title"].to_s, i["_last_update"].to_i] }.reverse
24
+ else
25
+ cat.sort_by {|i| [i["date"].to_s, i["title"].to_s, i["_last_update"].to_i] }
26
+ end
30
27
 
31
- list.each do |i|
28
+ list.each do |i|
32
29
  %>* [<%= i["title"].gsub('@', '\@') %>](<%= File.basename(i["_filename"].to_s, ".*") + ".html" %>) (<%= i["date"] %>)
33
- <% end %>
30
+ <% end
34
31
 
35
- % end
32
+ end %>
@@ -7,6 +7,9 @@ outdir: ../Build
7
7
  # Template file path.
8
8
  # ./template.html by default.
9
9
  template: template.erb
10
+ # Configure the template engine/template format. The default is eruby, and liquid and mustache can be specified.
11
+ # This setting is only effective when using a document processor that defaults to eRuby. It does not function when using a document processor that employs a different dedicated template engine (e.g., Pandoc).
12
+ # template_format: eruby
10
13
  #
11
14
  # Loading CSS files (userd by Pandoc's default template.)
12
15
  # This values must be *server's URL*.
@@ -21,6 +24,13 @@ template: template.erb
21
24
  # Enable eRuby template expansion. true or false. false by default.
22
25
  # This settings is not avilable on rdoc, rdoc_markdown, kramdown, redcarpet or cmark engine.
23
26
  post_eruby: false
27
+ # Specify the eRuby processor library.
28
+ # The default is erb; erubis and erubi can be specified.
29
+ # Since these libraries are not fully compatible with each other, specifying one may change behavior or cause it to fail to function properly.
30
+ eruby_lib: erb
31
+ # Specifies the value for the `trim_mode` parameter passed to the ERB constructor. The default is `%<>`.
32
+ # Specifying this value may cause .erb files used by the theme to malfunction.
33
+ # erb_trim_mode: "%<>"
24
34
  # Default metadata. If same key exists in document's frontmatter, document's frontmatter is given priority to this settings.
25
35
  default_meta:
26
36
  author: "John Doe"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pbsimply
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.6.2
4
+ version: 3.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masaki Haruka
@@ -37,10 +37,12 @@ files:
37
37
  - lib/pbsimply/docengine/pandoc.rb
38
38
  - lib/pbsimply/docengine/rdoc.rb
39
39
  - lib/pbsimply/document.rb
40
+ - lib/pbsimply/eruby.rb
40
41
  - lib/pbsimply/frontmatter.rb
41
42
  - lib/pbsimply/hooks.rb
42
43
  - lib/pbsimply/plugger.rb
43
44
  - lib/pbsimply/prayer.rb
45
+ - lib/pbsimply/template-engine.rb
44
46
  - themes/contribute/README.md
45
47
  - themes/default.yaml
46
48
  - themes/pandoc/_pandoc_base/.accsindex.erb