giblish 0.2.7 → 0.2.8
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 +4 -4
- data/data/testdocs/wellformed/adorned_purpose.adoc +17 -0
- data/giblish.gemspec +8 -5
- data/lib/giblish/buildindex.rb +34 -14
- data/lib/giblish/core.rb +15 -7
- data/lib/giblish/gititf.rb +92 -0
- data/lib/giblish/utils.rb +3 -3
- data/lib/giblish/version.rb +1 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ce62a2152e7a0d0f5a9b238503148ea15ab5801
|
4
|
+
data.tar.gz: 91650c824ddc81f807a59730f0daacec2892e154
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6623e343fcad2aa0c20217c18998825a84a5c20d5216da49629e0e63992a50cfc257cf4c489583e00ec159e9fc9bc129803fd680e543349ce105ae2c25f7ed23
|
7
|
+
data.tar.gz: 38aa18b7a25dad7c91bd43872a5862fd81ff7e9623f9b9fd31f2ff8347b68e7a7b55b2a80d182b796d5839272f34a0d7224fe539a71dc16a1b88e36aaed316f1
|
@@ -0,0 +1,17 @@
|
|
1
|
+
= Testing the 'purpose' section
|
2
|
+
:toc:
|
3
|
+
:docid: WF-002
|
4
|
+
:numbered:
|
5
|
+
|
6
|
+
== Purpose
|
7
|
+
|
8
|
+
To test how asciidoc formatting in the *_purpose_* section are shown in the index page.
|
9
|
+
|
10
|
+
List item::
|
11
|
+
Item one
|
12
|
+
|
13
|
+
* Unordered item 1
|
14
|
+
* Unordered item 2
|
15
|
+
|
16
|
+
. Ordered item 1
|
17
|
+
. Ordered item 2
|
data/giblish.gemspec
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
|
2
|
+
|
3
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
|
5
|
+
|
6
|
+
require "giblish/version"
|
5
7
|
|
6
8
|
Gem::Specification.new do |spec|
|
7
9
|
spec.name = "giblish"
|
@@ -9,10 +11,11 @@ Gem::Specification.new do |spec|
|
|
9
11
|
spec.authors = ["Anders Rillbert"]
|
10
12
|
spec.email = ["anders.rillbert@kutso.se"]
|
11
13
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
-
spec.homepage = "
|
14
|
+
spec.summary = "A tool for publishing asciidoc docs stored in git repos"
|
15
|
+
spec.description = "A tool for publishing asciidoc docs stored in git repos"
|
16
|
+
spec.homepage = "https://github.com/rillbert/giblish"
|
15
17
|
spec.license = "MIT"
|
18
|
+
spec.required_ruby_version = ">= 2.3"
|
16
19
|
|
17
20
|
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
21
|
# delete this section to allow pushing this gem to any host.
|
data/lib/giblish/buildindex.rb
CHANGED
@@ -5,6 +5,7 @@ require "pathname"
|
|
5
5
|
require "git"
|
6
6
|
require_relative "cmdline"
|
7
7
|
require_relative "pathtree"
|
8
|
+
require_relative "gititf"
|
8
9
|
|
9
10
|
# Container class for bundling together the data we cache for
|
10
11
|
# each asciidoc file we come across
|
@@ -39,11 +40,12 @@ end
|
|
39
40
|
# Base class with common functionality for all index builders
|
40
41
|
class BasicIndexBuilder
|
41
42
|
# set up the basic index building info
|
42
|
-
def initialize(path_manager)
|
43
|
+
def initialize(path_manager, handle_docid = false)
|
43
44
|
@paths = path_manager
|
44
45
|
@nof_missing_titles = 0
|
45
46
|
@added_docs = []
|
46
47
|
@src_str = ""
|
48
|
+
@manage_docid = handle_docid
|
47
49
|
end
|
48
50
|
|
49
51
|
# creates a DocInfo instance, fills it with basic info and
|
@@ -57,9 +59,6 @@ class BasicIndexBuilder
|
|
57
59
|
info.converted = true
|
58
60
|
info.stderr = adoc_stderr
|
59
61
|
|
60
|
-
# Get the doc id if it exists
|
61
|
-
info.doc_id = adoc.attributes["docid"]
|
62
|
-
|
63
62
|
# Get the purpose info if it exists
|
64
63
|
info.purpose_str = get_purpose_info adoc
|
65
64
|
|
@@ -71,9 +70,19 @@ class BasicIndexBuilder
|
|
71
70
|
@paths.dst_root_abs
|
72
71
|
)
|
73
72
|
|
74
|
-
# Get the
|
73
|
+
# Get the doc id if it exists
|
74
|
+
info.doc_id = adoc.attributes["docid"]
|
75
|
+
|
76
|
+
# Get the source file path
|
75
77
|
info.srcFile = adoc.attributes["docfile"]
|
76
|
-
|
78
|
+
|
79
|
+
# If a docid exists, set titel to docid - title if we care about
|
80
|
+
# doc ids.
|
81
|
+
info.title = if !info.doc_id.nil? && @manage_docid
|
82
|
+
"#{info.doc_id} - #{adoc.doctitle}"
|
83
|
+
else
|
84
|
+
adoc.doctitle
|
85
|
+
end
|
77
86
|
|
78
87
|
# Cache the created DocInfo
|
79
88
|
@added_docs << info
|
@@ -131,6 +140,8 @@ class BasicIndexBuilder
|
|
131
140
|
(section.level == 1) &&
|
132
141
|
(section.name =~ /^Purpose$/)
|
133
142
|
purpose_str = "Purpose::\n\n"
|
143
|
+
|
144
|
+
# filter out 'odd' text, such as lists etc...
|
134
145
|
section.blocks.each do |bb|
|
135
146
|
next unless bb.is_a?(Asciidoctor::Block)
|
136
147
|
purpose_str << "#{bb.source}\n+\n"
|
@@ -294,8 +305,8 @@ end
|
|
294
305
|
|
295
306
|
# A simple index generator that shows a table with the generated documents
|
296
307
|
class SimpleIndexBuilder < BasicIndexBuilder
|
297
|
-
def initialize(path_manager)
|
298
|
-
super path_manager
|
308
|
+
def initialize(path_manager, manage_docid = false)
|
309
|
+
super path_manager, manage_docid
|
299
310
|
end
|
300
311
|
|
301
312
|
def add_doc(adoc, adoc_stderr)
|
@@ -306,8 +317,8 @@ end
|
|
306
317
|
# Builds an index of the generated documents and includes some git metadata
|
307
318
|
# repository
|
308
319
|
class GitRepoIndexBuilder < BasicIndexBuilder
|
309
|
-
def initialize(path_manager, git_repo_root)
|
310
|
-
super path_manager
|
320
|
+
def initialize(path_manager, manage_docid, git_repo_root)
|
321
|
+
super path_manager, manage_docid
|
311
322
|
|
312
323
|
# initialize state variables
|
313
324
|
@git_repo_root = git_repo_root
|
@@ -331,13 +342,22 @@ class GitRepoIndexBuilder < BasicIndexBuilder
|
|
331
342
|
info.srcFile = Pathname.new(info.srcFile).relative_path_from(@git_repo_root).to_s
|
332
343
|
|
333
344
|
# Get the commit history of the doc
|
334
|
-
|
345
|
+
# (use a homegrown git log to get 'follow' flag)
|
346
|
+
gi = Giblish::GitItf.new(@git_repo_root)
|
347
|
+
gi.file_log(info.srcFile.to_s).each do |i|
|
335
348
|
h = DocInfo::DocHistory.new
|
336
|
-
h.date =
|
337
|
-
h.message =
|
338
|
-
h.author =
|
349
|
+
h.date = i["date"]
|
350
|
+
h.message = i["message"]
|
351
|
+
h.author = i["author"]
|
339
352
|
info.history << h
|
340
353
|
end
|
354
|
+
# @git_repo.log(50).object("*#{info.srcFile}").each do |l|
|
355
|
+
# h = DocInfo::DocHistory.new
|
356
|
+
# h.date = l.date
|
357
|
+
# h.message = l.message
|
358
|
+
# h.author = l.author.name
|
359
|
+
# info.history << h
|
360
|
+
# end
|
341
361
|
end
|
342
362
|
|
343
363
|
protected
|
data/lib/giblish/core.rb
CHANGED
@@ -93,6 +93,7 @@ class DocConverter
|
|
93
93
|
|
94
94
|
Giblog.logger.debug { "converter_options: #{@converter_options}" }
|
95
95
|
# do the actual conversion
|
96
|
+
|
96
97
|
Asciidoctor.convert_file filepath, @converter_options
|
97
98
|
end
|
98
99
|
|
@@ -236,9 +237,12 @@ class TreeConverter
|
|
236
237
|
# prepare the index page if requested
|
237
238
|
unless @options[:suppressBuildRef]
|
238
239
|
@index_builder = if @options[:gitRepoRoot]
|
239
|
-
GitRepoIndexBuilder.new(@paths,
|
240
|
+
GitRepoIndexBuilder.new(@paths,
|
241
|
+
options[:resolveDocid],
|
242
|
+
options[:gitRepoRoot])
|
240
243
|
else
|
241
|
-
SimpleIndexBuilder.new(@paths
|
244
|
+
SimpleIndexBuilder.new(@paths,
|
245
|
+
options[:resolveDocid])
|
242
246
|
end
|
243
247
|
end
|
244
248
|
|
@@ -288,8 +292,9 @@ class TreeConverter
|
|
288
292
|
end
|
289
293
|
|
290
294
|
def walk_dirs
|
291
|
-
#
|
292
|
-
|
295
|
+
# collect all doc ids and enable replacement of known doc ids with
|
296
|
+
# valid references to adoc files
|
297
|
+
manage_doc_ids if @options[:resolveDocid]
|
293
298
|
|
294
299
|
# traverse the src file tree and convert all files that ends with
|
295
300
|
# .adoc or .ADOC
|
@@ -311,11 +316,15 @@ class TreeConverter
|
|
311
316
|
|
312
317
|
private
|
313
318
|
|
319
|
+
# predicate that decides if a path is a asciidoc file or not
|
314
320
|
def adocfile?(path)
|
315
|
-
path.extname.casecmp(".ADOC").zero?
|
321
|
+
path.extname.casecmp(".ADOC").zero? && path.file?
|
316
322
|
end
|
317
323
|
|
318
|
-
|
324
|
+
# Register the asciidoctor extension that handles doc ids and traverse
|
325
|
+
# the source tree to collect all :docid: attributes found in document
|
326
|
+
# headers.
|
327
|
+
def manage_doc_ids
|
319
328
|
# Register the docid preprocessor hook
|
320
329
|
Giblish.register_extensions
|
321
330
|
|
@@ -331,7 +340,6 @@ class TreeConverter
|
|
331
340
|
end
|
332
341
|
idc
|
333
342
|
end
|
334
|
-
|
335
343
|
end
|
336
344
|
|
337
345
|
class GitRepoParser
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require "open3"
|
2
|
+
require_relative "utils"
|
3
|
+
|
4
|
+
module Giblish
|
5
|
+
# A home-grown interface class to git. Used for situations when the
|
6
|
+
# 'official' ruby git gem does not support an operation that is needed.
|
7
|
+
class GitItf
|
8
|
+
attr_reader :repo_root
|
9
|
+
attr_reader :git_dir
|
10
|
+
|
11
|
+
def initialize(path)
|
12
|
+
@repo_root = Giblish::PathManager.find_gitrepo_root(path)
|
13
|
+
if @repo_root.nil?
|
14
|
+
raise ArgumentError("The path: @{path} is not within a git repo!")
|
15
|
+
end
|
16
|
+
@git_dir = @repo_root + ".git"
|
17
|
+
end
|
18
|
+
|
19
|
+
# Get the log history of the supplied file as an array of
|
20
|
+
# hashes, each entry has keys:
|
21
|
+
# sha
|
22
|
+
# date
|
23
|
+
# author
|
24
|
+
# email
|
25
|
+
# parent
|
26
|
+
# message
|
27
|
+
def file_log(filename)
|
28
|
+
o, e, s = exec_cmd("log", %w[--follow --date=iso --], filename)
|
29
|
+
raise "Failed to get git log for #{filename}!!\n#{e}" if s.exitstatus != 0
|
30
|
+
|
31
|
+
process_log_output(o)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
# Process the log output from git
|
37
|
+
# (This is copied to 90% from the ruby-git gem)
|
38
|
+
def process_log_output(output)
|
39
|
+
in_message = false
|
40
|
+
hsh_array = []
|
41
|
+
hsh = nil
|
42
|
+
|
43
|
+
output.each_line do |line|
|
44
|
+
line = line.chomp
|
45
|
+
|
46
|
+
if line[0].nil?
|
47
|
+
in_message = !in_message
|
48
|
+
next
|
49
|
+
end
|
50
|
+
|
51
|
+
if in_message
|
52
|
+
hsh["message"] << "#{line[4..-1]}\n"
|
53
|
+
next
|
54
|
+
end
|
55
|
+
|
56
|
+
key, *value = line.split
|
57
|
+
key = key.sub(":", "").downcase
|
58
|
+
value = value.join(" ")
|
59
|
+
|
60
|
+
case key
|
61
|
+
when "commit"
|
62
|
+
hsh_array << hsh if hsh
|
63
|
+
hsh = { "sha" => value, "message" => "", "parent" => [] }
|
64
|
+
when "parent"
|
65
|
+
hsh["parent"] << value
|
66
|
+
when "author"
|
67
|
+
tmp = value.split("<")
|
68
|
+
hsh["author"] = tmp[0].strip
|
69
|
+
hsh["email"] = tmp[1].sub(">", "").strip
|
70
|
+
when "date"
|
71
|
+
hsh["date"] = DateTime.parse(value)
|
72
|
+
else
|
73
|
+
hsh[key] = value
|
74
|
+
end
|
75
|
+
end
|
76
|
+
hsh_array << hsh if hsh
|
77
|
+
end
|
78
|
+
|
79
|
+
# Execute engine for git commands,
|
80
|
+
# Returns same as capture3 (stdout, stderr, Process.Status)
|
81
|
+
def exec_cmd(cmd, flags, args)
|
82
|
+
# always add the git dir to the cmd to ensure that git is executed
|
83
|
+
# within the expected repo
|
84
|
+
gd_flag = "--git-dir=#{@git_dir}"
|
85
|
+
wt_flag = "--work-tree=#{@repo_root}"
|
86
|
+
flag_str = flags.join(" ")
|
87
|
+
git_cmd = "git #{gd_flag} #{wt_flag} #{cmd} #{flag_str} #{args}"
|
88
|
+
Giblog.debug { "running: #{git_cmd}" }
|
89
|
+
Open3.capture3(git_cmd.to_s)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
data/lib/giblish/utils.rb
CHANGED
@@ -130,7 +130,7 @@ module Giblish
|
|
130
130
|
if sr.exist?
|
131
131
|
sr.directory? ? sr.realpath : sr.dirname.realpath
|
132
132
|
else
|
133
|
-
sr.
|
133
|
+
sr.parent.expand_path
|
134
134
|
end
|
135
135
|
end
|
136
136
|
|
@@ -151,12 +151,12 @@ module Giblish
|
|
151
151
|
end
|
152
152
|
|
153
153
|
def with_captured_stderr
|
154
|
-
|
154
|
+
old_stderr = $stderr
|
155
155
|
$stderr = StringIO.new("", "w")
|
156
156
|
yield
|
157
157
|
$stderr.string
|
158
158
|
ensure
|
159
|
-
$stderr =
|
159
|
+
$stderr = old_stderr
|
160
160
|
end
|
161
161
|
module_function :with_captured_stderr
|
162
162
|
|
data/lib/giblish/version.rb
CHANGED
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.2.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anders Rillbert
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -132,6 +132,7 @@ files:
|
|
132
132
|
- bin/setup
|
133
133
|
- data/testdocs/malformed/no_header.adoc
|
134
134
|
- data/testdocs/toplevel.adoc
|
135
|
+
- data/testdocs/wellformed/adorned_purpose.adoc
|
135
136
|
- data/testdocs/wellformed/docidtest/docid_1.adoc
|
136
137
|
- data/testdocs/wellformed/docidtest/docid_2.adoc
|
137
138
|
- data/testdocs/wellformed/simple.adoc
|
@@ -143,6 +144,7 @@ files:
|
|
143
144
|
- lib/giblish/cmdline.rb
|
144
145
|
- lib/giblish/core.rb
|
145
146
|
- lib/giblish/docid.rb
|
147
|
+
- lib/giblish/gititf.rb
|
146
148
|
- lib/giblish/pathtree.rb
|
147
149
|
- lib/giblish/utils.rb
|
148
150
|
- lib/giblish/version.rb
|
@@ -155,7 +157,7 @@ files:
|
|
155
157
|
- resources/images/giblish_logo.png
|
156
158
|
- resources/images/giblish_logo.svg
|
157
159
|
- resources/themes/giblish.yml
|
158
|
-
homepage:
|
160
|
+
homepage: https://github.com/rillbert/giblish
|
159
161
|
licenses:
|
160
162
|
- MIT
|
161
163
|
metadata: {}
|
@@ -167,7 +169,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
167
169
|
requirements:
|
168
170
|
- - ">="
|
169
171
|
- !ruby/object:Gem::Version
|
170
|
-
version: '
|
172
|
+
version: '2.3'
|
171
173
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
172
174
|
requirements:
|
173
175
|
- - ">="
|