giblish 0.4.0 → 0.5.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a6a7fc123856a6321bbad8b7f8f527490a09faa9df0ebeeb1a984bbda4b22d78
4
- data.tar.gz: 2788cc7789ed4046307d9d4a7ad75be7f7b0f12c30a1b559500b18166602e966
3
+ metadata.gz: d917c8b6c513f7759aecbbdb5a93a7cb13cb5774d66ccf0d602a615248723f76
4
+ data.tar.gz: b94be771b19dd5890e238ffc0ee0ee5af361919c0e526d63ac4f380b4f6698a0
5
5
  SHA512:
6
- metadata.gz: 2ea03abe46dd0e23c06266e8b1a9bc444811931825a2155e9545ae911d9527fd7ad993d18287fd2ad5b7ce6a0e51ce40421d2c01454ec357161300969d7bdf57
7
- data.tar.gz: 308d7306d39641442e17fa7b5a1687e8f7ae473e438c6eabf3ffbb3650521b091e15a8b0ed36700cb41cad917fbcd9c3f95646b38d2d4199c112eaa75b00ca7b
6
+ metadata.gz: 4c9f6b75a6266c65baf0e7876016139703b7b46677fea2dcee54b9ad95b23c04756c8b9383398cdd8055c91e78ea3d275c7968eeabf1154478a44b76faf6c27c
7
+ data.tar.gz: c7cb03e7fe95cdf3a13a74c36f0d5efbb06e49828ff04db05b5d231f098bb411ab34584067e03b7a3b93c025224d3d93ccd13366e951fe93826cfdafeaae1bd9
data/.gitignore CHANGED
@@ -48,3 +48,6 @@ build-iPhoneSimulator/
48
48
 
49
49
  # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
50
  .rvmrc
51
+
52
+ # RubyMine idea files
53
+ /.idea/
@@ -1,7 +1,7 @@
1
1
  = giblish
2
2
  Generate docs from asciidoc files in a git repo
3
3
 
4
- image::https://travis-ci.com/rillbert/giblish.svg?branch=master[build status]
4
+ image::https://travis-ci.org/rillbert/giblish.svg?branch=master["Build Status", link="https://travis-ci.org/rillbert/giblish"]
5
5
 
6
6
  == Purpose
7
7
 
data/Rakefile CHANGED
@@ -10,9 +10,7 @@ end
10
10
  Rake::TestTask.new(:current) do |t|
11
11
  t.libs << "test"
12
12
  t.libs << "lib"
13
- t.test_files = FileList["test/**/docid_test.rb"]
14
- # t.test_files = FileList["test/**/index_heading_test.rb"]
15
- # t.test_files = FileList["test/**/depgraph_test.rb"]
13
+ t.test_files = FileList["test/**/index_heading_test.rb"]
16
14
  end
17
15
 
18
16
  Rake::TestTask.new(:sandbox) do |t|
@@ -5,14 +5,13 @@
5
5
  == Purpose
6
6
 
7
7
  To test the basic functionality of document id references.
8
- This paragraph can be referenced as <<:docid:WF-013#Purpose,This paragraph>>.
9
8
 
10
9
  Other valid docid references::
11
10
 
12
- * << :docid:WF-013,Using space before>>
13
- * << :docid: WF-013,Using space and tabs>>
14
- * <<:docid:WF-013#Testing Document ids>> No title but hash and section.
15
- * <<:docid:WF-013>> No title and no hash
11
+ * << :docid:WF-022,Using space before>>
12
+ * << :docid: WF-022,Using space and tabs>>
13
+ * <<:docid:WF-022#Testing Document ids>> No title but hash and section.
14
+ * <<:docid:WF-022>> No title and no hash
16
15
  * <<:docid:WF-022,docid_2 adoc>> Another document within the tree.
17
16
  * <<:docid:WF-022#Purpose, Purpose in WF-022>> Reference a section in another document
18
17
  * <<:docid:WF-022>> Two references on the same line <<:docid:WF-013>>.
@@ -30,17 +30,19 @@ Gem::Specification.new do |spec|
30
30
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
31
  spec.require_paths = ["lib"]
32
32
 
33
- spec.add_development_dependency "bundler", "~> 1.11"
33
+ spec.add_development_dependency "bundler", "~> 2.0"
34
34
  spec.add_development_dependency "minitest", "~> 5.0"
35
- spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rake", "~> 11.0"
36
+ spec.add_development_dependency "oga", "~> 2.15"
36
37
 
37
38
  # Usage: spec.add_runtime_dependency "[gem name]", [[version]]
38
- spec.add_runtime_dependency "asciidoctor", "~>1.5", ">= 1.5.8"
39
+ spec.add_runtime_dependency "asciidoctor", "~>2.0", ">= 2.0.10"
39
40
  spec.add_runtime_dependency "asciidoctor-diagram", ["~> 1.5"]
40
- spec.add_runtime_dependency "asciidoctor-pdf", [">= 1.5.0.alpha.16"]
41
- spec.add_runtime_dependency "asciidoctor-rouge", ["~> 0.3"]
41
+ spec.add_runtime_dependency "asciidoctor-pdf", [">= 1.5.0.alpha.18"]
42
42
  spec.add_runtime_dependency "git", "~> 1.3"
43
+ spec.add_runtime_dependency "rouge", "~> 3.3"
43
44
  # needed by asciidoctor-pdf, see instructions at
44
45
  # https://github.com/asciidoctor/asciidoctor-pdf/releases
45
- spec.add_runtime_dependency "prawn-svg", "~> 0.27.1"
46
+ # spec.add_runtime_dependency "prawn-svg", "~> 0.27.1"
47
+ spec.add_runtime_dependency "prawn-svg", "~> 0.29.1"
46
48
  end
@@ -31,21 +31,22 @@ module Giblish
31
31
  Giblog.logger.debug { "cmd line args: #{cmdline.args}" }
32
32
 
33
33
  # Convert using given args
34
+ conv_error = false
34
35
  begin
35
36
  if cmdline.args[:gitRepoRoot]
36
37
  Giblog.logger.info { "User asked to parse a git repo" }
37
38
  gc = GitRepoConverter.new cmdline.args
38
- gc.convert
39
+ conv_error = gc.convert
39
40
  else
40
41
  tc = FileTreeConverter.new cmdline.args
41
- tc.convert
42
+ conv_error = tc.convert
42
43
  end
43
44
  Giblog.logger.info { "Giblish is done!" }
44
- 0
45
45
  rescue Exception => e
46
46
  log_error e
47
- 1
47
+ conv_error = true
48
48
  end
49
+ conv_error ? 1 : 0
49
50
  end
50
51
 
51
52
  private
@@ -172,12 +172,11 @@ module Giblish
172
172
  def generate_conversion_info(d)
173
173
  return "" if d.stderr.empty?
174
174
  # extract conversion warnings from asciddoctor std err
175
- conv_warnings = d.stderr.gsub("asciidoctor:", "\n * asciidoctor:")
176
- Giblog.logger.warn {"Conversion warnings: #{conv_warnings}"}
175
+ conv_warnings = d.stderr.gsub(/^/, " * ")
177
176
 
178
177
  # assemble info to index page
179
178
  <<~CONV_INFO
180
- Conversion info::
179
+ Conversion issues::
181
180
 
182
181
  #{conv_warnings}
183
182
  CONV_INFO
@@ -205,15 +204,15 @@ module Giblish
205
204
  end
206
205
 
207
206
  # Generate an adoc string that will display as
208
- # DocTitle (warn) details
207
+ # DocTitle (conv issues) details
209
208
  # Where the DocTitle and details are links to the doc itself and a section
210
209
  # identified with the doc's title respectively.
211
210
  def tree_entry_converted(prefix_str, doc_info)
212
211
  # Get the elements of the entry
213
212
  doc_title, doc_link, doc_details = format_title_and_ref doc_info
214
- warning_label = doc_info.stderr.empty? ? "" : "(warn)"
213
+ warning_label = doc_info.stderr.empty? ? "" : "(conv issues)"
215
214
 
216
- # Calculate padding to get (warn) and details aligned between entries
215
+ # Calculate padding to get (conv issues) and details aligned between entries
217
216
  padding = 70
218
217
  [doc_title, prefix_str, warning_label].each {|p| padding -= p.length}
219
218
  padding = 0 unless padding.positive?
@@ -34,11 +34,11 @@ class CmdLineParser
34
34
  -i --include <regexp> include only files with a filename that matches the supplied
35
35
  regexp (defaults to '.*\.(?i)adoc$' meaning it matches all
36
36
  files ending in .adoc case-insensitive). The matching is made
37
- on the _file name only_, not the full path (i.e. for the full
37
+ on the _file name only_, not the full path (i.e. for the full
38
38
  path /my/file.adoc, only file.adoc is used in the matching).
39
- -j --exclude <regexp> exclude files with filenames matching the supplied
39
+ -j --exclude <regexp> exclude files with filenames matching the supplied
40
40
  regexp (no files are excluded by default). The matching is made
41
- on the _file name only_, not the full path (i.e. for the full
41
+ on the _file name only_, not the full path (i.e. for the full
42
42
  path /my/file.adoc, only file.adoc is used in the matching).
43
43
  -w --web-root <path> Specifies the top dir (DirectoryRoot) of a file system
44
44
  tree published by a web server. This switch is only used
@@ -57,13 +57,18 @@ class CmdLineParser
57
57
  branch on origin_.
58
58
  NOTE 2: In bash, use double quotes around your regexp if
59
59
  you need to quote it. Single quotes are treated as part
60
- of the regexp itself.
60
+ of the regexp itself.
61
61
  -t --git-tags <regExp> if the source_dir_top is located within a git repo,
62
62
  generate docs for all tags that matches the given
63
63
  regular expression. Each tag will be generated to
64
64
  a separate subdir under the destination root dir.
65
- -c --local-only do not try to fetch git info from any remotes of the
66
- repo before generating documents.
65
+ -c --local-only do not try to fetch git info from any remotes of
66
+ the repo before generating documents.
67
+ -a --attribute <key>=<value> set a document or asciidoctor attribute.
68
+ The contents of this flag is passed directly to the
69
+ underlying asciidoctor tool, for details above the
70
+ syntax and available attributes, see the documentation for
71
+ asciidoctor. This option can be specified more than once.
67
72
  -d --resolve-docid use two passes, the first to collect :docid:
68
73
  attributes in the doc headers, the second to
69
74
  generate the documents and use the collected
@@ -71,26 +76,26 @@ class CmdLineParser
71
76
  generated documents
72
77
  -m --make-searchable (only supported for html generation)
73
78
  take steps to make it possible to
74
- search the published content via a cgi-script. This
79
+ search the published content via a cgi-script. This
75
80
  flag will do the following:
76
81
  1. index all headings in all source files and store
77
82
  the result in a JSON file
78
83
  2. copy the JSON file and all source (adoc) files to
79
84
  a 'search_assets' folder in the top-level dir of
80
85
  the destination.
81
- 3. add html code that displays a search field in the
86
+ 3. add html code that displays a search field in the
82
87
  index page that will try to call the cgi-script
83
- 'giblish-search' when the user inputs some text.
84
- To actually provide search functionality for a user, you
88
+ 'giblish-search' when the user inputs some text.
89
+ To actually provide search functionality for a user, you
85
90
  need to provide the cgi-script and configure your web-server
86
- to invoke it when needed. NOTE: The generated search box cgi
87
- is currently hard-coded to look for the cgi script at the URL:
91
+ to invoke it when needed. NOTE: The generated search box cgi
92
+ is currently hard-coded to look for the cgi script at the URL:
88
93
  http://<your-web-domain>/cgi-bin/giblish-search.cgi
89
94
  E.g.
90
95
  http://example.com/cgi-bin/giblish-search.cgi
91
96
  An implementation of the giblish-search cgi-script is found
92
- within the lib folder of this gem, you can copy that to your
93
- cgi-bin dir in your webserver and rename it from .rb to .cgi
97
+ within the lib folder of this gem, you can copy that to your
98
+ cgi-bin dir in your webserver and rename it from .rb to .cgi
94
99
  --log-level set the log level explicitly. Must be one of
95
100
  debug, info (default), warn, error or fatal.
96
101
  ENDHELP
@@ -110,15 +115,10 @@ ENDHELP
110
115
  exit 0
111
116
  end
112
117
 
113
- # set log level
118
+ # act on the parsed cmd line args
114
119
  set_log_level
115
120
  sanity_check_input
116
121
  set_gitrepo_root
117
- # if @args[:logfile]
118
- # $stdout.reopen( ARGS[:logfile], "w" )
119
- # $stdout.sync = true
120
- # $stderr.reopen( $stdout )
121
- # end
122
122
  end
123
123
 
124
124
  def usage
@@ -185,6 +185,7 @@ ENDHELP
185
185
  when "-g", "--git-branches" then next_arg = :gitBranchRegexp
186
186
  when "-t", "--git-tags" then next_arg = :gitTagRegexp
187
187
  when "-c", "--local-only" then @args[:localRepoOnly] = true
188
+ when "-a", "--attribute" then next_arg = :attributes
188
189
  when "-d", "--resolve-docid" then @args[:resolveDocid] = true
189
190
  when "-m", "--make-searchable" then @args[:make_searchable] = true
190
191
  when "-s", "--style" then next_arg = :userStyle
@@ -192,7 +193,12 @@ ENDHELP
192
193
  when "--log-level" then next_arg = :logLevel
193
194
  else
194
195
  if next_arg
195
- @args[next_arg] = arg
196
+ if next_arg == :attributes
197
+ # support multiple invocations of -a
198
+ add_attribute arg
199
+ else
200
+ @args[next_arg] = arg
201
+ end
196
202
  unflagged_args.delete(next_arg)
197
203
  end
198
204
  next_arg = unflagged_args.first
@@ -200,6 +206,19 @@ ENDHELP
200
206
  end
201
207
  end
202
208
 
209
+ # adds the str (must be in key=value format) to the
210
+ # user defined attributes
211
+ def add_attribute(attrib_str)
212
+ kv = attrib_str.split('=')
213
+ if kv.length != 2
214
+ puts "Invalid attribute format: #{attrib_str} Must be <key>=<value>"
215
+ exit 1
216
+ end
217
+
218
+ @args[:attributes] ||= {}
219
+ @args[:attributes][kv[0]] = kv[1]
220
+ end
221
+
203
222
  def prevent_invalid_combos
204
223
  # Prevent contradicting options
205
224
  if !@args[:resourceDir] && @args[:userStyle]
@@ -36,6 +36,10 @@ module Giblish
36
36
  @search_assets_path = @paths.dst_root_abs.realpath.join("search_assets")
37
37
  end
38
38
 
39
+
40
+ # convert all adoc files
41
+ # return true if all conversions went ok, false if at least one
42
+ # failed
39
43
  def convert
40
44
  # collect all doc ids and enable replacement of known doc ids with
41
45
  # valid references to adoc files
@@ -46,38 +50,53 @@ module Giblish
46
50
 
47
51
  # traverse the src file tree and convert all files deemed as
48
52
  # adoc files
53
+ conv_error = false
49
54
  Find.find(@paths.src_root_abs) do |path|
50
55
  p = Pathname.new(path)
51
- to_asciidoc(p) if adocfile? p
56
+ begin
57
+ to_asciidoc(p) if adocfile? p
58
+ rescue Exception => e
59
+ str = "Error when converting file #{path.to_s}: #{e.message}\nBacktrace:\n"
60
+ e.backtrace.each {|l| str << " #{l}\n"}
61
+ Giblog.logger.error {str}
62
+ conv_error = true
63
+ end
52
64
  end if @paths.src_root_abs.directory?
53
65
 
54
66
  # create necessary search assets if needed
55
67
  create_search_assets if @options[:make_searchable]
56
68
 
57
- # check if we shall build index or not
58
- return if @options[:suppressBuildRef]
59
-
60
- # build a dependency graph (only if we resolve docids...)
61
- dep_graph_exist = if @options[:resolveDocid]
62
- if Giblish::GraphBuilderGraphviz.supported
63
- gb = Giblish::GraphBuilderGraphviz.new @processed_docs, @paths, {extension: @converter.converter_options[:fileext]}
64
- @converter.convert_str gb.source, @paths.dst_root_abs, "graph"
69
+ # build index and other fancy stuff if not suppressed
70
+ unless @options[:suppressBuildRef]
71
+ # build a dependency graph (only if we resolve docids...)
72
+ dep_graph_exist = if @options[:resolveDocid]
73
+ if Giblish::GraphBuilderGraphviz.supported
74
+ gb = Giblish::GraphBuilderGraphviz.new @processed_docs, @paths, {extension: @converter.converter_options[:fileext]}
75
+ @converter.convert_str(gb.source, @paths.dst_root_abs, "graph")
76
+ else
77
+ Giblog.logger.warn { "Lacking access to needed tools for generating a visual dependency graph." }
78
+ Giblog.logger.warn { "The dependency graph will not be generated !!" }
79
+ false
80
+ end
65
81
  else
66
- Giblog.logger.warn { "Lacking access to needed tools for generating a visual dependency graph." }
67
- Giblog.logger.warn { "The dependency graph will not be generated !!" }
68
82
  false
69
83
  end
70
- else
71
- false
72
- end
73
84
 
74
- # build a reference index
75
- ib = index_factory
76
- @converter.convert_str ib.source(dep_graph_exist,@options[:make_searchable]), @paths.dst_root_abs, "index"
77
-
78
- # clean up cached files and adoc resources
79
- remove_diagram_temps if dep_graph_exist
80
- GC.start
85
+ # build a reference index
86
+ adoc_logger = Giblish::AsciidoctorLogger.new Logger::Severity::WARN
87
+ ib = index_factory
88
+ @converter.convert_str(
89
+ ib.source(
90
+ dep_graph_exist,@options[:make_searchable]
91
+ ),
92
+ @paths.dst_root_abs, "index",
93
+ logger: adoc_logger)
94
+
95
+ # clean up cached files and adoc resources
96
+ remove_diagram_temps if dep_graph_exist
97
+ GC.start
98
+ end
99
+ conv_error
81
100
  end
82
101
 
83
102
  protected
@@ -148,19 +167,13 @@ module Giblish
148
167
  def to_asciidoc(filepath)
149
168
  adoc = nil
150
169
  begin
151
- # do the conversion and capture eventual errors that
152
- # the asciidoctor lib writes to stderr
153
- adoc_stderr = Giblish.with_captured_stderr do
154
- adoc = @converter.convert filepath
155
- end
170
+ adoc_logger = Giblish::AsciidoctorLogger.new Logger::Severity::WARN
171
+ adoc = @converter.convert(filepath,logger: adoc_logger)
156
172
 
157
- add_doc(adoc, adoc_stderr)
173
+ add_doc(adoc, adoc_logger.user_info_str.string)
158
174
  rescue Exception => e
159
- str = "Error when converting doc: #{e.message}\n"
160
- e.backtrace.each {|l| str << "#{l}\n"}
161
- Giblog.logger.error {str}
162
-
163
175
  add_doc_fail(filepath, e)
176
+ raise
164
177
  end
165
178
  end
166
179
 
@@ -258,20 +271,31 @@ module Giblish
258
271
  @user_tags = select_user_tags(options[:gitTagRegexp])
259
272
  end
260
273
 
261
- # Render the docs from each branch/tag and add info to the
262
- # summary page
274
+ # Convert the docs from each branch/tag and add info to the
275
+ # summary page.
276
+ # return true if all conversions went ok, false if at least one
277
+ # failed
263
278
  def convert
279
+ conv_error = false
264
280
  (@user_branches + @user_tags).each do |co|
265
- convert_one_checkout co
281
+ conv_error = conv_error || convert_one_checkout(co)
266
282
  end
267
283
 
268
284
  # Render the summary page
269
285
  index_builder = GitSummaryIndexBuilder.new @git_repo,
270
286
  @user_branches,
271
287
  @user_tags
272
- @converter.convert_str index_builder.source, @master_paths.dst_root_abs, "index"
288
+
289
+ conv_error = conv_error || @converter.convert_str(
290
+ index_builder.source,
291
+ @master_paths.dst_root_abs,
292
+ "index"
293
+ )
294
+
273
295
  # clean up
274
296
  GC.start
297
+
298
+ conv_error
275
299
  end
276
300
 
277
301
  protected
@@ -345,6 +369,9 @@ module Giblish
345
369
  tags
346
370
  end
347
371
 
372
+ # convert all docs from one particular git commit
373
+ # returns true if at least one doc failed to convert
374
+ # and false if everything went ok.
348
375
  def convert_one_checkout(co)
349
376
  # determine if we are called with a tag or a branch
350
377
  is_tag = (co.respond_to?(:tag?) && co.tag?)
@@ -31,13 +31,15 @@ module Giblish
31
31
  attr_accessor :paths
32
32
 
33
33
  def initialize(paths, options)
34
- # access the source highlight module
35
- require "asciidoctor-rouge"
36
-
37
34
  @paths = paths
38
35
  @user_style = options[:userStyle]
39
36
  @converter_options = COMMON_CONVERTER_OPTS.dup
37
+
38
+ # use the default options and override them with options set by
39
+ # the user if applicable
40
40
  @converter_options[:attributes] = DEFAULT_ATTRIBUTES.dup
41
+ @converter_options[:attributes].merge!(options[:attributes]) unless options[:attributes].nil?
42
+
41
43
  @converter_options[:backend] = options[:backend]
42
44
  end
43
45
 
@@ -47,7 +49,7 @@ module Giblish
47
49
  # filepath - a pathname with the absolute path to the input file to convert
48
50
  #
49
51
  # Returns: The resulting Asciidoctor::Document object
50
- def convert(filepath)
52
+ def convert(filepath, logger: nil)
51
53
  unless filepath.is_a?(Pathname)
52
54
  raise ArgumentError, "Trying to invoke convert with non-pathname!"
53
55
  end
@@ -63,10 +65,18 @@ module Giblish
63
65
  Giblish::PathManager.get_new_basename(filepath,
64
66
  @converter_options[:fileext])
65
67
 
68
+ # set a specific logger instance to-be-used by asciidoctor
69
+ @converter_options[:logger] = logger unless logger.nil?
70
+
66
71
  Giblog.logger.debug {"converter_options: #{@converter_options}"}
67
72
 
68
73
  # do the actual conversion
69
- Asciidoctor.convert_file filepath, @converter_options
74
+ doc = Asciidoctor.convert_file filepath, @converter_options
75
+
76
+ if logger && logger.max_severity && logger.max_severity > Logger::Severity::WARN
77
+ raise RuntimeError, "Failed to convert the file #{filepath}"
78
+ end
79
+ doc
70
80
  end
71
81
 
72
82
  # converts the supplied string to the file
@@ -75,8 +85,9 @@ module Giblish
75
85
  # the supplied string must pass asciidoctor without
76
86
  # any error to stderr, otherwise, nothing will be written
77
87
  # to disk.
78
- # returns 'true' if a file was written, 'false' if not
79
- def convert_str(src_str, dst_dir, basename)
88
+ # Returns: whether any errors occured during conversion (true) or
89
+ # not (false).
90
+ def convert_str(src_str, dst_dir, basename,logger: nil)
80
91
  index_opts = @converter_options.dup
81
92
 
82
93
  # use the same options as when converting all docs
@@ -89,27 +100,29 @@ module Giblish
89
100
 
90
101
  # load and convert the document using the converter options
91
102
  doc = nil, output = nil
92
- adoc_stderr = Giblish.with_captured_stderr do
103
+
104
+ begin
105
+ conv_error = false
106
+ # set a specific logger instance to-be-used by asciidoctor
107
+ index_opts[:logger] = logger unless logger.nil?
93
108
  doc = Asciidoctor.load src_str, index_opts
94
109
  output = doc.convert index_opts
95
- end
96
110
 
97
- index_filepath = dst_dir + "#{basename}.#{index_opts[:fileext]}"
111
+ index_filepath = dst_dir + "#{basename}.#{index_opts[:fileext]}"
98
112
 
99
- # if we get anything from asciidoctor to stderr,
100
- # consider this a failure and do not emit a file.
101
- if !adoc_stderr.length.zero?
102
- Giblog.logger.error {"Errors when converting string to asciidoc!!"}
103
- Giblog.logger.error {"Will _not_ generate file #{index_filepath.to_s}"}
104
- Giblog.logger.error {"Got following warnings/errors from asciidoc conversion:"}
105
- Giblog.logger.error {adoc_stderr}
106
- return false
113
+ if logger && logger.max_severity && logger.max_severity > Logger::Severity::WARN
114
+ raise RuntimeError, "Failed to convert string to asciidoc!! Will _not_ generate #{index_filepath.to_s}"
115
+ end
116
+ rescue Exception => e
117
+ Giblog.logger.error(e)
118
+ conv_error = true
107
119
  end
108
120
 
121
+
109
122
  # write the converted document to an index file located at the
110
123
  # destination root
111
124
  doc.write output, index_filepath.to_s
112
- true
125
+ conv_error
113
126
  end
114
127
 
115
128
  protected
@@ -10,7 +10,7 @@ module Giblish
10
10
  # Asciidoctor processes the adoc content.
11
11
  #
12
12
  # It indexes all headings found in all documents in the tree.
13
- # The resulting index can be serialized to a JSON file file
13
+ # The resulting index can be serialized to a JSON file
14
14
  # with the following format:
15
15
  #
16
16
  # {
@@ -96,27 +96,66 @@ module Giblish
96
96
  "sections" => sections
97
97
  }
98
98
 
99
- # build the 'sections' array
100
- line_no = 1
101
- regex = Regexp.new(/^=+\s+(.*)$/)
99
+ index_sections(reader,file_info_hash)
100
+
101
+ heading_index["file_infos"] << file_info_hash
102
+ reader
103
+ end
104
+
105
+ private
106
+
107
+ # build the 'sections' array
108
+ def index_sections(reader, file_info_hash)
109
+ sections = file_info_hash["sections"]
110
+
111
+ heading_regex = Regexp.new(/^=+\s+(.*)$/)
112
+ anchor_regex = Regexp.new(/^\[\[(\w+)\]\]\s*$/)
113
+
114
+ line_no = 0
115
+ m = nil
116
+ match_str = ""
117
+ state = :text
102
118
  reader.lines.each do |line|
103
- m = regex.match(line)
104
- if m
105
- # We found a heading, index it
106
- section = { "id" => get_unique_id(file_info_hash, m[1]) }
119
+ line_no += 1
120
+ # implement a state machine that supports both custom
121
+ # anchors for a heading and the default heading ids generated
122
+ # by asciidoctor
123
+ case state
124
+ when :text
125
+ m = heading_regex.match(line)
126
+ if m
127
+ state = :heading
128
+ match_str = m[1]
129
+ else
130
+ m = anchor_regex.match(line)
131
+ if m
132
+ state = :expecting_heading
133
+ match_str = m[1]
134
+ end
135
+ end
136
+ when :expecting_heading
137
+ m = heading_regex.match(line)
138
+ if m
139
+ # we have an anchor and got a heading as expected, index it
140
+ section = { "id" => match_str }
141
+ section["title"] = m[1].strip
142
+ section["line_no"] = line_no
143
+ sections << section
144
+ else
145
+ Giblog.logger.debug {"Did not index the anchor: #{match_str} at line #{line_no}, probably not associated with a heading."}
146
+ end
147
+ state = :text
148
+ when :heading
149
+ # we got a heading without an accompanying anchor, index it
150
+ section = { "id" => get_unique_id(file_info_hash, match_str) }
107
151
  section["title"] = m[1].strip
108
152
  section["line_no"] = line_no
109
153
  sections << section
154
+ state = :text
110
155
  end
111
- line_no += 1
112
156
  end
113
-
114
- heading_index["file_infos"] << file_info_hash
115
- reader
116
157
  end
117
158
 
118
- private
119
-
120
159
  def find_title(lines)
121
160
  title = "No title Found!"
122
161
  Giblish.process_header_lines(lines) do |line|
@@ -2,13 +2,20 @@ require "logger"
2
2
  require "pathname"
3
3
  require "fileutils"
4
4
 
5
+ class GiblogFormatter
6
+ def call severity, datetime, progname, msg
7
+ "#{datetime.strftime('%H:%M:%S')} #{severity} - #{msg}\n"
8
+ end
9
+ end
10
+
5
11
  class Giblog
6
12
  def self.setup
7
13
  return if defined? @logger
8
14
  @logger = Logger.new(STDOUT)
9
- @logger.formatter = proc do |severity, datetime, _progname, msg|
10
- "#{datetime.strftime('%H:%M:%S')} #{severity} - #{msg}\n"
11
- end
15
+ @logger.formatter = GiblogFormatter.new
16
+ # @logger.formatter = proc do |severity, datetime, _progname, msg|
17
+ # "#{datetime.strftime('%H:%M:%S')} #{severity} - #{msg}\n"
18
+ # end
12
19
  end
13
20
 
14
21
  def self.logger
@@ -21,8 +28,58 @@ class Giblog
21
28
  end
22
29
  end
23
30
 
31
+
32
+
24
33
  # Public: Contains a number of generic utility methods.
25
34
  module Giblish
35
+
36
+ class UserInfoFormatter
37
+ SEVERITY_LABELS = { 'WARN' => 'WARNING', 'FATAL' => 'FAILED' }
38
+
39
+ # {:text=>"...",
40
+ # :source_location=>#<Asciidoctor::Reader::Cursor:0x000055e65a8729e0
41
+ # @file="<full adoc filename>",
42
+ # @dir="<full src dir>",
43
+ # @path="<only file name>",
44
+ # @lineno=<src line no>
45
+ # }
46
+ def call severity, datetime, progname, msg
47
+ message = case msg
48
+ when ::String
49
+ msg
50
+ when ::Hash
51
+ # asciidoctor seem to emit a hash with error text and source location info
52
+ # for warnings and errors
53
+ str = ""
54
+ str << "Line #{msg[:source_location].lineno.to_s} - " if msg[:source_location]
55
+ str << "#{msg[:text].to_s}" if msg[:text]
56
+ str
57
+ else
58
+ msg.inspect
59
+ end
60
+ %(#{datetime.strftime('%H:%M:%S')} #{progname}: #{SEVERITY_LABELS[severity] || severity}: #{message}\n)
61
+ end
62
+ end
63
+ class AsciidoctorLogger < ::Logger
64
+
65
+ attr_reader :max_severity
66
+ attr_reader :user_info_str
67
+
68
+ def initialize user_info_log_level
69
+ super(STDOUT,progname: "(from asciidoctor)", formatter: UserInfoFormatter.new)
70
+ @user_info_str = StringIO.new
71
+ @user_info_logger = ::Logger.new(@user_info_str, formatter: UserInfoFormatter.new, level: user_info_log_level)
72
+ end
73
+
74
+ def add severity, message = nil, progname = nil
75
+ if (severity ||= UNKNOWN) > (@max_severity ||= severity)
76
+ @max_severity = severity
77
+ end
78
+ @user_info_logger.add(severity,message,progname)
79
+ super
80
+ end
81
+ end
82
+
26
83
  # Helper class to ease construction of different paths for input and output
27
84
  # files and directories
28
85
  class PathManager
@@ -161,7 +218,7 @@ module Giblish
161
218
  return p if git_dir.directory?
162
219
  end
163
220
  end
164
- end
221
+ end # end of PathManager
165
222
 
166
223
  # Helper method that provides the user with a way of processing only the
167
224
  # lines within the asciidoc header block.
@@ -1,3 +1,3 @@
1
1
  module Giblish
2
- VERSION = "0.4.0".freeze
2
+ VERSION = "0.5.2".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: giblish
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anders Rillbert
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-03-17 00:00:00.000000000 Z
11
+ date: 2019-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.11'
19
+ version: '2.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.11'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,34 +44,48 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '11.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: '11.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: oga
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.15'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.15'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: asciidoctor
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: '1.5'
75
+ version: '2.0'
62
76
  - - ">="
63
77
  - !ruby/object:Gem::Version
64
- version: 1.5.8
78
+ version: 2.0.10
65
79
  type: :runtime
66
80
  prerelease: false
67
81
  version_requirements: !ruby/object:Gem::Requirement
68
82
  requirements:
69
83
  - - "~>"
70
84
  - !ruby/object:Gem::Version
71
- version: '1.5'
85
+ version: '2.0'
72
86
  - - ">="
73
87
  - !ruby/object:Gem::Version
74
- version: 1.5.8
88
+ version: 2.0.10
75
89
  - !ruby/object:Gem::Dependency
76
90
  name: asciidoctor-diagram
77
91
  requirement: !ruby/object:Gem::Requirement
@@ -92,56 +106,56 @@ dependencies:
92
106
  requirements:
93
107
  - - ">="
94
108
  - !ruby/object:Gem::Version
95
- version: 1.5.0.alpha.16
109
+ version: 1.5.0.alpha.18
96
110
  type: :runtime
97
111
  prerelease: false
98
112
  version_requirements: !ruby/object:Gem::Requirement
99
113
  requirements:
100
114
  - - ">="
101
115
  - !ruby/object:Gem::Version
102
- version: 1.5.0.alpha.16
116
+ version: 1.5.0.alpha.18
103
117
  - !ruby/object:Gem::Dependency
104
- name: asciidoctor-rouge
118
+ name: git
105
119
  requirement: !ruby/object:Gem::Requirement
106
120
  requirements:
107
121
  - - "~>"
108
122
  - !ruby/object:Gem::Version
109
- version: '0.3'
123
+ version: '1.3'
110
124
  type: :runtime
111
125
  prerelease: false
112
126
  version_requirements: !ruby/object:Gem::Requirement
113
127
  requirements:
114
128
  - - "~>"
115
129
  - !ruby/object:Gem::Version
116
- version: '0.3'
130
+ version: '1.3'
117
131
  - !ruby/object:Gem::Dependency
118
- name: git
132
+ name: rouge
119
133
  requirement: !ruby/object:Gem::Requirement
120
134
  requirements:
121
135
  - - "~>"
122
136
  - !ruby/object:Gem::Version
123
- version: '1.3'
137
+ version: '3.3'
124
138
  type: :runtime
125
139
  prerelease: false
126
140
  version_requirements: !ruby/object:Gem::Requirement
127
141
  requirements:
128
142
  - - "~>"
129
143
  - !ruby/object:Gem::Version
130
- version: '1.3'
144
+ version: '3.3'
131
145
  - !ruby/object:Gem::Dependency
132
146
  name: prawn-svg
133
147
  requirement: !ruby/object:Gem::Requirement
134
148
  requirements:
135
149
  - - "~>"
136
150
  - !ruby/object:Gem::Version
137
- version: 0.27.1
151
+ version: 0.29.1
138
152
  type: :runtime
139
153
  prerelease: false
140
154
  version_requirements: !ruby/object:Gem::Requirement
141
155
  requirements:
142
156
  - - "~>"
143
157
  - !ruby/object:Gem::Version
144
- version: 0.27.1
158
+ version: 0.29.1
145
159
  description: A tool for publishing asciidoc docs stored in git repos
146
160
  email:
147
161
  - anders.rillbert@kutso.se