Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
828 additions
and
785 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = function(src) { | ||
return src.replace(/\r\n/g, '\n'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
module.exports = function(grunt, config) { | ||
config.all_plugins = {}; | ||
config.all_langs = {}; | ||
config.loaded_plugins = []; | ||
config.loaded_langs = []; | ||
config.js_files_to_load = config.js_core_files.slice(); | ||
config.all_js_files = config.js_core_files.slice(); | ||
|
||
// list available plugins and languages | ||
grunt.file.expand('src/plugins/**/plugin.js') | ||
.forEach(function(f) { | ||
var n = f.split('/')[2]; | ||
config.all_plugins[n] = f; | ||
}); | ||
|
||
grunt.file.expand('src/i18n/*.json') | ||
.forEach(function(f) { | ||
var n = f.split(/[\/\.]/)[2]; | ||
config.all_langs[n] = f; | ||
}); | ||
|
||
// fill all js files | ||
for (var p in config.all_plugins) { | ||
config.all_js_files.push(config.all_plugins[p]); | ||
} | ||
|
||
// parse 'plugins' parameter | ||
var arg_plugins = grunt.option('plugins'); | ||
if (typeof arg_plugins === 'string') { | ||
arg_plugins.replace(/ /g, '').split(',').forEach(function(p) { | ||
if (config.all_plugins[p]) { | ||
config.js_files_to_load.push(config.all_plugins[p]); | ||
config.loaded_plugins.push(p); | ||
} | ||
else { | ||
grunt.fail.warn('Plugin ' + p + ' unknown'); | ||
} | ||
}); | ||
} | ||
else if (arg_plugins === undefined) { | ||
for (var p in config.all_plugins) { | ||
config.js_files_to_load.push(config.all_plugins[p]); | ||
config.loaded_plugins.push(p); | ||
} | ||
} | ||
|
||
// default language | ||
config.js_files_to_load.push('.temp/i18n/en.js'); | ||
config.loaded_langs.push('en'); | ||
|
||
// parse 'lang' parameter | ||
var arg_langs = grunt.option('languages'); | ||
if (typeof arg_langs === 'string') { | ||
arg_langs.replace(/ /g, '').split(',').forEach(function(l) { | ||
if (config.all_langs[l]) { | ||
if (l !== 'en') { | ||
config.js_files_to_load.push(config.all_langs[l].replace(/^src/, '.temp').replace(/json$/, 'js')); | ||
config.loaded_langs.push(l); | ||
} | ||
} | ||
else { | ||
grunt.fail.warn('Language ' + l + ' unknown'); | ||
} | ||
}); | ||
} | ||
|
||
return config; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
var deepmerge = require('deepmerge'); | ||
|
||
module.exports = function(grunt, loaded_plugins) { | ||
return function(file, src, wrapper) { | ||
var lang = file.split(/[\/\.]/)[2]; | ||
var content = JSON.parse(src); | ||
wrapper = wrapper || ['', '']; | ||
|
||
grunt.config.set('lang_locale', content.__locale || lang); | ||
grunt.config.set('lang_author', content.__author); | ||
var header = grunt.template.process('<%= langBanner %>'); | ||
|
||
loaded_plugins.forEach(function(p) { | ||
var plugin_file = 'src/plugins/' + p + '/i18n/' + lang + '.json'; | ||
|
||
if (grunt.file.exists(plugin_file)) { | ||
content = deepmerge(content, grunt.file.readJSON(plugin_file)); | ||
} | ||
}); | ||
|
||
return header | ||
+ '\n\n' | ||
+ wrapper[0] | ||
+ 'QueryBuilder.regional[\'' + lang + '\'] = ' | ||
+ JSON.stringify(content, null, 2) | ||
+ ';\n\n' | ||
+ 'QueryBuilder.defaults({ lang_code: \'' + lang + '\' });' | ||
+ wrapper[1]; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = function(src) { | ||
return src | ||
.replace(/\/\*jshint [a-z:]+ \*\/\r?\n\r?\n?/g, '') | ||
.replace(/\/\*jshint -[EWI]{1}[0-9]{3} \*\/\r?\n\r?\n?/g, ''); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module.exports = function(grunt, config) { | ||
grunt.registerTask('describe_errors', 'List QueryBuilder errors.', function() { | ||
var errors = {}; | ||
var total = 0; | ||
|
||
for (var f in config.all_js_files) { | ||
grunt.file.read(config.all_js_files[f]).split(/\r?\n/).forEach(function(line, i) { | ||
var matches = /Utils\.error\((?:[^)]+, )?'(\w+)', '([^)]+)'([^)]*)\);/.exec(line); | ||
if (matches !== null) { | ||
(errors[matches[1]] = errors[matches[1]] || []).push({ | ||
type: matches[1], | ||
message: matches[2], | ||
file: config.all_js_files[f], | ||
line: i, | ||
args: matches[3].slice(2).split(', ') | ||
}); | ||
|
||
total++; | ||
} | ||
}); | ||
} | ||
|
||
grunt.log.write('\n'); | ||
|
||
for (var e in errors) { | ||
grunt.log.writeln((e + 'Error')['cyan']); | ||
errors[e].forEach(function(error) { | ||
var message = error.message.replace(/{([0-9]+)}/g, function(m, i) { | ||
return error.args[parseInt(i)]['yellow']; | ||
}); | ||
grunt.log.writeln(' ' + (error.file + ':' + error.line)['red']); | ||
grunt.log.writeln(' ' + message); | ||
}); | ||
grunt.log.write('\n'); | ||
} | ||
|
||
grunt.log.writeln((total + ' Errors in QueryBuilder.')['cyan']['bold']); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module.exports = function(grunt, config) { | ||
grunt.registerTask('describe_triggers', 'List QueryBuilder triggers.', function() { | ||
var triggers = {}; | ||
var total = 0; | ||
|
||
for (var f in config.all_js_files) { | ||
grunt.file.read(config.all_js_files[f]).split(/\r?\n/).forEach(function(line, i) { | ||
var matches = /(e = )?(?:this|that)\.(trigger|change)\('(\w+)'([^)]*)\);/.exec(line); | ||
if (matches !== null) { | ||
triggers[matches[3]] = { | ||
name: matches[3], | ||
type: matches[2], | ||
file: config.all_js_files[f], | ||
line: i, | ||
args: matches[4].slice(2), | ||
prevent: !!matches[1] | ||
}; | ||
|
||
total++; | ||
} | ||
}); | ||
} | ||
|
||
grunt.log.write('\n'); | ||
|
||
for (var t in triggers) { | ||
grunt.log.write(t['cyan'] + ' ' + triggers[t].type['magenta']); | ||
if (triggers[t].prevent) grunt.log.write(' (*)'['yellow']); | ||
grunt.log.write('\n'); | ||
grunt.log.writeln(' ' + (triggers[t].file + ':' + triggers[t].line)['red'] + ' ' + triggers[t].args); | ||
grunt.log.write('\n'); | ||
} | ||
|
||
grunt.log.writeln((total + ' Triggers in QueryBuilder.')['cyan']['bold']); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module.exports = function(grunt, config) { | ||
grunt.registerTask('list_modules', 'List QueryBuilder plugins and languages.', function() { | ||
grunt.log.writeln('\nAvailable QueryBuilder plugins:\n'); | ||
|
||
for (var p in config.all_plugins) { | ||
grunt.log.write(p['cyan']); | ||
|
||
if (grunt.file.exists(config.all_plugins[p].replace(/js$/, 'scss'))) { | ||
grunt.log.write(' + CSS'); | ||
} | ||
|
||
grunt.log.write('\n'); | ||
} | ||
|
||
grunt.log.writeln('\nAvailable QueryBuilder languages:\n'); | ||
|
||
for (var l in config.all_langs) { | ||
if (l !== 'en') { | ||
grunt.log.writeln(l['cyan']); | ||
} | ||
} | ||
}); | ||
}; |
Oops, something went wrong.