Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion tests/norm-rule/expected/test-norm-rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
}
]
}
]
}
Binary file modified tests/norm-rule/expected/test-norm-rules.xlsx
Binary file not shown.
4 changes: 3 additions & 1 deletion tests/norm-rule/expected/test-norm-tags.json
Original file line number Diff line number Diff line change
@@ -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:",
Expand Down Expand Up @@ -29,7 +30,8 @@
}
],
"tags": [
"norm:inline"
"norm:inline",
"norm:tag_with_newlines"
]
},
{
Expand Down
4 changes: 4 additions & 0 deletions tests/norm-rule/test.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down
4 changes: 3 additions & 1 deletion tests/norm-rule/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
48 changes: 29 additions & 19 deletions tools/create_normative_rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down