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
data/lib/giblish/core.rb DELETED
@@ -1,442 +0,0 @@
1
- require "find"
2
- require "fileutils"
3
- require "logger"
4
- require "pathname"
5
-
6
- require_relative "buildindex"
7
- require_relative "docconverter"
8
- require_relative "docid"
9
- require_relative "indexheadings"
10
- require_relative "docinfo"
11
- require_relative "buildgraph"
12
-
13
- module Giblish
14
-
15
- # Parse a directory tree and convert all asciidoc files matching the
16
- # supplied critera to the supplied format
17
- class FileTreeConverter
18
-
19
- attr_reader :converter
20
-
21
- # Required options:
22
- # srcDirRoot
23
- # dstDirRoot
24
- # resourceDir
25
- def initialize(options)
26
- @options = options.dup
27
-
28
- @paths = Giblish::PathManager.new(
29
- @options[:srcDirRoot],
30
- @options[:dstDirRoot],
31
- @options[:resourceDir],
32
- @options[:makeSearchable]
33
- )
34
-
35
- # set the path to the search data that will be sent to the cgi search script
36
- deploy_search_path = if @options[:makeSearchable]
37
- @options[:searchAssetsDeploy].nil? ?
38
- @paths.search_assets_abs : Pathname.new(@options[:searchAssetsDeploy]).join("search_assets")
39
- else
40
- nil
41
- end
42
-
43
- @deploy_info = Giblish::DeploymentPaths.new(
44
- @options[:webPath],
45
- deploy_search_path
46
- )
47
- @processed_docs = []
48
- @converter = converter_factory
49
- end
50
-
51
-
52
- # convert all adoc files
53
- # return true if all conversions went ok, false if at least one
54
- # failed
55
- def convert
56
- # collect all doc ids and enable replacement of known doc ids with
57
- # valid references to adoc files
58
- manage_doc_ids if @options[:resolveDocid]
59
-
60
- # register add-on for handling searchability
61
- manage_searchability(@options) if @options[:makeSearchable]
62
-
63
- # traverse the src file tree and convert all files deemed as
64
- # adoc files
65
- conv_error = false
66
- Find.find(@paths.src_root_abs) do |path|
67
- p = Pathname.new(path)
68
- begin
69
- to_asciidoc(p) if adocfile? p
70
- rescue Exception => e
71
- str = "Error when converting file #{path.to_s}: #{e.message}\nBacktrace:\n"
72
- e.backtrace.each { |l| str << " #{l}\n" }
73
- Giblog.logger.error { str }
74
- conv_error = true
75
- end
76
- end if @paths.src_root_abs.directory?
77
-
78
- # create necessary search assets if needed
79
- create_search_assets if @options[:makeSearchable]
80
-
81
- # build index and other fancy stuff if not suppressed
82
- unless @options[:suppressBuildRef]
83
- # build a dependency graph (only if we resolve docids...)
84
- dep_graph_exist = @options[:resolveDocid] && build_graph_page
85
-
86
- # build a reference index
87
- build_index_page(dep_graph_exist)
88
- end
89
- conv_error
90
- end
91
-
92
- protected
93
-
94
- def build_graph_page
95
- begin
96
- adoc_logger = Giblish::AsciidoctorLogger.new Logger::Severity::WARN
97
- gb = graph_builder_factory
98
- errors = @converter.convert_str(
99
- gb.source(
100
- @options[:makeSearchable]
101
- ),
102
- @paths.dst_root_abs,
103
- "graph",
104
- logger: adoc_logger
105
- )
106
- gb.cleanup
107
- !errors
108
- rescue Exception => e
109
- Giblog.logger.warn { e.message }
110
- Giblog.logger.warn { "The dependency graph will not be generated !!" }
111
- end
112
- false
113
- end
114
-
115
- def build_index_page(dep_graph_exist)
116
- # build a reference index
117
- adoc_logger = Giblish::AsciidoctorLogger.new Logger::Severity::WARN
118
- ib = index_factory
119
- @converter.convert_str(
120
- ib.source(
121
- dep_graph_exist, @options[:makeSearchable]
122
- ),
123
- @paths.dst_root_abs,
124
- @options[:indexBaseName],
125
- logger: adoc_logger
126
- )
127
-
128
- # clean up cached files and adoc resources
129
- GC.start
130
- end
131
-
132
- # get the correct index builder type depending on supplied
133
- # user options
134
- def index_factory
135
- raise "Internal logic error!" if @options[:suppressBuildRef]
136
- SimpleIndexBuilder.new(@processed_docs, @converter, @paths, @deploy_info,
137
- @options[:resolveDocid])
138
- end
139
-
140
- def graph_builder_factory
141
- Giblish::GraphBuilderGraphviz.new @processed_docs, @paths, @deploy_info,
142
- @converter.converter_options
143
- end
144
-
145
- # get the correct converter type
146
- def converter_factory
147
- case @options[:format]
148
- when "html" then
149
- HtmlConverter.new @paths, @deploy_info, @options
150
- when "pdf" then
151
- PdfConverter.new @paths, @deploy_info, @options
152
- else
153
- raise ArgumentError, "Unknown conversion format: #{@options[:format]}"
154
- end
155
- end
156
-
157
- # creates a DocInfo instance, fills it with basic info and
158
- # returns the filled in instance so that derived implementations can
159
- # add more data
160
- def add_doc(adoc, adoc_stderr)
161
- Giblog.logger.debug do
162
- "Adding adoc: #{adoc} Asciidoctor stderr: #{adoc_stderr}"
163
- end
164
- Giblog.logger.debug { "Doc attributes: #{adoc.attributes}" }
165
-
166
- info = DocInfo.new(adoc: adoc, dst_root_abs: @paths.dst_root_abs, adoc_stderr: adoc_stderr)
167
- @processed_docs << info
168
- info
169
- end
170
-
171
- def add_doc_fail(filepath, exception)
172
- info = DocInfo.new
173
-
174
- # the only info we have is the source file name
175
- info.converted = false
176
- info.src_file = filepath.to_s
177
- info.error_msg = exception.message
178
-
179
- @processed_docs << info
180
- info
181
- end
182
-
183
- private
184
-
185
- # convert a single adoc doc to whatever the user wants
186
- def to_asciidoc(filepath)
187
- adoc = nil
188
- begin
189
- adoc_logger = Giblish::AsciidoctorLogger.new Logger::Severity::WARN
190
- adoc = @converter.convert(filepath, logger: adoc_logger)
191
-
192
- add_doc(adoc, adoc_logger.user_info_str.string)
193
- rescue Exception => e
194
- add_doc_fail(filepath, e)
195
- raise
196
- end
197
- end
198
-
199
- # predicate that decides if a path is a asciidoc file or not
200
- def adocfile?(path)
201
- fs = path.to_s
202
- unless @options[:excludeRegexp].nil?
203
- # exclude file if user wishes
204
- er = Regexp.new @options[:excludeRegexp]
205
- return false unless er.match(fs).nil?
206
- end
207
-
208
- # only include files matching the include regexp
209
- ir = Regexp.new @options[:includeRegexp]
210
- return !ir.match(fs).nil?
211
- end
212
-
213
- def manage_searchability(opts)
214
- # register the extension
215
- Giblish.register_index_heading_extension
216
-
217
- # make sure we start from a clean slate
218
- IndexHeadings.clear_index
219
-
220
- # propagate user-given id attributes to the indexing class
221
- attr = opts[:attributes]
222
- if !attr.nil?
223
- if attr.has_key?("idprefix")
224
- IndexHeadings.id_elements[:id_prefix] = attr["idprefix"]
225
- end
226
- if attr.has_key?("idseparator")
227
- IndexHeadings.id_elements[:id_separator] = attr["idseparator"]
228
- end
229
- end
230
- end
231
-
232
- # top_dir
233
- # |- web_assets
234
- # |- branch_1_top_dir
235
- # | |- index.html
236
- # | |- file1.html
237
- # | |- dir_1
238
- # | | |- file2.html
239
- # |- search_assets
240
- # | |- branch_1
241
- # | |- heading_index.json
242
- # | |- file1.adoc
243
- # | |- dir_1
244
- # | | |- file2.html
245
- # | |- ...
246
- # | |- branch_2
247
- # | | ...
248
- # |- branch_2_top_dir
249
- # | ...
250
- def create_search_assets
251
- # get the proper dir for the search assets
252
- assets_dir = @paths.search_assets_abs
253
-
254
- # store the JSON file
255
- IndexHeadings.serialize assets_dir, @paths.src_root_abs
256
-
257
- # traverse the src file tree and copy all published adoc files
258
- # to the search_assets dir
259
- Find.find(@paths.src_root_abs) do |path|
260
- p = Pathname.new(path)
261
- next unless adocfile? p
262
-
263
- dst_dir = assets_dir.join(@paths.reldir_from_src_root(p))
264
- FileUtils.mkdir_p(dst_dir)
265
- FileUtils.cp(p.to_s, dst_dir)
266
- end if @paths.src_root_abs.directory?
267
- end
268
-
269
- # Register the asciidoctor extension that handles doc ids and traverse
270
- # the source tree to collect all :docid: attributes found in document
271
- # headers.
272
- def manage_doc_ids
273
- # Register the docid preprocessor hook
274
- Giblish.register_docid_extension
275
-
276
- # Make sure that no prior docid's are hangning around
277
- DocidCollector.clear_cache
278
- DocidCollector.clear_deps
279
- idc = DocidCollector.new
280
-
281
- # traverse the src file tree and collect ids from all
282
- # .adoc or .ADOC files
283
- Find.find(@paths.src_root_abs) do |path|
284
- p = Pathname.new(path)
285
- idc.parse_file(p) if adocfile? p
286
- end if @paths.src_root_abs.directory?
287
- idc
288
- end
289
- end
290
-
291
- class GitRepoConverter < FileTreeConverter
292
- def initialize(options)
293
- super(options)
294
- # cache the top of the tree since we need to redefine the
295
- # paths per branch/tag later on.
296
- @master_paths = @paths.dup
297
- @master_deployment_info = @deploy_info.dup
298
- @git_repo_root = options[:gitRepoRoot]
299
- @git_repo = init_git_repo @git_repo_root, options[:localRepoOnly]
300
- @user_branches = select_user_branches(options[:gitBranchRegexp])
301
- @user_tags = select_user_tags(options[:gitTagRegexp])
302
- end
303
-
304
- # Convert the docs from each branch/tag and add info to the
305
- # summary page.
306
- # return true if all conversions went ok, false if at least one
307
- # failed
308
- def convert
309
- conv_error = false
310
- (@user_branches + @user_tags).each do |co|
311
- conv_error = conv_error || convert_one_checkout(co)
312
- end
313
-
314
- # Render the summary page
315
- index_builder = GitSummaryIndexBuilder.new @git_repo,
316
- @user_branches,
317
- @user_tags
318
-
319
- conv_error = conv_error || @converter.convert_str(
320
- index_builder.source,
321
- @master_paths.dst_root_abs,
322
- "index"
323
- )
324
-
325
- # clean up
326
- GC.start
327
-
328
- conv_error
329
- end
330
-
331
- protected
332
-
333
- def index_factory
334
- GitRepoIndexBuilder.new(@processed_docs, @converter, @paths, @deploy_info,
335
- @options[:resolveDocid], @options[:gitRepoRoot])
336
- end
337
-
338
- def graph_builder_factory
339
- Giblish::GitGraphBuilderGraphviz.new @processed_docs, @paths, @deploy_info,
340
- @converter.converter_options, @git_repo
341
- end
342
-
343
- def add_doc(adoc, adoc_stderr)
344
- info = super(adoc, adoc_stderr)
345
-
346
- # Redefine the srcFile to mean the relative path to the git repo root
347
- src_file = Pathname.new(info.src_file).relative_path_from(@git_repo_root).to_s
348
- # Get the commit history of the doc
349
- # (use a homegrown git log to get 'follow' flag)
350
- gi = Giblish::GitItf.new(@git_repo_root)
351
- gi.file_log(src_file).each do |i|
352
- h = DocInfo::DocHistory.new
353
- h.date = i["date"]
354
- h.message = i["message"]
355
- h.author = i["author"]
356
- info.history << h
357
- end
358
- end
359
-
360
- private
361
-
362
- def init_git_repo(git_repo_root, local_only)
363
- # Sanity check git repo root
364
- git_repo_root || raise(ArgumentError("No git repo root dir given"))
365
-
366
- # Connect to the git repo
367
- begin
368
- git_repo = Git.open(git_repo_root)
369
- rescue Exception => e
370
- raise "Could not find a git repo at #{git_repo_root} !"\
371
- "\n\n(#{e.message})"
372
- end
373
-
374
- # fetch all remote refs if ok with user
375
- begin
376
- git_repo.fetch unless local_only
377
- rescue Exception => e
378
- raise "Could not fetch from origin"\
379
- "(do you need '--local-only'?)!\n\n(#{e.message})"
380
- end
381
- git_repo
382
- end
383
-
384
- # Get the branches/tags the user wants to parse
385
- def select_user_branches(checkout_regexp)
386
- return unless @options[:gitBranchRegexp]
387
-
388
- regexp = Regexp.new checkout_regexp
389
- user_checkouts = @git_repo.branches.remote.select do |b|
390
- # match branches but remove eventual HEAD -> ... entry
391
- regexp.match b.name unless b.name =~ /^HEAD/
392
- end
393
- Giblog.logger.debug { "selected git branches: #{user_checkouts}" }
394
- user_checkouts
395
- end
396
-
397
- def select_user_tags(tag_regexp)
398
- return [] unless tag_regexp
399
-
400
- regexp = Regexp.new @options[:gitTagRegexp]
401
- tags = @git_repo.tags.select do |t|
402
- regexp.match t.name
403
- end
404
- tags
405
- end
406
-
407
- # convert all docs from one particular git commit
408
- # returns true if at least one doc failed to convert
409
- # and false if everything went ok.
410
- def convert_one_checkout(co)
411
- # determine if we are called with a tag or a branch
412
- is_tag = (co.respond_to?(:tag?) && co.tag?)
413
-
414
- Giblog.logger.info { "Checking out #{co.name}" }
415
- @git_repo.checkout co.name
416
-
417
- unless is_tag
418
- # if this is a branch, make sure it is up-to-date
419
- Giblog.logger.info { "Merging with origin/#{co.name}" }
420
- @git_repo.merge "origin/#{co.name}"
421
- end
422
-
423
- # assign a checkout-unique dst-dir
424
- dir_name = co.name.tr("/", "_") << "/"
425
-
426
- # Update needed base class members before converting a new checkout
427
- @processed_docs = []
428
- @paths.dst_root_abs = @master_paths.dst_root_abs.realpath.join(dir_name)
429
-
430
- if @options[:makeSearchable] && !@master_deployment_info.search_assets_path.nil?
431
- @paths.search_assets_abs = @master_paths.search_assets_abs.join(dir_name)
432
- @deploy_info.search_assets_path = @master_deployment_info.search_assets_path.join(dir_name)
433
- Giblog.logger.info { "will store search data in #{@paths.search_assets_abs}" }
434
- end
435
-
436
- # Parse and convert docs using given args
437
- Giblog.logger.info { "Convert docs into dir #{@paths.dst_root_abs}" }
438
- # parent_convert
439
- FileTreeConverter.instance_method(:convert).bind(self).call
440
- end
441
- end
442
- end