Skip to content

Commit 3856485

Browse files
committed
Make doc generation method standalone
1 parent f2f084d commit 3856485

File tree

1 file changed

+31
-21
lines changed

1 file changed

+31
-21
lines changed

lib/docurium.rb

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818
Rocco::Markdown = RedcarpetCompat
1919

2020
class Docurium
21-
attr_accessor :branch, :output_dir, :data
21+
attr_accessor :branch, :output_dir, :data, :head_data
2222

2323
def initialize(config_file, repo = nil)
2424
raise "You need to specify a config file" if !config_file
2525
raise "You need to specify a valid config file" if !valid_config(config_file)
2626
@sigs = {}
27+
@head_data = nil
2728
@repo = repo || Rugged::Repository.discover(config_file)
2829
end
2930

@@ -116,8 +117,31 @@ def format_examples!(data, version)
116117
def generate_doc_for(version)
117118
index = Rugged::Index.new
118119
read_subtree(index, version, option_version(version, 'input', ''))
119-
data = parse_headers(index, version)
120-
data
120+
121+
data = parse_headers(index, version, reference)
122+
examples = format_examples!(data, version)
123+
[data, examples]
124+
end
125+
126+
def process_project(versions)
127+
nversions = versions.count
128+
Parallel.each_with_index(versions, finish: -> (version, index, result) do
129+
data, examples = result
130+
# There's still some work we need to do serially
131+
tally_sigs!(version, data)
132+
force_utf8(data)
133+
134+
puts "Adding documentation for #{version} [#{index}/#{nversions}]"
135+
136+
# Store it so we can show it at the end
137+
@head_data = data if version == 'HEAD'
138+
139+
yield index, version, result if block_given?
140+
141+
end) do |version, index|
142+
puts "Generating documentation for #{version} [#{index}/#{nversions}]"
143+
generate_doc_for(version)
144+
end
121145
end
122146

123147
def generate_docs(options)
@@ -136,29 +160,15 @@ def generate_docs(options)
136160
versions = vers
137161
end
138162

139-
head_data = nil
140-
nversions = versions.count
141-
Parallel.each_with_index(versions, finish: -> (version, index, result) do
142-
version, data, examples = result
143-
# There's still some work we need to do serially
144-
tally_sigs!(version, data)
145-
force_utf8(data)
146-
sha = @repo.write(data.to_json, :blob)
147-
148-
puts "Adding documentation for #{version} [#{index}/#{nversions}]"
149-
150-
# Store it so we can show it at the end
151-
head_data = data if version == 'HEAD'
163+
process_project(versions) do |i, version, result|
164+
print "Writing documentation [#{i}/#{versions.count}]\r"
165+
data, examples = result
152166

167+
sha = @repo.write(data.to_json, :blob)
153168
output_index.add(:path => "#{version}.json", :oid => sha, :mode => 0100644)
154169
examples.each do |path, id|
155170
output_index.add(:path => path, :oid => id, :mode => 0100644)
156171
end
157-
end) do |version, index|
158-
puts "Generating documentation for #{version} [#{index}/#{nversions}]"
159-
data = generate_doc_for(version)
160-
examples = format_examples!(data, version)
161-
[version, data, examples]
162172
end
163173

164174
if head_data

0 commit comments

Comments
 (0)