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,310 +0,0 @@
1
- require "pathname"
2
- require "asciidoctor"
3
- require "asciidoctor-pdf"
4
-
5
- require_relative "utils"
6
-
7
- module Giblish
8
-
9
- # Base class for document converters. It contains a hash of
10
- # conversion options used by derived classes
11
- class DocConverter
12
- # a common set of converter options used for all output formats
13
- COMMON_CONVERTER_OPTS = {
14
- safe: Asciidoctor::SafeMode::UNSAFE,
15
- header_footer: true,
16
- mkdirs: true
17
- }.freeze
18
-
19
- # the giblish attribute defaults used if nothing else
20
- # is required by the user
21
- DEFAULT_ATTRIBUTES = {
22
- "source-highlighter" => "rouge",
23
- "xrefstyle" => "short"
24
- }.freeze
25
-
26
- # setup common options that are used regardless of the
27
- # specific output format used
28
- attr_reader :converter_options
29
-
30
- # the path manager used by this converter
31
- attr_accessor :paths
32
-
33
- def initialize(paths, deployment_info, options)
34
- @paths = paths
35
- @deployment_info = deployment_info
36
- @user_style = options[:userStyle]
37
- @converter_options = COMMON_CONVERTER_OPTS.dup
38
-
39
- # use the default options and override them with options set by
40
- # the user if applicable
41
- @converter_options[:attributes] = DEFAULT_ATTRIBUTES.dup
42
- @converter_options[:attributes].merge!(options[:attributes]) unless options[:attributes].nil?
43
- @converter_options[:backend] = options[:backend]
44
-
45
- # give derived classes the opportunity to add options and attributes
46
- add_backend_options(@converter_options)
47
- add_backend_attributes(@converter_options[:attributes])
48
- end
49
-
50
- # Public: Convert one single adoc file using the specific conversion
51
- # options.
52
- #
53
- # filepath - a pathname with the absolute path to the input file to convert
54
- #
55
- # Returns: The resulting Asciidoctor::Document object
56
- def convert(filepath, logger: nil)
57
- unless filepath.is_a?(Pathname)
58
- raise ArgumentError, "Trying to invoke convert with non-pathname!"
59
- end
60
-
61
- Giblog.logger.info {"Processing: #{filepath}"}
62
-
63
- # update the relevant options for each specific document
64
- set_common_doc_specific_options(filepath,logger)
65
-
66
- # give derived classes the opportunity to set doc specific attributes
67
- add_doc_specific_attributes(filepath,true, @converter_options[:attributes])
68
-
69
- Giblog.logger.debug {"converter_options: #{@converter_options}"}
70
-
71
- # do the actual conversion
72
- doc = Asciidoctor.convert_file filepath, @converter_options
73
-
74
- # bail out if asciidoctor failed to convert the doc
75
- if logger && logger.max_severity && logger.max_severity > Logger::Severity::WARN
76
- raise RuntimeError, "Failed to convert the file #{filepath}"
77
- end
78
- doc
79
- end
80
-
81
- # converts the supplied string to the file
82
- # dst_dir/basename.<backend-ext>
83
- #
84
- # the supplied string must pass asciidoctor without
85
- # any error to stderr, otherwise, nothing will be written
86
- # to disk.
87
- # Returns: whether any errors occured during conversion (true) or
88
- # not (false).
89
- def convert_str(src_str, dst_dir, basename,logger: nil)
90
-
91
- index_opts = @converter_options.dup
92
-
93
- # use the same options as when converting all docs
94
- # in the tree but make sure we don't write to file
95
- # by trial and error, the following dirs seem to be
96
- # necessary to change
97
- index_opts[:to_dir] = dst_dir.to_s
98
- index_opts[:base_dir] = dst_dir.to_s
99
- index_opts.delete_if {|k, _v| %i[to_file].include? k}
100
-
101
- # give derived classes the opportunity to set doc specific attributes
102
- index_filepath = dst_dir + "#{basename}.#{index_opts[:fileext]}"
103
- add_doc_specific_attributes(index_filepath,false, index_opts[:attributes])
104
-
105
- # load and convert the document using the converter options
106
- doc = nil, output = nil
107
-
108
- begin
109
- conv_error = false
110
- # set a specific logger instance to-be-used by asciidoctor
111
- index_opts[:logger] = logger unless logger.nil?
112
- doc = Asciidoctor.load src_str, index_opts
113
- output = doc.convert index_opts
114
-
115
- if logger && logger.max_severity && logger.max_severity > Logger::Severity::WARN
116
- raise RuntimeError, "Failed to convert string to asciidoc!! Will _not_ generate #{index_filepath.to_s}"
117
- end
118
-
119
- # write the converted document to an index file located at the
120
- # destination root
121
- doc.write output, index_filepath.to_s
122
- rescue Exception => e
123
- Giblog.logger.error(e)
124
- conv_error = true
125
- end
126
-
127
- conv_error
128
- end
129
-
130
- protected
131
-
132
- # Hook for specific converters to inject their own options.
133
- # The following options must be provided by the derived class:
134
- # :fileext - a string with the filename extention to use for the
135
- # generated file
136
- #
137
- # backend_options - the option dict from the backend implementation
138
- def add_backend_options(backend_options)
139
- @converter_options.merge!(backend_options)
140
- end
141
-
142
- # Hook for specific converters to inject their own attributes
143
- # valid for all conversions.
144
- # backend_attributes - the attribute dict from the backend implementation
145
- def add_backend_attributes(backend_attributes)
146
- @converter_options[:attributes].merge!(backend_attributes)
147
- end
148
-
149
- # Hook for specific converters to inject attributes on a per-doc
150
- # basis
151
- def add_doc_specific_attributes(filepath, is_src, attributes)
152
-
153
- end
154
-
155
- private
156
-
157
- def set_common_doc_specific_options(src_filepath,logger)
158
- # create an asciidoc doc object and convert to requested
159
- # output using current conversion options
160
- @converter_options[:to_dir] = @paths.adoc_output_dir(src_filepath).to_s
161
- @converter_options[:base_dir] =
162
- Giblish::PathManager.closest_dir(src_filepath).to_s
163
- @converter_options[:to_file] =
164
- Giblish::PathManager.get_new_basename(src_filepath,
165
- @converter_options[:fileext])
166
- @converter_options[:logger] = logger unless logger.nil?
167
- end
168
- end
169
-
170
- # Converts asciidoc files to html5 output.
171
- class HtmlConverter < DocConverter
172
- def initialize(paths, deployment_info, options)
173
- super paths, deployment_info, options
174
-
175
- # validate that things are ok on the resource front
176
- # and copy if needed
177
- @dst_asset_dir = @paths.dst_root_abs.join("web_assets")
178
- validate_and_copy_resources @dst_asset_dir
179
-
180
- # identify ourselves as an html converter
181
- add_backend_options({backend: "html5", fileext: "html"})
182
- # setup the attributes specific for this converter
183
- add_backend_attributes(get_common_attributes)
184
- end
185
-
186
- protected
187
-
188
- def add_doc_specific_attributes(filepath, is_src_file, attributes)
189
- doc_attrib = {}
190
- if @paths.resource_dir_abs
191
- # user has given a resource dir, use the css from that dir
192
- doc_attrib.merge!(
193
- {
194
- "linkcss" => 1,
195
- "stylesheet" => @user_style ||= "giblish.css",
196
- "copycss!" => 1
197
- }
198
- )
199
- if @deployment_info.web_path.nil?
200
- # user wants to deploy without web server, the css
201
- # link shall thus be the relative path from the
202
- # generated doc to the css directory
203
- dst_css_dir = @dst_asset_dir.join("css")
204
- css_rel_dir = if is_src_file
205
- # the filepath is a src path
206
- @paths.relpath_to_dir_after_generate(
207
- filepath,
208
- dst_css_dir
209
- )
210
- else
211
- # the given file path is the destination path of
212
- # the generated file, find the relative path to the
213
- # css dir
214
- dst_dir = PathManager.closest_dir(filepath)
215
- dst_css_dir.relative_path_from(dst_dir)
216
- end
217
- doc_attrib["stylesdir"] = css_rel_dir.to_s
218
- else
219
- # user has given a web deployment path, the css shall then
220
- # be linked using that path
221
- doc_attrib["stylesdir"] = @deployment_info.web_path.join("css").cleanpath.to_s
222
- end
223
- end
224
- Giblog.logger.debug {"Rendered docs expect a css at: #{doc_attrib["stylesdir"]}"}
225
- Giblog.logger.debug {"The expected css is named: #{doc_attrib["stylesheet"]}"}
226
-
227
- attributes.merge!(doc_attrib)
228
- end
229
-
230
- private
231
-
232
- def get_common_attributes
233
- # Setting 'data-uri' makes asciidoctor embed images in the resulting
234
- # html file
235
- html_attrib = {
236
- "data-uri" => 1,
237
- }
238
- html_attrib
239
- end
240
-
241
- def copy_resource_dir(dst_dir)
242
- # create assets_dir and copy everything in the resource dir
243
- # to the destination
244
- Dir.exist?(dst_dir) || FileUtils.mkdir_p(dst_dir)
245
-
246
- # copy all subdirs that exist in the source tree to the
247
- # dst tree
248
- %i[css fonts images].each do |dir|
249
- src = "#{@paths.resource_dir_abs}/#{dir}"
250
- Dir.exist?(src) && FileUtils.copy_entry(src, "#{dst_dir}/#{dir}")
251
- end
252
- end
253
-
254
- # make as sure as we can that the user has given a
255
- # directory with valid resources
256
- def validate_and_copy_resources(dst_dir)
257
- # we don't have a resource path, which is fine, use
258
- # defaults
259
- return nil unless @paths.resource_dir_abs
260
-
261
- # If user has requested the use of a specific css, use that,
262
- # otherwise use asciidoctor default css
263
- if @user_style
264
- # Make sure that a user supplied stylesheet ends with .css or .CSS
265
- @user_style && @user_style =
266
- /\.(css|CSS)$/ =~ @user_style ? @user_style : "#{@user_style}.css"
267
-
268
- # bail out if we can not find the given css file
269
- src_css_path = @paths.resource_dir_abs.
270
- join("css").join(Pathname.new(@user_style))
271
- raise RuntimeError, "Could not find the specified " +
272
- "css file at: #{src_css_path}" unless src_css_path.exist?
273
- end
274
-
275
- copy_resource_dir dst_dir
276
- end
277
- end
278
-
279
- class PdfConverter < DocConverter
280
- def initialize(paths, deployment_info, options)
281
- super paths, deployment_info, options
282
-
283
- # identify ourselves as a pdf converter
284
- add_backend_options({backend: "pdf", fileext: "pdf"})
285
- # setup the attributes specific for this converter
286
- add_backend_attributes(setup_pdf_attribs)
287
- end
288
-
289
- private
290
-
291
- def setup_pdf_attribs()
292
- # only set this up if user has specified a resource dir
293
- return {} unless @paths.resource_dir_abs
294
-
295
- pdf_attrib = {
296
- "pdf-stylesdir" => "#{@paths.resource_dir_abs}/themes",
297
- "pdf-style" => "giblish.yml",
298
- "pdf-fontsdir" => "#{@paths.resource_dir_abs}/fonts",
299
- "icons" => "font"
300
- }
301
-
302
- # Make sure that the stylesheet ends with .yml or YML
303
- @user_style &&
304
- pdf_attrib["pdf-style"] =
305
- /\.(yml|YML)$/ =~ @user_style ? @user_style : "#{@user_style}.yml"
306
-
307
- pdf_attrib
308
- end
309
- end
310
- end
data/lib/giblish/docid.rb DELETED
@@ -1,188 +0,0 @@
1
-
2
- require_relative "./utils"
3
- require "asciidoctor"
4
- require "asciidoctor/extensions"
5
-
6
- module Giblish
7
- # Parse all adoc files for :docid: attributes
8
- class DocidCollector < Asciidoctor::Extensions::Preprocessor
9
- # Use a class-global docid_cache since asciidoctor creates a new instance
10
- # for each preprocessor hook
11
- # a hash of {doc_id => Pathname(src_path)}
12
- @docid_cache = {}
13
-
14
- # A class-global hash of {src_path => [target doc_ids] }
15
- @docid_deps = {}
16
-
17
- class << self
18
- def docid_cache
19
- @docid_cache
20
- end
21
-
22
- def docid_deps
23
- @docid_deps
24
- end
25
-
26
- def clear_cache
27
- @docid_cache = {}
28
- end
29
-
30
- def clear_deps
31
- @docid_deps = {}
32
- end
33
- end
34
-
35
- # The minimum number of characters required for a valid doc id
36
- ID_MIN_LENGTH = 2
37
-
38
- # The maximum number of characters required for a valid doc id
39
- ID_MAX_LENGTH = 10
40
-
41
- # Note: I don't know how to hook into the 'initialize' or if I should
42
- # let this be, currently it is disabled...
43
- # def initialize(*everything)
44
- # super(everything)
45
- # end
46
-
47
- # Check if a :docid: <id> entry exists in the header.
48
- # According to http://www.methods.co.nz/asciidoc/userguide.html#X95
49
- # the header is optional, but if it exists it:
50
- # - must start with a titel (=+ <My Title>)
51
- # - ends with one or more blank lines
52
- # - does not contain any blank line
53
- def parse_file(path)
54
- Giblog.logger.debug { "parsing file #{path} for docid..." }
55
- Giblish.process_header_lines_from_file(path) do |line|
56
- m = /^:docid: +(.*)$/.match(line)
57
- if m
58
- # There is a docid defined, cache the path and doc id
59
- validate_and_add m[1], path
60
- end
61
- end
62
- end
63
-
64
- # add a new source document to the docid_deps
65
- def add_source_dep(src_path)
66
- return if docid_deps.key? src_path
67
- docid_deps[src_path] = []
68
- end
69
-
70
- # This hook is called by Asciidoctor once for each document _before_
71
- # Asciidoctor processes the adoc content.
72
- #
73
- # It replaces references of the format <<:docid: ID-1234,Hello >> with
74
- # references to a resolved relative path.
75
- def process(document, reader)
76
- # Add doc as a source dependency for doc ids
77
- src_path = document.attributes["docfile"]
78
-
79
- # Note: the nil check is there to prevent us adding generated
80
- # asciidoc docs that does not exist in the file system (e.g. the
81
- # generated index pages). This is a bit hackish and should maybe be
82
- # done differently
83
- return if src_path.nil?
84
-
85
- add_source_dep src_path
86
-
87
- # Convert all docid refs to valid relative refs
88
- reader.lines.each do |line|
89
- line.gsub!(/<<\s*:docid:\s*(.*?)>>/) do |_m|
90
- # parse the ref
91
- target_id, section, display_str =
92
- parse_doc_id_ref Regexp.last_match(1)
93
-
94
- # The result is a valid ref in the form
95
- # <<target_doc.adoc#[section][,display_str]>>
96
- Giblog.logger.debug { "Replace docid ref in doc #{src_path}..." }
97
- if docid_cache.key? target_id
98
- # add the referenced doc id as a target dependency of this document
99
- docid_deps[src_path] << target_id
100
- docid_deps[src_path] = docid_deps[src_path].uniq
101
-
102
- # resolve the doc id ref to a valid relative path
103
- "<<#{get_rel_path(src_path, target_id)}##{section}#{display_str}>>"
104
- else
105
- "<<UNKNOWN_DOC, Could not resolve doc id reference !!!>>"
106
- end
107
- end
108
- end
109
- reader
110
- end
111
-
112
- private
113
-
114
- # Helper method to shorten calls to docid_cache from instance methods
115
- def docid_cache
116
- self.class.docid_cache
117
- end
118
-
119
- def docid_deps
120
- self.class.docid_deps
121
- end
122
-
123
- # Get the relative path from the src doc to the
124
- # doc with the given doc id
125
- def get_rel_path(src_path, doc_id)
126
- unless docid_cache.key? doc_id
127
- raise ArgumentError("unknown doc id: #{doc_id}")
128
- end
129
-
130
- rel_path = docid_cache[doc_id]
131
- .dirname
132
- .relative_path_from(Pathname.new(src_path).dirname) +
133
- docid_cache[doc_id].basename
134
- rel_path.to_s
135
- end
136
-
137
- # input_str shall be the expression between
138
- # <<:docid:<input_str>>> where the <input_str> is in the form
139
- # <id>[#section][,display_str]
140
- #
141
- # returns an array with [id, section, display_str]
142
- def parse_doc_id_ref(input_str)
143
- ref, display_str = input_str.split(",").each(&:strip)
144
- id, section = ref.split "#"
145
-
146
- display_str = id.dup if display_str.nil?
147
- display_str.prepend ","
148
-
149
- section = "" if section.nil?
150
-
151
- [id, section, display_str]
152
- end
153
-
154
- # make sure the id is within the designated length and
155
- # does not contain a '#' symbol
156
- def doc_id_ok?(doc_id)
157
- (doc_id.length.between?(ID_MIN_LENGTH, ID_MAX_LENGTH) &&
158
- !doc_id.include?("#"))
159
- end
160
-
161
- def validate_and_add(doc_id, path)
162
- id = doc_id.strip
163
- Giblog.logger.debug { "found possible docid: #{id}" }
164
-
165
- unless doc_id_ok? doc_id
166
- Giblog.logger.error { "Invalid docid: #{id} in file #{path}, this will be ignored!" }
167
- return
168
- end
169
-
170
- if docid_cache.key? id
171
- Giblog.logger.warn { "Found same doc id twice (#{id})." }
172
- Giblog.logger.warn { "Assigning this id to the file #{path}." }
173
- Giblog.logger.warn { "Discarding this id from the file #{docid_cache[id]}." }
174
- end
175
- docid_cache[id] = Pathname(path)
176
- end
177
- end
178
-
179
-
180
- # Helper method to register the docid preprocessor extension with
181
- # the asciidoctor engine.
182
- def register_docid_extension
183
- Asciidoctor::Extensions.register do
184
- preprocessor DocidCollector
185
- end
186
- end
187
- module_function :register_docid_extension
188
- end
@@ -1,100 +0,0 @@
1
- require "pathname"
2
-
3
- module Giblish
4
- # Container class for bundling together the data we cache for
5
- # each asciidoc file we come across
6
- class DocInfo
7
- # Cache git info
8
- class DocHistory
9
- attr_accessor :date
10
- attr_accessor :author
11
- attr_accessor :message
12
- end
13
-
14
- attr_accessor :converted
15
- attr_accessor :doc_id
16
- attr_accessor :purpose_str
17
- attr_accessor :status
18
- attr_accessor :history
19
- attr_accessor :error_msg
20
- attr_accessor :stderr
21
-
22
- # these members can have encoding issues when
23
- # running in a mixed Windows/Linux setting.
24
- # that is why we explicitly encodes them when
25
- # writing to them
26
- def title
27
- @title
28
- end
29
- def title=(rhs)
30
- @title = rhs.nil? ? nil : rhs.encode("utf-8")
31
- end
32
- def rel_path
33
- @rel_path
34
- end
35
- # attr_accessor :rel_path
36
- def src_file
37
- @src_file
38
- end
39
- def src_file=(rhs)
40
- @src_file = rhs.nil? ? nil : rhs.encode("utf-8")
41
- end
42
- # attr_accessor :src_file
43
-
44
- # def relPath_utf8
45
- # return nil if @rel_path.nil?
46
- # @rel_path.to_s.encode("utf-8")
47
- # end
48
- #
49
- # def srcFile_utf8
50
- # return nil if @src_file.nil?
51
- # @src_file.to_s.encode("utf-8")
52
- # end
53
-
54
- def initialize(adoc: nil, dst_root_abs: nil, adoc_stderr: "")
55
- @src_file = nil
56
- @history = []
57
- @converted = true
58
- @stderr = adoc_stderr
59
- return unless adoc
60
-
61
- # Get the purpose info if it exists
62
- @purpose_str = get_purpose_info adoc
63
-
64
- # fill in doc meta data
65
- d_attr = adoc.attributes
66
- self.src_file=(d_attr["docfile"])
67
- self.title=(adoc.doctitle)
68
- @doc_id = d_attr["docid"]
69
- return if dst_root_abs.nil?
70
-
71
- # Get the relative path beneath the root dir to the doc
72
- @rel_path = Pathname.new(
73
- "#{d_attr['outdir']}/#{d_attr['docname']}#{d_attr['docfilesuffix']}".encode("utf-8")
74
- ).relative_path_from(dst_root_abs)
75
- end
76
-
77
- def to_s
78
- "DocInfo: title: #{@title} src_file: #{@src_file}"
79
- end
80
-
81
- private
82
-
83
- def get_purpose_info(adoc)
84
- # Get the 'Purpose' section if it exists
85
- purpose_str = ""
86
- adoc.blocks.each do |section|
87
- next unless section.is_a?(Asciidoctor::Section) &&
88
- (section.level == 1) &&
89
- (section.name =~ /^Purpose$/)
90
-
91
- # filter out 'odd' text, such as lists etc...
92
- section.blocks.each do |bb|
93
- next unless bb.is_a?(Asciidoctor::Block)
94
- purpose_str << "#{bb.source}\n+\n"
95
- end
96
- end
97
- purpose_str
98
- end
99
- end
100
- end