giblish 0.7.6 → 1.0.0.rc2

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