Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Enable user to optionally remove `var namespace` statement at start of file #6

Closed
wants to merge 1 commit into from

3 participants

@JofArnold

Previously script would fail if namespaces contained a . (due to attempting to var stuff like App.Name). Plus the var namespace code isn't necessary in all circumstances and reduces flexibility for the user.

@JofArnold

Actually, on second thoughts it would've probably been enough just to make the var optional.

@georgebonnr

#7
@JofArnold
FYI I implemented this as an option in my fork, if you still need anything like this. Can set your package.json to "grunt-json": "git://github.com/georgebonnr/grunt-json.git#master" or some other such hack if you're curious.

@AndiOxidant
Owner

Feature is already implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 26, 2013
  1. @JofArnold

    Enable user to optionally remove `var namespace` statement at start o…

    JofArnold authored
    …f file. Backwards compatible
This page is out of date. Refresh to see the latest.
Showing with 4 additions and 2 deletions.
  1. +4 −2 tasks/json.js
View
6 tasks/json.js
@@ -20,13 +20,15 @@ module.exports = function (grunt) {
var namespace = options && options.namespace || 'myjson'; // Allows the user to customize the namespace but will have a default if one is not given.
var includePath = options && options.includePath || false; // Allows the user to include the full path of the file and the extension.
var processName = options.processName || defaultProcessNameFunction; // Allows the user to modify the path/name that will be used as the identifier.
+ var initializeNamespace = options && (options.initializeNamespace || options.initializeNamespace === undefined) ? 'var ' + namespace + ' = ' + namespace + ' || {};\n' : ''
+ // Allows the user to add or exclude the `var namespace` on the first line
var basename;
var filename;
- return 'var ' + namespace + ' = ' + namespace + ' || {};' + files.map(function (filepath) {
+ return initializeNamespace + files.map(function (filepath) {
basename = path.basename(filepath, '.json');
filename = (includePath) ? processName(filepath) : processName(basename);
- return '\n' + namespace + '["' + filename + '"] = ' + grunt.file.read(filepath) + ';';
+ return namespace + '["' + filename + '"] = ' + grunt.file.read(filepath) + ';';
}).join('');
};
Something went wrong with that request. Please try again.