giblish 0.7.6 → 0.8.0

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.
@@ -1,5 +1,3 @@
1
- #!/usr/bin/env ruby
2
-
3
1
  # This class can convert the following paths:
4
2
  # basedir/file_1
5
3
  # basedir/file_2
@@ -19,8 +17,7 @@
19
17
  # dir3
20
18
  # file_5
21
19
  class PathTree
22
- attr_reader :name
23
- attr_reader :data
20
+ attr_reader :name, :data
24
21
 
25
22
  def initialize(tail = nil, data = nil)
26
23
  @children = []
@@ -37,7 +34,7 @@ class PathTree
37
34
  end
38
35
  end
39
36
 
40
- def add_path(tail,data = nil)
37
+ def add_path(tail, data = nil)
41
38
  tail = tail.split("/") unless tail.is_a?(Array)
42
39
  return if tail.empty?
43
40
 
data/lib/giblish/utils.rb CHANGED
@@ -2,22 +2,24 @@ 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"
5
+ # The logger used from within giblish
6
+ class Giblog
7
+ # Defines the format for log messages from giblish.
8
+ class GiblogFormatter
9
+ def call(severity, datetime, _progname, msg)
10
+ "#{datetime.strftime('%H:%M:%S')} #{severity} - #{msg}\n"
11
+ end
8
12
  end
9
- end
10
13
 
11
- class Giblog
14
+ # bootstrap the application-wide logger object
12
15
  def self.setup
13
16
  return if defined? @logger
14
- @logger = Logger.new(STDOUT)
17
+
18
+ @logger = Logger.new($stdout)
15
19
  @logger.formatter = GiblogFormatter.new
16
- # @logger.formatter = proc do |severity, datetime, _progname, msg|
17
- # "#{datetime.strftime('%H:%M:%S')} #{severity} - #{msg}\n"
18
- # end
19
20
  end
20
21
 
22
+ # returns the application-wide logger instance.
21
23
  def self.logger
22
24
  unless defined? @logger
23
25
  puts "!!!! Error: Trying to access logger before setup !!!!"
@@ -28,76 +30,81 @@ class Giblog
28
30
  end
29
31
  end
30
32
 
31
-
32
-
33
33
  # Public: Contains a number of generic utility methods.
34
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
35
+ # a logger customized to process info received from asciidoctors
36
+ # stdout.
63
37
  class AsciidoctorLogger < ::Logger
38
+ # log formatter specialized for formatting messages from
39
+ # asciidoctor's stdout
40
+ class UserInfoFormatter
41
+ SEVERITY_LABELS = { "WARN" => "WARNING", "FATAL" => "FAILED" }.freeze
42
+
43
+ # The hash that can be emitted as the msg from asciidoctor have the
44
+ # following format:
45
+ # {:text=>"...",
46
+ # :source_location=>#<Asciidoctor::Reader::Cursor:0x000055e65a8729e0
47
+ # @file="<full adoc filename>",
48
+ # @dir="<full src dir>",
49
+ # @path="<only file name>",
50
+ # @lineno=<src line no>
51
+ # }
52
+ def call(severity, datetime, progname, msg)
53
+ message = case msg
54
+ when ::String
55
+ msg
56
+ when ::Hash
57
+ # asciidoctor seem to emit a hash with error text and source location info
58
+ # for warnings and errors
59
+ str = String.new("")
60
+ src_loc = msg.fetch(:source_location, nil)
61
+ err_txt = msg.fetch(:text, nil)
62
+ str << "Line #{src_loc.lineno} - " if src_loc
63
+ str << err_txt.to_s if err_txt
64
+ str
65
+ else
66
+ msg.inspect
67
+ end
68
+ %(#{datetime.strftime('%H:%M:%S')} #{progname}: #{SEVERITY_LABELS[severity] || severity}: #{message}\n)
69
+ end
70
+ end
64
71
 
65
- attr_reader :max_severity
66
- attr_reader :user_info_str
72
+ attr_reader :max_severity, :user_info_str
67
73
 
68
- def initialize user_info_log_level
69
- super(STDOUT,progname: "(from asciidoctor)", formatter: UserInfoFormatter.new)
74
+ def initialize(user_info_log_level)
75
+ super($stdout, progname: "(from asciidoctor)", formatter: UserInfoFormatter.new)
70
76
  @user_info_str = StringIO.new
71
77
  @user_info_logger = ::Logger.new(@user_info_str, formatter: UserInfoFormatter.new, level: user_info_log_level)
72
78
  end
73
79
 
74
- def add severity, message = nil, progname = nil
80
+ def add(severity, message = nil, progname = nil)
75
81
  if (severity ||= UNKNOWN) > (@max_severity ||= severity)
76
82
  @max_severity = severity
77
83
  end
78
- @user_info_logger.add(severity,message,progname)
84
+ @user_info_logger.add(severity, message, progname)
79
85
  super
80
86
  end
81
87
  end
82
88
 
89
+ # returns the paths to the search assets and web assets
90
+ # in the deployment machine's file system.
83
91
  class DeploymentPaths
84
-
85
92
  attr_reader :web_path
86
93
 
87
94
  def initialize(web_path, search_asset_path)
88
95
  @search_assets_path = if search_asset_path.nil?
89
96
  nil
90
97
  else
91
- Pathname.new("/#{search_asset_path.to_s}").cleanpath
98
+ Pathname.new("/#{search_asset_path}").cleanpath
92
99
  end
93
100
  @web_path = if web_path.nil?
94
101
  nil
95
102
  else
96
- Pathname.new("/#{web_path.to_s}/web_assets").cleanpath
103
+ Pathname.new("/#{web_path}/web_assets").cleanpath
97
104
  end
98
105
  end
99
106
 
100
- def search_assets_path(branch_dir=nil)
107
+ def search_assets_path(branch_dir = nil)
101
108
  if branch_dir.nil?
102
109
  @search_assets_path
103
110
  else
@@ -105,18 +112,13 @@ module Giblish
105
112
  end
106
113
  end
107
114
 
108
- def search_assets_path=(path)
109
- @search_assets_path = path
110
- end
115
+ attr_writer :search_assets_path
111
116
  end
112
117
 
113
118
  # Helper class to ease construction of different paths for input and output
114
119
  # files and directories
115
120
  class PathManager
116
- attr_reader :src_root_abs
117
- attr_reader :dst_root_abs
118
- attr_reader :resource_dir_abs
119
- attr_reader :search_assets_abs
121
+ attr_reader :src_root_abs, :dst_root_abs, :resource_dir_abs, :search_assets_abs
120
122
 
121
123
  # Public:
122
124
  #
@@ -128,13 +130,12 @@ module Giblish
128
130
  # resources
129
131
  # create_search_asset_dir - true if this instance shall create a dir for storing
130
132
  # search artefacts, false otherwise
131
- def initialize(src_root, dst_root, resource_dir = nil,create_search_asset_dir=false)
133
+ def initialize(src_root, dst_root, resource_dir = nil, create_search_asset_dir = false)
132
134
  # Make sure that the source root exists in the file system
133
135
  @src_root_abs = Pathname.new(src_root).realpath
134
136
  self.dst_root_abs = dst_root
135
137
 
136
- self.search_assets_abs = create_search_asset_dir ?
137
- @dst_root_abs.join("search_assets") : nil
138
+ self.search_assets_abs = (@dst_root_abs.join("search_assets") if create_search_asset_dir)
138
139
 
139
140
  # Make sure that the resource dir exists if user gives a path to it
140
141
  resource_dir && (@resource_dir_abs = Pathname.new(resource_dir).realpath)
@@ -208,7 +209,7 @@ module Giblish
208
209
  # return the relative path from a generated document to
209
210
  # the supplied folder given the corresponding absolute source
210
211
  # file path
211
- def relpath_to_dir_after_generate(src_filepath,dir_path)
212
+ def relpath_to_dir_after_generate(src_filepath, dir_path)
212
213
  dst_abs = dst_abs_from_src_abs(src_filepath)
213
214
  dir = self.class.to_pathname(dir_path)
214
215
  dir.relative_path_from(dst_abs)
@@ -281,7 +282,7 @@ module Giblish
281
282
  # - the directory itself when called with an existing directory
282
283
  # - the parent dir when called with a non-existing file/directory
283
284
  def self.closest_dir(in_path)
284
- sr = self.to_pathname(in_path)
285
+ sr = to_pathname(in_path)
285
286
  if sr.exist?
286
287
  sr.directory? ? sr.realpath : sr.dirname.realpath
287
288
  else
@@ -303,7 +304,7 @@ module Giblish
303
304
  return p if git_dir.directory?
304
305
  end
305
306
  end
306
- end # end of PathManager
307
+ end
307
308
 
308
309
  # Helper method that provides the user with a way of processing only the
309
310
  # lines within the asciidoc header block.
@@ -345,7 +346,7 @@ module Giblish
345
346
  # end
346
347
  def process_header_lines_from_file(path)
347
348
  lines = File.readlines(path)
348
- process_header_lines(lines,&Proc.new)
349
+ process_header_lines(lines, &Proc.new)
349
350
  end
350
351
  module_function :process_header_lines_from_file
351
352
 
@@ -362,8 +363,8 @@ module Giblish
362
363
  module_function :with_captured_stderr
363
364
 
364
365
  # transforms strings to valid asciidoctor id strings
365
- def to_valid_id(input_str,id_prefix="_", id_separator="_")
366
- id_str = input_str.strip.downcase.gsub(%r{[^a-z0-9]+}, id_separator)
366
+ def to_valid_id(input_str, id_prefix = "_", id_separator = "_")
367
+ id_str = input_str.strip.downcase.gsub(/[^a-z0-9]+/, id_separator)
367
368
  id_str = "#{id_prefix}#{id_str}"
368
369
  id_str.chomp(id_separator)
369
370
  end
@@ -375,18 +376,17 @@ module Giblish
375
376
  # Ex
376
377
  # which('ruby') #=> /usr/bin/ruby
377
378
  def which(cmd)
378
- exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
379
- ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
380
- exts.each { |ext|
379
+ exts = ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [""]
380
+ ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
381
+ exts.each do |ext|
381
382
  exe = File.join(path, "#{cmd}#{ext}")
382
383
  return exe if File.executable?(exe) && !File.directory?(exe)
383
- }
384
+ end
384
385
  end
385
- return nil
386
+ nil
386
387
  end
387
388
  module_function :which
388
389
 
389
-
390
390
  # returns raw html that displays a search box to let the user
391
391
  # acces the text search functionality.
392
392
  #
@@ -401,14 +401,13 @@ module Giblish
401
401
  # as seen from the local file system on the machine that
402
402
  # runs the search script)
403
403
  def generate_search_box_html(css, cgi_path, opts)
404
-
405
404
  # Replace the button with the below to use a text-only version of the btn
406
405
  # <button id="search" type="submit">Search</button>
407
406
  <<~SEARCH_INFO
408
407
  ++++
409
408
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
410
409
  <form class="example" action="#{cgi_path}" style="margin:20px 0px 20px 0px;max-width:790px">
411
- Search all documents:
410
+ Search all documents:
412
411
  <input id="searchphrase" type="text" placeholder="Search.." name="searchphrase"/>
413
412
  <button id="search" type="submit"><i class="fa fa-search"></i></button>
414
413
  <br>
@@ -421,12 +420,11 @@ module Giblish
421
420
 
422
421
  <input type="hidden" name="searchassetstop" value="#{opts[:search_assets_top]}"</input>
423
422
  <input type="hidden" name="webassetstop" value="#{opts[:web_assets_top]}"</input>
424
- #{'<input type="hidden" name="css" value="' + css +'"</input>' unless css.nil? }
423
+ #{%(<input type="hidden" name="css" value="#{css}"</input>) unless css.nil?}
425
424
  </form>
426
425
  ++++
427
426
 
428
427
  SEARCH_INFO
429
428
  end
430
429
  module_function :generate_search_box_html
431
-
432
430
  end
@@ -1,3 +1,3 @@
1
1
  module Giblish
2
- VERSION = "0.7.6".freeze
2
+ VERSION = "0.8.0".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.7.6
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anders Rillbert
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-04 00:00:00.000000000 Z
11
+ date: 2021-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.20.3
83
+ - !ruby/object:Gem::Dependency
84
+ name: asciidoctor-mathematical
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.3.5
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.3.5
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: asciidoctor
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -89,7 +103,7 @@ dependencies:
89
103
  version: '2.0'
90
104
  - - ">="
91
105
  - !ruby/object:Gem::Version
92
- version: 2.0.10
106
+ version: 2.0.16
93
107
  type: :runtime
94
108
  prerelease: false
95
109
  version_requirements: !ruby/object:Gem::Requirement
@@ -99,83 +113,83 @@ dependencies:
99
113
  version: '2.0'
100
114
  - - ">="
101
115
  - !ruby/object:Gem::Version
102
- version: 2.0.10
116
+ version: 2.0.16
103
117
  - !ruby/object:Gem::Dependency
104
118
  name: asciidoctor-diagram
105
119
  requirement: !ruby/object:Gem::Requirement
106
120
  requirements:
107
121
  - - "~>"
108
122
  - !ruby/object:Gem::Version
109
- version: '1.5'
123
+ version: '2.1'
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: '1.5'
130
+ version: '2.1'
117
131
  - !ruby/object:Gem::Dependency
118
132
  name: asciidoctor-pdf
119
133
  requirement: !ruby/object:Gem::Requirement
120
134
  requirements:
121
135
  - - "~>"
122
136
  - !ruby/object:Gem::Version
123
- version: '1.5'
137
+ version: '1.6'
124
138
  - - ">="
125
139
  - !ruby/object:Gem::Version
126
- version: 1.5.3
140
+ version: 1.6.0
127
141
  type: :runtime
128
142
  prerelease: false
129
143
  version_requirements: !ruby/object:Gem::Requirement
130
144
  requirements:
131
145
  - - "~>"
132
146
  - !ruby/object:Gem::Version
133
- version: '1.5'
147
+ version: '1.6'
134
148
  - - ">="
135
149
  - !ruby/object:Gem::Version
136
- version: 1.5.3
150
+ version: 1.6.0
137
151
  - !ruby/object:Gem::Dependency
138
152
  name: git
139
153
  requirement: !ruby/object:Gem::Requirement
140
154
  requirements:
141
155
  - - "~>"
142
156
  - !ruby/object:Gem::Version
143
- version: '1.7'
157
+ version: '1.9'
144
158
  type: :runtime
145
159
  prerelease: false
146
160
  version_requirements: !ruby/object:Gem::Requirement
147
161
  requirements:
148
162
  - - "~>"
149
163
  - !ruby/object:Gem::Version
150
- version: '1.7'
164
+ version: '1.9'
151
165
  - !ruby/object:Gem::Dependency
152
166
  name: rouge
153
167
  requirement: !ruby/object:Gem::Requirement
154
168
  requirements:
155
169
  - - "~>"
156
170
  - !ruby/object:Gem::Version
157
- version: '3.24'
171
+ version: '3.0'
158
172
  type: :runtime
159
173
  prerelease: false
160
174
  version_requirements: !ruby/object:Gem::Requirement
161
175
  requirements:
162
176
  - - "~>"
163
177
  - !ruby/object:Gem::Version
164
- version: '3.24'
178
+ version: '3.0'
165
179
  - !ruby/object:Gem::Dependency
166
180
  name: prawn-svg
167
181
  requirement: !ruby/object:Gem::Requirement
168
182
  requirements:
169
183
  - - "~>"
170
184
  - !ruby/object:Gem::Version
171
- version: 0.30.0
185
+ version: 0.32.0
172
186
  type: :runtime
173
187
  prerelease: false
174
188
  version_requirements: !ruby/object:Gem::Requirement
175
189
  requirements:
176
190
  - - "~>"
177
191
  - !ruby/object:Gem::Version
178
- version: 0.30.0
192
+ version: 0.32.0
179
193
  description: |
180
194
  giblish generates indexed and searchable documents from a tree of
181
195
  asciidoc files.
@@ -258,14 +272,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
258
272
  requirements:
259
273
  - - ">="
260
274
  - !ruby/object:Gem::Version
261
- version: '2.3'
275
+ version: '2.7'
262
276
  required_rubygems_version: !ruby/object:Gem::Requirement
263
277
  requirements:
264
278
  - - ">="
265
279
  - !ruby/object:Gem::Version
266
280
  version: '0'
267
281
  requirements: []
268
- rubygems_version: 3.0.1
282
+ rubygems_version: 3.1.6
269
283
  signing_key:
270
284
  specification_version: 4
271
285
  summary: A tool for publishing asciidoc docs stored in git repos