patrickkettner / grunt-compile-handlebars

grunt plugin to compile static html from a handlebars plugin
MIT License
115 stars 29 forks source link

using Handlebars.SafeString in helper? #11

Closed marcoow closed 10 years ago

marcoow commented 10 years ago

I'm using marked to render markdown via a helper:

var marked = require('../vendor/marked');

module.exports = function(string) {
  return new Handlebars.SafeString(marked(srting));
}

But of course Handlebars is not defined. What's the suggested way to return a safe string from a helper?

patrickkettner commented 10 years ago

forgive a silly question, but did you try

var marked = require('../vendor/marked');
var Handlebars  = require('handlebars');?

module.exports = function(string) {
  return new Handlebars.SafeString(marked(srting));
}
marcoow commented 10 years ago

Yep, that doesn't work (the handlebar file is somewhere on node_modules). I'd say it would be best if the helper loader would somehow make Handlebars available for the helpers?

Am 24.02.2014 um 19:08 schrieb patrick kettner notifications@github.com:

forgive a silly question, but did you try

var marked = require('../vendor/marked'); var Handlebars = require('handlebars');?

module.exports = function(string) { return new Handlebars.SafeString(marked(srting)); } — Reply to this email directly or view it on GitHub.

patrickkettner commented 10 years ago

Im still not quite clear on what is going on here - what is the module you are exporting in relation to this helper?

marcoow commented 10 years ago

Not sure what you mean - above code is the complete helper; marked is this: https://github.com/chjj/marked

patrickkettner commented 10 years ago

Sorry, wasn't very clear.

if your project dir is /foo, then this helper (ie grunt-compiler-handlebars) is at /foo/node_modules/grunt-compile-handlebars.

Where is the file you listed

var marked = require('../vendor/marked');

module.exports = function(string) {
  return new Handlebars.SafeString(marked(srting));
}

relative to the other two files?

marcoow commented 10 years ago

I see; fortunately it's an open source project, so you can look at the code here: https://github.com/simplabs/ember-simple-auth/tree/es6-modules

patrickkettner commented 10 years ago

I meant where in the file system does this file reside relative to this helper?

marcoow commented 10 years ago

it's here: https://github.com/simplabs/ember-simple-auth/tree/es6-modules/docs/theme/helpers, "marked" is in a different directory: https://github.com/simplabs/ember-simple-auth/tree/es6-modules/docs/theme/vendor - both directories are in subdirectories in the project root

patrickkettner commented 10 years ago

The best thing to do in this situation would be to add Handlebars as a dependency in your package.json, and then require('handlebars') in your code like I mentioned above.

marcoow commented 10 years ago

Sometimes it's actually so simple ;) Thanks!

patrickkettner commented 10 years ago

my pleasure!