patrickkettner / grunt-compile-handlebars

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

Allow plain objects in "globals" option #37

Closed isadovskiy closed 9 years ago

isadovskiy commented 9 years ago

Right now globals option support just list of json files.

'compile-handlebars': {
    all: {
        ...
        globals: ['file1.json', 'file2.json']
    }
}

This pull request allows to provide plain JS objects for globals as well.

'compile-handlebars': {
    all: {
        ...
        globals: [
            'file1.json', 
            'file2.json',
            {
                property1: 'value1',
                property2: 'value2'
            }
        ]
    }
}
patrickkettner commented 9 years ago

Looks great! Few things, though.

I would rather it be upside down, like

globals.forEach(function(global) {
  if (grunt.util.kindOf(global) === 'object') {
    fragment = global;
  } else {
    if (!grunt.file.exists(global)) {
      grunt.log.error("JSON file " + global + " not found.");
    } else {
      try {
        fragment = grunt.file.readJSON(global);
      } catch (e) {
        grunt.fail.warn(e);
      }
    }
  }
    _merge(json, fragment);
});

Then, could you add a test file with the results you expect? Finally, add yourself to the contributors.md file, and please squash the whole thing down to a single commit

cheers!

isadovskiy commented 9 years ago

NP! Will do tomorrow.

isadovskiy commented 9 years ago

Creating another pull request