pbsimply 2.0.0 → 3.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/bin/pbsimply +3 -0
- data/bin/pbsimply-testserver +1 -1
- data/lib/pbsimply/accs.rb +110 -0
- data/lib/pbsimply/docdb.rb +83 -0
- data/lib/pbsimply/docengine/base.rb +5 -0
- data/lib/pbsimply/docengine/docutils.rb +60 -0
- data/lib/pbsimply/docengine/misc.rb +84 -0
- data/lib/pbsimply/docengine/pandoc.rb +80 -0
- data/lib/pbsimply/docengine/rdoc.rb +62 -0
- data/lib/pbsimply/frontmatter.rb +204 -0
- data/lib/pbsimply/hooks.rb +85 -0
- data/lib/pbsimply/plugger.rb +77 -0
- data/lib/pbsimply/prayer.rb +107 -0
- data/lib/pbsimply.rb +155 -807
- metadata +15 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7687be75df33cb36e8e9f7f694d3bc9639ef6c90cd82a14f321188315dfa56f1
|
4
|
+
data.tar.gz: ff4499686dde84ac858f4f30ce25c1a2aee14167ab3ff9c2ede36f058dd1c5b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efa4bcaeb69f92002b2aec97058af9b7594a1b25022e12ed80a41c8d0b4f41b00117c9459f7179d74ca5d3f12357747ca479fb736a6e657089ca2bf4eaa2ba6f
|
7
|
+
data.tar.gz: b6ee58f40592e3e88c5009f0cbfe0f9556df9beff62b55dbe59aae8e03c2621f9e85558f2c45198276e27049d6a0783a1736d263231db04e768baa3f1982daff
|
data/bin/pbsimply
CHANGED
data/bin/pbsimply-testserver
CHANGED
@@ -9,7 +9,7 @@ File.open(".pbsimply.yaml") do |f|
|
|
9
9
|
end
|
10
10
|
|
11
11
|
srv = WEBrick::HTTPServer.new({ :DocumentRoot => @config["outdir"],
|
12
|
-
:BindAddress => '127.0.0.1',
|
12
|
+
:BindAddress => (@config["testserver_address"] || '127.0.0.1'),
|
13
13
|
:Port => (@config["testserver_port"] || 8000 )})
|
14
14
|
trap("INT"){ srv.shutdown }
|
15
15
|
srv.start
|
@@ -0,0 +1,110 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# ACCS namespace.
|
4
|
+
module PBSimply::ACCS
|
5
|
+
DEFINITIONS = {}
|
6
|
+
|
7
|
+
# Built-in Accs index eRuby string.
|
8
|
+
INDEX = <<'EOF'
|
9
|
+
<%= YAML.dump(
|
10
|
+
{
|
11
|
+
"title" => @index["title"],
|
12
|
+
"date" => @index["date"],
|
13
|
+
"author" => @index["author"]
|
14
|
+
}
|
15
|
+
) %>
|
16
|
+
---
|
17
|
+
|
18
|
+
<%
|
19
|
+
articles = Hash.new {|h,k| h[k] = Array.new }
|
20
|
+
|
21
|
+
if @config["accs_across_category"]
|
22
|
+
@indexes.each {|filename, index| articles["default"].push index }
|
23
|
+
else
|
24
|
+
@indexes.each {|filename, index| articles[(index["category"] || "default")].push index }
|
25
|
+
end
|
26
|
+
|
27
|
+
%>
|
28
|
+
|
29
|
+
% articles.keys.sort.each do |catname|
|
30
|
+
% cat = articles[catname]
|
31
|
+
|
32
|
+
% unless articles.length == 1
|
33
|
+
# <%= catname %>
|
34
|
+
% end
|
35
|
+
|
36
|
+
<%
|
37
|
+
sort_method = case @config["accs_sort_by"]
|
38
|
+
when "title"
|
39
|
+
lambda {|i| [i["title"].to_s, i["date"]] }
|
40
|
+
when "name"
|
41
|
+
lambda {|i| [i["_filename"].to_s, i["title"].to_s, i["date"]] }
|
42
|
+
when "serial"
|
43
|
+
lambda {|i| [i["serial"].to_s, i["date"], i["_filename"].to_s] }
|
44
|
+
else
|
45
|
+
lambda {|i| [i["date"], i["title"].to_s, i["_last_update"].to_i] }
|
46
|
+
end
|
47
|
+
|
48
|
+
list = if @config["accs_order"] == "desc"
|
49
|
+
cat.sort_by(&sort_method).reverse
|
50
|
+
else
|
51
|
+
cat.sort_by(&sort_method)
|
52
|
+
end
|
53
|
+
|
54
|
+
list.each do |i|
|
55
|
+
%>* [<%= i["title"] %>](<%= i["page_url"] %>)
|
56
|
+
<% end %>
|
57
|
+
|
58
|
+
% end
|
59
|
+
EOF
|
60
|
+
|
61
|
+
# letsaccs
|
62
|
+
#
|
63
|
+
# This method called on the assumption that processed all documents and run as directory mode.
|
64
|
+
def process_accs
|
65
|
+
STDERR.puts "Processing ACCS index..."
|
66
|
+
if File.exist?(File.join(@dir, ".accsindex.erb"))
|
67
|
+
erbtemplate = File.read(File.join(@dir, ".accsindex.erb"))
|
68
|
+
elsif File.exist?(".accsindex.erb")
|
69
|
+
erbtemplate = File.read(".accsindex.erb")
|
70
|
+
else
|
71
|
+
erbtemplate = INDEX
|
72
|
+
end
|
73
|
+
|
74
|
+
# Get infomation
|
75
|
+
@accs_index = Psych.unsafe_load(File.read([@dir, ".accs.yaml"].join("/")))
|
76
|
+
|
77
|
+
@accs_index["title"] ||= (@config["accs_index_title"] || "Index")
|
78
|
+
@accs_index["date"] ||= Time.now.strftime("%Y-%m-%d")
|
79
|
+
@accs_index["pagetype"] = "accs_index"
|
80
|
+
|
81
|
+
@index = @frontmatter.merge @accs_index
|
82
|
+
|
83
|
+
@hooks.accs.run({index: @index, indexes: @indexes})
|
84
|
+
|
85
|
+
doc = ERB.new(erbtemplate, trim_mode: "%<>").result(binding)
|
86
|
+
File.open(File.join(@dir, ".index.md"), "w") do |f|
|
87
|
+
f.write doc
|
88
|
+
end
|
89
|
+
|
90
|
+
accsmode
|
91
|
+
@dir = File.join(@dir, ".index.md")
|
92
|
+
main
|
93
|
+
end
|
94
|
+
|
95
|
+
# Turn on ACCS processing mode.
|
96
|
+
def accsmode
|
97
|
+
@accs_processing = true
|
98
|
+
@singlemode = true
|
99
|
+
@skip_index = true
|
100
|
+
end
|
101
|
+
|
102
|
+
# letsaccs in single page.
|
103
|
+
def single_accs filename, frontmatter
|
104
|
+
unless @skip_index
|
105
|
+
@indexes[filename] = frontmatter
|
106
|
+
@db.dump(@indexes)
|
107
|
+
end
|
108
|
+
process_accs
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
class PBSimply
|
5
|
+
class CustomYAML
|
6
|
+
def self.dump(*arg)
|
7
|
+
YAML.dump(*arg)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.load(*arg)
|
11
|
+
Psych.unsafe_load(*arg)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# Abstruct super class.
|
16
|
+
class DocDB
|
17
|
+
def dump(object)
|
18
|
+
File.open(File.join(@dir, ".indexes.#{@ext}"), "w") do |f|
|
19
|
+
f.write @store_class.dump(object)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def load
|
24
|
+
File.open(File.join(@dir, ".indexes.#{@ext}"), "r") do |f|
|
25
|
+
next @store_class.load(f)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def exist?
|
30
|
+
File.exist?(File.join(@dir, ".indexes.#{@ext}"))
|
31
|
+
end
|
32
|
+
|
33
|
+
def path
|
34
|
+
File.join(@dir, ".indexes.#{@ext}")
|
35
|
+
end
|
36
|
+
|
37
|
+
def cmp_obj(frontmatter)
|
38
|
+
@store_class.load(@store_class.dump(frontmatter))
|
39
|
+
end
|
40
|
+
|
41
|
+
# Use Ruby Marshal
|
42
|
+
class Marshal < DocDB
|
43
|
+
def initialize(dir)
|
44
|
+
@dir = dir
|
45
|
+
@store_class = ::Marshal
|
46
|
+
@ext = "rbm"
|
47
|
+
end
|
48
|
+
|
49
|
+
def cmp_obj(frontmatter)
|
50
|
+
frontmatter.dup
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Use JSON with bundled library
|
55
|
+
class JSON < DocDB
|
56
|
+
def initialize(dir)
|
57
|
+
require 'json'
|
58
|
+
@dir = dir
|
59
|
+
@store_class = ::JSON
|
60
|
+
@ext = "json"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# Use JSON with Oj gem
|
65
|
+
class Oj < DocDB::JSON
|
66
|
+
def initialize(dir)
|
67
|
+
require 'oj'
|
68
|
+
@dir = dir
|
69
|
+
@ext = "json"
|
70
|
+
@store_class = ::Oj
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# Use YAML
|
75
|
+
class YAML < DocDB
|
76
|
+
def initialize(dir)
|
77
|
+
@dir = dir
|
78
|
+
@store_class = CustomYAML
|
79
|
+
@ext = "yaml"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
class PBSimply
|
4
|
+
module Processor
|
5
|
+
# Docutils processor (rst2html5 command)
|
6
|
+
class Docutils < PBSimply
|
7
|
+
def initialize(config)
|
8
|
+
@docutils_cli_options = []
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
def setup_config(dir)
|
13
|
+
super
|
14
|
+
@docutils_cli_options.push("--template=#{@config["template"]}") if @config["template"]
|
15
|
+
|
16
|
+
if @config["css"]
|
17
|
+
if @config["css"].kind_of?(String)
|
18
|
+
@docutils_cli_options.push("--stylesheet=#{@config["css"]}")
|
19
|
+
elsif @config["css"].kind_of?(Array)
|
20
|
+
@docutils_cli_options.push("--stylesheet=#{@config["css"].join(",")}")
|
21
|
+
else
|
22
|
+
abort "css in Config should be a String or an Array."
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
if Array === @config["docutils_options"]
|
27
|
+
@docutils_cli_options.concat! @config["docutils_options"]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Invoke pandoc, parse and format and write out.
|
32
|
+
def print_fileproc_msg(filename)
|
33
|
+
STDERR.puts "#{filename} is going Docutils."
|
34
|
+
end
|
35
|
+
|
36
|
+
def process_document(dir, filename, frontmatter, orig_filepath, ext, procdoc)
|
37
|
+
doc = nil
|
38
|
+
|
39
|
+
# Go Docutils
|
40
|
+
cmdline = ["rst2html5"]
|
41
|
+
cmdline += @docutils_cli_options
|
42
|
+
cmdline += [ procdoc ]
|
43
|
+
IO.popen((cmdline)) do |io|
|
44
|
+
doc = io.read
|
45
|
+
end
|
46
|
+
|
47
|
+
# Abort if pandoc returns non-zero status
|
48
|
+
if $?.exitstatus != 0
|
49
|
+
abort "Docutils (rst2html5) returns exit code #{$?.exitstatus}"
|
50
|
+
end
|
51
|
+
|
52
|
+
doc
|
53
|
+
end
|
54
|
+
|
55
|
+
def target_file_extensions
|
56
|
+
[".rst"]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
class PBSimply
|
4
|
+
module Processor
|
5
|
+
# RedCarpet Processor
|
6
|
+
class PbsRedCarpet < PBSimply
|
7
|
+
def initialize(config)
|
8
|
+
require 'redcarpet'
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
def setup_config(dir)
|
13
|
+
super
|
14
|
+
@rc_extension = @config["redcarpet_extensions"] || {}
|
15
|
+
end
|
16
|
+
|
17
|
+
def print_fileproc_msg(filename)
|
18
|
+
STDERR.puts "#{filename} generate with Redcarpet Markdown"
|
19
|
+
end
|
20
|
+
|
21
|
+
def process_document(dir, filename, frontmatter, orig_filepath, ext, procdoc)
|
22
|
+
# Getting HTML string.
|
23
|
+
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, **@rc_extension)
|
24
|
+
article_body = markdown.render(File.read procdoc)
|
25
|
+
|
26
|
+
# Process with eRuby temaplte.
|
27
|
+
erb_template = ERB.new(File.read(@config["template"]), trim_mode: '%<>')
|
28
|
+
doc = erb_template.result(binding)
|
29
|
+
|
30
|
+
doc
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Kramdown Processor
|
35
|
+
class PbsKramdown < PBSimply
|
36
|
+
def initialize(config)
|
37
|
+
require 'kramdown'
|
38
|
+
super
|
39
|
+
end
|
40
|
+
|
41
|
+
def print_fileproc_msg(filename)
|
42
|
+
STDERR.puts "#{filename} generate with Kramdown"
|
43
|
+
end
|
44
|
+
|
45
|
+
def process_document(dir, filename, frontmatter, orig_filepath, ext, procdoc)
|
46
|
+
# Set feature options
|
47
|
+
features = @config["kramdown_features"] || {}
|
48
|
+
|
49
|
+
# Getting HTML string.
|
50
|
+
markdown = Kramdown::Document.new(File.read(procdoc), **features)
|
51
|
+
article_body = markdown.to_html
|
52
|
+
|
53
|
+
# Process with eRuby temaplte.
|
54
|
+
erb_template = ERB.new(File.read(@config["template"]), trim_mode: '%<>')
|
55
|
+
doc = erb_template.result(binding)
|
56
|
+
|
57
|
+
doc
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# CommonMark Processor
|
62
|
+
class PbsCommonMark < PBSimply
|
63
|
+
def initialize(config)
|
64
|
+
require 'commonmarker'
|
65
|
+
super
|
66
|
+
end
|
67
|
+
|
68
|
+
def print_fileproc_msg(filename)
|
69
|
+
STDERR.puts "#{filename} generate with CommonMarker (cmark-gfm)"
|
70
|
+
end
|
71
|
+
|
72
|
+
def process_document(dir, filename, frontmatter, orig_filepath, ext, procdoc)
|
73
|
+
# Getting HTML string.
|
74
|
+
article_body = CommonMarker.render_doc(File.read(procdoc), :DEFAULT, [:table, :strikethrough]).to_html
|
75
|
+
|
76
|
+
# Process with eRuby temaplte.
|
77
|
+
erb_template = ERB.new(File.read(@config["template"]), trim_mode: '%<>')
|
78
|
+
doc = erb_template.result(binding)
|
79
|
+
|
80
|
+
doc
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
###############################################
|
4
|
+
# DOCUMENT PROCESSORS #
|
5
|
+
###############################################
|
6
|
+
|
7
|
+
class PBSimply
|
8
|
+
module Processor
|
9
|
+
|
10
|
+
# Pandoc processor
|
11
|
+
class Pandoc < PBSimply
|
12
|
+
def initialize(config)
|
13
|
+
@pandoc_default_file = {}
|
14
|
+
|
15
|
+
# -d
|
16
|
+
@pandoc_default_file = {
|
17
|
+
"to" => "html5",
|
18
|
+
"standalone" => true
|
19
|
+
}
|
20
|
+
super
|
21
|
+
end
|
22
|
+
|
23
|
+
def setup_config(dir)
|
24
|
+
super
|
25
|
+
@pandoc_default_file["template"] = @config["template"]
|
26
|
+
|
27
|
+
if @config["css"]
|
28
|
+
if @config["css"].kind_of?(String)
|
29
|
+
@pandoc_default_file["css"] = [@config["css"]]
|
30
|
+
elsif @config["css"].kind_of?(Array)
|
31
|
+
@pandoc_default_file["css"] = @config["css"]
|
32
|
+
else
|
33
|
+
abort "css in Config should be a String or an Array."
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
if @config["toc"]
|
38
|
+
@pandoc_default_file["toc"] = true
|
39
|
+
end
|
40
|
+
|
41
|
+
if Hash === @config["pandoc_additional_options"]
|
42
|
+
@pandoc_default_file.merge! @config["pandoc_additional_options"]
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
# Invoke pandoc, parse and format and write out.
|
48
|
+
def print_fileproc_msg(filename)
|
49
|
+
STDERR.puts "#{filename} is going Pandoc."
|
50
|
+
end
|
51
|
+
|
52
|
+
def process_document(dir, filename, frontmatter, orig_filepath, ext, procdoc)
|
53
|
+
doc = nil
|
54
|
+
|
55
|
+
File.open(@workfile_pandoc_defaultfiles, "w") {|f| YAML.dump(@pandoc_default_file, f)}
|
56
|
+
File.open(@workfile_frontmatter, "w") {|f| YAML.dump(frontmatter, f)}
|
57
|
+
|
58
|
+
# Go Pandoc
|
59
|
+
pandoc_cmdline = ["pandoc"]
|
60
|
+
pandoc_cmdline += ["-d", @workfile_pandoc_defaultfiles, "--metadata-file", @workfile_frontmatter, "-M", "title:#{frontmatter["title"]}"]
|
61
|
+
pandoc_cmdline += ["-f", frontmatter["input_format"]] if frontmatter["input_format"]
|
62
|
+
pandoc_cmdline += [ procdoc ]
|
63
|
+
IO.popen((pandoc_cmdline)) do |io|
|
64
|
+
doc = io.read
|
65
|
+
end
|
66
|
+
|
67
|
+
# Abort if pandoc returns non-zero status
|
68
|
+
if $?.exitstatus != 0
|
69
|
+
abort "Pandoc returns exit code #{$?.exitstatus}"
|
70
|
+
end
|
71
|
+
|
72
|
+
doc
|
73
|
+
end
|
74
|
+
|
75
|
+
def target_file_extensions
|
76
|
+
[".md", ".rst"]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
class PBSimply
|
4
|
+
module Processor
|
5
|
+
# RDoc family Base
|
6
|
+
class PbsRBase < PBSimply
|
7
|
+
def initialize(config)
|
8
|
+
require 'rdoc'
|
9
|
+
require 'rdoc/markup/to_html'
|
10
|
+
|
11
|
+
@rdoc_options = RDoc::Options.new
|
12
|
+
@rdoc_markup = RDoc::Markup.new
|
13
|
+
|
14
|
+
super
|
15
|
+
end
|
16
|
+
|
17
|
+
def process_document(dir, filename, frontmatter, orig_filepath, ext, procdoc)
|
18
|
+
# Getting HTML string.
|
19
|
+
rdoc = RDoc::Markup::ToHtml.new(@rdoc_options, @rdoc_markup)
|
20
|
+
article_body = rdoc.convert(get_markup_document(procdoc))
|
21
|
+
|
22
|
+
# Process with eRuby temaplte.
|
23
|
+
erb_template = ERB.new(File.read(@config["template"]), trim_mode: '%<>')
|
24
|
+
doc = erb_template.result(binding)
|
25
|
+
|
26
|
+
doc
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# RDoc/Markdown processor
|
31
|
+
class PbsRMakrdown < PbsRBase
|
32
|
+
def initialize(config)
|
33
|
+
require 'rdoc'
|
34
|
+
require 'rdoc/markdown'
|
35
|
+
super
|
36
|
+
end
|
37
|
+
|
38
|
+
def print_fileproc_msg(filename)
|
39
|
+
STDERR.puts "#{filename} generate with RDoc/Markdown"
|
40
|
+
end
|
41
|
+
|
42
|
+
def get_markup_document procdoc
|
43
|
+
RDoc::Markdown.parse(File.read procdoc)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# RDoc processor
|
48
|
+
class PbsRDoc < PbsRBase
|
49
|
+
def print_fileproc_msg(filename)
|
50
|
+
STDERR.puts "#{filename} generate with RDoc"
|
51
|
+
end
|
52
|
+
|
53
|
+
def get_markup_document procdoc
|
54
|
+
File.read procdoc
|
55
|
+
end
|
56
|
+
|
57
|
+
def target_file_extensions
|
58
|
+
[".rdoc"]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|