broccoli-json-global
Advanced tools
Comparing version 0.0.2 to 0.0.3
11
index.js
@@ -15,2 +15,3 @@ var Filter = require('broccoli-filter'); | ||
this.globalName = options.globalName || 'JSON_DATA'; | ||
this.nestData = options.nestData; | ||
} | ||
@@ -20,4 +21,10 @@ | ||
JSONFilter.prototype.targetExtension = 'js'; | ||
JSONFilter.prototype.processString = function(string) { | ||
return 'var ' + this.globalName + ' = ' + string + ';'; | ||
JSONFilter.prototype.processString = function(string, relativePath) { | ||
var varName = 'window.' + this.globalName; | ||
var initializer = ''; | ||
if (this.nestData) { | ||
initializer = varName + ' = ' + varName + ' || {}; '; | ||
varName += '[\'' + relativePath.replace(/.json$/, '') + '\']'; | ||
} | ||
return initializer + varName + ' = ' + string + ';'; | ||
} |
{ | ||
"name": "broccoli-json-global", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Takes a JSON tree and converts it to a .js file that exposes it globally.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -14,4 +14,11 @@ # broccoli-json-global | ||
var tree = broccoli.makeTree('public/data'); | ||
tree = jsonGlobal(tree); | ||
tree = jsonGlobal('public/data', { | ||
// The name of your globals object. Default is JSON_DATA. | ||
globalName: 'GLOBALS', | ||
// Whether or not to nest data. Keys will be the file name. Default is false. | ||
nestData: true | ||
}); | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3020
24
24