7
8
9
10
11
12
13
14
15
16
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
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/commenter/filler.rb', line 7
def fill(template_path, output_path, , options = {})
doc = Docx::Document.open(template_path)
table = doc.tables.first
raise "No table found in template" unless table
raise "Template table must have at least one row" if table.row_count < 1
template_row = table.rows.first
.each_with_index do |, _index|
= symbolize_keys()
begin
new_row = template_row.copy
new_row.insert_before(template_row)
row = new_row
rescue StandardError => e
puts "Warning: Could not add row for comment #{[:id]}: #{e.message}"
next
end
set_cell_text(row.cells[0], [:id] || "")
set_cell_text(row.cells[1], .dig(:locality, :line_number) || "")
set_cell_text(row.cells[2], .dig(:locality, :clause) || "")
set_cell_text(row.cells[3], .dig(:locality, :element) || "")
set_cell_text(row.cells[4], [:type] || "")
set_cell_text(row.cells[5], [:comments] || "")
set_cell_text(row.cells[6], [:proposed_change] || "")
observations = [:observations]
if observations && !observations.empty?
set_cell_text(row.cells[7], observations)
apply_shading(row.cells[7], observations) if options[:shading]
end
end
template_row.remove if template_row.respond_to?(:remove)
doc.save(output_path)
end
|