helpers / handlebars-helpers

188 handlebars helpers in ~20 categories. Can be used with Assemble, Ghost, YUI, express.js etc.
http://assemble.io/helpers/
MIT License
2.22k stars 364 forks source link

md helper exports async by default #241

Open blueowl0708 opened 7 years ago

blueowl0708 commented 7 years ago

Hi,

I'm using gulp with assemble 0.17.1 and handlebars-helpers 0.7.7 and the md helper isn't working. We're loading the helper module as described in the readme and other helpers are working (e.g. markdown, isnt, foreach).

Usage within the templates is as described in the docs:

{{md 'path/to/md/file.md'}}

The error message i get is: Error: md async helper expects callback to be a function. Did you mean to use md.sync?

I'm migrating a site from a very old grunt version of assemble and it uses the md helper quite heavily so I'm keen to get this working. I've managed to bodge around it for now by overriding the md helper, but it's a bit of a bodge and it'd be great if it could work without this :)

`app.helper('md', function (fpath) {

    var fs = require('fs'),
        path = require('path'),
        content = fs.readFileSync(fpath, 'utf8'),
        Remarkable = require('remarkable');

    var markd = new Remarkable({
        html:       true,
        xhtmlOut:   false,
        breaks:     true
    });

    return markd.render(content);

});`
doowb commented 7 years ago

I'm doing this in a project and it's working without the additional code.

// helpers
app.helpers(helpers);
app.helper('md', helpers.md.sync);
jonschlinkert commented 7 years ago

hmm, I didn't realize (or remember) that the md helper was exporting the async version by default. In handlebars-helpers we should just wrap it and return the sync function to avoid this issue.

@blueowl0708 would you mind creating an issue on handlebars-helpers regarding exporting the sync function? If not I'll be back from codemash this weekend and can work on it then, thanks

edit: lol I clicked on this from a link on my phone. since the title said "assemble" I thought it was on assemble. anyway, we can change the title of this issue I think. However, it might be better to do what @doowb mentioned, but try also doing:

app.asyncHelper('md', helpers.md);
blueowl0708 commented 7 years ago

@doowb Thank you, that's working.. I was just going to ask if that's an issue that needs fixing or if it's just the docs that require an update but having seen @jonschlinkert 's response above that's answered too.

I'll raise the new issue shortly, should this issue remain open and be linked?

jonschlinkert commented 7 years ago

should this issue remain open and be linked?

just leave as-is for now. I'd like to explore more when I get back, thanks

blueowl0708 commented 7 years ago

@jonschlinkert - title updated, hope this is sufficient.. change it to something more appropriate if not :)

Thanks to both you and @doowb for the extremely quick response to this!