patrickkettner / grunt-compile-handlebars

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

Add YAML template data support #69

Closed khaliddermoumi closed 8 years ago

khaliddermoumi commented 8 years ago

This is a feature request.

It would be very nice to have YAML support for template data, not just JSON, because JSON is very poor for document-like data (data with human readable texts in it f. e.). YAML is far better for this, XML would be another alternative that beats JSON in this respect.

Anyway, thx for this good tool!

patrickkettner commented 8 years ago

would you be interested in creating a PR to add support for this?

khaliddermoumi commented 8 years ago

Hi! I have played around a bit and figured out it isn't really difficult getting this done with the existing code, by using a programmatic approach. Like this:

  1. install the yamljs package:

npm install yamljs // add --save-dev or --save

  1. in your project (gruntfile or wherever your code is):
(...)
    var yaml = require('yamljs');
    var templateData = yaml.load('./template-data.yml');
(...)
  1. In the grunt-job:
 'compile-handlebars': {
            mytarget: {
                files: [{
                      ....
                }],
                templateData: templateData
            }
        }

It may still be nice to have YAML support out of the box, would save the coding. YAML is great because then you can comment your data, comment out unused stuff you don't want to delete, and generally the handling of strings is better, plus you get a lot of other extra features. What do you think?

patrickkettner commented 8 years ago

I'd be happy to review a PR adding support for this, but since I don't use yaml, and we are using alce for parsing, which supports comments in JSON, I don't have a lot of incentive to create this myself.

lemme know if you want to PR it!

khaliddermoumi commented 8 years ago

Well I think let's see if someone else is interested. If many people wait for this to happen, it may be worthwhile. Otherwise just close this issue.

patrickkettner commented 8 years ago

I don't think many folks would go aroudn to find this issue just to plus one it. It should be fairly trivial to add (if input file ends in .yml or something, convert to JSON via parser, then continue as needed)

So, if y'all wanna add it, sweet. i'll merge. I'll close this out until then, though