pbsimply 3.5.1 → 3.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e6667388a878546c3fb8b5c5880661c66012a3ad65f4ce834fba8da89d470dc
4
- data.tar.gz: 14b13fbe88d551bffb92d5a2c61f8e6a1378a437baa2a805a170e152314f37c5
3
+ metadata.gz: 3a417c6d496dfde4f431192332a64cab522fe757da468ea06a4b6a4e7b954e83
4
+ data.tar.gz: 2d07b51d00a2e4ac75b9c990cd4555b9af4d98a5e489c1126b688edd405024d3
5
5
  SHA512:
6
- metadata.gz: d650ffb297c0bd3ce21e05fc0edbb8d67f01c24af295b4a2ca387ccfacecefd81649469e7ddd1600958ed0943ba2f4bf46839fb6fbd0ed0c5d7e4c8efeede449
7
- data.tar.gz: 5d35227c8476719684bc8c0abf04bf49ba4c34cbf065b487230750aeea5a1d0582b187299603ccdaf93d0047017b8a9b276bd6d8a49fa04c17ad577d173da1db
6
+ metadata.gz: 1e02c628a504036bb28d7350a70de24cc6c7faf0080d365f805ef1dae20bbbb32a2fbfda9827f8ac0c11a594578e53b21695627e2708be7c33019257998bdd72
7
+ data.tar.gz: 54cabd5b56b889be92c4e3a2d9a8d201874bb044688130b14682099f45b227ad7a4356d9d1322cea48d516de36a210bdfe205314dd450e70570e654fca5220fb
data/bin/pbsimply CHANGED
@@ -2,35 +2,37 @@
2
2
 
3
3
  require 'pbsimply'
4
4
 
5
- PBSimply.find_docroot
6
- config = PBSimply.load_config
5
+ begin
6
+ PBSimply.find_docroot
7
+ config = PBSimply.load_config
7
8
 
8
- pbs_class = case config["pbsimply_processor"]
9
- when "docutils"
10
- PBSimply::Processor::Docutils
11
- when "redcarpet"
12
- PBSimply::Processor::PbsRedCarpet
13
- when "kramdown"
14
- PBSimply::Processor::PbsKramdown
15
- when "cmark"
16
- PBSimply::Processor::PbsCommonMark
17
- when "rdoc_markdown"
18
- PBSimply::Processor::PbsRMakrdown
19
- when "rdoc"
20
- PBSimply::Processor::PbsRDoc
21
- else
22
- PBSimply::Processor::Pandoc
23
- end
9
+ pbs_class = case config["pbsimply_processor"]
10
+ when "docutils"
11
+ PBSimply::Processor::Docutils
12
+ when "redcarpet"
13
+ PBSimply::Processor::PbsRedCarpet
14
+ when "kramdown"
15
+ PBSimply::Processor::PbsKramdown
16
+ when "cmark"
17
+ PBSimply::Processor::PbsCommonMark
18
+ when "rdoc_markdown"
19
+ PBSimply::Processor::PbsRMakrdown
20
+ when "rdoc"
21
+ PBSimply::Processor::PbsRDoc
22
+ else
23
+ PBSimply::Processor::Pandoc
24
+ end
24
25
 
25
- # Alias for compatibility.
26
- PureBuilder = pbs_class
26
+ # Alias for compatibility.
27
+ PureBuilder = pbs_class
27
28
 
28
- begin
29
29
  pbs = pbs_class.new(config)
30
30
  pbs.treat_cmdline
31
31
 
32
32
  pbs.main
33
- rescue PBSimply::CommandLineError => e
34
- $stderr.puts e.to_s
35
- exit 1
33
+ rescue PBSimply::PBSimplyError => e
34
+ if PBSimply::ConfigChecker::InvalidConfigError === e.original_error
35
+ $stderr.puts e.original_error
36
+ end
37
+ abort e.to_s
36
38
  end
data/bin/pbsimply-init CHANGED
@@ -2,8 +2,28 @@
2
2
  require 'yaml'
3
3
  require 'fileutils'
4
4
  require 'optparse'
5
+ require 'erb'
5
6
 
6
7
  class PBSimplyInit
8
+ class ConfigErb
9
+ def initialize theme_dir, source_dir, build_dir
10
+ @theme_dir = theme_dir
11
+ @source_dir = source_dir
12
+ @build_dir = build_dir
13
+
14
+ @erb = ERB.new(File.read(File.join(@source_dir, ".pbsimply.yaml.erb")), trim_mode: "%")
15
+ end
16
+
17
+ attr_writer :processor
18
+
19
+ def generate
20
+ generated_config = @erb.result(binding)
21
+ File.open(File.join(@source_dir, ".pbsimply.yaml"), "w") do |f|
22
+ f.puts generated_config
23
+ end
24
+ File.delete(File.join(@source_dir, ".pbsimply.yaml.erb"))
25
+ end
26
+ end
7
27
  def initialize
8
28
  set_gemroot
9
29
  load_default_theme
@@ -33,6 +53,8 @@ class PBSimplyInit
33
53
  list_theme
34
54
  exit true
35
55
  end
56
+
57
+ @config_erb_params = {}
36
58
  end
37
59
 
38
60
  def list_theme
@@ -43,8 +65,19 @@ class PBSimplyInit
43
65
  themes[theme_name] ||= YAML.load File.read i
44
66
  end
45
67
  end
46
- themes.each do |k, v|
47
- puts [k, v["name"], v["description"]].join(" ")
68
+
69
+ # Expand rbmdlib -> [kramdown, redcarpet, cmark]
70
+ rbmdlib = themes.keys.select {|i| i =~ %r:^rbmdlib/: }
71
+ rbmdlib.each do |k|
72
+ themes[k.sub(%r:^rbmdlib/:, "kramdown/")] = themes[k]
73
+ themes[k.sub(%r:^rbmdlib/:, "redcarpet/")] = themes[k]
74
+ themes[k.sub(%r:^rbmdlib/:, "cmark/")] = themes[k]
75
+ themes.delete k
76
+ end
77
+
78
+ sorted_keys = themes.keys.sort
79
+ sorted_keys.each do |k|
80
+ puts [k, themes[k]["name"], themes[k]["description"]].join(" ")
48
81
  end
49
82
  end
50
83
 
@@ -82,6 +115,20 @@ class PBSimplyInit
82
115
  else
83
116
  @theme = @default_theme
84
117
  end
118
+
119
+ @config_erb_params[:processor] = @theme[0]
120
+
121
+ if %w:kramdown redcarpet cmark:.include? @theme[0]
122
+ unified_theme = @theme.clone
123
+ unified_theme[0] = "rbmdlib"
124
+ theme_path = search_theme unified_theme
125
+ if theme_path
126
+ @config_erb_params[:theme_dir] = theme_path
127
+ @theme = unified_theme
128
+ return load_theme_yaml theme_path
129
+ end
130
+ end
131
+
85
132
  theme_path = search_theme @theme
86
133
  load_theme_yaml theme_path
87
134
  end
@@ -134,6 +181,13 @@ class PBSimplyInit
134
181
  FileUtils.cp_r(File.join(@source_dir, *i), @build_dir)
135
182
  end
136
183
  end
184
+
185
+ if @theme_yaml["config_erb"]
186
+ $stderr.puts "Building .pbsimply.yaml..."
187
+ erb = ConfigErb.new(@config_erb_params[:theme_dir], @source_dir, @build_dir)
188
+ erb.processor = @config_erb_params[:processor]
189
+ erb.generate
190
+ end
137
191
  end
138
192
 
139
193
  $stderr.puts "Done"
@@ -2,9 +2,6 @@
2
2
 
3
3
  class PBSimply
4
4
  class ConfigChecker
5
- class InvalidConfigError < StandardError
6
- end
7
-
8
5
  def self.verify_config config
9
6
  # blessmethod_accs_rel
10
7
  if config["blessmethod_accs_rel"] && ! %w:numbering date timestamp lexical:.include?(config["blessmethod_accs_rel"])
@@ -19,7 +19,7 @@ class PBSimply
19
19
  elsif @config["css"].kind_of?(Array)
20
20
  @docutils_cli_options.push("--stylesheet=#{@config["css"].join(",")}")
21
21
  else
22
- abort "css in Config should be a String or an Array."
22
+ raise PBLoadError.new "css in Config should be a String or an Array."
23
23
  end
24
24
  end
25
25
 
@@ -44,9 +44,9 @@ class PBSimply
44
44
  doc = io.read
45
45
  end
46
46
 
47
- # Abort if pandoc returns non-zero status
47
+ # Abort if docutils returns non-zero status
48
48
  if $?.exitstatus != 0
49
- abort "Docutils (rst2html5) returns exit code #{$?.exitstatus}"
49
+ raise ProcessorError.new "Docutils (rst2html5) returns exit code #{$?.exitstatus}"
50
50
  end
51
51
 
52
52
  doc
@@ -66,14 +66,14 @@ class PBSimply
66
66
  end
67
67
 
68
68
  def print_fileproc_msg(filename)
69
- $stderr.puts "#{filename} generate with CommonMarker (cmark-gfm)"
69
+ $stderr.puts "#{filename} generate with Commonmarker (cmark-gfm)"
70
70
  end
71
71
 
72
72
  def process_document(dir, filename, frontmatter, orig_filepath, ext, procdoc)
73
- options = @config["commonmarker_options"]&.map(&:to_sym) || [:table, :strikethrough]
73
+ options = @config["commonmarker_options"] ? @config["commonmarker_options"].transform_keys(&:to_sym) : {}
74
74
 
75
75
  # Getting HTML string.
76
- article_body = CommonMarker.render_doc(File.read(procdoc), :DEFAULT, options).to_html
76
+ article_body = Commonmarker.parse(File.read(procdoc), options: options).to_html
77
77
 
78
78
  # Process with eRuby temaplte.
79
79
  erb_template = ERB.new(File.read(@config["template"]), trim_mode: '%<>')
@@ -37,7 +37,7 @@ class PBSimply
37
37
  elsif @config["css"].kind_of?(Array)
38
38
  @pandoc_default_file["css"] = @config["css"]
39
39
  else
40
- abort "css in Config should be a String or an Array."
40
+ raise PBLoadError.new "css in Config should be a String or an Array."
41
41
  end
42
42
  end
43
43
 
@@ -71,14 +71,14 @@ class PBSimply
71
71
  pandoc_cmdline += ["-f", @pandoc_input_extmap[File.extname filename]]
72
72
  end
73
73
  pandoc_cmdline += [ procdoc ]
74
- pp pandoc_cmdline if @debug
74
+ pp pandoc_cmdline if $debug
75
75
  IO.popen((pandoc_cmdline)) do |io|
76
76
  doc = io.read
77
77
  end
78
78
 
79
79
  # Abort if pandoc returns non-zero status
80
80
  if $?.exitstatus != 0
81
- abort "Pandoc returns exit code #{$?.exitstatus}"
81
+ raise ProcessorError.new "Pandoc returns exit code #{$?.exitstatus}"
82
82
  end
83
83
 
84
84
  doc
@@ -131,8 +131,8 @@ module PBSimply::Frontmatter
131
131
  end
132
132
  end
133
133
 
134
- abort "This document has no frontmatter" unless frontmatter
135
- abort "This document has no title." unless frontmatter["title"]
134
+ raise PBSimply::DocumentError.new("This document has no frontmatter") unless frontmatter
135
+ raise PBSimply::DocumentError.new("This document has no title.") unless frontmatter["title"]
136
136
 
137
137
  outpath = case
138
138
  when @outfile
@@ -50,11 +50,11 @@ module PBSimply::Prayer
50
50
  File.open(@workfile_frontmatter, "w") {|f| f.write PBSimply::JSON_LIB.dump(frontmatter) }
51
51
  # BLESSING (Always)
52
52
  if @config["bless_cmd"]
53
- (Array === @config["bless_cmd"] ? system(*@config["bless_cmd"]) : system(@config["bless_cmd"]) ) or abort "*** BLESS COMMAND RETURNS NON-ZERO STATUS"
53
+ (Array === @config["bless_cmd"] ? system(*@config["bless_cmd"]) : system(@config["bless_cmd"]) ) or raise BlessError.new "*** BLESS COMMAND RETURNS NON-ZERO STATUS"
54
54
  end
55
55
  # BLESSING (ACCS)
56
56
  if @config["bless_accscmd"]
57
- (Array === @config["bless_accscmd"] ? system({"pbsimply_workdir" => @workdir, "pbsimply_frontmatter" => @workfile_frontmatter, "pbsimply_indexes" => @db.path}, *@config["bless_accscmd"]) : system({"pbsimply_workdir" => @workdir, "pbsimply_frontmatter" => @workfile_frontmatter, "pbsimply_indexes" => @db.path}, @config["bless_accscmd"]) ) or abort "*** BLESS COMMAND RETURNS NON-ZERO STATUS"
57
+ (Array === @config["bless_accscmd"] ? system({"pbsimply_workdir" => @workdir, "pbsimply_frontmatter" => @workfile_frontmatter, "pbsimply_indexes" => @db.path}, *@config["bless_accscmd"]) : system({"pbsimply_workdir" => @workdir, "pbsimply_frontmatter" => @workfile_frontmatter, "pbsimply_indexes" => @db.path}, @config["bless_accscmd"]) ) or raise BlessError.new "*** BLESS COMMAND RETURNS NON-ZERO STATUS"
58
58
  end
59
59
  mod_frontmatter = JSON.load(File.read(@workfile_frontmatter))
60
60
  frontmatter.replace(mod_frontmatter)
@@ -77,14 +77,14 @@ module PBSimply::Prayer
77
77
  when "date"
78
78
  begin
79
79
  @article_order = @indexes.to_a.sort_by {|i| i[1]["date"]}
80
- rescue
81
- abort "*** Automatic Blessing Method Error: Maybe some article has no date."
80
+ rescue => e
81
+ raise BlessError.new("*** Automatic Blessing Method Error: Maybe some article has no date.", e)
82
82
  end
83
83
  when "timestamp"
84
84
  begin
85
85
  @article_order = @indexes.to_a.sort_by {|i| i[1]["timestamp"]}
86
- rescue
87
- abort "*** Automatic Blessing Method Error: Maybe some article has no timetsamp."
86
+ rescue => e
87
+ raise BlessError.new("*** Automatic Blessing Method Error: Maybe some article has no timetsamp.", e)
88
88
  end
89
89
  when "lexical"
90
90
  @article_order = @indexes.to_a.sort_by {|i| i[1]["_filename"]}
data/lib/pbsimply.rb CHANGED
@@ -26,7 +26,37 @@ class PBSimply
26
26
  include ACCS
27
27
 
28
28
  # Custom exception
29
- class CommandLineError < StandardError
29
+ class PBSimplyError < StandardError
30
+ def initialize(*arg)
31
+ @original_error = nil
32
+ if arg.size == 2
33
+ @original_error = arg.pop
34
+ print_error(@original_error)
35
+ end
36
+
37
+ super(*arg)
38
+ end
39
+
40
+ attr_reader :original_error
41
+
42
+ private
43
+ def print_error(e)
44
+ $stderr.puts e.full_message if $debug && e
45
+ end
46
+ end
47
+ class CommandLineError < PBSimplyError
48
+ end
49
+ class BlessError < PBSimplyError
50
+ end
51
+ class PBLoadError < PBSimplyError
52
+ end
53
+ class DocumentError < PBSimplyError
54
+ end
55
+ class ProcessorError < PBSimplyError
56
+ end
57
+ class ConfigChecker
58
+ class InvalidConfigError < PBSimplyError
59
+ end
30
60
  end
31
61
 
32
62
  # Use Oj as JSON library for frontmatter passing if possible.
@@ -47,7 +77,7 @@ class PBSimply
47
77
  until File.exist?(".pbsimply.yaml")
48
78
  Dir.chdir ".."
49
79
  if lastwd == Dir.pwd
50
- abort "PureBuilder Simply document root not found."
80
+ raise PBLoadError.new "PureBuilder Simply document root not found."
51
81
  end
52
82
  lastwd = Dir.pwd
53
83
  end
@@ -61,14 +91,12 @@ class PBSimply
61
91
  config = Psych.unsafe_load(f)
62
92
  end
63
93
  ConfigChecker.verify_config config
64
- rescue PBSimply::ConfigChecker::InvalidConfigError
65
- abort $!.to_s
66
- rescue
67
- abort "Failed to load config file (./.pbsimply.yaml)"
94
+ rescue => e
95
+ raise PBLoadError.new "Failed to load config file (./.pbsimply.yaml)", e
68
96
  end
69
97
 
70
98
  # Required values
71
- config["outdir"] or abort "Output directory is not set (outdir)."
99
+ config["outdir"] or raise PBLoadError.new "Output directory is not set (outdir)."
72
100
  config["template"] ||= "./template.html"
73
101
 
74
102
  config
@@ -133,7 +161,7 @@ class PBSimply
133
161
  @frontmatter = {}
134
162
  @accs_processing = false
135
163
 
136
- @debug = (ENV["DEBUG"] == "yes")
164
+ $debug = (ENV["DEBUG"] == "yes")
137
165
  end
138
166
 
139
167
  attr_reader :config, :dir, :frontmatter, :now, :accs_processing, :outfile
@@ -150,6 +178,7 @@ class PBSimply
150
178
  opts.on("-o FILE", "--output") {|v| @outfile = v }
151
179
  opts.on("-m FILE", "--additional-metafile") {|v| @add_meta = Psych.unsafe_load(File.read(v))}
152
180
  opts.on("-a", "--only-accs") { @accs_only = true }
181
+ opts.on("--debug") { $debug = true }
153
182
  opts.parse!(ARGV)
154
183
 
155
184
  if File.exist?(".pbsimply-bless.rb")
@@ -199,6 +228,7 @@ class PBSimply
199
228
  $stderr.puts "Checking Frontmatter..."
200
229
  Dir.foreach(@dir) do |filename|
201
230
  next if filename == "." || filename == ".." || filename == ".index.md"
231
+ next unless File.file? File.join(@dir, filename)
202
232
  if filename =~ /^\./ || filename =~ /^draft-/
203
233
  draft_articles.push({
204
234
  article_filename: filename.sub(/^(?:\.|draft-)/, ""),
@@ -106,12 +106,12 @@ pandoc_additional_options:
106
106
  #redcarpet_extensions: {}
107
107
  #
108
108
  #################################################
109
- # CommonMarker engine option
109
+ # Commonmarker engine option
110
110
  #################################################
111
111
  #pbsimply_processor: cmark
112
112
  #
113
- # An array showing `CommonMarker.render_doc`'s 3rd agrument.
114
- #commonmarker_options: []
113
+ # An Hash showing `Commonmarker.prase`'s `options` argument.
114
+ #commonmarker_options: {}
115
115
  #
116
116
  #################################################
117
117
  # Docutils engine option
@@ -103,12 +103,12 @@ pandoc_additional_options:
103
103
  #redcarpet_extensions: {}
104
104
  #
105
105
  #################################################
106
- # CommonMarker engine option
106
+ # Commonmarker engine option
107
107
  #################################################
108
108
  #pbsimply_processor: cmark
109
109
  #
110
- # An array showing `CommonMarker.render_doc`'s 3rd agrument.
111
- #commonmarker_options: []
110
+ # An Hash showing `Commonmarker.prase`'s `options` argument.
111
+ #commonmarker_options: {}
112
112
  #
113
113
  #################################################
114
114
  # Docutils engine option
@@ -88,24 +88,36 @@ self_url_external_prefix: https://example.com/
88
88
  #################################################
89
89
  # Kramdown engine option
90
90
  #################################################
91
+ % if @processor == "kramdown"
91
92
  pbsimply_processor: kramdown
93
+ % else
94
+ #pbsimply_processor: kramdown
95
+ % end
92
96
  # An associative array passed as the second argument to `Kramdown::Document.new`. See the https://kramdown.gettalong.org/rdoc/Kramdown/Options.html for detail.
93
97
  #kramdown_features: {}
94
98
  #
95
99
  #################################################
96
100
  # RedCarpet engine option
97
101
  #################################################
102
+ % if @processor == "redcarpet"
103
+ pbsimply_processor: redcarpet
104
+ % else
98
105
  #pbsimply_processor: redcarpet
106
+ % end
99
107
  # An associative array showing the extensions to Redcarpet. See the https://github.com/vmg/redcarpet for details.
100
108
  #redcarpet_extensions: {}
101
109
  #
102
110
  #################################################
103
- # CommonMarker engine option
111
+ # Commonmarker engine option
104
112
  #################################################
113
+ % if @processor == "cmark"
114
+ pbsimply_processor: cmark
115
+ % else
105
116
  #pbsimply_processor: cmark
117
+ % end
106
118
  #
107
- # An array showing `CommonMarker.render_doc`'s 3rd agrument.
108
- #commonmarker_options: []
119
+ # An Hash showing `Commonmarker.prase`'s `options` argument.
120
+ #commonmarker_options: {}
109
121
  #
110
122
  #################################################
111
123
  # Docutils engine option
@@ -2,4 +2,5 @@ name: Init_3.2.2
2
2
  description: Theme used in PureBuilder Simply 3.2.2's pbsimply-init.
3
3
  initial_control:
4
4
  build_cpr:
5
- - [css]
5
+ - [css]
6
+ config_erb: true
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.5.1
4
+ version: 3.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masaki Haruka
@@ -11,7 +11,7 @@ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: A flexible, programmable static site generator for Markdown, reStructuredText,
13
13
  and RDoc formats. PureBuilder Simply supports both embedded and external content
14
- processors—including Kramdown, Redcarpet, CommonMarker, RDoc, Pandoc, Docutils—and
14
+ processors—including Kramdown, Redcarpet, Commonmarker, RDoc, Pandoc, Docutils—and
15
15
  enables customizable conversion workflows and CLI-based project generation.
16
16
  email:
17
17
  - yek@reasonset.net
@@ -43,15 +43,6 @@ files:
43
43
  - lib/pbsimply/prayer.rb
44
44
  - themes/contribute/README.md
45
45
  - themes/default.yaml
46
- - themes/kramdown/init322/.accsindex.erb
47
- - themes/kramdown/init322/.pbsimply.yaml
48
- - themes/kramdown/init322/.theme.yaml
49
- - themes/kramdown/init322/articles/.accs.yaml
50
- - themes/kramdown/init322/articles/20231028-untitled.md
51
- - themes/kramdown/init322/css/style.css
52
- - themes/kramdown/init322/index.md
53
- - themes/kramdown/init322/menu.yaml
54
- - themes/kramdown/init322/template.erb
55
46
  - themes/pandoc/_pandoc_base/.accsindex.erb
56
47
  - themes/pandoc/_pandoc_base/.pbsimply.yaml
57
48
  - themes/pandoc/_pandoc_base/css/base.css
@@ -86,6 +77,15 @@ files:
86
77
  - themes/pandoc/practical/css/layout.css
87
78
  - themes/pandoc/warm/.theme.yaml
88
79
  - themes/pandoc/warm/css/base.css
80
+ - themes/rbmdlib/init322/.accsindex.erb
81
+ - themes/rbmdlib/init322/.pbsimply.yaml.erb
82
+ - themes/rbmdlib/init322/.theme.yaml
83
+ - themes/rbmdlib/init322/articles/.accs.yaml
84
+ - themes/rbmdlib/init322/articles/20231028-untitled.md
85
+ - themes/rbmdlib/init322/css/style.css
86
+ - themes/rbmdlib/init322/index.md
87
+ - themes/rbmdlib/init322/menu.yaml
88
+ - themes/rbmdlib/init322/template.erb
89
89
  homepage: https://purebuilder.app/
90
90
  licenses:
91
91
  - Apache-2.0
File without changes
File without changes
File without changes
File without changes