giblish 0.8.2 → 2.0.0.pre.alpha1

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.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/unit_tests.yml +30 -0
  3. data/.gitignore +7 -3
  4. data/.ruby-version +1 -1
  5. data/Changelog.adoc +59 -0
  6. data/README.adoc +261 -0
  7. data/docs/concepts/text_search.adoc +213 -0
  8. data/docs/concepts/text_search_im/cgi-search_request.puml +35 -0
  9. data/docs/concepts/text_search_im/cgi-search_request.svg +397 -0
  10. data/docs/concepts/text_search_im/search_request.puml +40 -0
  11. data/docs/concepts/text_search_im/search_request.svg +408 -0
  12. data/docs/howtos/trigger_generation.adoc +180 -0
  13. data/docs/{setup_server_assets → howtos/trigger_generation_im}/Render Documents.png +0 -0
  14. data/docs/{setup_server_assets → howtos/trigger_generation_im}/View Documents.png +0 -0
  15. data/docs/{setup_server_assets → howtos/trigger_generation_im}/deploy_with_hooks.graphml +0 -0
  16. data/docs/{setup_server_assets → howtos/trigger_generation_im}/deploy_with_hooks.svg +0 -0
  17. data/docs/{setup_server_assets → howtos/trigger_generation_im}/deploy_with_jenkins.graphml +0 -0
  18. data/docs/{setup_server_assets → howtos/trigger_generation_im}/deploy_with_jenkins.svg +0 -0
  19. data/docs/howtos/trigger_generation_im/docgen_github.puml +51 -0
  20. data/docs/{setup_server_assets → howtos/trigger_generation_im}/giblish_deployment.graphml +0 -0
  21. data/docs/howtos/trigger_generation_im/post-receive-example.sh +50 -0
  22. data/docs/reference/box_flow_spec.adoc +22 -0
  23. data/docs/reference/search_spec.adoc +185 -0
  24. data/giblish.gemspec +54 -32
  25. data/lib/giblish/adocsrc_providers.rb +23 -0
  26. data/lib/giblish/application.rb +214 -41
  27. data/lib/giblish/cmdline.rb +273 -259
  28. data/lib/giblish/config_utils.rb +41 -0
  29. data/lib/giblish/configurator.rb +163 -0
  30. data/lib/giblish/conversion_info.rb +120 -0
  31. data/lib/giblish/docattr_providers.rb +125 -0
  32. data/lib/giblish/docid/docid.rb +181 -0
  33. data/lib/giblish/github_trigger/webhook_manager.rb +64 -0
  34. data/lib/giblish/gitrepos/checkoutmanager.rb +124 -0
  35. data/lib/giblish/{gititf.rb → gitrepos/gititf.rb} +30 -4
  36. data/lib/giblish/gitrepos/gitsummary.erb +61 -0
  37. data/lib/giblish/gitrepos/gitsummaryprovider.rb +78 -0
  38. data/lib/giblish/gitrepos/history_pb.rb +41 -0
  39. data/lib/giblish/indexbuilders/d3treegraph.rb +88 -0
  40. data/lib/giblish/indexbuilders/depgraphbuilder.rb +109 -0
  41. data/lib/giblish/indexbuilders/dotdigraphadoc.rb +174 -0
  42. data/lib/giblish/indexbuilders/standard_index.erb +10 -0
  43. data/lib/giblish/indexbuilders/subtree_indices.rb +132 -0
  44. data/lib/giblish/indexbuilders/templates/circles.html.erb +111 -0
  45. data/lib/giblish/indexbuilders/templates/flame.html.erb +61 -0
  46. data/lib/giblish/indexbuilders/templates/tree.html.erb +366 -0
  47. data/lib/giblish/indexbuilders/templates/treemap.html.erb +127 -0
  48. data/lib/giblish/indexbuilders/verbatimtree.rb +94 -0
  49. data/lib/giblish/pathtree.rb +473 -74
  50. data/lib/giblish/resourcepaths.rb +150 -0
  51. data/lib/giblish/search/expand_adoc.rb +55 -0
  52. data/lib/giblish/search/headingindexer.rb +312 -0
  53. data/lib/giblish/search/request_manager.rb +110 -0
  54. data/lib/giblish/search/searchquery.rb +68 -0
  55. data/lib/giblish/search/textsearcher.rb +349 -0
  56. data/lib/giblish/subtreeinfobuilder.rb +77 -0
  57. data/lib/giblish/treeconverter.rb +272 -0
  58. data/lib/giblish/utils.rb +142 -294
  59. data/lib/giblish/version.rb +1 -1
  60. data/lib/giblish.rb +10 -7
  61. data/scripts/hooks/post-receive.example +66 -0
  62. data/{docgen/scripts/githook_examples → scripts/hooks}/post-update.example +0 -0
  63. data/{docgen → scripts}/resources/css/adoc-colony.css +0 -0
  64. data/scripts/resources/css/giblish-serif.css +419 -0
  65. data/scripts/resources/css/giblish.css +1979 -419
  66. data/{docgen → scripts}/resources/fonts/Ubuntu-B.ttf +0 -0
  67. data/{docgen → scripts}/resources/fonts/Ubuntu-BI.ttf +0 -0
  68. data/{docgen → scripts}/resources/fonts/Ubuntu-R.ttf +0 -0
  69. data/{docgen → scripts}/resources/fonts/Ubuntu-RI.ttf +0 -0
  70. data/{docgen → scripts}/resources/fonts/mplus1p-regular-fallback.ttf +0 -0
  71. data/{docgen → scripts}/resources/images/giblish_logo.png +0 -0
  72. data/{docgen → scripts}/resources/images/giblish_logo.svg +0 -0
  73. data/{docgen → scripts}/resources/themes/giblish.yml +0 -0
  74. data/scripts/wserv_development.rb +32 -0
  75. data/web_apps/cgi_search/gibsearch.rb +43 -0
  76. data/web_apps/gh_webhook_trigger/config.ru +2 -0
  77. data/web_apps/gh_webhook_trigger/gh_webhook_trigger.rb +73 -0
  78. data/web_apps/gh_webhook_trigger/public/dummy.txt +3 -0
  79. data/web_apps/sinatra_search/config.ru +2 -0
  80. data/web_apps/sinatra_search/public/dummy.txt +3 -0
  81. data/web_apps/sinatra_search/sinatra_search.rb +34 -0
  82. data/web_apps/sinatra_search/tmp/restart.txt +0 -0
  83. metadata +188 -85
  84. data/.rubocop.yml +0 -7
  85. data/.travis.yml +0 -3
  86. data/Changelog +0 -16
  87. data/Gemfile +0 -4
  88. data/README.adoc +0 -1
  89. data/Rakefile +0 -41
  90. data/bin/console +0 -14
  91. data/bin/setup +0 -8
  92. data/data/testdocs/malformed/no_header.adoc +0 -5
  93. data/data/testdocs/toplevel.adoc +0 -19
  94. data/data/testdocs/wellformed/adorned_purpose.adoc +0 -17
  95. data/data/testdocs/wellformed/docidtest/docid_1.adoc +0 -24
  96. data/data/testdocs/wellformed/docidtest/docid_2.adoc +0 -8
  97. data/data/testdocs/wellformed/simple.adoc +0 -14
  98. data/data/testdocs/wellformed/source_highlighting/highlight_source.adoc +0 -38
  99. data/docgen/resources/css/giblish.css +0 -1979
  100. data/docgen/scripts/Jenkinsfile +0 -18
  101. data/docgen/scripts/gen_adoc_org.sh +0 -58
  102. data/docs/README.adoc +0 -387
  103. data/docs/setup_server.adoc +0 -202
  104. data/lib/giblish/buildgraph.rb +0 -216
  105. data/lib/giblish/buildindex.rb +0 -459
  106. data/lib/giblish/core.rb +0 -451
  107. data/lib/giblish/docconverter.rb +0 -308
  108. data/lib/giblish/docid.rb +0 -180
  109. data/lib/giblish/docinfo.rb +0 -75
  110. data/lib/giblish/indexheadings.rb +0 -251
  111. data/lib/giblish-search.cgi +0 -459
  112. data/scripts/hooks/post-receive +0 -57
  113. data/scripts/publish_html.sh +0 -99
@@ -1,216 +0,0 @@
1
- module Giblish
2
- # Builds an asciidoc page with an svg image with a
3
- # digraph showing how documents reference each other.
4
- #
5
- # Graphviz is used as the graph generator and must be available
6
- # as a valid engine via asciidoctor-diagram for this class to work.
7
- class GraphBuilderGraphviz
8
- # the dependency graph relies on graphwiz (dot), check if we can access that
9
- def self.supported
10
- !Giblish.which("dot").nil?
11
- end
12
-
13
- # Supported options:
14
- # :extension - file extension for URL links (default is .html)
15
- def initialize(processed_docs, paths, deployment_info, options = {})
16
- # this class relies on graphwiz (dot), make sure we can access that
17
- raise "Could not find the 'dot' tool needed to generate a dependency graph!" unless GraphBuilderGraphviz.supported
18
-
19
- # require asciidoctor module needed for generating diagrams
20
- require "asciidoctor-diagram/graphviz"
21
-
22
- @noid_docs = {}
23
- @next_id = 0
24
- @processed_docs = processed_docs
25
- @paths = paths
26
- @deployment_info = deployment_info
27
- @converter_options = options.dup
28
- @extension = @converter_options.key?(:extension) ? options[:extension] : "html"
29
- @docid_cache = DocidCollector.docid_cache
30
- @docid_deps = DocidCollector.docid_deps
31
- @dep_graph = build_dep_graph
32
- @search_opts = {
33
- web_assets_top: @deployment_info.web_path,
34
- search_assets_top: @deployment_info.search_assets_path
35
- }
36
- end
37
-
38
- # get the asciidoc source for the document.
39
- def source(make_searchable: false)
40
- s = <<~DOC_STR
41
- #{generate_header}
42
- #{add_search_box if make_searchable}
43
- #{generate_graph_header}
44
- #{generate_labels}
45
- #{generate_deps}
46
- #{generate_footer}
47
- DOC_STR
48
- s
49
- end
50
-
51
- def cleanup
52
- # remove cache dir and svg image created by asciidoctor-diagram
53
- # when creating the document dependency graph
54
- adoc_diag_cache = @paths.dst_root_abs.join(".asciidoctor")
55
- FileUtils.remove_dir(adoc_diag_cache) if adoc_diag_cache.directory?
56
- Giblog.logger.info { "Removing cached files at: #{@paths.dst_root_abs.join('docdeps.svg')}" }
57
- @paths.dst_root_abs.join("docdeps.svg").delete
58
- end
59
-
60
- private
61
-
62
- # build a hash with {DocInfo => [doc_id array]}
63
- def build_dep_graph
64
- result = {}
65
- @docid_deps.each do |src_file, id_array|
66
- d = @processed_docs.find do |doc|
67
- doc.src_file.to_s.eql? src_file
68
- end
69
- raise "Inconsistent docs when building graph!! found no match for #{src_file}" if d.nil?
70
-
71
- result[d] = id_array if d.converted
72
- end
73
- result
74
- end
75
-
76
- def generate_graph_header
77
- <<~DOC_STR
78
- Below is a graph that visualizes what documents (by doc-id) a specific
79
- document references.
80
-
81
- [graphviz,"docdeps","svg",options="inline"]
82
- ....
83
- digraph notebook {
84
- bgcolor="#33333310"
85
- node [shape=note,
86
- fillcolor="#ebf26680",
87
- style="filled,solid"
88
- ]
89
-
90
- rankdir="LR"
91
-
92
- DOC_STR
93
- end
94
-
95
- def generate_header
96
- t = Time.now
97
- <<~DOC_STR
98
- = Document-id reference graph
99
- from #{@paths.src_root_abs}
100
-
101
- Generated by Giblish at::
102
- #{t.strftime('%Y-%m-%d %H:%M')}
103
-
104
- DOC_STR
105
- end
106
-
107
- def generate_footer
108
- <<~DOC_STR
109
- }
110
- ....
111
- DOC_STR
112
- end
113
-
114
- def add_search_box
115
- Giblish.generate_search_box_html(
116
- @converter_options[:attributes]["stylesheet"],
117
- "/cgi-bin/giblish-search.cgi",
118
- @search_opts
119
- )
120
- end
121
-
122
- def make_dot_entry(doc_dict, info)
123
- # split title into multiple rows if it is too long
124
- line_length = 15
125
- lines = [""]
126
- unless info&.title.nil?
127
- info.title.split(" ").inject("") do |l, w|
128
- line = "#{l} #{w}"
129
- lines[-1] = line
130
- if line.length > line_length
131
- # create a new, empty, line
132
- lines << ""
133
- ""
134
- else
135
- line
136
- end
137
- end
138
- end
139
- title = lines.select { |l| l.length.positive? }.map { |l| l }.join("\n")
140
-
141
- # create the label used to display the node in the graph
142
- dot_entry = if info.doc_id.nil?
143
- doc_id = next_fake_id
144
- @noid_docs[info] = doc_id
145
- "\"#{doc_id}\"[label=\"-\\n#{title}\""
146
- else
147
- doc_id = info.doc_id
148
- "\"#{info.doc_id}\"[label=\"#{info.doc_id}\\n#{title}\""
149
- end
150
- # add clickable links in the case of html output (this is not supported
151
- # out-of-the-box for pdf).
152
- rp = info.rel_path.sub_ext(".#{@extension}")
153
- dot_entry += case @extension
154
- when "html"
155
- ", URL=\"#{rp}\" ]"
156
- else
157
- " ]"
158
- end
159
- doc_dict[doc_id] = dot_entry
160
- end
161
-
162
- def generate_labels
163
- # create an entry in the 'dot' description for each
164
- # document, sort them according to descending doc id to
165
- # get them displayed in the opposite order in the graph
166
- node_dict = {}
167
- @dep_graph.each_key do |info|
168
- make_dot_entry node_dict, info
169
- end
170
- # sort the nodes by reverse doc id
171
- node_dict = node_dict.sort.reverse.to_h
172
-
173
- # produce the string with all node entries
174
- node_dict.map do |_k, v|
175
- v
176
- end.join("\n")
177
- end
178
-
179
- def generate_deps
180
- dep_str = ""
181
- @dep_graph.each do |info, targets|
182
- # set either the real or the generated id as source
183
- src_part = if info.doc_id.nil?
184
- "\"#{@noid_docs[info]}\""
185
- else
186
- "\"#{info.doc_id}\""
187
- end
188
-
189
- if targets.length.zero?
190
- dep_str += "#{src_part}\n"
191
- next
192
- end
193
-
194
- dep_str += "#{src_part} -> {" + targets.reduce("") do |acc, target|
195
- acc + " \"#{target}\""
196
- end
197
- # replace last comma with newline
198
- dep_str += "}\n"
199
- end
200
- dep_str
201
- end
202
-
203
- def next_fake_id
204
- @next_id += 1
205
- "_generated_id_#{@next_id.to_s.rjust(4, '0')}"
206
- end
207
- end
208
-
209
- # specializes generation of a document dependency graph for
210
- # docs rendered from a git repo.
211
- class GitGraphBuilderGraphviz < GraphBuilderGraphviz
212
- def initialize(processed_docs, paths, deployment_info, options = {}, _git_repo)
213
- super(processed_docs, paths, deployment_info, options)
214
- end
215
- end
216
- end
@@ -1,459 +0,0 @@
1
- require "pathname"
2
- require "git"
3
-
4
- require_relative "pathtree"
5
- require_relative "gititf"
6
- require_relative "docinfo"
7
-
8
- module Giblish
9
- # Base class with common functionality for all index builders
10
- class BasicIndexBuilder
11
- # set up the basic index building info
12
- def initialize(processed_docs, converter, path_manager, deployment_info, handle_docid = false)
13
- @paths = path_manager
14
- @deployment_info = deployment_info
15
- @nof_missing_titles = 0
16
- @processed_docs = processed_docs
17
- @converter = converter
18
- @src_str = ""
19
- @manage_docid = handle_docid
20
- @search_opts = {
21
- web_assets_top: @deployment_info.web_path,
22
- search_assets_top: @deployment_info.search_assets_path
23
- }
24
- end
25
-
26
- def source(dep_graph_exists: false, make_searchable: false)
27
- <<~DOC_STR
28
- #{generate_title_and_header}
29
-
30
- #{generate_date_info}
31
-
32
- #{add_search_box if make_searchable}
33
-
34
- #{add_docid_info if @manage_docid}
35
-
36
- #{add_depgraph_id if dep_graph_exists}
37
-
38
- #{generate_tree}
39
-
40
- #{generate_details}
41
-
42
- #{generate_footer}
43
- DOC_STR
44
- end
45
-
46
- protected
47
-
48
- def source_root
49
- @paths.src_root_abs
50
- end
51
-
52
- def generate_title_and_header
53
- <<~DOC_HEADER
54
- = Document index
55
- from #{source_root}
56
- :icons: font
57
- DOC_HEADER
58
- end
59
-
60
- # return the adoc string for displaying the source file
61
- def display_source_file(doc_info)
62
- <<~SRC_FILE_TXT
63
- Source file::
64
- #{doc_info.src_file}
65
- SRC_FILE_TXT
66
- end
67
-
68
- def generate_date_info
69
- t = Time.now
70
- <<~DOC_HEADER
71
- *Generated by Giblish at:* #{t.strftime('%Y-%m-%d %H:%M')}
72
- DOC_HEADER
73
- end
74
-
75
- def add_search_box
76
- Giblish.generate_search_box_html(
77
- @converter.converter_options[:attributes]["stylesheet"],
78
- "/cgi-bin/giblish-search.cgi",
79
- @search_opts
80
- )
81
- end
82
-
83
- def docid_statistics
84
- largest = ""
85
- clash = []
86
- @processed_docs.each do |d|
87
- # get the lexically largest doc id
88
- largest = d.doc_id if !d.doc_id.nil? && d.doc_id > largest
89
-
90
- # collect all ids in an array to find duplicates later on
91
- clash << d.doc_id unless d.doc_id.nil?
92
- end
93
- # find the duplicate doc ids (if any)
94
- duplicates = clash.select { |id| clash.count(id) > 1 }.uniq.sort
95
-
96
- [largest, duplicates]
97
- end
98
-
99
- def add_docid_info
100
- largest, duplicates = docid_statistics
101
- <<~DOC_ID_INFO
102
- *Document id numbers:* The 'largest' document id found when resolving
103
- :docid: tags in all documents is *#{largest}*.
104
-
105
- #{if duplicates.length.zero?
106
- ''
107
- else
108
- 'WARNING: The following document ids are used for '\
109
- 'more than one document. '\
110
- "_#{duplicates.map(&:to_s).join(',')}_"
111
- end}
112
-
113
- DOC_ID_INFO
114
- end
115
-
116
- def add_depgraph_id
117
- # include link to dependency graph if it exists
118
- <<~DEPGRAPH_STR
119
- _A visual graph of document dependencies can be found
120
- <<./graph.adoc#,here>>
121
- DEPGRAPH_STR
122
- end
123
-
124
- def generate_tree
125
- # output tree intro
126
- tree_string = String.new(
127
- <<~DOC_HEADER
128
- [subs=\"normal\"]
129
- ----
130
- DOC_HEADER
131
- )
132
-
133
- # build up tree of paths
134
- root = PathTree.new
135
- @processed_docs.each do |d|
136
- root.add_path(d.rel_path.to_s, d)
137
- end
138
-
139
- # sort the tree
140
- root.sort_children
141
-
142
- # generate each tree entry string
143
- root.traverse_top_down do |level, node|
144
- tree_string << tree_entry_string(level, node)
145
- end
146
-
147
- # generate the tree footer
148
- tree_string << "\n----\n"
149
- end
150
-
151
- def generate_footer
152
- ""
153
- end
154
-
155
- private
156
-
157
- def generate_conversion_info(doc_info)
158
- return "" if doc_info.stderr.empty?
159
-
160
- # extract conversion warnings from asciddoctor std err
161
- conv_warnings = doc_info.stderr.gsub(/^/, " * ")
162
-
163
- # assemble info to index page
164
- <<~CONV_INFO
165
- Conversion issues::
166
-
167
- #{conv_warnings}
168
- CONV_INFO
169
- end
170
-
171
- # Private: Return adoc elements for displaying a clickable title
172
- # and a 'details' ref that points to a section that uses the title as an id.
173
- #
174
- # Returns [ title, clickableTitleStr, clickableDetailsStr ]
175
- def format_title_and_ref(doc_info)
176
- unless doc_info.title
177
- @nof_missing_titles += 1
178
- doc_info.title = "NO TITLE FOUND (#{@nof_missing_titles}) !"
179
- end
180
-
181
- # Manipulate the doc title if we have a doc id
182
- title = if !doc_info.doc_id.nil? && @manage_docid
183
- "#{doc_info.doc_id} - #{doc_info.title}"
184
- else
185
- doc_info.title
186
- end
187
-
188
- [title, "<<#{doc_info.rel_path}#,#{title}>>",
189
- "<<#{Giblish.to_valid_id(doc_info.title)},details>>\n"]
190
- end
191
-
192
- # Generate an adoc string that will display as
193
- # DocTitle (conv issues) details
194
- # Where the DocTitle and details are links to the doc itself and a section
195
- # identified with the doc's title respectively.
196
- def tree_entry_converted(prefix_str, doc_info)
197
- # Get the elements of the entry
198
- doc_title, doc_link, doc_details = format_title_and_ref doc_info
199
- warning_label = doc_info.stderr.empty? ? "" : "(conv issues)"
200
-
201
- # Calculate padding to get (conv issues) and details aligned between entries
202
- padding = 70
203
- [doc_title, prefix_str, warning_label].each { |p| padding -= p.length }
204
- padding = 0 unless padding.positive?
205
- "#{prefix_str} #{doc_link}#{' ' * padding}#{warning_label} #{doc_details}"
206
- end
207
-
208
- def tree_entry_string(level, node)
209
- # indent 2 * level
210
- prefix_str = " " * (level + 1)
211
-
212
- # return only name for directories
213
- return "#{prefix_str} #{node.name}\n" unless node.leaf?
214
-
215
- # return links to content and details for files
216
- # node.data is a DocInfo instance
217
- d = node.data
218
- if d.converted
219
- tree_entry_converted prefix_str, d
220
- else
221
- # no converted file exists, show what we know
222
- "#{prefix_str} FAIL: #{d.src_file} <<#{d.src_file},details>>\n"
223
- end
224
- end
225
-
226
- # Derived classes can override this with useful info
227
- def generate_history_info(_doc_info)
228
- ""
229
- end
230
-
231
- def generate_detail_fail(doc_info)
232
- <<~FAIL_INFO
233
- === #{doc_info.src_file}
234
-
235
- #{display_source_file(d)}
236
-
237
- Error detail::
238
- #{doc_info.stderr}
239
-
240
- ''''
241
-
242
- FAIL_INFO
243
- end
244
-
245
- def generate_detail(doc_info)
246
- # Generate detail info
247
- purpose_str = if doc_info.purpose_str.nil?
248
- ""
249
- else
250
- "Purpose::\n#{doc_info.purpose_str}"
251
- end
252
-
253
- doc_id_str = if !doc_info.doc_id.nil? && @manage_docid
254
- "Doc id::\n_#{doc_info.doc_id}_"
255
- else
256
- ""
257
- end
258
-
259
- <<~DETAIL_SRC
260
- [[#{Giblish.to_valid_id(doc_info.title.encode('utf-8'))}]]
261
- === #{doc_info.title.encode('utf-8')}
262
-
263
- #{doc_id_str}
264
-
265
- #{purpose_str}
266
-
267
- #{generate_conversion_info doc_info}
268
-
269
- #{display_source_file(doc_info)}
270
-
271
- #{generate_history_info doc_info}
272
-
273
- ''''
274
-
275
- DETAIL_SRC
276
- end
277
-
278
- def generate_details
279
- root = PathTree.new
280
- @processed_docs.each do |d|
281
- root.add_path(d.rel_path.to_s, d)
282
- end
283
-
284
- details_str = String.new("== Document details\n\n")
285
-
286
- root.traverse_top_down do |_level, node|
287
- details_str << if node.leaf?
288
- d = node.data
289
- if d.converted
290
- generate_detail(d)
291
- else
292
- generate_detail_fail(d)
293
- end
294
- else
295
- ""
296
- end
297
- end
298
- details_str
299
- end
300
- end
301
-
302
- # A simple index generator that shows a table with the generated documents
303
- class SimpleIndexBuilder < BasicIndexBuilder
304
- def initialize(processed_docs, converter, path_manager, deployment_info, manage_docid = false)
305
- super processed_docs, converter, path_manager, deployment_info, manage_docid
306
- end
307
- end
308
-
309
- # Builds an index of the generated documents and includes some git metadata
310
- # from the repository
311
- class GitRepoIndexBuilder < BasicIndexBuilder
312
- def initialize(processed_docs, converter, path_manager, deployment_info, manage_docid, git_repo_root)
313
- super processed_docs, converter, path_manager, deployment_info, manage_docid
314
-
315
- # no repo root given...
316
- return unless git_repo_root
317
-
318
- begin
319
- # Make sure that we can "talk" to git if user feeds us
320
- # a git repo root
321
- @git_repo = Git.open(git_repo_root)
322
- @git_repo_root = git_repo_root
323
- rescue StandardError => e
324
- Giblog.logger.error { "No git repo! exception: #{e.message}" }
325
- end
326
- end
327
-
328
- protected
329
-
330
- # override basic version and use the relative path to the
331
- # git repo root instead
332
- def display_source_file(doc_info)
333
- # Use the path relative to the git repo root as display
334
- src_file = Pathname
335
- .new(doc_info.src_file)
336
- .relative_path_from(@git_repo_root).to_s
337
- <<~SRC_FILE_TXT
338
- Source file::
339
- #{src_file}
340
- SRC_FILE_TXT
341
- end
342
-
343
- def source_root
344
- @git_repo.current_branch
345
- end
346
-
347
- def generate_history_info(doc_info)
348
- str = String.new(
349
- <<~HISTORY_HEADER
350
- File history::
351
-
352
- [cols=\"2,3,8\",options=\"header\"]
353
- |===
354
- |Date |Author |Message
355
- HISTORY_HEADER
356
- )
357
-
358
- # Generate table rows of history information
359
- doc_info.history.each do |h|
360
- str << <<~HISTORY_ROW
361
- |#{h.date.strftime('%Y-%m-%d')}
362
- |#{h.author}
363
- |#{h.message}
364
-
365
- HISTORY_ROW
366
- end
367
- str << "|===\n\n"
368
- end
369
- end
370
-
371
- # Builds an index page with a summary of what branches have
372
- # been generated
373
- class GitSummaryIndexBuilder
374
- def initialize(repo, branches, tags)
375
- @branches = branches
376
- @tags = tags
377
- @git_repo = repo
378
- @repo_url = repo.remote.url
379
- end
380
-
381
- def source
382
- <<~ADOC_SRC
383
- #{generate_header}
384
- #{generate_branch_info}
385
- #{generate_tag_info}
386
- #{generate_footer}
387
- ADOC_SRC
388
- end
389
-
390
- private
391
-
392
- def generate_header
393
- t = Time.now
394
- <<~DOC_HEADER
395
- = Document repository
396
- From #{@repo_url}
397
-
398
- Generated by Giblish at::
399
- #{t.strftime('%Y-%m-%d %H:%M')}
400
-
401
- DOC_HEADER
402
- end
403
-
404
- def generate_footer
405
- ""
406
- end
407
-
408
- def generate_branch_info
409
- return "" if @branches.empty?
410
-
411
- # get the branch-unique dst-dir
412
- str = <<~BRANCH_INFO
413
- == Branches
414
-
415
- BRANCH_INFO
416
-
417
- @branches.each do |b|
418
- dirname = b.name.tr "/", "_"
419
- str << " * link:#{dirname}/index.html[#{b.name}]\n"
420
- end
421
- str
422
- end
423
-
424
- def generate_tag_info
425
- return "" if @tags.empty?
426
-
427
- # get the branch-unique dst-dir
428
- str = <<~TAG_INFO
429
- == Tags
430
-
431
- |===
432
- |Tag |Tag comment |Creator |Tagged commit
433
- TAG_INFO
434
-
435
- str << @tags.collect do |t|
436
- dirname = t.name.tr "/", "_"
437
- c = @git_repo.gcommit(t.sha)
438
-
439
- <<~A_ROW
440
- |link:#{dirname}/index.html[#{t.name}]
441
- |#{t.annotated? ? t.message : '-'}
442
- |#{t.annotated? ? t.tagger.name : '-'}
443
- |#{t.sha[0, 8]}... committed at #{c.author.date}
444
- A_ROW
445
- end.join("\n")
446
-
447
- str << "|===\n"
448
-
449
- # @tags.each do |t|
450
- # dirname = t.name.tr "/", "_"
451
- # str << " * link:#{dirname}/index.html[#{t.name}]"
452
- # if t.annotated?
453
- # str << "created at #{t.tagger.date} by #{t.tagger.name} with message: #{t.message}"
454
- # end
455
- # end
456
- str
457
- end
458
- end
459
- end