dmd icon indicating copy to clipboard operation
dmd copied to clipboard

Handlebars Partials

Open mdelbuono opened this issue 5 years ago • 1 comments

In index.js, line 92 loads the default partials as follows:

 registerPartials(path.resolve(__dirname, './partials/**/*.hbs'))  

The glob path gests unfolded usign FileSet which in turns uses glob. The problem is that, if __dirname contains special glob characters (e.g. [ ] like in my case), FileSet will fail listing all the .hbs files and no partial will be registered.

Bottomline is: __dirname should be escaped.

mdelbuono avatar Aug 02 '20 09:08 mdelbuono

I fixed it as follows:

registerPartials(path.resolve(escapeGlob(__dirname), './partials/**/*.hbs'))

Where the escapeGlob function is defined below:

function escapeGlob (glob) {
  return glob
    .replace(/\\/g, '\\\\')
    .replace(/\*/g, '\\*')
    .replace(/\?/g, '\\?')
    .replace(/\[/g, '\\[')
    .replace(/\]/g, '\\]')
    .replace(/\{/g, '\\{')
    .replace(/\}/g, '\\}')
    .replace(/\)/g, '\\)')
    .replace(/\(/g, '\\(')
    .replace(/\!/g, '\\!');
}

mdelbuono avatar Aug 02 '20 09:08 mdelbuono

A fix for this has been implemented and will be in the next version of dmd & jsdoc2md.. All internal partials are now cached and imported as a module at run time, removing the requirement to load each partial file on every invocation..

Closing for now, watch this space for the new version..

75lb avatar Aug 27 '24 14:08 75lb