Permalink
Browse files

grunt 0.4.0rc7 work

* Upgraded to grunt 0.4.0rc7
* Added jshint and nodeunit depedencies
* Replaced deprecated registerHelper() calls
  • Loading branch information...
1 parent e9aadfb commit 7366a352d6879ba6776e9f738674f075314c727e @existentialism existentialism committed Jan 28, 2013
View
@@ -1,2 +1,3 @@
.DS_Store
-node_modules
+node_modules
+tmp
View
@@ -0,0 +1,75 @@
+'use strict';
+
+module.exports = function(grunt) {
+
+ // Project configuration.
+ grunt.initConfig({
+
+ // Before generating any new files, remove any previously-created files.
+ clean: {
+ test: ['tmp']
+ },
+
+ // Configuration to be run (and then tested).
+ messageformat: {
+ en: {
+ locale: 'en',
+ inputdir: 'test/fixtures/en',
+ output: 'tmp/en/i18n.js'
+ },
+ de: {
+ locale: 'de',
+ inputdir: 'test/fixtures/de',
+ output: 'tmp/de/i18n.js'
+ }
+ },
+
+ // Unit tests.
+ nodeunit: {
+ all: ['test/**/*_test.js']
+ },
+
+ watch: {
+ files: '<config:jshint.all>',
+ tasks: 'default'
+ },
+
+ jshint: {
+ all: ['grunt.js', 'tasks/**/*.js', 'test/**/*.js'],
+ options: {
+ curly: true,
+ eqeqeq: true,
+ immed: true,
+ latedef: true,
+ newcap: true,
+ noarg: true,
+ sub: true,
+ undef: true,
+ boss: true,
+ asi: true,
+ expr: true,
+ strict: false,
+ eqnull: true,
+ node: true,
+ browser: true
+ }
+ }
+
+ });
+
+ // Actually load this plugin's task(s).
+ grunt.loadTasks('tasks');
+
+ // These plugins provide necessary tasks
+ grunt.loadNpmTasks('grunt-contrib-clean');
+ grunt.loadNpmTasks('grunt-contrib-jshint');
+ grunt.loadNpmTasks('grunt-contrib-nodeunit');
+
+ // Whenever the "test" task is run, first clean the "tmp" dir, then run this
+ // plugin's task(s), then test the result.
+ grunt.registerTask('test', ['clean', 'messageformat', 'nodeunit']);
+
+ // By default, lint and run all tests.
+ grunt.registerTask('default', [ 'jshint', 'test' ]);
+
+};
View
@@ -1,43 +0,0 @@
-module.exports = function(grunt) {
-
- // Project configuration.
- grunt.initConfig({
- test: {
- files: ['test/**/*_test.js']
- },
- lint: {
- files: ['grunt.js', 'tasks/**/*.js', 'test/**/*.js']
- },
- watch: {
- files: '<config:lint.files>',
- tasks: 'default'
- },
- jshint: {
- options: {
- curly: true,
- eqeqeq: true,
- immed: true,
- latedef: true,
- newcap: true,
- noarg: true,
- sub: true,
- undef: true,
- boss: true,
- asi: true,
- expr: true,
- strict: false,
- eqnull: true,
- node: true,
- browser: true
- },
- globals: {}
- }
- });
-
- // Load local tasks.
- grunt.loadTasks('tasks');
-
- // Default task.
- grunt.registerTask('default', 'lint test');
-
-};
View
@@ -35,9 +35,12 @@
"async": "~0.1.22"
},
"devDependencies": {
- "grunt": "~0.3.17"
+ "grunt": "0.4.0rc7",
+ "grunt-contrib-clean": "~0.4.0rc6",
+ "grunt-contrib-jshint": "0.1.1rc6",
+ "grunt-contrib-nodeunit": "0.1.2rc6"
},
"keywords": [
"gruntplugin"
]
-}
+}
View
@@ -18,11 +18,18 @@ module.exports = function(grunt) {
grunt.registerMultiTask('messageformat', 'messageformat compiler for grunt', function () {
var done = this.async();
- var task = grunt.config('messageformat');
- var data = this.data;
- grunt.helper('messageformat', data, function (err, js) {
+ var defaults = {
+ namespace: 'window.i18n',
+ include: '**/*.json'
+ };
+
+ var data = _.extend({}, defaults, this.data);
+ var options = this.options(data);
+
+ grunt.verbose.writeflags(options, 'Options');
+ compiler.compile(options, grunt.log, function (err, js) {
if (err) {
grunt.log.error(err);
done(false);
@@ -31,25 +38,7 @@ module.exports = function(grunt) {
grunt.file.write(data.output, js);
done(true);
}
-
});
});
-
- grunt.registerHelper('messageformat', function(options, done) {
-
- var defaults = {
- namespace: 'window.i18n',
- include: '**/*.json'
- };
-
- _.defaults(options, defaults);
-
- compiler.compile(options, grunt.log, function (err, js) {
- return done(err, js);
- });
-
- });
-
};
-
View
@@ -0,0 +1,21 @@
+(function(){ window.i18n || (window.i18n = {})
+var MessageFormat = { locale: {} };
+MessageFormat.locale.de = function ( n ) {
+ if ( n === 1 ) {
+ return "one";
+ }
+ return "other";
+};
+
+window.i18n["greetings"] = {}
+window.i18n["greetings"]["hello"] = function(d){
+var r = "";
+r += "Guten Tag";
+return r;
+}
+window.i18n["greetings"]["goodbye"] = function(d){
+var r = "";
+r += "Auf Wiedersehen";
+return r;
+}
+})();
File renamed without changes.
@@ -0,0 +1,4 @@
+{
+ "hello": "Guten Tag",
+ "goodbye": "Auf Wiedersehen"
+}
View
@@ -1,67 +1,19 @@
-/*jshint curly:true, eqeqeq:true, immed:true, latedef:true,
- newcap:true, noarg:true, sub:true, undef:true, boss:true,
- strict:false, eqnull:true, browser:true, node:true */
-
var grunt = require('grunt');
-var fs = require('fs');
-var path = require('path');
-
-/*
- ======== A Handy Little Nodeunit Reference ========
- https://github.com/caolan/nodeunit
-
- Test methods:
- test.expect(numAssertions)
- test.done()
- Test assertions:
- test.ok(value, [message])
- test.equal(actual, expected, [message])
- test.notEqual(actual, expected, [message])
- test.deepEqual(actual, expected, [message])
- test.notDeepEqual(actual, expected, [message])
- test.strictEqual(actual, expected, [message])
- test.notStrictEqual(actual, expected, [message])
- test.throws(block, [error], [message])
- test.doesNotThrow(block, [error], [message])
- test.ifError(value)
-*/
-
-exports['unit test messageformat'] = {
-
- 'setUp': function(done) {
-
- var self = this;
- var localeFile = path.join(__dirname,
- 'fixtures', 'en', 'i18n.js');
-
- fs.readFile(localeFile, 'utf8', function (err, js) {
-
- self.parsedJs = js;
- done();
- });
+exports.messageformat = {
+ main: function(test) {
+ 'use strict';
- },
+ test.expect(2);
- 'helper should parse messages': function(test) {
+ var actual = grunt.file.read('tmp/en/i18n.js');
+ var expected = grunt.file.read('test/expected/en/i18n.js');
+ test.equal(expected, actual, 'should compile messageformat - en');
+ actual = grunt.file.read('tmp/de/i18n.js');
+ expected = grunt.file.read('test/expected/de/i18n.js');
+ test.equal(expected, actual, 'should compile messageformat - de');
- var expected = this.parsedJs;
- var options = {
- inputdir: './test/fixtures/en',
- locale: 'en'
- };
-
-
- test.expect(1);
-
- grunt.helper('messageformat', options, function (err, parsedJs) {
-
- test.equal(expected, parsedJs);
- test.done();
-
- });
-
+ test.done();
}
-
};

0 comments on commit 7366a35

Please sign in to comment.