Skip to content

Commit 8ce18d9

Browse files
authored
Merge pull request #100 from Mogztter/issue-98-template-dir
resolves #98 add --template-dir option
2 parents 777553d + 51318b0 commit 8ce18d9

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

lib/options.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const convertOptions = (args, attrs) => {
1313
const baseDir = args['base-dir']
1414
const destinationDir = args['destination-dir']
1515
const outFile = args['out-file']
16+
const templateDir = args['template-dir']
1617
const templateEngine = args['template-engine']
1718
const quiet = args.quiet
1819
const verbose = args.verbose
@@ -38,6 +39,7 @@ const convertOptions = (args, attrs) => {
3839
console.log('trace ' + trace)
3940
console.log('base-dir ' + baseDir)
4041
console.log('destination-dir ' + destinationDir)
42+
console.log('template-dir ' + templateDir)
4143
console.log('template-engine ' + templateEngine)
4244
}
4345
const verboseMode = quiet ? 0 : verbose ? 2 : 1
@@ -70,7 +72,12 @@ const convertOptions = (args, attrs) => {
7072
if (destinationDir != null) {
7173
options.to_dir = destinationDir
7274
}
73-
options.template_engine = templateEngine
75+
if (templateDir) {
76+
options.template_dirs = templateDir
77+
}
78+
if (templateEngine) {
79+
options.template_engine = templateEngine
80+
}
7481
if (typeof outFile !== 'undefined') {
7582
if (outFile === '') {
7683
options.to_file = '-'
@@ -188,6 +195,12 @@ class Options {
188195
describe: 'enable timings mode',
189196
type: 'boolean'
190197
})
198+
.option('template-dir', {
199+
alias: 'T',
200+
array: true,
201+
describe: 'a directory containing custom converter templates that override the built-in converter (may be specified multiple times)',
202+
type: 'string'
203+
})
191204
.option('template-engine', {
192205
alias: 'E',
193206
describe: 'template engine to use for the custom converter templates',
@@ -217,6 +230,7 @@ show this usage if TOPIC is not specified or recognized
217230
show an overview of the AsciiDoc syntax if TOPIC is syntax`,
218231
type: 'string'
219232
})
233+
.nargs('template-dir', 1)
220234
.nargs('attribute', 1)
221235
.nargs('require', 1)
222236
.usage(`$0 [options...] files...

test/test.js

+25
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,31 @@ describe('Require option', () => {
306306
})
307307
})
308308

309+
describe('Template directory', () => {
310+
it('should parse a command with a single template directory', () => {
311+
const result = argsParser.parse('--template-dir /path/to/templates file.adoc')
312+
expect(result.files).to.have.length(1)
313+
expect(result.files).to.include('file.adoc')
314+
expect(result['template-dir']).to.have.length(1)
315+
expect(result['template-dir']).to.include('/path/to/templates')
316+
})
317+
318+
it('should parse a command with a multiple template directories', () => {
319+
const result = argsParser.parse('--template-dir=/path/to/templates -T /path/to/others file.adoc')
320+
expect(result.files).to.have.length(1)
321+
expect(result.files).to.include('file.adoc')
322+
expect(result['template-dir']).to.have.length(2)
323+
expect(result['template-dir']).to.include('/path/to/templates')
324+
expect(result['template-dir']).to.include('/path/to/others')
325+
})
326+
it('should set template_dirs option when --template-dir is defined', () => {
327+
const opts = new Options({}).parse('node asciidoctor --template-dir /path/to/templates -b html5 file.adoc')
328+
expect(opts.options.backend).to.equal('html5')
329+
expect(opts.options.template_dirs).to.have.length(1)
330+
expect(opts.options.template_dirs).to.include('/path/to/templates')
331+
})
332+
})
333+
309334
describe('Template engine', () => {
310335
it('should parse a command with the --template-engine argument', () => {
311336
const result = argsParser.parse('--template-engine=nunjucks -a foo=bar file.adoc')

0 commit comments

Comments
 (0)