giblish 0.2.12 → 0.3.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.
- checksums.yaml +5 -5
- data/.ruby-version +1 -0
- data/Rakefile +2 -3
- data/giblish.gemspec +1 -0
- data/lib/giblish/application.rb +14 -5
- data/lib/giblish/buildgraph.rb +179 -0
- data/lib/giblish/buildindex.rb +361 -414
- data/lib/giblish/cmdline.rb +11 -7
- data/lib/giblish/core.rb +251 -400
- data/lib/giblish/docconverter.rb +231 -0
- data/lib/giblish/docid.rb +107 -58
- data/lib/giblish/docinfo.rb +85 -0
- data/lib/giblish/gititf.rb +1 -0
- data/lib/giblish/utils.rb +29 -5
- data/lib/giblish/version.rb +1 -1
- metadata +21 -3
data/lib/giblish/cmdline.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
#!/usr/bin/ruby
|
2
|
-
|
3
1
|
require_relative "utils"
|
4
2
|
require_relative "version"
|
5
3
|
|
@@ -18,8 +16,8 @@ class CmdLineParser
|
|
18
16
|
Options:
|
19
17
|
-h --help show this help text
|
20
18
|
-v --version show version nr and exit
|
21
|
-
-f --format <format> the output format, currently
|
22
|
-
*
|
19
|
+
-f --format <format> the output format, currently html or pdf are supported
|
20
|
+
*html* is used if -f is not supplied
|
23
21
|
-n --no-build-ref suppress generation of a reference document at the destination
|
24
22
|
tree root.
|
25
23
|
-r --resource-dir <dir> specify a directory where fonts, themes, css and other
|
@@ -50,10 +48,16 @@ class CmdLineParser
|
|
50
48
|
tree (DirectoryRoot on Apache) and not the full absolute
|
51
49
|
path to the css directory.
|
52
50
|
-g --git-branches <regExp> if the source_dir_top is located within a git repo,
|
53
|
-
generate docs for all
|
51
|
+
generate docs for all _remote branches on origin_ that matches
|
54
52
|
the given regular expression. Each git branch will
|
55
53
|
be generated to a separate subdir under the destination
|
56
54
|
root dir.
|
55
|
+
NOTE: To do this, giblish will _explicitly check out the
|
56
|
+
matching branches and merge them with the corresponding
|
57
|
+
branch on origin_.
|
58
|
+
NOTE 2: In bash, use double quotes around your regexp if
|
59
|
+
you need to quote it. Single quotes are treated as part
|
60
|
+
of the regexp itself.
|
57
61
|
-t --git-tags <regExp> if the source_dir_top is located within a git repo,
|
58
62
|
generate docs for all tags that matches the given
|
59
63
|
regular expression. Each tag will be generated to
|
@@ -66,7 +70,7 @@ class CmdLineParser
|
|
66
70
|
doc ids to resolve relative paths between the
|
67
71
|
generated documents
|
68
72
|
--log-level set the log level explicitly. Must be one of
|
69
|
-
debug, info
|
73
|
+
debug, info (default), warn, error or fatal.
|
70
74
|
ENDHELP
|
71
75
|
|
72
76
|
def initialize(cmdline_args)
|
@@ -102,7 +106,7 @@ ENDHELP
|
|
102
106
|
private
|
103
107
|
|
104
108
|
def set_log_level
|
105
|
-
log_level = @args[:logLevel] || "
|
109
|
+
log_level = @args[:logLevel] || "info"
|
106
110
|
case log_level
|
107
111
|
when "debug" then Giblog.logger.sev_threshold = Logger::DEBUG
|
108
112
|
when "info" then Giblog.logger.sev_threshold = Logger::INFO
|
data/lib/giblish/core.rb
CHANGED
@@ -1,465 +1,316 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
#
|
3
|
-
# Converts a tree of asciidoc docs to pdf/html
|
4
|
-
#
|
5
|
-
#
|
6
|
-
|
7
1
|
require "find"
|
8
2
|
require "fileutils"
|
9
3
|
require "logger"
|
10
4
|
require "pathname"
|
11
|
-
require "asciidoctor"
|
12
|
-
require "asciidoctor-pdf"
|
13
5
|
|
14
|
-
require_relative "cmdline"
|
15
6
|
require_relative "buildindex"
|
7
|
+
require_relative "docconverter"
|
16
8
|
require_relative "docid"
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
# :resourceDir
|
43
|
-
def initialize(options)
|
44
|
-
@paths = Giblish::PathManager.new(
|
45
|
-
options[:srcDirRoot], options[:dstDirRoot], options[:resourceDir]
|
46
|
-
)
|
47
|
-
|
48
|
-
@user_style = options[:userStyle]
|
49
|
-
@converter_options = COMMON_CONVERTER_OPTS.dup
|
50
|
-
@converter_options[:attributes] = DEFAULT_ATTRIBUTES.dup
|
51
|
-
@converter_options[:backend] = options[:backend]
|
52
|
-
end
|
53
|
-
|
54
|
-
def convert_str(input_str, src_path, output_file = nil)
|
55
|
-
unless input_str.is_a?(String)
|
56
|
-
raise ArgumentError("Trying to invoke convert_str with non-string!")
|
9
|
+
require_relative "docinfo"
|
10
|
+
require_relative "buildgraph"
|
11
|
+
|
12
|
+
module Giblish
|
13
|
+
|
14
|
+
# Parse a directory tree and convert all asciidoc files matching the
|
15
|
+
# supplied critera to the supplied format
|
16
|
+
class FileTreeConverter
|
17
|
+
|
18
|
+
attr_reader :converter
|
19
|
+
|
20
|
+
# Required options:
|
21
|
+
# srcDirRoot
|
22
|
+
# dstDirRoot
|
23
|
+
# resourceDir
|
24
|
+
def initialize(options)
|
25
|
+
@options = options.dup
|
26
|
+
|
27
|
+
@paths = Giblish::PathManager.new(
|
28
|
+
@options[:srcDirRoot],
|
29
|
+
@options[:dstDirRoot],
|
30
|
+
@options[:resourceDir]
|
31
|
+
)
|
32
|
+
@processed_docs = []
|
33
|
+
@converter = converter_factory
|
57
34
|
end
|
58
35
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
36
|
+
def convert
|
37
|
+
# collect all doc ids and enable replacement of known doc ids with
|
38
|
+
# valid references to adoc files
|
39
|
+
manage_doc_ids if @options[:resolveDocid]
|
40
|
+
|
41
|
+
# traverse the src file tree and convert all files deemed as
|
42
|
+
# adoc files
|
43
|
+
Find.find(@paths.src_root_abs) do |path|
|
44
|
+
p = Pathname.new(path)
|
45
|
+
to_asciidoc(p) if adocfile? p
|
46
|
+
end if @paths.src_root_abs.directory?
|
47
|
+
|
48
|
+
# check if we shall build index or not
|
49
|
+
return if @options[:suppressBuildRef]
|
50
|
+
|
51
|
+
# build a dependency graph (only if we resolve docids...)
|
52
|
+
dep_graph_exist = if @options[:resolveDocid]
|
53
|
+
if Giblish::GraphBuilderGraphviz.supported
|
54
|
+
gb = Giblish::GraphBuilderGraphviz.new @processed_docs, @paths, {extension: @converter.converter_options[:fileext]}
|
55
|
+
@converter.convert_str gb.source, @paths.dst_root_abs, "graph"
|
56
|
+
else
|
57
|
+
Giblog.logger.warn { "Lacking access to needed tools for generating a visual dependency graph." }
|
58
|
+
Giblog.logger.warn { "The dependency graph will not be generated !!" }
|
59
|
+
false
|
60
|
+
end
|
61
|
+
else
|
62
|
+
false
|
63
|
+
end
|
64
64
|
|
65
|
-
|
66
|
-
|
67
|
-
|
65
|
+
# build a reference index
|
66
|
+
ib = index_factory
|
67
|
+
@converter.convert_str ib.source(dep_graph_exist), @paths.dst_root_abs, "index"
|
68
68
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
@converter_options[:fileext])
|
69
|
+
# clean up cached files and adoc resources
|
70
|
+
remove_diagram_temps if dep_graph_exist
|
71
|
+
GC.start
|
73
72
|
end
|
74
73
|
|
75
|
-
|
76
|
-
doc.write output, output_file.to_s
|
77
|
-
doc
|
78
|
-
end
|
74
|
+
protected
|
79
75
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
def convert(filepath)
|
87
|
-
unless filepath.is_a?(Pathname)
|
88
|
-
raise ArgumentError, "Trying to invoke convert with non-pathname!"
|
76
|
+
# get the correct index builder type depending on supplied
|
77
|
+
# user options
|
78
|
+
def index_factory
|
79
|
+
raise "Internal logic error!" if @options[:suppressBuildRef]
|
80
|
+
SimpleIndexBuilder.new(@processed_docs, @paths,
|
81
|
+
@options[:resolveDocid])
|
89
82
|
end
|
90
83
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
Giblog.logger.debug { "converter_options: #{@converter_options}" }
|
103
|
-
# do the actual conversion
|
104
|
-
|
105
|
-
Asciidoctor.convert_file filepath, @converter_options
|
106
|
-
end
|
107
|
-
|
108
|
-
protected
|
109
|
-
|
110
|
-
# Protected: Adds the supplied backend specific options and
|
111
|
-
# attributes to the base ones.
|
112
|
-
# The following options must be provided by the derived class:
|
113
|
-
# :fileext - a string with the filename extention to use for the
|
114
|
-
# generated file
|
115
|
-
#
|
116
|
-
# backend_opts - the options specific to the asciidoctor backend
|
117
|
-
# that the derived class supports
|
118
|
-
# backend_attribs - the attributes specific to the asciidoctor backend
|
119
|
-
# that the derived class supports
|
120
|
-
def add_backend_options(backend_opts, backend_attribs)
|
121
|
-
@converter_options = @converter_options.merge(backend_opts)
|
122
|
-
@converter_options[:attributes] =
|
123
|
-
@converter_options[:attributes].merge(backend_attribs)
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
# Converts asciidoc files to html5 output.
|
128
|
-
class HtmlConverter < DocConverter
|
129
|
-
# Public: Setup common converter options. Required options are:
|
130
|
-
# :srcDirRoot
|
131
|
-
# :dstDirRoot
|
132
|
-
# :resourceDir
|
133
|
-
def initialize(options)
|
134
|
-
super options
|
135
|
-
|
136
|
-
# require access to asciidoc-rouge
|
137
|
-
require "asciidoctor-rouge"
|
138
|
-
|
139
|
-
# handle needed assets for the styling (css et al)
|
140
|
-
html_attrib = setup_web_assets options[:webRoot]
|
141
|
-
|
142
|
-
# Setting 'data-uri' makes asciidoctor embed images in the resulting
|
143
|
-
# html file
|
144
|
-
html_attrib["data-uri"] = 1
|
145
|
-
|
146
|
-
# tell asciidoctor to use the html5 backend
|
147
|
-
backend_options = { backend: "html5", fileext: "html" }
|
148
|
-
add_backend_options backend_options, html_attrib
|
149
|
-
end
|
84
|
+
# get the correct converter type
|
85
|
+
def converter_factory
|
86
|
+
case @options[:format]
|
87
|
+
when "html" then
|
88
|
+
HtmlConverter.new @paths, @options
|
89
|
+
when "pdf" then
|
90
|
+
PdfConverter.new @paths, @options
|
91
|
+
else
|
92
|
+
raise ArgumentError, "Unknown conversion format: #{@options[:format]}"
|
93
|
+
end
|
94
|
+
end
|
150
95
|
|
151
|
-
|
96
|
+
# creates a DocInfo instance, fills it with basic info and
|
97
|
+
# returns the filled in instance so that derived implementations can
|
98
|
+
# add more data
|
99
|
+
def add_doc(adoc, adoc_stderr)
|
100
|
+
Giblog.logger.debug do
|
101
|
+
"Adding adoc: #{adoc} Asciidoctor stderr: #{adoc_stderr}"
|
102
|
+
end
|
103
|
+
Giblog.logger.debug {"Doc attributes: #{adoc.attributes}"}
|
152
104
|
|
153
|
-
|
154
|
-
|
105
|
+
info = DocInfo.new(adoc: adoc, dst_root_abs: @paths.dst_root_abs, adoc_stderr: adoc_stderr)
|
106
|
+
@processed_docs << info
|
107
|
+
info
|
108
|
+
end
|
155
109
|
|
156
|
-
|
157
|
-
|
158
|
-
"stylesdir" => css_dir,
|
159
|
-
"stylesheet" => "giblish.css",
|
160
|
-
"copycss!" => 1 }
|
110
|
+
def add_doc_fail(filepath, exception)
|
111
|
+
info = DocInfo.new
|
161
112
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
Giblog.logger.debug {"stylesheet attributes: #{attrib}"}
|
167
|
-
attrib
|
168
|
-
end
|
113
|
+
# the only info we have is the source file name
|
114
|
+
info.converted = false
|
115
|
+
info.src_file = filepath
|
116
|
+
info.error_msg = exception.message
|
169
117
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
return {} unless @paths.resource_dir_abs
|
118
|
+
@processed_docs << info
|
119
|
+
info
|
120
|
+
end
|
174
121
|
|
175
|
-
|
176
|
-
assets_dir = "#{@paths.dst_root_abs}/web_assets"
|
177
|
-
Dir.exist?(assets_dir) || FileUtils.mkdir_p(assets_dir)
|
122
|
+
private
|
178
123
|
|
179
|
-
#
|
180
|
-
|
181
|
-
|
182
|
-
|
124
|
+
# remove cache dir and svg image created by asciidoctor-diagram
|
125
|
+
# when creating the document dependency graph
|
126
|
+
def remove_diagram_temps
|
127
|
+
adoc_diag_cache = @paths.dst_root_abs.join(".asciidoctor")
|
128
|
+
FileUtils.remove_dir(adoc_diag_cache) if adoc_diag_cache.directory?
|
129
|
+
Giblog.logger.info {"Removing cached files at: #{@paths.dst_root_abs.join("docdeps.svg").to_s}"}
|
130
|
+
@paths.dst_root_abs.join("docdeps.svg").delete
|
183
131
|
end
|
184
132
|
|
185
|
-
#
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
133
|
+
# convert a single adoc doc to whatever the user wants
|
134
|
+
def to_asciidoc(filepath)
|
135
|
+
adoc = nil
|
136
|
+
begin
|
137
|
+
# do the conversion and capture eventual errors that
|
138
|
+
# the asciidoctor lib writes to stderr
|
139
|
+
adoc_stderr = Giblish.with_captured_stderr do
|
140
|
+
adoc = @converter.convert filepath
|
141
|
+
end
|
142
|
+
|
143
|
+
add_doc(adoc, adoc_stderr)
|
144
|
+
rescue Exception => e
|
145
|
+
str = "Error when converting doc: #{e.message}\n"
|
146
|
+
e.backtrace.each {|l| str << "#{l}\n"}
|
147
|
+
Giblog.logger.error {str}
|
148
|
+
|
149
|
+
add_doc_fail(filepath, e)
|
150
|
+
end
|
193
151
|
end
|
194
152
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
end
|
199
|
-
|
200
|
-
class PdfConverter < DocConverter
|
201
|
-
def initialize(options)
|
202
|
-
super options
|
203
|
-
|
204
|
-
pdf_attrib = setup_pdf_attribs
|
153
|
+
# predicate that decides if a path is a asciidoc file or not
|
154
|
+
def adocfile?(path)
|
155
|
+
fs = path.basename.to_s
|
205
156
|
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
def setup_pdf_attribs()
|
213
|
-
# only set this up if user has specified a resource dir
|
214
|
-
return {} unless @paths.resource_dir_abs
|
215
|
-
|
216
|
-
pdf_attrib = {
|
217
|
-
"pdf-stylesdir" => "#{@paths.resource_dir_abs}/themes",
|
218
|
-
"pdf-style" => "giblish.yml",
|
219
|
-
"pdf-fontsdir" => "#{@paths.resource_dir_abs}/fonts",
|
220
|
-
"icons" => "font"
|
221
|
-
}
|
222
|
-
|
223
|
-
# Make sure that the stylesheet ends with .yml or YML
|
224
|
-
@user_style &&
|
225
|
-
pdf_attrib["pdf-style"] =
|
226
|
-
/\.(yml|YML)$/ =~ @user_style ? @user_style : "#{@user_style}.yml"
|
157
|
+
unless @options[:excludeRegexp].nil?
|
158
|
+
# exclude file if user wishes
|
159
|
+
er = Regexp.new @options[:excludeRegexp]
|
160
|
+
return false unless er.match(fs).nil?
|
161
|
+
end
|
227
162
|
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
class TreeConverter
|
233
|
-
|
234
|
-
# Required options:
|
235
|
-
# srcDirRoot
|
236
|
-
# dstDirRoot
|
237
|
-
# resourceDir
|
238
|
-
def initialize(options)
|
239
|
-
@options = options.dup
|
240
|
-
|
241
|
-
@paths = Giblish::PathManager.new(
|
242
|
-
@options[:srcDirRoot],
|
243
|
-
@options[:dstDirRoot],
|
244
|
-
@options[:resourceDir]
|
245
|
-
)
|
246
|
-
|
247
|
-
# init_dst_root
|
248
|
-
|
249
|
-
# prepare the index page if requested
|
250
|
-
unless @options[:suppressBuildRef]
|
251
|
-
@index_builder = if @options[:gitRepoRoot]
|
252
|
-
GitRepoIndexBuilder.new(@paths,
|
253
|
-
options[:resolveDocid],
|
254
|
-
options[:gitRepoRoot])
|
255
|
-
else
|
256
|
-
SimpleIndexBuilder.new(@paths,
|
257
|
-
options[:resolveDocid])
|
258
|
-
end
|
163
|
+
# only include files
|
164
|
+
ir = Regexp.new @options[:includeRegexp]
|
165
|
+
return !ir.match(fs).nil?
|
259
166
|
end
|
260
167
|
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
168
|
+
# Register the asciidoctor extension that handles doc ids and traverse
|
169
|
+
# the source tree to collect all :docid: attributes found in document
|
170
|
+
# headers.
|
171
|
+
def manage_doc_ids
|
172
|
+
# Register the docid preprocessor hook
|
173
|
+
Giblish.register_extensions
|
174
|
+
|
175
|
+
# Make sure that no prior docid's are hangning around
|
176
|
+
DocidCollector.clear_cache
|
177
|
+
DocidCollector.clear_deps
|
178
|
+
idc = DocidCollector.new
|
179
|
+
|
180
|
+
# traverse the src file tree and collect ids from all
|
181
|
+
# .adoc or .ADOC files
|
182
|
+
Find.find(@paths.src_root_abs) do |path|
|
183
|
+
p = Pathname.new(path)
|
184
|
+
idc.parse_file(p) if adocfile? p
|
185
|
+
end if @paths.src_root_abs.directory?
|
186
|
+
idc
|
187
|
+
end
|
268
188
|
end
|
269
189
|
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
# write the converted document to an index file located at the
|
282
|
-
# destination root
|
283
|
-
index_filepath = dst_dir + "index.#{index_opts[:fileext]}"
|
284
|
-
doc.write output, index_filepath.to_s
|
285
|
-
end
|
190
|
+
class GitRepoConverter < FileTreeConverter
|
191
|
+
def initialize(options)
|
192
|
+
super(options)
|
193
|
+
# cache the top of the tree since we need to redefine the
|
194
|
+
# paths per branch/tag later on.
|
195
|
+
@master_paths = @paths.dup
|
196
|
+
@git_repo_root = options[:gitRepoRoot]
|
197
|
+
@git_repo = init_git_repo @git_repo_root, options[:localRepoOnly]
|
198
|
+
@user_branches = select_user_branches(options[:gitBranchRegexp])
|
199
|
+
@user_tags = select_user_tags(options[:gitTagRegexp])
|
200
|
+
end
|
286
201
|
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
adoc_stderr = Giblish.with_captured_stderr do
|
293
|
-
adoc = @conversion.convert filepath
|
202
|
+
# Render the docs from each branch/tag and add info to the
|
203
|
+
# summary page
|
204
|
+
def convert
|
205
|
+
(@user_branches + @user_tags).each do |co|
|
206
|
+
convert_one_checkout co
|
294
207
|
end
|
295
208
|
|
296
|
-
#
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
209
|
+
# Render the summary page
|
210
|
+
index_builder = GitSummaryIndexBuilder.new @git_repo,
|
211
|
+
@user_branches,
|
212
|
+
@user_tags
|
213
|
+
@converter.convert_str index_builder.source, @master_paths.dst_root_abs, "index"
|
214
|
+
# clean up
|
215
|
+
GC.start
|
303
216
|
end
|
304
|
-
end
|
305
217
|
|
306
|
-
|
307
|
-
# collect all doc ids and enable replacement of known doc ids with
|
308
|
-
# valid references to adoc files
|
309
|
-
manage_doc_ids if @options[:resolveDocid]
|
218
|
+
protected
|
310
219
|
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
p = Pathname.new(path)
|
315
|
-
to_asciidoc(p) if adocfile? p
|
220
|
+
def index_factory
|
221
|
+
GitRepoIndexBuilder.new(@processed_docs, @paths,
|
222
|
+
@options[:resolveDocid], @options[:gitRepoRoot])
|
316
223
|
end
|
317
224
|
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
fs = path.basename.to_s
|
334
|
-
|
335
|
-
unless @options[:excludeRegexp].nil?
|
336
|
-
# exclude file if user wishes
|
337
|
-
er = Regexp.new @options[:excludeRegexp]
|
338
|
-
return false unless er.match(fs).nil?
|
225
|
+
def add_doc(adoc, adoc_stderr)
|
226
|
+
info = super(adoc, adoc_stderr)
|
227
|
+
|
228
|
+
# Redefine the srcFile to mean the relative path to the git repo root
|
229
|
+
src_file = Pathname.new(info.src_file).relative_path_from(@git_repo_root).to_s
|
230
|
+
# Get the commit history of the doc
|
231
|
+
# (use a homegrown git log to get 'follow' flag)
|
232
|
+
gi = Giblish::GitItf.new(@git_repo_root)
|
233
|
+
gi.file_log(src_file).each do |i|
|
234
|
+
h = DocInfo::DocHistory.new
|
235
|
+
h.date = i["date"]
|
236
|
+
h.message = i["message"]
|
237
|
+
h.author = i["author"]
|
238
|
+
info.history << h
|
239
|
+
end
|
339
240
|
end
|
340
241
|
|
341
|
-
|
342
|
-
ir = Regexp.new @options[:includeRegexp]
|
343
|
-
return !ir.match(fs).nil?
|
344
|
-
end
|
242
|
+
private
|
345
243
|
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
idc = Giblish::DocidCollector.new
|
356
|
-
|
357
|
-
# traverse the src file tree and collect ids from all
|
358
|
-
# .adoc or .ADOC files
|
359
|
-
Find.find(@paths.src_root_abs) do |path|
|
360
|
-
p = Pathname.new(path)
|
361
|
-
idc.parse_file(p) if adocfile? p
|
362
|
-
end
|
363
|
-
idc
|
364
|
-
end
|
365
|
-
end
|
366
|
-
|
367
|
-
class GitRepoParser
|
368
|
-
def initialize(options)
|
369
|
-
@options = options
|
370
|
-
@paths = Giblish::PathManager.new(
|
371
|
-
@options[:srcDirRoot],
|
372
|
-
@options[:dstDirRoot],
|
373
|
-
@options[:resourceDir]
|
374
|
-
)
|
375
|
-
@git_repo_root = options[:gitRepoRoot]
|
376
|
-
|
377
|
-
# Sanity check git repo root
|
378
|
-
@git_repo_root || raise(ArgumentError("No git repo root dir given"))
|
379
|
-
|
380
|
-
# Connect to the git repo
|
381
|
-
begin
|
382
|
-
@git_repo = Git.open(@git_repo_root)
|
383
|
-
rescue Exception => e
|
384
|
-
raise "Could not find a git repo at #{@git_repo_root} !"\
|
244
|
+
def init_git_repo(git_repo_root, local_only)
|
245
|
+
# Sanity check git repo root
|
246
|
+
git_repo_root || raise(ArgumentError("No git repo root dir given"))
|
247
|
+
|
248
|
+
# Connect to the git repo
|
249
|
+
begin
|
250
|
+
git_repo = Git.open(git_repo_root)
|
251
|
+
rescue Exception => e
|
252
|
+
raise "Could not find a git repo at #{git_repo_root} !"\
|
385
253
|
"\n\n(#{e.message})"
|
386
|
-
|
254
|
+
end
|
387
255
|
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
256
|
+
# fetch all remote refs if ok with user
|
257
|
+
begin
|
258
|
+
git_repo.fetch unless local_only
|
259
|
+
rescue Exception => e
|
260
|
+
raise "Could not fetch from origin"\
|
393
261
|
"(do you need '--local-only'?)!\n\n(#{e.message})"
|
262
|
+
end
|
263
|
+
git_repo
|
394
264
|
end
|
395
265
|
|
396
|
-
#
|
397
|
-
|
266
|
+
# Get the branches/tags the user wants to parse
|
267
|
+
def select_user_branches(checkout_regexp)
|
268
|
+
return unless @options[:gitBranchRegexp]
|
398
269
|
|
399
|
-
|
400
|
-
|
401
|
-
regexp = Regexp.new options[:gitBranchRegexp]
|
402
|
-
@user_branches = @git_repo.branches.remote.select do |b|
|
270
|
+
regexp = Regexp.new checkout_regexp
|
271
|
+
user_checkouts = @git_repo.branches.remote.select do |b|
|
403
272
|
# match branches but remove eventual HEAD -> ... entry
|
404
273
|
regexp.match b.name unless b.name =~ /^HEAD/
|
405
274
|
end
|
406
|
-
Giblog.logger.debug {
|
407
|
-
|
408
|
-
# Render the docs from each branch and add info to the
|
409
|
-
# summary page
|
410
|
-
@user_branches.each do |b|
|
411
|
-
render_one_branch b, @options
|
412
|
-
@index_builder.add_branch b
|
413
|
-
end
|
275
|
+
Giblog.logger.debug {"selected git branches: #{user_checkouts}"}
|
276
|
+
user_checkouts
|
414
277
|
end
|
415
278
|
|
416
|
-
|
417
|
-
|
418
|
-
regexp = Regexp.new options[:gitTagRegexp]
|
419
|
-
@user_tags = @git_repo.tags.select do |t|
|
420
|
-
regexp.match t.name
|
421
|
-
end
|
279
|
+
def select_user_tags(tag_regexp)
|
280
|
+
return [] unless tag_regexp
|
422
281
|
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
render_one_branch t, @options, true
|
427
|
-
@index_builder.add_tag t
|
282
|
+
regexp = Regexp.new @options[:gitTagRegexp]
|
283
|
+
tags = @git_repo.tags.select do |t|
|
284
|
+
regexp.match t.name
|
428
285
|
end
|
286
|
+
tags
|
429
287
|
end
|
430
288
|
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
# clean up
|
436
|
-
@index_builder = nil
|
437
|
-
GC.start
|
438
|
-
end
|
439
|
-
|
440
|
-
def render_one_branch(b, opts, is_tag = false)
|
441
|
-
# work with local options
|
442
|
-
options = opts.dup
|
289
|
+
def convert_one_checkout(co)
|
290
|
+
# determine if we are called with a tag or a branch
|
291
|
+
is_tag = (co.respond_to?(:tag?) && co.tag?)
|
443
292
|
|
444
|
-
|
445
|
-
|
446
|
-
Giblog.logger.info { "Checking out #{b.name}" }
|
447
|
-
@git_repo.checkout b.name
|
293
|
+
Giblog.logger.info {"Checking out #{co.name}"}
|
294
|
+
@git_repo.checkout co.name
|
448
295
|
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
296
|
+
unless is_tag
|
297
|
+
# if this is a branch, make sure it is up-to-date
|
298
|
+
Giblog.logger.info {"Merging with origin/#{co.name}"}
|
299
|
+
@git_repo.merge "origin/#{co.name}"
|
300
|
+
end
|
453
301
|
|
454
|
-
|
455
|
-
|
302
|
+
# assign a checkout-unique dst-dir
|
303
|
+
dir_name = co.name.tr("/", "_") << "/"
|
456
304
|
|
457
|
-
|
458
|
-
|
305
|
+
# Update needed base class members before converting a new checkout
|
306
|
+
@processed_docs = []
|
307
|
+
@paths.dst_root_abs = @master_paths.dst_root_abs.realpath.join(dir_name)
|
308
|
+
# @converter.paths = @paths
|
459
309
|
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
310
|
+
# Parse and convert docs using given args
|
311
|
+
Giblog.logger.info {"Convert docs into dir #{@paths.dst_root_abs}"}
|
312
|
+
# parent_convert
|
313
|
+
FileTreeConverter.instance_method(:convert).bind(self).call
|
314
|
+
end
|
464
315
|
end
|
465
|
-
end
|
316
|
+
end
|