Skip to content

Commit

Permalink
minor refactor.. test plugins can override helpers correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
75lb committed Aug 31, 2024
1 parent 4d912ed commit 17f6dce
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ const HandlebarsTemplate = require('./lib/handlebars-template.js')
const pkg = JSON.parse(fs.readFileSync(path.resolve(__dirname, './package.json'), 'utf8'))
const dmdVersion = pkg.version

/**
* @module dmd
*/

/**
* Transforms jsdoc-parse data into markdown documentation.
* @param {object[]}
Expand Down Expand Up @@ -64,12 +68,11 @@ async function generate (templateData, options) {
const inputData = templateData.map(row => Object.assign({}, row))
const inputOptions = Object.assign({}, options)

options = Object.assign(new DmdOptions(), options)
options.plugin = arrayify(options.plugin)
/* used by helpers.headingDepth */
options._depth = 0
/* used by helpers.indexDepth */
options._indexDepth = 0
/* This gives all helper code access to the dmd options */
templateData.options = options

/* state module, for sharing data between the helpers - functions as a global object */
Expand Down
9 changes: 0 additions & 9 deletions lib/handlebars-template.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
const handlebars = require('handlebars')
const path = require('path')
const fs = require('fs')

class HandlebarsTemplate {
handlebars = handlebars

async registerPartialFile (file) {
handlebars.registerPartial(
path.basename(file, '.hbs'),
fs.readFileSync(file, 'utf8') || ''
)
}

generate (template, templateData) {
const compiled = handlebars.compile(template, {
preventIndent: true,
Expand Down
8 changes: 6 additions & 2 deletions test/fixture/dmd-plugin-example/helper/helper.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
exports.generatedDate = function(){
return new Date().toUTCString();
exports.generatedDate = function () {
return new Date().toUTCString()
}

exports.orphans = function () {
return 'Orphans Override.\n'
}
7 changes: 7 additions & 0 deletions test/fixture/dmd-plugin-example/lib/dmd-plugin-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@ module.exports = function(options){
helper: __dirname + "/../helper/*.js"
};
};

/*
Command to test this plugin:
jsdoc2md --plugin test/fixture/dmd-plugin-example/lib/dmd-plugin-example.js --files index.js
*/

2 changes: 2 additions & 0 deletions test/fixture/dmd-plugin-example/partial/main.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
{{>all-docs~}}

**documentation generated on {{generatedDate}}**

The system helper `\{{#orphans}}` was overrided in this example.

0 comments on commit 17f6dce

Please sign in to comment.