diff --git a/tests/norm-rule/expected/test-norm-rules.json b/tests/norm-rule/expected/test-norm-rules.json index 0418e1e..82ea840 100644 --- a/tests/norm-rule/expected/test-norm-rules.json +++ b/tests/norm-rule/expected/test-norm-rules.json @@ -39,7 +39,7 @@ "instances": [ "MY_PARAMETER" ], - "description": "Here's a one line description but it is very wide so should wrap within a cell.", + "description": "One line description", "tags": [ { "name": "norm:note-1", @@ -86,6 +86,18 @@ "tag_filename": "/build/test-norm-tags.json" } ] + }, + { + "name": "rule_with_newlines", + "def_filename": "tests/norm-rule/test.yaml", + "chapter_name": "my-chapter_name", + "tags": [ + { + "name": "norm:tag_with_newlines", + "text": "Here’s the first line.\nHere’s the second line.", + "tag_filename": "/build/test-norm-tags.json" + } + ] } ] } \ No newline at end of file diff --git a/tests/norm-rule/expected/test-norm-rules.xlsx b/tests/norm-rule/expected/test-norm-rules.xlsx index a9b62f2..c134b25 100644 Binary files a/tests/norm-rule/expected/test-norm-rules.xlsx and b/tests/norm-rule/expected/test-norm-rules.xlsx differ diff --git a/tests/norm-rule/expected/test-norm-tags.json b/tests/norm-rule/expected/test-norm-tags.json index 640a833..3f57f1b 100644 --- a/tests/norm-rule/expected/test-norm-tags.json +++ b/tests/norm-rule/expected/test-norm-tags.json @@ -1,6 +1,7 @@ { "tags": { "norm:inline": "inside inline", + "norm:tag_with_newlines": "Here’s the first line.\nHere’s the second line.", "norm:para": "Paragraph anchor", "norm:table-name-empty-tag-just-anchor": "", "norm:unordered-list-heading": "Unordered List:", @@ -29,7 +30,8 @@ } ], "tags": [ - "norm:inline" + "norm:inline", + "norm:tag_with_newlines" ] }, { diff --git a/tests/norm-rule/test.adoc b/tests/norm-rule/test.adoc index 263bc6c..4e3900c 100644 --- a/tests/norm-rule/test.adoc +++ b/tests/norm-rule/test.adoc @@ -8,6 +8,10 @@ Before inline [#norm:inline]#inside inline# outside inline. Before bad inline [#norm:bad-inline]# inside bad inline# outside bad inline.# +[[norm:tag_with_newlines]] +Here's the first line. +Here's the second line. + === Chapter 1.1 [[norm:para]] diff --git a/tests/norm-rule/test.yaml b/tests/norm-rule/test.yaml index 7840137..031c5a4 100644 --- a/tests/norm-rule/test.yaml +++ b/tests/norm-rule/test.yaml @@ -18,9 +18,11 @@ normative_rule_definitions: It's got 2 lines. tags: ["norm:para"] - name: note_with_2_tags - description: Here's a one line description but it is very wide so should wrap within a cell. + description: One line description kind: parameter instances: [MY_PARAMETER] tags: ["norm:note-1", "norm:note-3"] - names: [desc1, desc2] tags: ["norm:description-item-1", "norm:description-item-3"] + - name: rule_with_newlines + tags: ["norm:tag_with_newlines"] diff --git a/tools/create_normative_rules.rb b/tools/create_normative_rules.rb index 8652eba..fe0de78 100644 --- a/tools/create_normative_rules.rb +++ b/tools/create_normative_rules.rb @@ -191,7 +191,6 @@ def initialize(name, def_filename, chapter_name, data) end # class NormativeRuleDef # Holds one reference to a tag by a rule definition. -# XXX - Not testing kind/instances (are they needed?) class NormativeTagRef attr_reader :name # String (mandatory) attr_reader :kind # String (optional, can be nil) @@ -584,51 +583,62 @@ def output_xlsx(filename, defs, tags) columns: [ { header: "Chapter Name" }, { header: "Rule Name" }, - { header: "Summary" }, - { header: "Description" }, + { header: "Rule Definition" }, + { header: "Rule Definition Sources" }, { header: "Kind" }, - { header: "Instances" }, - { header: "Tagged Text" } + { header: "Instances" } ] } # Add normative rules in rows. One row for each tag if multiple tags. row_num = 1 - right_arrow = "\u2192" defs.norm_rule_defs.each do |d| worksheet.write(row_num, 0, d.chapter_name) worksheet.write(row_num, 1, d.name, wrap_format) - worksheet.write(row_num, 2, d.summary) unless d.summary.nil? - worksheet.write(row_num, 3, d.description.chomp, wrap_format) unless d.description.nil? - worksheet.write(row_num, 4, d.kind) unless d.kind.nil? - worksheet.write(row_num, 5, d.instances.join(",")) unless d.instances.empty? - tags_str = [] + rule_defs = [] + rule_def_sources = [] + + unless d.summary.nil? + rule_defs.append(d.summary.chomp) + rule_def_sources.append("Summary") + end + + unless d.description.nil? + rule_defs.append(d.description.chomp) + rule_def_sources.append("Description") + end + + tag_sources = [] d.tag_refs.each do |tag_ref| tag_ref_name = tag_ref.name - - # Lookup tag tag = tags.get_tag(tag_ref_name) - fatal("Normative rule #{d.name} defined in file #{d.def_filename} references non-existent tag #{tag_ref_name}") if tag.nil? - - tags_str.append("#{tag.name} #{right_arrow} \"#{tag.text}\"") + rule_defs.append(tag.text.chomp) + tag_sources.append('"' + tag.name + '"') end + rule_def_sources.append('[' + tag_sources.join(', ') + ']') unless tag_sources.empty? + + worksheet.write(row_num, 2, rule_defs.join("\n"), wrap_format) unless rule_defs.empty? + worksheet.write(row_num, 3, rule_def_sources.join(", "), wrap_format) unless rule_def_sources.empty? + worksheet.write(row_num, 4, d.kind) unless d.kind.nil? + worksheet.write(row_num, 5, d.instances.join(', ')) unless d.instances.empty? - worksheet.write(row_num, 6, tags_str.join("\n"), wrap_format) unless tags_str.empty? row_num += 1 end num_rows = row_num - 1 - worksheet.add_table("A1:G#{num_rows}", table_props) + # Make into a table. Assume columns A to F. + worksheet.add_table("A1:F#{num_rows}", table_props) # Set column widths to hold data width. worksheet.autofit # Override autofit for really wide columns worksheet.set_column(1, 1, 20) # name column - worksheet.set_column(3, 3, 30) # description column + worksheet.set_column(2, 2, 80) # definition column + worksheet.set_column(3, 3, 40) # definition sources column workbook.close end