Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

md helper exports async by default #241

Open
blueowl0708 opened this issue Jan 13, 2017 · 5 comments
Open

md helper exports async by default #241

blueowl0708 opened this issue Jan 13, 2017 · 5 comments

Comments

@blueowl0708
Copy link

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
Copy link
Member

doowb commented Jan 13, 2017

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
Copy link
Member

jonschlinkert commented Jan 13, 2017

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
Copy link
Author

@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
Copy link
Member

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 blueowl0708 changed the title md helper not working with Assemble md helper exports async by default (was md helper not working with Assemble) Jan 13, 2017
@blueowl0708
Copy link
Author

@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!

@jonschlinkert jonschlinkert changed the title md helper exports async by default (was md helper not working with Assemble) md helper exports async by default Jan 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants