giblish 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -30,8 +30,9 @@ module Giblish
30
30
  # the path manager used by this converter
31
31
  attr_accessor :paths
32
32
 
33
- def initialize(paths, options)
33
+ def initialize(paths, deployment_info, options)
34
34
  @paths = paths
35
+ @deployment_info = deployment_info
35
36
  @user_style = options[:userStyle]
36
37
  @converter_options = COMMON_CONVERTER_OPTS.dup
37
38
 
@@ -168,17 +169,14 @@ module Giblish
168
169
 
169
170
  # Converts asciidoc files to html5 output.
170
171
  class HtmlConverter < DocConverter
171
- def initialize(paths, options)
172
- super paths, options
172
+ def initialize(paths, deployment_info, options)
173
+ super paths, deployment_info, options
173
174
 
174
175
  # validate that things are ok on the resource front
175
176
  # and copy if needed
176
177
  @dst_asset_dir = @paths.dst_root_abs.join("web_assets")
177
178
  validate_and_copy_resources @dst_asset_dir
178
179
 
179
- # convenience path to css dir
180
- @dst_css_dir = @dst_asset_dir.join("css")
181
-
182
180
  # identify ourselves as an html converter
183
181
  add_backend_options({backend: "html5", fileext: "html"})
184
182
  # setup the attributes specific for this converter
@@ -188,28 +186,45 @@ module Giblish
188
186
  protected
189
187
 
190
188
  def add_doc_specific_attributes(filepath, is_src_file, attributes)
191
- doc_attributes = {}
192
- if @paths.resource_dir_abs and not @web_root
193
- # user wants to use own styling without use of a
194
- # web root. the correct css link is the relative path
195
- # from the specific doc to the common css directory
196
- css_rel_dir = if is_src_file
197
- # the filepath is a src path
198
- @paths.relpath_to_dir_after_generate(
199
- filepath,
200
- @dst_css_dir
201
- )
202
- else
203
- # the given file path is the destination path of
204
- # the generated file, find the relative path to the
205
- # css dir
206
- dst_dir = PathManager.closest_dir(filepath)
207
- @dst_css_dir.relative_path_from(dst_dir)
208
- end
209
- doc_attributes["stylesdir"] = css_rel_dir.to_s
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
210
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"]}"}
211
226
 
212
- attributes.merge!(doc_attributes)
227
+ attributes.merge!(doc_attrib)
213
228
  end
214
229
 
215
230
  private
@@ -220,29 +235,6 @@ module Giblish
220
235
  html_attrib = {
221
236
  "data-uri" => 1,
222
237
  }
223
-
224
- if @paths.resource_dir_abs
225
- # user wants to use own styling, set common attributes
226
- html_attrib.merge!(
227
- {
228
- "linkcss" => 1,
229
- "stylesheet" => @user_style ||= "giblish.css",
230
- "copycss!" => 1
231
- }
232
- )
233
-
234
- # check if user wants to use a web root path
235
- @web_root = @paths.web_root_abs
236
-
237
- if @web_root
238
- # if user requested a web root to be used, the correct
239
- # css link is the relative path from the web root to the
240
- # css file. This is true for all documents
241
- wr_rel = @dst_css_dir.relative_path_from @web_root
242
- Giblog.logger.info {"Relative web root: #{wr_rel}"}
243
- html_attrib["stylesdir"] = "/" << wr_rel.to_s
244
- end
245
- end
246
238
  html_attrib
247
239
  end
248
240
 
@@ -285,8 +277,8 @@ module Giblish
285
277
  end
286
278
 
287
279
  class PdfConverter < DocConverter
288
- def initialize(paths, options)
289
- super paths, options
280
+ def initialize(paths, deployment_info, options)
281
+ super paths, deployment_info, options
290
282
 
291
283
  # identify ourselves as a pdf converter
292
284
  add_backend_options({backend: "pdf", fileext: "pdf"})
@@ -41,7 +41,18 @@ module Giblish
41
41
  # of this class for each processed file
42
42
  @heading_index = {"file_infos" => []}
43
43
 
44
+ # prio order:
45
+ # 1. values in this hash
46
+ # 2. values taken from the document
47
+ # 3. default values
48
+ @id_elements = {
49
+ # prefix: "_",
50
+ # separator: "_"
51
+ }
52
+
44
53
  class << self
54
+ attr_accessor :id_elements
55
+
45
56
  def heading_index
46
57
  @heading_index
47
58
  end
@@ -67,7 +78,7 @@ module Giblish
67
78
  end
68
79
 
69
80
  Giblog.logger.info { "writing json to #{dst_dir.join("heading_index.json").to_s}" }
70
- File.open(dst_dir.join("heading_index.json").to_s,"w") do |f|
81
+ File.open(dst_dir.join("heading_index.json").to_s, "w") do |f|
71
82
  f.write(heading_index.to_json)
72
83
  end
73
84
  end
@@ -87,6 +98,10 @@ module Giblish
87
98
  # processed the text)
88
99
  title = find_title reader.lines
89
100
 
101
+ # make sure we use the correct id elements when indexing
102
+ # sections
103
+ opts = set_id_attributes(reader.lines)
104
+
90
105
  # Index all headings in the doc
91
106
  Giblog.logger.debug { "indexing headings in #{src_path}" }
92
107
  sections = []
@@ -96,7 +111,7 @@ module Giblish
96
111
  "sections" => sections
97
112
  }
98
113
 
99
- index_sections(reader,file_info_hash)
114
+ index_sections(reader, file_info_hash, opts)
100
115
 
101
116
  heading_index["file_infos"] << file_info_hash
102
117
  reader
@@ -105,7 +120,7 @@ module Giblish
105
120
  private
106
121
 
107
122
  # build the 'sections' array
108
- def index_sections(reader, file_info_hash)
123
+ def index_sections(reader, file_info_hash, opts)
109
124
  sections = file_info_hash["sections"]
110
125
 
111
126
  heading_regex = Regexp.new(/^=+\s+(.*)$/)
@@ -137,17 +152,17 @@ module Giblish
137
152
  m = heading_regex.match(line)
138
153
  if m
139
154
  # we have an anchor and got a heading as expected, index it
140
- section = { "id" => match_str }
155
+ section = {"id" => match_str}
141
156
  section["title"] = m[1].strip
142
157
  section["line_no"] = line_no
143
158
  sections << section
144
159
  else
145
- Giblog.logger.debug {"Did not index the anchor: #{match_str} at line #{line_no}, probably not associated with a heading."}
160
+ Giblog.logger.debug { "Did not index the anchor: #{match_str} at line #{line_no}, probably not associated with a heading." }
146
161
  end
147
162
  state = :text
148
163
  when :heading
149
164
  # we got a heading without an accompanying anchor, index it
150
- section = { "id" => get_unique_id(file_info_hash, match_str) }
165
+ section = {"id" => get_unique_id(file_info_hash, match_str, opts)}
151
166
  section["title"] = m[1].strip
152
167
  section["line_no"] = line_no
153
168
  sections << section
@@ -168,8 +183,46 @@ module Giblish
168
183
  title
169
184
  end
170
185
 
171
- def get_unique_id(doc_heading_dict, heading_str)
172
- id_base = Giblish.to_valid_id(heading_str)
186
+ # id elements prio:
187
+ # 1. values in class variable
188
+ # 2. values taken from doc
189
+ # 3. default values
190
+ def set_id_attributes(lines)
191
+ # default values
192
+ result = {
193
+ id_prefix: "_",
194
+ id_separator: "_"
195
+ }
196
+
197
+ # check if the doc specifies id attributes
198
+ Giblish.process_header_lines(lines) do |line|
199
+ m = /^:idprefix:(.*)$/.match(line)
200
+ n = /^:idseparator:(.*)$/.match(line)
201
+ if m
202
+ # We found a id prefix
203
+ result[:id_prefix] = m[1].strip
204
+ end
205
+ if n
206
+ # We found a id separator
207
+ result[:id_separator] = n[1].strip
208
+ end
209
+ end
210
+
211
+
212
+ if IndexHeadings.id_elements.has_key?(:id_prefix)
213
+ result[:id_prefix] = IndexHeadings.id_elements[:id_prefix]
214
+ end
215
+
216
+ if IndexHeadings.id_elements.has_key?(:id_separator)
217
+ result[:id_separator] = IndexHeadings.id_elements[:id_separator]
218
+ end
219
+
220
+ result
221
+ end
222
+
223
+ def get_unique_id(doc_heading_dict, heading_str, opts)
224
+
225
+ id_base = Giblish.to_valid_id(heading_str, opts[:id_prefix], opts[:id_separator])
173
226
  return id_base if !doc_heading_dict.key? id_base
174
227
 
175
228
  # handle the case with several sections with the same name
@@ -190,7 +243,6 @@ module Giblish
190
243
  end
191
244
  end
192
245
 
193
-
194
246
  # Helper method to register the docid preprocessor extension with
195
247
  # the asciidoctor engine.
196
248
  def register_index_heading_extension
@@ -198,5 +250,6 @@ module Giblish
198
250
  preprocessor IndexHeadings
199
251
  end
200
252
  end
253
+
201
254
  module_function :register_index_heading_extension
202
255
  end
@@ -80,13 +80,43 @@ module Giblish
80
80
  end
81
81
  end
82
82
 
83
+ class DeploymentPaths
84
+
85
+ attr_reader :web_path
86
+
87
+ def initialize(web_path, search_asset_path)
88
+ @search_assets_path = if search_asset_path.nil?
89
+ nil
90
+ else
91
+ Pathname.new("/#{search_asset_path.to_s}").cleanpath
92
+ end
93
+ @web_path = if web_path.nil?
94
+ nil
95
+ else
96
+ Pathname.new("/#{web_path.to_s}/web_assets").cleanpath
97
+ end
98
+ end
99
+
100
+ def search_assets_path(branch_dir=nil)
101
+ if branch_dir.nil?
102
+ @search_assets_path
103
+ else
104
+ @search_assets_path.join(branch_dir)
105
+ end
106
+ end
107
+
108
+ def search_assets_path=(path)
109
+ @search_assets_path = path
110
+ end
111
+ end
112
+
83
113
  # Helper class to ease construction of different paths for input and output
84
114
  # files and directories
85
115
  class PathManager
86
116
  attr_reader :src_root_abs
87
117
  attr_reader :dst_root_abs
88
118
  attr_reader :resource_dir_abs
89
- attr_reader :web_root_abs
119
+ attr_reader :search_assets_abs
90
120
 
91
121
  # Public:
92
122
  #
@@ -96,20 +126,30 @@ module Giblish
96
126
  # tree
97
127
  # resource_dir - a string or pathname with the directory containing
98
128
  # resources
99
- def initialize(src_root, dst_root, resource_dir = nil, web_root = nil)
129
+ # create_search_asset_dir - true if this instance shall create a dir for storing
130
+ # search artefacts, false otherwise
131
+ def initialize(src_root, dst_root, resource_dir = nil,create_search_asset_dir=false)
100
132
  # Make sure that the source root exists in the file system
101
133
  @src_root_abs = Pathname.new(src_root).realpath
102
134
  self.dst_root_abs = dst_root
103
135
 
136
+ self.search_assets_abs = create_search_asset_dir ?
137
+ @dst_root_abs.join("search_assets") : nil
138
+
104
139
  # Make sure that the resource dir exists if user gives a path to it
105
140
  resource_dir && (@resource_dir_abs = Pathname.new(resource_dir).realpath)
141
+ end
106
142
 
107
- # Set web root if given by user
108
- @web_root_abs = nil
109
- if web_root
110
- web_root = "/" + web_root unless web_root[0] == '/'
111
- @web_root_abs = web_root ? Pathname.new(web_root) : nil
143
+ def search_assets_abs=(path)
144
+ if path.nil?
145
+ @search_assets_abs = nil
146
+ return
112
147
  end
148
+ # Make sure that the destination root exists and expand it to an
149
+ # absolute path
150
+ dir = Pathname.new(path)
151
+ dir.mkpath
152
+ @search_assets_abs = dir.realpath
113
153
  end
114
154
 
115
155
  def dst_root_abs=(dst_root)
@@ -174,18 +214,6 @@ module Giblish
174
214
  dir.relative_path_from(dst_abs)
175
215
  end
176
216
 
177
- def reldir_from_web_root(path)
178
- p = self.class.closest_dir path
179
- return p if @web_root_abs.nil?
180
- p.relative_path_from(@web_root_abs)
181
- end
182
-
183
- def reldir_to_web_root(path)
184
- p = self.class.closest_dir path
185
- return p if @web_root_abs.nil?
186
- @web_root_abs.relative_path_from(p)
187
- end
188
-
189
217
  def adoc_output_file(infile_path, extension)
190
218
  # Get absolute source dir path
191
219
  src_dir_abs = self.class.closest_dir infile_path
@@ -334,10 +362,10 @@ module Giblish
334
362
  module_function :with_captured_stderr
335
363
 
336
364
  # transforms strings to valid asciidoctor id strings
337
- def to_valid_id(input_str)
338
- id_str = "_#{input_str.strip.downcase}"
339
- id_str.gsub!(%r{[^a-z0-9]+},"_")
340
- id_str.chomp('_')
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)
367
+ id_str = "#{id_prefix}#{id_str}"
368
+ id_str.chomp(id_separator)
341
369
  end
342
370
  module_function :to_valid_id
343
371
 
@@ -362,32 +390,38 @@ module Giblish
362
390
  # returns raw html that displays a search box to let the user
363
391
  # acces the text search functionality.
364
392
  #
365
- # css - the name of the css file to use for the search box layout
366
- # cgi_path - the path to a cgi script that implements the server side
393
+ # css - the name of the css file to use for the search result layout
394
+ # cgi_path - the (uri) path to a cgi script that implements the server side
367
395
  # functionality of searching the text
368
- # path_manager - an instance of the path manager class to keep track of all
369
- # destinations.
370
- def generate_search_box_html(css, cgi_path, paths)
371
-
372
- # button with magnifying glass icon (not working when deployed)
373
- # <button id="search" type="submit"><i class="fa fa-search"></i></button>
396
+ # opts:
397
+ # :web_assets_top => string # the path to the 'web_assets' dir as seen when serving
398
+ # the web server (eg www.mysite.com/blah/doc_root ->
399
+ # web_assets_top shall be '/blah/doc_root')
400
+ # :search_assets_top => string # the path to where the 'heading.json' file is located (
401
+ # as seen from the local file system on the machine that
402
+ # runs the search script)
403
+ def generate_search_box_html(css, cgi_path, opts)
404
+
405
+ # Replace the button with the below to use a text-only version of the btn
406
+ # <button id="search" type="submit">Search</button>
374
407
  <<~SEARCH_INFO
375
408
  ++++
376
- <form class="example" action="#{cgi_path}" style="margin:20px 0px 20px 0px;max-width:380px">
409
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
410
+ <form class="example" action="#{cgi_path}" style="margin:20px 0px 20px 0px;max-width:790px">
377
411
  Search all documents:
378
412
  <input id="searchphrase" type="text" placeholder="Search.." name="searchphrase"/>
379
- <button id="search" type="submit">Search</button>
413
+ <button id="search" type="submit"><i class="fa fa-search"></i></button>
380
414
  <br>
381
415
 
382
416
  <input id="ignorecase" type="checkbox" value="true" name="ignorecase" checked/>
383
417
  <label for="ignorecase">Ignore Case</label>
384
418
  &nbsp;&nbsp;
385
- <input id="useregexp" type="checkbox" value="true" name="regexp"/>
419
+ <input id="useregexp" type="checkbox" value="true" name="useregexp"/>
386
420
  <label for="useregexp">Use Regexp</label>
387
421
 
388
- <input type="hidden" name="topdir" value="#{paths.dst_root_abs}"</input>
389
- <input type="hidden" name="reltop" value="#{paths.reldir_from_web_root(paths.dst_root_abs)}"</input>
390
- <input type="hidden" name="css" value="#{css}"</input>
422
+ <input type="hidden" name="searchassetstop" value="#{opts[:search_assets_top]}"</input>
423
+ <input type="hidden" name="webassetstop" value="#{opts[:web_assets_top]}"</input>
424
+ #{'<input type="hidden" name="css" value="' + css +'"</input>' unless css.nil? }
391
425
  </form>
392
426
  ++++
393
427
 
@@ -1,3 +1,3 @@
1
1
  module Giblish
2
- VERSION = "0.6.1".freeze
2
+ VERSION = "0.7.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.6.1
4
+ version: 0.7.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: 2019-11-19 00:00:00.000000000 Z
11
+ date: 2020-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -106,14 +106,14 @@ dependencies:
106
106
  requirements:
107
107
  - - ">="
108
108
  - !ruby/object:Gem::Version
109
- version: 1.5.0.beta.6
109
+ version: 1.5.0.rc.1
110
110
  type: :runtime
111
111
  prerelease: false
112
112
  version_requirements: !ruby/object:Gem::Requirement
113
113
  requirements:
114
114
  - - ">="
115
115
  - !ruby/object:Gem::Version
116
- version: 1.5.0.beta.6
116
+ version: 1.5.0.rc.1
117
117
  - !ruby/object:Gem::Dependency
118
118
  name: git
119
119
  requirement: !ruby/object:Gem::Requirement
@@ -148,15 +148,17 @@ dependencies:
148
148
  requirements:
149
149
  - - "~>"
150
150
  - !ruby/object:Gem::Version
151
- version: 0.29.1
151
+ version: 0.30.0
152
152
  type: :runtime
153
153
  prerelease: false
154
154
  version_requirements: !ruby/object:Gem::Requirement
155
155
  requirements:
156
156
  - - "~>"
157
157
  - !ruby/object:Gem::Version
158
- version: 0.29.1
159
- description: A tool for publishing asciidoc docs stored in git repos
158
+ version: 0.30.0
159
+ description: |
160
+ giblish generates indexed and searchable documents from a tree of
161
+ asciidoc files.
160
162
  email:
161
163
  - anders.rillbert@kutso.se
162
164
  executables:
@@ -168,6 +170,7 @@ files:
168
170
  - ".rubocop.yml"
169
171
  - ".ruby-version"
170
172
  - ".travis.yml"
173
+ - Changelog
171
174
  - Gemfile
172
175
  - LICENSE
173
176
  - README.adoc
@@ -181,6 +184,7 @@ files:
181
184
  - data/testdocs/wellformed/docidtest/docid_2.adoc
182
185
  - data/testdocs/wellformed/simple.adoc
183
186
  - data/testdocs/wellformed/source_highlighting/highlight_source.adoc
187
+ - docgen/resources/css/adoc-colony.css
184
188
  - docgen/resources/css/giblish.css
185
189
  - docgen/resources/fonts/Ubuntu-B.ttf
186
190
  - docgen/resources/fonts/Ubuntu-BI.ttf
@@ -191,6 +195,7 @@ files:
191
195
  - docgen/resources/images/giblish_logo.svg
192
196
  - docgen/resources/themes/giblish.yml
193
197
  - docgen/scripts/Jenkinsfile
198
+ - docgen/scripts/gen_adoc_org.sh
194
199
  - docgen/scripts/githook_examples/post-update.example
195
200
  - docs/setup_server.adoc
196
201
  - docs/setup_server_assets/Render Documents.png