Class: Commenter::Filler
- Inherits:
-
Object
- Object
- Commenter::Filler
- Defined in:
- lib/commenter/filler.rb
Constant Summary collapse
- HEADER_METADATA =
Labels of the sheet metadata fields in the template's page header (word/header*.xml). Values supplied to #fill are appended after each label; the docx gem cannot write header parts (see docx PR #73), so this is done by rewriting the entry directly.
{ date: "Date", document: "Document", project: "Project" }.freeze
Instance Method Summary collapse
Instance Method Details
#fill(template_path, output_path, comments, options = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/commenter/filler.rb', line 14 def fill(template_path, output_path, comments, = {}) 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 # The template row (first row in the table) is copied for each comment; # all original template rows are removed afterwards via their XML # nodes (the shipped 2012-03 template carries extra blank rows beyond # the first, and the docx gem's Row exposes no #remove). template_rows = table.rows.to_a comments.each { |comment| fill_row(template_rows.first, comment, ) } template_rows.each { |row| row.node.remove } doc.save(output_path) (output_path, ) output_path end |