giblish 2.1.2 → 2.2.0

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: 22133b3cded62a83b48e863debd9f87aa046934504fa382251b96253926e7475
4
- data.tar.gz: 59aaff1c7e7264fd3e02303dd07b8ffe736b66b41ea62af23bc5a9923cfa0de8
3
+ metadata.gz: 695c1b3dfb96c74e96d97663179345ab09f875bfb0839ea1816b6599d61d4721
4
+ data.tar.gz: 15d5cac96d3d8fbcdcc418a9e62385bec617699139203d8c94ccc1080f90b3f8
5
5
  SHA512:
6
- metadata.gz: 01c930aa02c6cbb16325f3fb9981bd1d53396d992e7386cc189fa6c21804e872d56da7a6a343f0988c9403697bf64c3b5ea583363c9433813fcd0d65aa82f149
7
- data.tar.gz: b1cb48faa21d4305adf4981f75148b1db995a5a23af0187f0bcd69fffb0e920b6a4c980917bfc6adf24a39b0d889b75cf071a7194163af137cf71d6628fb80e9
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
- * Implement a way for a user to customize the index page
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
- * An index page listing all rendered documents with clickable links.
39
- * If the source directory tree is part of a git repository, giblish can generate separate html/pdf trees for branches and/or tags that match a user specified regexp (see examples below).
40
- * Document ids - Note: the implementation of this is giblish-specific and thus you need to render your adoc files using giblish to make this work as intended. You can use document ids to:
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
- * 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.
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
- Here follows a number of usages for giblish in increasing order of complexity.
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.
@@ -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.resource_dir.nil? ^ opts.style_name.nil?
280
- raise OptionParser::InvalidArgument, "Either both '-s' and '-r' flags must be given or none of them."
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
@@ -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
@@ -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
- case config_opts
23
- in resource_dir:
24
- # copy local resources to dst and link the generated html with
25
- # the given css
26
- @pre_builders << CopyResourcesPreBuild.new(config_opts)
27
-
28
- # make sure generated html has relative link to the copied css
29
- @docattr_providers << RelativeCssDocAttr.new(ResourcePaths.new(config_opts).dst_style_path_rel)
30
- in 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
- else
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
@@ -49,7 +47,7 @@ module Giblish
49
47
  # A combined docattr_provider and post-processor that:
50
48
  # - instructs asciidoctor-mathematical to use svg as format
51
49
  # - removes svg cache files produced by asciidoctor-mathematical
52
- class PdfMathHelper
50
+ class PdfMathPostbuilder
53
51
  # called by the TreeConverter during the post_build phase
54
52
  def on_postbuild(src_topdir, dst_tree, converter)
55
53
  dst_top = src_topdir.pathname
@@ -71,7 +69,7 @@ module Giblish
71
69
  class PdfLayoutConfig
72
70
  attr_reader :pre_builders, :post_builders, :adoc_extensions, :adoc_api_opts, :docattr_providers
73
71
 
74
- def initialize(config_opts)
72
+ def initialize(resource_paths)
75
73
  @adoc_api_opts = {backend: "pdf"}
76
74
  @pre_builders = []
77
75
  @post_builders = []
@@ -80,17 +78,19 @@ module Giblish
80
78
 
81
79
  begin
82
80
  require "asciidoctor-mathematical"
83
- cc = PdfMathHelper.new
81
+ cc = PdfMathPostbuilder.new
84
82
  @post_builders << cc
85
83
  @docattr_providers << cc
86
84
  rescue LoadError
87
85
  Giblog.logger.warn { "Did not find asciidoctor-mathematical. stem blocks will not be rendered correctly!" }
88
86
  end
89
87
 
90
- unless config_opts.resource_dir.nil?
88
+ if resource_paths.src_style_path_abs
91
89
  # generate pdf using asciidoctor-pdf with custom styling
92
- rp = ResourcePaths.new(config_opts)
93
- @docattr_providers << PdfCustomStyle.new(rp.src_style_path_abs, *rp.font_dirs_abs.to_a)
90
+ @docattr_providers << PdfCustomStyle.new(
91
+ resource_paths.src_style_path_abs,
92
+ *resource_paths.font_dirs_abs.to_a
93
+ )
94
94
  end
95
95
  end
96
96
  end
@@ -103,6 +103,8 @@ module Giblish
103
103
  # config_opts:: a Cmdline::Options instance with config info
104
104
  def initialize(config_opts)
105
105
  @config_opts = config_opts
106
+ @resource_paths = ResourcePaths.new(config_opts)
107
+
106
108
  @build_options = {
107
109
  pre_builders: [],
108
110
  post_builders: [],
@@ -117,8 +119,8 @@ module Giblish
117
119
  )
118
120
 
119
121
  layout_config = case config_opts
120
- in format: "html" then HtmlLayoutConfig.new(config_opts)
121
- in format: "pdf" then PdfLayoutConfig.new(config_opts)
122
+ in format: "html" then HtmlLayoutConfig.new(@resource_paths, config_opts)
123
+ in format: "pdf" then PdfLayoutConfig.new(@resource_paths)
122
124
  else
123
125
  raise OptionParser::InvalidArgument, "The given cmd line flags are not supported: #{config_opts.inspect}"
124
126
  end
@@ -131,7 +133,7 @@ module Giblish
131
133
  )
132
134
 
133
135
  setup_docid(config_opts, @build_options, @doc_attr)
134
- setup_index_generation(config_opts, @build_options, @doc_attr)
136
+ setup_index_generation(config_opts, @resource_paths, @build_options, @doc_attr)
135
137
 
136
138
  # setup all pre,post, and build options
137
139
  @build_options[:adoc_api_opts] = layout_config.adoc_api_opts
@@ -147,11 +149,14 @@ module Giblish
147
149
 
148
150
  protected
149
151
 
150
- def setup_index_generation(config_opts, build_options, doc_attr)
152
+ def setup_index_generation(config_opts, resource_paths, build_options, doc_attr)
151
153
  return if config_opts.no_index
152
154
 
153
155
  # setup index generation
154
- idx = SubtreeInfoBuilder.new(doc_attr, nil, SubtreeIndexBase, config_opts.index_basename)
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)
155
160
  build_options[:post_builders] << idx
156
161
  end
157
162
 
@@ -184,11 +189,16 @@ module Giblish
184
189
 
185
190
  protected
186
191
 
187
- def setup_index_generation(config_opts, build_options, doc_attr)
192
+ def setup_index_generation(config_opts, resource_paths, build_options, doc_attr)
188
193
  return if config_opts.no_index
189
194
 
190
195
  build_options[:post_builders] << AddHistoryPostBuilder.new(@git_repo_dir)
191
- build_options[:post_builders] << SubtreeInfoBuilder.new(doc_attr, nil, SubtreeIndexGit, config_opts.index_basename)
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)
192
202
  end
193
203
  end
194
204
  end
@@ -19,7 +19,6 @@ module Giblish
19
19
  dst_node.data.add(FileHistory.new(current_branch))
20
20
  next
21
21
  end
22
- # next unless dst_node.leaf?
23
22
 
24
23
  src_node = dst_node.data.src_node
25
24
  next unless src_node.pathname.exist?
@@ -1,4 +1,4 @@
1
- = Documents under '<%= @title %>'
1
+ = Documents under '<%= @dirname %>'
2
2
  Generated at: <%= Time.now.strftime("%Y-%m-%d %H:%M") %>
3
3
  :icons: font
4
4
 
@@ -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
- DEFAULT_INDEX_ERB = "/standard_index.erb"
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
- def initialize(pathtree, output_basename)
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
- @src_location = pathtree.pathname.dirname
15
- @title = pathtree.segment
16
- end
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
- STYLE_EXTENSIONS = {
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
- RESOURCE_DST_TOP_BASENAME = Pathname.new("web_assets")
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 :dst_resource_dir_abs
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
- @style_ext = STYLE_EXTENSIONS.fetch(cmd_opts.format, nil)
35
- raise OptionParser::InvalidArgument, "Unsupported format: #{cmd_opts.format}" if @style_ext.nil?
36
-
37
- # Cache all file paths in the resource area
38
- r_top = cmd_opts.resource_dir
39
- file_tree = PathTree.build_from_fs(r_top)
40
-
41
- # find and validate paths
42
- @dst_resource_dir_abs = cmd_opts.dstdir / RESOURCE_DST_TOP_BASENAME
43
- @src_style_path_rel = find_style_file(file_tree, cmd_opts)
44
- @src_style_path_abs = r_top / @src_style_path_rel
45
- @dst_style_path_rel = RESOURCE_DST_TOP_BASENAME / @src_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, cmd_opts)
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(cmd_opts.style_name).sub_ext(@style_ext)
56
- style_tree = file_tree.match(/.*#{style_basename}$/)
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
- # make sure we have exactly one css file with the given name
59
- raise OptionParser::InvalidArgument, "Did not find #{style_basename} under #{file_tree.pathname}" if style_tree.nil?
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
- l = style_tree.leave_pathnames(prune: true)
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(cmd_opts)
91
- @opts = cmd_opts.dup
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(@opts)
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(cmd_opts)
103
- web_assets_dir = @paths.dst_resource_dir_abs
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 = cmd_opts.resource_dir.cleanpath.to_s + "/."
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
- attr_reader :adoc_source
7
- def initialize(dst_node, output_basename)
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
- # get the adoc source from the provider (Class or instance)
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
@@ -1,3 +1,3 @@
1
1
  module Giblish
2
- VERSION = "2.1.2".freeze
2
+ VERSION = "2.2.0".freeze
3
3
  end
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.1.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-02-04 00:00:00.000000000 Z
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/standard_index.erb
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