giblish 2.1.1 → 2.2.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/Changelog.adoc +10 -2
- data/README.adoc +43 -23
- data/lib/giblish/cmdline.rb +6 -2
- data/lib/giblish/config_utils.rb +3 -0
- data/lib/giblish/configurator.rb +67 -26
- data/lib/giblish/gitrepos/gitsummaryprovider.rb +0 -2
- data/lib/giblish/gitrepos/history_pb.rb +0 -1
- data/lib/giblish/indexbuilders/{standard_index.erb → idx_template.erb} +1 -1
- data/lib/giblish/indexbuilders/subtree_indices.rb +23 -11
- data/lib/giblish/resourcepaths.rb +86 -28
- data/lib/giblish/subtreeinfobuilder.rb +20 -8
- data/lib/giblish/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 695c1b3dfb96c74e96d97663179345ab09f875bfb0839ea1816b6599d61d4721
|
4
|
+
data.tar.gz: 15d5cac96d3d8fbcdcc418a9e62385bec617699139203d8c94ccc1080f90b3f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb87d5182932e143e3a98330d70b730dcc110849c9ce8d6bdf18509ca87eb9751407660b58b352464ae803e2a08aa1264279aec440226fbc026a8acc932d29f9
|
7
|
+
data.tar.gz: d8ff66b28ed0c6e4987ca56795abf20061af0ed50d08c9e7ff01fc45f0712f5762bacb94153868c0d2f0fe66a02977f30f76f5ddfb0b6cecd93085fce3118334
|
data/Changelog.adoc
CHANGED
@@ -3,11 +3,19 @@
|
|
3
3
|
|
4
4
|
== Some of the things Not yet in place
|
5
5
|
|
6
|
-
* Investigate how to remove tmp/cache files and dirs during graph generation
|
7
6
|
* Update docs for giblish.
|
8
7
|
** write instructions for github webhook triggered generation
|
9
8
|
* Update the default css for giblish html generation.
|
10
|
-
|
9
|
+
|
10
|
+
== v2.2.0
|
11
|
+
|
12
|
+
* enable customization of the index pages using erb templates
|
13
|
+
|
14
|
+
== v2.1.2
|
15
|
+
|
16
|
+
* enable asciidoc-mathematical (if it is accessible on the system) when rendering pdfs
|
17
|
+
** force the output format for equations to svg
|
18
|
+
** remove stem-...svg files created by asciidoctor-mathematical
|
11
19
|
|
12
20
|
== v2.1.0
|
13
21
|
|
data/README.adoc
CHANGED
@@ -9,6 +9,15 @@ image::https://github.com/rillbert/giblish/actions/workflows/unit_tests.yml/badg
|
|
9
9
|
|
10
10
|
giblish converts a source directory tree containing AsciiDoc files to a destination directory tree containing the corresponding html or pdf files. It adds some handy tools for easier navigation of the resulting destination tree.
|
11
11
|
|
12
|
+
.Two-liner conversion
|
13
|
+
[source, bash]
|
14
|
+
----
|
15
|
+
# install giblish (requires a working ruby installation on the system)
|
16
|
+
gem install giblish
|
17
|
+
# convert all adoc files recursively under 'my/src' and place them (recursively) under "the/dest"
|
18
|
+
$ giblish my/src the/dest
|
19
|
+
----
|
20
|
+
|
12
21
|
== Examples
|
13
22
|
|
14
23
|
IMPORTANT: The examples below are *not* the official documentation for the corresponding projects.
|
@@ -35,13 +44,14 @@ IMPORTANT: The examples below are *not* the official documentation for the corre
|
|
35
44
|
|
36
45
|
The features of giblish include:
|
37
46
|
|
38
|
-
*
|
39
|
-
*
|
40
|
-
*
|
47
|
+
* Simple conversion of whole document trees into both html and pdf.
|
48
|
+
* Customizable index pages that list all rendered documents with clickable links.
|
49
|
+
* Generate separate destination trees per branch in a git repo in one go (see examples below).
|
50
|
+
* Document ids - a (non-standard) way of referencing other documents in the same tree, you can use document ids to:
|
41
51
|
** Reference one doc in the source tree from another doc without depending on file names or relative paths. The referenced doc can thus be moved within the source tree or change its file name and the reference will still be valid.
|
42
52
|
** Validate doc id references during document rendering and thus be alerted to any invalid doc id references.
|
43
53
|
** Let giblish generate a clickable graph of all document references (requires graphviz and the 'dot' tool).
|
44
|
-
*
|
54
|
+
* Text-search - a stripped-down, but nonetheless useful, text-search of your html documents. This requires that you publish your docs to a web-server and setup an application on that same web-server. `giblish` provides most of the scaffolding though.
|
45
55
|
|
46
56
|
== Dependencies and credits
|
47
57
|
|
@@ -63,24 +73,6 @@ When using giblish for generating docs the following applies:
|
|
63
73
|
* giblish requires that the git working tree and index of the repo containing source documents are clean when generating documentation.
|
64
74
|
* giblish will make explicit check-outs of all the branches or tags that matches the selection criteria. The working dir of the source git repo will thus have the last branch that giblish checked-out as the current branch after doc generation.
|
65
75
|
|
66
|
-
== Contributing
|
67
|
-
|
68
|
-
If you want to contribute to giblish, great :) Use the standard GitHub flow of forking the repo and submit a pull request.
|
69
|
-
|
70
|
-
Pull requests must meet the following to be considered for merging:
|
71
|
-
|
72
|
-
* Tests have been added for new or updated functionality
|
73
|
-
* The code has been linted using the `standardrb` tool.
|
74
|
-
** The version of standardrb shall be the same as the one used in the target branch for the PR.
|
75
|
-
|
76
|
-
To develop on giblish, you:
|
77
|
-
|
78
|
-
. Install ruby on your local machine (rbenv is a good choice for handling ruby installations)
|
79
|
-
. Install necessary dependencies to install the ruby 'mathematica' gem, see eg https://github.com/gjtorikian/mathematical/blob/47041d5492cc7c5f04105031430fb44119406f49/script/install_linux_deps
|
80
|
-
. Install graphviz
|
81
|
-
. Clone or fork the repository
|
82
|
-
. Run the `bin/setup` script from a bash prompt
|
83
|
-
|
84
76
|
== Document ids and the reference graph
|
85
77
|
|
86
78
|
NOTE: This is a non-standard extension of asciidoc. If you use this feature, you will need to generate your documents using giblish to make this work as intended.
|
@@ -139,7 +131,7 @@ The above reference will work even if either document changes location or file n
|
|
139
131
|
[[usage_examples]]
|
140
132
|
== Usage Examples
|
141
133
|
|
142
|
-
|
134
|
+
A number of use cases for giblish in increasing order of complexity.
|
143
135
|
|
144
136
|
=== Get available options
|
145
137
|
|
@@ -163,6 +155,16 @@ The default asciidoctor css will be used in the html conversion.
|
|
163
155
|
|
164
156
|
The default asciidoctor pdf theme will be used in the pdf conversion.
|
165
157
|
|
158
|
+
=== Customize the index pages generated by giblish
|
159
|
+
|
160
|
+
Add a file `idx_template.erb` under a directory of your choice, in this example `style_resources` is used. An example of the available customization options is https://github.com/rillbert/giblish/blob/personal/rillbert/data/resources/erb/idx_template.erb[this file] from the giblish test data set.
|
161
|
+
|
162
|
+
Invoke `giblish` with the resource directory set using the `-r` flag.
|
163
|
+
|
164
|
+
giblish -r style_resource my_src_root my_dst_root
|
165
|
+
|
166
|
+
Your erb template is used to generate the index page(es).
|
167
|
+
|
166
168
|
=== Using a custom css for the generated html
|
167
169
|
|
168
170
|
Generate html that can be browsed locally from file:://<my_dst_root>.
|
@@ -192,6 +194,24 @@ Generate html that can be browsed locally from file:://<my_dst_root>.
|
|
192
194
|
** generate an index page named `index.html` that contains links and some info about the converted files. The file is placed in the `my_dst_root/<branch_name` dir.
|
193
195
|
* generate a summary page containing links to a all branches and place it in the `my_dst_root` dir.
|
194
196
|
|
197
|
+
== Contributing
|
198
|
+
|
199
|
+
If you want to contribute to giblish, great :) Use the standard GitHub flow of forking the repo and submit a pull request.
|
200
|
+
|
201
|
+
Pull requests must meet the following to be considered for merging:
|
202
|
+
|
203
|
+
* Tests have been added for new or updated functionality
|
204
|
+
* The code has been linted using the `standardrb` tool.
|
205
|
+
** The version of standardrb shall be the same as the one used in the target branch for the PR.
|
206
|
+
|
207
|
+
To develop on giblish, you:
|
208
|
+
|
209
|
+
. Install ruby on your local machine (rbenv is a good choice for handling ruby installations)
|
210
|
+
. Install necessary dependencies to install the ruby 'mathematica' gem, see eg https://github.com/gjtorikian/mathematical/blob/47041d5492cc7c5f04105031430fb44119406f49/script/install_linux_deps
|
211
|
+
. Install graphviz
|
212
|
+
. Clone or fork the repository
|
213
|
+
. Run the `bin/setup` script from a bash prompt
|
214
|
+
|
195
215
|
// === Publish the asciidoctor.org documents with text search
|
196
216
|
|
197
217
|
// giblish can be used to generate html docs suitable for serving via a web server (e.g. Apache). You can use the cgi script included in the giblish gem to provide text search capabilities.
|
data/lib/giblish/cmdline.rb
CHANGED
@@ -276,10 +276,14 @@ module Giblish
|
|
276
276
|
raise OptionParser::InvalidArgument, "The '-w' flag can only be used for the 'html' format flags"
|
277
277
|
end
|
278
278
|
|
279
|
-
if opts.
|
280
|
-
raise OptionParser::InvalidArgument, "
|
279
|
+
if opts.style_name && opts.resource_dir.nil?
|
280
|
+
raise OptionParser::InvalidArgument, "The '-s' flag requires the use of the '-r' flag as well."
|
281
281
|
end
|
282
282
|
|
283
|
+
# if opts.resource_dir.nil? ^ opts.style_name.nil?
|
284
|
+
# raise OptionParser::InvalidArgument, "Either both '-s' and '-r' flags must be given or none of them."
|
285
|
+
# end
|
286
|
+
|
283
287
|
if opts.resource_dir && !opts.resource_dir.exist?
|
284
288
|
raise OptionParser::InvalidArgument, "Could not find resource path #{opts.resource_dir}"
|
285
289
|
end
|
data/lib/giblish/config_utils.rb
CHANGED
@@ -26,6 +26,9 @@ module Giblish
|
|
26
26
|
|
27
27
|
def method_missing(m, *args, &block)
|
28
28
|
del = @delegates&.find { |d| d.respond_to?(m) }
|
29
|
+
if del.nil?
|
30
|
+
Giblog.logger.warn { "Did not find method '#{m}' in any delegate (#{@delegates}"}
|
31
|
+
end
|
29
32
|
|
30
33
|
del.nil? ? super : del.send(m, *args, &block)
|
31
34
|
end
|
data/lib/giblish/configurator.rb
CHANGED
@@ -13,26 +13,24 @@ module Giblish
|
|
13
13
|
class HtmlLayoutConfig
|
14
14
|
attr_reader :pre_builders, :post_builders, :adoc_extensions, :adoc_api_opts, :docattr_providers
|
15
15
|
|
16
|
-
def initialize(config_opts)
|
16
|
+
def initialize(resource_paths, config_opts)
|
17
17
|
@adoc_api_opts = {backend: "html"}
|
18
18
|
@pre_builders = []
|
19
19
|
@post_builders = []
|
20
20
|
@adoc_extensions = {}
|
21
21
|
@docattr_providers = []
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
4 == 5 # workaround for bug in standardrb formatting
|
35
|
-
end
|
22
|
+
|
23
|
+
if resource_paths.src_resource_dir_abs && resource_paths.dst_style_path_rel
|
24
|
+
# copy local resources to dst and link the generated html with
|
25
|
+
# the given css
|
26
|
+
@pre_builders << CopyResourcesPreBuild.new(resource_paths)
|
27
|
+
|
28
|
+
# make sure generated html has relative link to the copied css
|
29
|
+
@docattr_providers << RelativeCssDocAttr.new(resource_paths.dst_style_path_rel)
|
30
|
+
elsif config_opts.server_css
|
31
|
+
# do not copy any local resources, use the given web path to link to css
|
32
|
+
@docattr_providers << AbsoluteLinkedCss.new(config_opts.server_css)
|
33
|
+
end
|
36
34
|
|
37
35
|
if config_opts.make_searchable
|
38
36
|
# enabling text search
|
@@ -46,20 +44,53 @@ module Giblish
|
|
46
44
|
end
|
47
45
|
end
|
48
46
|
|
47
|
+
# A combined docattr_provider and post-processor that:
|
48
|
+
# - instructs asciidoctor-mathematical to use svg as format
|
49
|
+
# - removes svg cache files produced by asciidoctor-mathematical
|
50
|
+
class PdfMathPostbuilder
|
51
|
+
# called by the TreeConverter during the post_build phase
|
52
|
+
def on_postbuild(src_topdir, dst_tree, converter)
|
53
|
+
dst_top = src_topdir.pathname
|
54
|
+
dst_top.each_child do |c|
|
55
|
+
if c.basename.to_s.match?(/^stem-[0-9a-f]*\.svg$/)
|
56
|
+
Giblog.logger.debug("will remove #{c}")
|
57
|
+
c.delete
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def document_attributes(src_node, dst_node, dst_top)
|
63
|
+
{
|
64
|
+
"mathematical-format" => "svg"
|
65
|
+
}
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
49
69
|
class PdfLayoutConfig
|
50
70
|
attr_reader :pre_builders, :post_builders, :adoc_extensions, :adoc_api_opts, :docattr_providers
|
51
71
|
|
52
|
-
def initialize(
|
72
|
+
def initialize(resource_paths)
|
53
73
|
@adoc_api_opts = {backend: "pdf"}
|
54
74
|
@pre_builders = []
|
55
75
|
@post_builders = []
|
56
76
|
@adoc_extensions = {}
|
57
77
|
@docattr_providers = []
|
58
78
|
|
59
|
-
|
79
|
+
begin
|
80
|
+
require "asciidoctor-mathematical"
|
81
|
+
cc = PdfMathPostbuilder.new
|
82
|
+
@post_builders << cc
|
83
|
+
@docattr_providers << cc
|
84
|
+
rescue LoadError
|
85
|
+
Giblog.logger.warn { "Did not find asciidoctor-mathematical. stem blocks will not be rendered correctly!" }
|
86
|
+
end
|
87
|
+
|
88
|
+
if resource_paths.src_style_path_abs
|
60
89
|
# generate pdf using asciidoctor-pdf with custom styling
|
61
|
-
|
62
|
-
|
90
|
+
@docattr_providers << PdfCustomStyle.new(
|
91
|
+
resource_paths.src_style_path_abs,
|
92
|
+
*resource_paths.font_dirs_abs.to_a
|
93
|
+
)
|
63
94
|
end
|
64
95
|
end
|
65
96
|
end
|
@@ -72,6 +103,8 @@ module Giblish
|
|
72
103
|
# config_opts:: a Cmdline::Options instance with config info
|
73
104
|
def initialize(config_opts)
|
74
105
|
@config_opts = config_opts
|
106
|
+
@resource_paths = ResourcePaths.new(config_opts)
|
107
|
+
|
75
108
|
@build_options = {
|
76
109
|
pre_builders: [],
|
77
110
|
post_builders: [],
|
@@ -86,8 +119,8 @@ module Giblish
|
|
86
119
|
)
|
87
120
|
|
88
121
|
layout_config = case config_opts
|
89
|
-
in format: "html" then HtmlLayoutConfig.new(config_opts)
|
90
|
-
in format: "pdf" then PdfLayoutConfig.new(
|
122
|
+
in format: "html" then HtmlLayoutConfig.new(@resource_paths, config_opts)
|
123
|
+
in format: "pdf" then PdfLayoutConfig.new(@resource_paths)
|
91
124
|
else
|
92
125
|
raise OptionParser::InvalidArgument, "The given cmd line flags are not supported: #{config_opts.inspect}"
|
93
126
|
end
|
@@ -100,7 +133,7 @@ module Giblish
|
|
100
133
|
)
|
101
134
|
|
102
135
|
setup_docid(config_opts, @build_options, @doc_attr)
|
103
|
-
setup_index_generation(config_opts, @build_options, @doc_attr)
|
136
|
+
setup_index_generation(config_opts, @resource_paths, @build_options, @doc_attr)
|
104
137
|
|
105
138
|
# setup all pre,post, and build options
|
106
139
|
@build_options[:adoc_api_opts] = layout_config.adoc_api_opts
|
@@ -116,11 +149,14 @@ module Giblish
|
|
116
149
|
|
117
150
|
protected
|
118
151
|
|
119
|
-
def setup_index_generation(config_opts, build_options, doc_attr)
|
152
|
+
def setup_index_generation(config_opts, resource_paths, build_options, doc_attr)
|
120
153
|
return if config_opts.no_index
|
121
154
|
|
122
155
|
# setup index generation
|
123
|
-
|
156
|
+
adoc_src_provider = SubtreeIndexBase.new(
|
157
|
+
{erb_template_path: resource_paths.idx_erb_template_abs}
|
158
|
+
)
|
159
|
+
idx = SubtreeInfoBuilder.new(doc_attr, nil, adoc_src_provider, config_opts.index_basename)
|
124
160
|
build_options[:post_builders] << idx
|
125
161
|
end
|
126
162
|
|
@@ -153,11 +189,16 @@ module Giblish
|
|
153
189
|
|
154
190
|
protected
|
155
191
|
|
156
|
-
def setup_index_generation(config_opts, build_options, doc_attr)
|
192
|
+
def setup_index_generation(config_opts, resource_paths, build_options, doc_attr)
|
157
193
|
return if config_opts.no_index
|
158
194
|
|
159
195
|
build_options[:post_builders] << AddHistoryPostBuilder.new(@git_repo_dir)
|
160
|
-
|
196
|
+
|
197
|
+
# setup index generation
|
198
|
+
adoc_src_provider = SubtreeIndexGit.new(
|
199
|
+
{erb_template_path: resource_paths.idx_erb_template_abs}
|
200
|
+
)
|
201
|
+
build_options[:post_builders] << SubtreeInfoBuilder.new(doc_attr, nil, adoc_src_provider, config_opts.index_basename)
|
161
202
|
end
|
162
203
|
end
|
163
204
|
end
|
@@ -1,22 +1,30 @@
|
|
1
1
|
require "erb"
|
2
2
|
require_relative "verbatimtree"
|
3
3
|
require_relative "d3treegraph"
|
4
|
+
require_relative "../resourcepaths"
|
4
5
|
|
5
6
|
module Giblish
|
6
7
|
class SubtreeIndexBase < SubtreeSrcItf
|
7
8
|
attr_reader :src_location
|
8
9
|
|
9
|
-
|
10
|
+
# Required options:
|
11
|
+
# :erb_template_path - the absolute path to the erb template that will be used when generating
|
12
|
+
# the indices.
|
13
|
+
def initialize(opts)
|
14
|
+
raise InvalidArgument unless opts.key?(:erb_template_path)
|
10
15
|
|
11
|
-
|
16
|
+
@erb_path = Pathname(opts[:erb_template_path])
|
17
|
+
end
|
18
|
+
|
19
|
+
def adoc_source(pathtree, output_basename)
|
12
20
|
@pathtree = pathtree
|
13
21
|
@output_basename = output_basename
|
14
|
-
@
|
15
|
-
@
|
16
|
-
|
22
|
+
@parent_dirpath = pathtree.pathname.dirname
|
23
|
+
@dirname = pathtree.segment
|
24
|
+
|
25
|
+
Giblog.logger.debug { "using erb template: #{@erb_path} for index generation" }
|
26
|
+
erb_template = File.read(@erb_path)
|
17
27
|
|
18
|
-
def adoc_source
|
19
|
-
erb_template = File.read(__dir__ + DEFAULT_INDEX_ERB)
|
20
28
|
ERB.new(erb_template, trim_mode: "<>").result(binding)
|
21
29
|
end
|
22
30
|
|
@@ -91,17 +99,21 @@ module Giblish
|
|
91
99
|
# The fixed heading of the table used to display file history
|
92
100
|
HISTORY_TABLE_HEADING = <<~HISTORY_HEADER
|
93
101
|
File history::
|
94
|
-
|
102
|
+
|
95
103
|
[cols=\"2,3,8,3\",options=\"header\"]
|
96
104
|
|===
|
97
105
|
|Date |Author |Message |Sha1
|
98
106
|
HISTORY_HEADER
|
99
107
|
|
100
108
|
HISTORY_TABLE_FOOTING = <<~HIST_FOOTER
|
101
|
-
|
109
|
+
|
102
110
|
|===\n\n
|
103
111
|
HIST_FOOTER
|
104
112
|
|
113
|
+
def initialize(erb_template_path)
|
114
|
+
super(erb_template_path)
|
115
|
+
end
|
116
|
+
|
105
117
|
def subtitle(dst_node)
|
106
118
|
"from #{dst_node.data.branch}"
|
107
119
|
end
|
@@ -122,8 +134,8 @@ module Giblish
|
|
122
134
|
<<~HISTORY_ROW
|
123
135
|
|#{h.date.strftime("%Y-%m-%d")}
|
124
136
|
|#{h.author}
|
125
|
-
|#{h.message}
|
126
|
-
|#{h.sha1[0..7]} ...
|
137
|
+
|#{h.message}
|
138
|
+
|#{h.sha1[0..7]} ...
|
127
139
|
HISTORY_ROW
|
128
140
|
end.join("\n\n")
|
129
141
|
HISTORY_TABLE_HEADING + rows + HISTORY_TABLE_FOOTING
|
@@ -3,7 +3,7 @@ require "pathname"
|
|
3
3
|
module Giblish
|
4
4
|
# Provides relevant paths for layout resources based on the given options
|
5
5
|
class ResourcePaths
|
6
|
-
|
6
|
+
FORMAT_CONVENTIONS = {
|
7
7
|
"html5" => ".css",
|
8
8
|
"html" => ".css",
|
9
9
|
"pdf" => ".yml",
|
@@ -11,7 +11,8 @@ module Giblish
|
|
11
11
|
}
|
12
12
|
|
13
13
|
FONT_REGEX = /.*\.(ttf)|(TTF)$/
|
14
|
-
|
14
|
+
WEB_ASSET_TOP_BASENAME = Pathname.new("web_assets")
|
15
|
+
IDX_ERB_TEMPLATE_BASENAME = "idx_template.erb"
|
15
16
|
|
16
17
|
# the relative path from the top of the resource area to the
|
17
18
|
# style file
|
@@ -28,37 +29,91 @@ module Giblish
|
|
28
29
|
attr_reader :dst_style_path_rel
|
29
30
|
|
30
31
|
# the abs path to the top of the destination dir for resources
|
31
|
-
attr_reader :
|
32
|
+
attr_reader :dst_webasset_dir_abs
|
32
33
|
|
34
|
+
# the abs path to the top of the source dir for resources
|
35
|
+
attr_reader :src_resource_dir_abs
|
36
|
+
|
37
|
+
# the relative path to the erb template for index generation
|
38
|
+
attr_reader :idx_erb_template_rel
|
39
|
+
|
40
|
+
# the absolute path to the erb template for index generation
|
41
|
+
attr_reader :idx_erb_template_abs
|
42
|
+
|
43
|
+
# attributes:
|
44
|
+
# .format required
|
45
|
+
# .resource_dir required
|
46
|
+
# .dst_dir required
|
47
|
+
# .style_name optional
|
48
|
+
# .idx_erb_basename optional
|
33
49
|
def initialize(cmd_opts)
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
@src_style_path_rel = find_style_file(file_tree, cmd_opts)
|
44
|
-
@src_style_path_abs =
|
45
|
-
@dst_style_path_rel =
|
50
|
+
raise InvalidArgument, "Unsupported format: #{cmd_opts.format}" unless FORMAT_CONVENTIONS.key?(cmd_opts.format)
|
51
|
+
|
52
|
+
init_to_default(cmd_opts)
|
53
|
+
|
54
|
+
return if @src_resource_dir_abs.nil?
|
55
|
+
|
56
|
+
# Tweak paths based on the content of a given resource dir
|
57
|
+
file_tree = PathTree.build_from_fs(@src_resource_dir_abs)
|
58
|
+
|
59
|
+
@src_style_path_rel = find_style_file(file_tree, cmd_opts.format, cmd_opts.style_name)
|
60
|
+
@src_style_path_abs = @src_resource_dir_abs / @src_style_path_rel if @src_style_path_rel
|
61
|
+
@dst_style_path_rel = WEB_ASSET_TOP_BASENAME / @src_style_path_rel if @src_style_path_rel
|
62
|
+
|
46
63
|
@font_dirs_abs = find_font_dirs(file_tree)
|
64
|
+
|
65
|
+
erb_template = find_unique_file(file_tree, IDX_ERB_TEMPLATE_BASENAME)
|
66
|
+
if erb_template
|
67
|
+
@idx_erb_template_rel = erb_template
|
68
|
+
@idx_erb_template_abs = @src_resource_dir_abs / @idx_erb_template_rel
|
69
|
+
end
|
47
70
|
end
|
48
71
|
|
49
72
|
private
|
50
73
|
|
74
|
+
# initialize paths to default values
|
75
|
+
def init_to_default(cmd_opts)
|
76
|
+
# the top dir for resources
|
77
|
+
@src_resource_dir_abs = cmd_opts.resource_dir
|
78
|
+
|
79
|
+
# the destination dir for webassets is always valid for html conversion
|
80
|
+
@dst_webasset_dir_abs = cmd_opts.dstdir / WEB_ASSET_TOP_BASENAME if cmd_opts.format.start_with?("html")
|
81
|
+
|
82
|
+
# use the hard-coded default erb template
|
83
|
+
@idx_erb_template_rel = Pathname("indexbuilders/#{IDX_ERB_TEMPLATE_BASENAME}")
|
84
|
+
@idx_erb_template_abs = Pathname(__dir__) / @idx_erb_template_rel
|
85
|
+
|
86
|
+
@src_style_path_rel = nil
|
87
|
+
@src_style_path_abs = nil
|
88
|
+
|
89
|
+
@font_dirs_abs = nil
|
90
|
+
end
|
91
|
+
|
51
92
|
# returns:: the relative path from the top of the file_tree to
|
52
93
|
# the style file
|
53
|
-
def find_style_file(file_tree,
|
94
|
+
def find_style_file(file_tree, format, style_name)
|
95
|
+
return nil if style_name.nil?
|
96
|
+
|
54
97
|
# Get all files matching the style name
|
55
|
-
style_basename = Pathname.new(
|
56
|
-
|
98
|
+
style_basename = Pathname.new(style_name).sub_ext(
|
99
|
+
FORMAT_CONVENTIONS[format]
|
100
|
+
)
|
101
|
+
find_unique_file(file_tree, style_basename)
|
102
|
+
end
|
57
103
|
|
58
|
-
|
59
|
-
|
104
|
+
# returns the (relative) pathname of the file with the given basename or
|
105
|
+
# nil if no match was found.
|
106
|
+
#
|
107
|
+
# Throws if multiple entries exists.
|
108
|
+
def find_unique_file(file_tree, basename)
|
109
|
+
files = file_tree.match(/.*#{basename}$/)
|
60
110
|
|
61
|
-
|
111
|
+
if files.nil?
|
112
|
+
Giblog.logger.warn { "Did not find #{basename} under #{file_tree.pathname}" }
|
113
|
+
return nil
|
114
|
+
end
|
115
|
+
|
116
|
+
l = files.leave_pathnames(prune: true)
|
62
117
|
if l.count > 1
|
63
118
|
raise OptionParser::InvalidArgument, "Found #{l.count} instances of #{style_basename} under #{file_tree.pathname}. Requires exactly one."
|
64
119
|
end
|
@@ -67,6 +122,8 @@ module Giblish
|
|
67
122
|
l[0]
|
68
123
|
end
|
69
124
|
|
125
|
+
# returns:: a Set(Pathname) with all (absolute) directories matching the name criteria
|
126
|
+
# for fonts
|
70
127
|
def find_font_dirs(file_tree)
|
71
128
|
tree = file_tree.match(FONT_REGEX)
|
72
129
|
dirs = Set.new
|
@@ -87,23 +144,22 @@ module Giblish
|
|
87
144
|
# style_name:: basename of the css to use for styling
|
88
145
|
# dstdir:: Pathname to the destination dir where the copied resources will be
|
89
146
|
# stored.
|
90
|
-
def initialize(
|
91
|
-
@
|
92
|
-
@paths = ResourcePaths.new(cmd_opts)
|
147
|
+
def initialize(resource_paths)
|
148
|
+
@paths = resource_paths
|
93
149
|
end
|
94
150
|
|
95
151
|
def on_prebuild(src_tree, dst_tree, converter)
|
96
|
-
copy_resource_area
|
152
|
+
copy_resource_area
|
97
153
|
end
|
98
154
|
|
99
155
|
private
|
100
156
|
|
101
157
|
# copy everyting under cmd_opts.resource_dir to @web_asset_dir
|
102
|
-
def copy_resource_area
|
103
|
-
web_assets_dir = @paths.
|
158
|
+
def copy_resource_area
|
159
|
+
web_assets_dir = @paths.dst_webasset_dir_abs
|
104
160
|
web_assets_dir.mkpath unless web_assets_dir.exist?
|
105
161
|
|
106
|
-
resource_dir =
|
162
|
+
resource_dir = @paths.src_resource_dir_abs.to_s + "/."
|
107
163
|
|
108
164
|
Giblog.logger&.info "Copy web assets (stylesheets et al) from #{resource_dir} to #{web_assets_dir}"
|
109
165
|
FileUtils.cp_r(
|
@@ -113,6 +169,8 @@ module Giblish
|
|
113
169
|
end
|
114
170
|
end
|
115
171
|
|
172
|
+
# copy all directories whose name matches a given regex from
|
173
|
+
# the source tree to the destination tree.
|
116
174
|
class CopyAssetDirsPostBuild
|
117
175
|
def initialize(cmd_opts)
|
118
176
|
@asset_regex = cmd_opts.copy_asset_folders
|
@@ -3,12 +3,21 @@ require_relative "pathtree"
|
|
3
3
|
|
4
4
|
module Giblish
|
5
5
|
class SubtreeSrcItf
|
6
|
-
|
7
|
-
|
6
|
+
def initialize(opts = {})
|
7
|
+
raise NotImplementedError
|
8
|
+
end
|
9
|
+
|
10
|
+
def adoc_source(dst_node, output_basename)
|
8
11
|
raise NotImplementedError
|
9
12
|
end
|
10
13
|
end
|
11
14
|
|
15
|
+
# A post builder that provides the ability for a adoc source provider to
|
16
|
+
# run on each directory node in the destination pathtree output from the build step.
|
17
|
+
#
|
18
|
+
# The adoc source provider is invoked on each directory node depth-first. The
|
19
|
+
# resulting adoc source is converted and the result added to the destination
|
20
|
+
# pathtree from the build step.
|
12
21
|
class SubtreeInfoBuilder
|
13
22
|
attr_accessor :docattr_provider
|
14
23
|
|
@@ -21,7 +30,15 @@ module Giblish
|
|
21
30
|
def initialize(docattr_provider = nil, api_opt_provider = nil, adoc_src_provider = nil, basename = DEFAULT_BASENAME)
|
22
31
|
@docattr_provider = docattr_provider
|
23
32
|
@api_opt_provider = api_opt_provider
|
33
|
+
|
24
34
|
@adoc_src_provider = adoc_src_provider || SubtreeIndexBase
|
35
|
+
if @adoc_src_provider.is_a?(Class)
|
36
|
+
@adoc_src_provider = @adoc_src_provider.new(
|
37
|
+
{docattr_provider: docattr_provider,
|
38
|
+
api_opt_provider: api_opt_provider}
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
25
42
|
@basename = basename
|
26
43
|
@adoc_source = nil
|
27
44
|
end
|
@@ -52,12 +69,7 @@ module Giblish
|
|
52
69
|
index_dir = dst_node.pathname.relative_path_from(dst_tree.pathname).cleanpath
|
53
70
|
Giblog.logger.debug { "Creating #{@basename} under #{index_dir}" }
|
54
71
|
|
55
|
-
|
56
|
-
@adoc_source = if @adoc_src_provider.is_a?(Class)
|
57
|
-
@adoc_src_provider.new(dst_node, @basename).adoc_source
|
58
|
-
else
|
59
|
-
@adoc_src_provider.adoc_source
|
60
|
-
end
|
72
|
+
@adoc_source = @adoc_src_provider.adoc_source(dst_node, @basename)
|
61
73
|
|
62
74
|
# add a virtual 'index.adoc' node as the only node in a source tree
|
63
75
|
# with this object as source for conversion options
|
data/lib/giblish/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: giblish
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anders Rillbert
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -322,7 +322,7 @@ files:
|
|
322
322
|
- lib/giblish/indexbuilders/d3treegraph.rb
|
323
323
|
- lib/giblish/indexbuilders/depgraphbuilder.rb
|
324
324
|
- lib/giblish/indexbuilders/dotdigraphadoc.rb
|
325
|
-
- lib/giblish/indexbuilders/
|
325
|
+
- lib/giblish/indexbuilders/idx_template.erb
|
326
326
|
- lib/giblish/indexbuilders/subtree_indices.rb
|
327
327
|
- lib/giblish/indexbuilders/templates/circles.html.erb
|
328
328
|
- lib/giblish/indexbuilders/templates/flame.html.erb
|