commonform-docx 6.0.0 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin.js CHANGED
@@ -14,20 +14,23 @@ const usage = [
14
14
  ' -h, --help Show this screen.',
15
15
  ' -v, --version Show version.',
16
16
  ' -H, --hash Render form hash',
17
- ' -a, --a4-paper A4 paper.',
18
- ' -b TEXT, --blank-text TEXT Render blanks with custom text.',
17
+ ' -a, --a4-paper A4 paper',
18
+ ' -b TEXT, --blank-text TEXT Render blanks with custom text',
19
+ ' --component-style STYLE Change component style [default: both]',
19
20
  ' -d JSON --directions JSON Use directions to fill in blanks',
20
21
  ' -e VERSION, --form-version VERSION Form version to be rendered',
21
22
  ' -i, --indent-margins Indent margins, commonwealth style',
23
+ ' --incorporate-component-text TEXT Verb for component references [default: Incorporate]',
24
+ ' --quote-component-text TEXT Text for introducing quoted components',
22
25
  ' -l, --left-align-title Align title flush to left margin',
23
26
  ' -m, --mark-filled Mark filled blanks',
24
27
  ' -p, --smart Render Unicode punctuation',
25
28
  ' -n STYLE, --number STYLE Numbering style [default: decimal]',
26
29
  ' -r --left-align-body Left-align body paragraphs.',
27
30
  ' -s PAGES, --signatures PAGES Signature page data',
28
- ' -t TITLE, --title TITLE Render title as <h1>.',
31
+ ' -t TITLE, --title TITLE Render title as <h1>',
29
32
  ' -v JSON --values JSON Use values to fill in blanks',
30
- ' -y JSON, --styles JSON Render with custom styles.'
33
+ ' -y JSON, --styles JSON Render with custom styles'
31
34
  ].join('\n')
32
35
 
33
36
  const parsed = docopt(usage, { version: require('./package.json').version })
@@ -99,6 +102,10 @@ if (parsed['--blank-text']) options.blanks = parsed['--blank-text']
99
102
 
100
103
  if (parsed['--mark-filled']) options.markFilled = true
101
104
 
105
+ options.loadedComponentStyle = parsed['--component-style']
106
+ if (parsed['--quote-component-text']) options.quoteComponentText = parsed['--quote-component-text']
107
+ options.incorporateComponentText = parsed['--incorporate-component-text']
108
+
102
109
  function readJSON (file) {
103
110
  return JSON.parse(fs.readFileSync(path.resolve(file)))
104
111
  }
package/index.js CHANGED
@@ -33,11 +33,14 @@ module.exports = (
33
33
  after = '',
34
34
  blanks = { text: '[•]', highlight: 'yellow' },
35
35
  hash = false,
36
+ incorporateComponentText = 'Incorporate',
36
37
  indentMargins = false,
37
38
  leftAlignBody = false,
38
39
  leftAlignTitle = false,
40
+ loadedComponentStyle = 'inline',
39
41
  markFilled = false,
40
42
  numberStyle = decimalNumbering,
43
+ quoteComponentText = 'Quoting for convenience, with any conflicts resolved in favor of the standard:',
41
44
  smart,
42
45
  styles,
43
46
  title,
@@ -56,12 +59,15 @@ module.exports = (
56
59
  a4,
57
60
  after,
58
61
  blanks,
59
- leftAlignTitle,
60
62
  hash,
63
+ incorporateComponentText,
61
64
  indentMargins,
62
65
  leftAlignBody,
66
+ leftAlignTitle,
67
+ loadedComponentStyle,
63
68
  markFilled,
64
69
  numberStyle,
70
+ quoteComponentText,
65
71
  smart,
66
72
  styles,
67
73
  title,
package/lint.log ADDED
@@ -0,0 +1,4 @@
1
+
2
+ > commonform-docx@6.0.0 lint
3
+ > standard
4
+
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "commonform-docx",
3
3
  "description": "render Common Forms in Office Open XML (Microsoft Word .docx format)",
4
- "version": "6.0.0",
4
+ "version": "7.0.0",
5
5
  "author": "Kyle E. Mitchell <kyle@kemitchell.com> (http://kemitchell.com)",
6
6
  "bin": "bin.js",
7
7
  "dependencies": {
@@ -14,6 +14,7 @@
14
14
  "decimal-numbering": "^3.0.2",
15
15
  "has": "^1.0.3",
16
16
  "jszip": "^3.2.1",
17
+ "number-to-words-en": "^1.2.5",
17
18
  "ooxml-signature-pages": "^3.0.2",
18
19
  "outline-numbering": "^2.0.0",
19
20
  "plan-addenda-exhibits-numbering": "^3.0.0",
@@ -24,7 +25,7 @@
24
25
  "run-series": "^1.1.8",
25
26
  "standard": "^17.0.0",
26
27
  "tape": "^5.0.1",
27
- "textract": "^2.4.0"
28
+ "textract": "^2.5.0"
28
29
  },
29
30
  "keywords": [
30
31
  "Microsoft Office",
@@ -1,5 +1,6 @@
1
1
  const escape = require('../escape')
2
2
  const has = require('has')
3
+ const numberToWords = require('number-to-words-en')
3
4
  const run = require('./run')
4
5
  const tag = require('./tag')
5
6
 
@@ -55,37 +56,48 @@ module.exports = (element, options) => {
55
56
  const conspicuous = has(element, 'conspicuous')
56
57
  const hasComponent = has(element, 'component')
57
58
  const hasContent = has(element, 'content')
58
- return tag('w:p',
59
- properties(element, number, options.indentMargins) +
60
- (number ? makeRun(number, false) + TAB : '') +
61
- (
62
- has(element, 'heading')
63
- ? (
64
- makeRun({ caption: element.heading }, conspicuous) +
65
- (/\.$/.test(element.heading) ? '' : makeRun('.', false)) +
66
- (((hasComponent && !hasContent) || element.content.length === 0) ? '' : makeRun(' ', false))
67
- )
68
- : ''
69
- ) +
70
- (
71
- hasComponent
72
- ? hasContent
73
- ? (
74
- referenceContent(element.reference, options.rIdForHREF) +
75
- makeRun(' Quoting for convenience, with any conflicts resolved in favor of the standard:') +
76
- '</w:p>' +
77
- '<w:p>' +
78
- properties(
79
- Object.assign({}, element, { depth: element.depth + 1 }),
80
- number,
81
- options.indentMargins
82
- ) +
83
- childContent({ content: element.content })
84
- )
85
- : referenceContent(element, options.rIdForHREF)
86
- : childContent(element)
87
- )
88
- )
59
+ let returned = '<w:p>'
60
+ returned += properties(element, number, options.indentMargins)
61
+ returned += number ? makeRun(number, false) + TAB : ''
62
+ if (has(element, 'heading')) {
63
+ returned += makeRun({ caption: element.heading }, conspicuous)
64
+ if (!/\.$/.test(element.heading)) {
65
+ returned += makeRun('.', false)
66
+ }
67
+ if ((hasComponent && !hasContent) || element.content.length === 0) {
68
+ // pass
69
+ } else {
70
+ returned += makeRun(' ', false)
71
+ }
72
+ }
73
+ if (hasComponent) {
74
+ if (hasContent) {
75
+ const style = options.loadedComponentStyle
76
+ if (style === 'both') {
77
+ returned += componentReference(element.reference, element.component)
78
+ returned += makeRun(' ' + options.quoteComponentText)
79
+ returned += '</w:p><w:p>'
80
+ returned += properties(
81
+ Object.assign({}, element, { depth: element.depth + 1 }),
82
+ number,
83
+ options.indentMargins
84
+ )
85
+ returned += childContent({ content: element.content })
86
+ } else if (style === 'copy') {
87
+ returned += childContent({ content: element.content })
88
+ } else if (style === 'reference') {
89
+ returned += componentReference(element.reference, element.component)
90
+ } else {
91
+ throw new Error('Uknown Loaded Component Style: ' + style)
92
+ }
93
+ } else {
94
+ returned += componentReference(element)
95
+ }
96
+ } else {
97
+ returned += childContent(element)
98
+ }
99
+ returned += '</w:p>'
100
+ return returned
89
101
 
90
102
  function childContent (element) {
91
103
  const conspicuous = has(element, 'conspicuous')
@@ -98,13 +110,20 @@ module.exports = (element, options) => {
98
110
  return run(element, conspicuous, options)
99
111
  }
100
112
 
101
- function referenceContent (component, rIdForHREF) {
113
+ function componentReference (component, meta) {
102
114
  const href = component.component + '/' + component.version
103
- const returned = [makeRun('Incorporate ')]
104
- const rId = rIdForHREF(href)
105
- returned.push(
106
- '<w:hyperlink r:id="' + rId + '" w:history="1"><w:r><w:rPr><w:color w:val="0000EE"/><w:u w:val="single"/></w:rPr><w:t>' + escape(href) + '</w:t></w:r></w:hyperlink>'
107
- )
115
+ const returned = [makeRun(options.incorporateComponentText + ' ')]
116
+ const rId = options.rIdForHREF(href)
117
+ const link = '<w:hyperlink r:id="' + rId + '" w:history="1"><w:r><w:rPr><w:color w:val="0000EE"/><w:u w:val="single"/></w:rPr><w:t>' + escape(href) + '</w:t></w:r></w:hyperlink>'
118
+ if (meta) {
119
+ returned.push(
120
+ makeRun(meta.publisher + ' ' + meta.name + ' Version ' + meta.version + ' ('),
121
+ link,
122
+ makeRun(')')
123
+ )
124
+ } else {
125
+ returned.push(link)
126
+ }
108
127
  const substitutions = component.substitutions
109
128
  const hasSubstitutions = (
110
129
  Object.keys(substitutions.terms).length > 0 ||
@@ -115,11 +134,28 @@ module.exports = (element, options) => {
115
134
  const phrases = []
116
135
  Object.keys(substitutions.terms).forEach(from => {
117
136
  const to = substitutions.terms[from]
118
- phrases.push(makeRun('the term ' + quote(to) + ' for the term ' + quote(from)))
137
+ phrases.push(
138
+ makeRun('the term ') +
139
+ makeRun({ use: to }) +
140
+ makeRun(' for the term ') +
141
+ makeRun({ use: from })
142
+ )
119
143
  })
120
144
  Object.keys(substitutions.headings).forEach(from => {
121
145
  const to = substitutions.headings[from]
122
- phrases.push(makeRun('references to ' + quote(to) + ' for references to ' + quote(from)))
146
+ phrases.push(
147
+ makeRun('references to ') +
148
+ makeRun({ use: to }) +
149
+ makeRun(' for references to ') +
150
+ makeRun({ use: from })
151
+ )
152
+ })
153
+ Object.keys(substitutions.blanks).forEach(number => {
154
+ const value = substitutions.blanks[number]
155
+ phrases.push(
156
+ makeRun(quote(value)) +
157
+ makeRun(' for the ' + numberToWords.toWordsOrdinal(parseInt(number)) + ' blank')
158
+ )
123
159
  })
124
160
  const length = phrases.length
125
161
  if (length === 1) {
package/test.log ADDED
@@ -0,0 +1,98 @@
1
+
2
+ > commonform-docx@6.0.0 pretest
3
+ > npm run prepublish
4
+
5
+
6
+ > commonform-docx@6.0.0 prepublish
7
+ > node build/scaffold.js data/scaffold.docx > data/scaffold.json
8
+
9
+
10
+ > commonform-docx@6.0.0 test
11
+ > tape test.js
12
+
13
+ TAP version 13
14
+ # renders text
15
+ ok 1 no render error
16
+ ok 2 no textract error
17
+ ok 3 text appears in output
18
+ # renders definitions
19
+ ok 4 no render error
20
+ ok 5 no textract error
21
+ ok 6 defined term appears in output
22
+ # renders uses
23
+ ok 7 no render error
24
+ ok 8 no textract error
25
+ ok 9 term appears in output
26
+ # renders references
27
+ ok 10 no render error
28
+ ok 11 no textract error
29
+ ok 12 reference appears in output
30
+ # handles components without headings
31
+ ok 13 no render error
32
+ # handles components with substitutions
33
+ ok 14 no render error
34
+ # omits period after heading ending w/ period
35
+ ok 15 no render error
36
+ ok 16 no textract error
37
+ ok 17 double period does not appear in output
38
+ # adds space between heading and defined term
39
+ ok 18 no render error
40
+ ok 19 no textract error
41
+ ok 20 space between heading and term
42
+ # adds space between heading and text
43
+ ok 21 no render error
44
+ ok 22 no textract error
45
+ ok 23 space between heading and text
46
+ # renders broken references
47
+ ok 24 no render error
48
+ ok 25 no textract error
49
+ ok 26 reference appears in output
50
+ # fills blanks
51
+ ok 27 no render error
52
+ ok 28 no textract error
53
+ ok 29 value appears in output
54
+ # custom blank text
55
+ ok 30 no render error
56
+ ok 31 no textract error
57
+ ok 32 value appears in output
58
+ # renders empty blank placeholders
59
+ ok 33 no render error
60
+ ok 34 no textract error
61
+ ok 35 placeholder appears in output
62
+ # renders custom empty blank placeholders
63
+ ok 36 no render error
64
+ ok 37 no textract error
65
+ ok 38 placeholder appears in output
66
+ # renders custom empty blank placeholders
67
+ ok 39 no render error
68
+ ok 40 no textract error
69
+ ok 41 placeholder appears in output
70
+ # renders conspicuous text
71
+ ok 42 no render error
72
+ ok 43 no textract error
73
+ ok 44 conspicuous text appears in output
74
+ # renders titles
75
+ ok 45 no render error
76
+ ok 46 no textract error
77
+ ok 47 title appears in output
78
+ # renders centered titles
79
+ ok 48 no render error
80
+ ok 49 no textract error
81
+ ok 50 title appears in output
82
+ # renders versions
83
+ ok 51 no render error
84
+ ok 52 no textract error
85
+ ok 53 version appears in output
86
+ # renders hashes
87
+ ok 54 no render error
88
+ ok 55 no textract error
89
+ ok 56 hash symbol appears in output
90
+ # throws for invalid content
91
+ ok 57 throw an error
92
+
93
+ 1..57
94
+ # tests 57
95
+ # pass 57
96
+
97
+ # ok
98
+
package/outdated.log DELETED
File without changes