From 2f5c371f3208cc05847debcf2bcdcee09a20f05d Mon Sep 17 00:00:00 2001 From: David OSTERMANN Date: Thu, 2 Apr 2015 22:52:35 +0200 Subject: [PATCH 01/13] rep are module inject gettext + adapt requirejs add-on --- lib/compile.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/compile.js b/lib/compile.js index 6d3e426..32c1fe1 100644 --- a/lib/compile.js +++ b/lib/compile.js @@ -9,7 +9,7 @@ var formats = { return ' gettextCatalog.setStrings(\'' + locale + '\', ' + JSON.stringify(strings) + ');\n'; }, format: function (locales, options) { - var module = 'angular.module(\'' + options.module + '\')' + + var module = 'angular.module(\'' + options.module + '\',[\'gettext\'])\n' + '.run([\'gettextCatalog\', function (gettextCatalog) {\n' + '/* jshint -W100 */\n' + locales.join('') + @@ -20,7 +20,7 @@ var formats = { module += '}]);'; if (options.requirejs) { - return 'define([\'angular\', \'' + options.modulePath + '\'], function (angular) {\n' + module + '\n});'; + return 'define([\'' + options.modulePath + '\'], function (angular) {\nreturn ' + module + '\n});'; } return module; From 40f0240d022cab3788f5f068f8ddff9e77d25a66 Mon Sep 17 00:00:00 2001 From: David OSTERMANN Date: Thu, 2 Apr 2015 23:00:49 +0200 Subject: [PATCH 02/13] remove angular parameter --- lib/compile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/compile.js b/lib/compile.js index 32c1fe1..75d1504 100644 --- a/lib/compile.js +++ b/lib/compile.js @@ -20,7 +20,7 @@ var formats = { module += '}]);'; if (options.requirejs) { - return 'define([\'' + options.modulePath + '\'], function (angular) {\nreturn ' + module + '\n});'; + return 'define([\'' + options.modulePath + '\'], function () {\nreturn ' + module + '\n});'; } return module; From ca5d9d69e58d30c77f93b6e196050b318bf0d1ed Mon Sep 17 00:00:00 2001 From: David OSTERMANN Date: Fri, 3 Apr 2015 17:24:52 +0200 Subject: [PATCH 03/13] =?UTF-8?q?add=20options=20=E2=80=98moduleName?= =?UTF-8?q?=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/compile.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/compile.js b/lib/compile.js index 75d1504..4f91200 100644 --- a/lib/compile.js +++ b/lib/compile.js @@ -20,7 +20,8 @@ var formats = { module += '}]);'; if (options.requirejs) { - return 'define([\'' + options.modulePath + '\'], function () {\nreturn ' + module + '\n});'; + var moduleName = (options.moduleName) ? options.moduleName : ''; + return 'define('+moduleName+'[\'' + options.modulePath + '\'], function () {\nreturn ' + module + '\n});'; } return module; From a94448a71d6da53ffc11931d34dad405997e7eb0 Mon Sep 17 00:00:00 2001 From: David OSTERMANN Date: Fri, 3 Apr 2015 17:28:38 +0200 Subject: [PATCH 04/13] switch require path module --- lib/compile.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/compile.js b/lib/compile.js index 4f91200..5eb0ae1 100644 --- a/lib/compile.js +++ b/lib/compile.js @@ -20,8 +20,8 @@ var formats = { module += '}]);'; if (options.requirejs) { - var moduleName = (options.moduleName) ? options.moduleName : ''; - return 'define('+moduleName+'[\'' + options.modulePath + '\'], function () {\nreturn ' + module + '\n});'; + var modulePath = (options.modulePath) ? options.modulePath : ''; + return 'define('+modulePath+'[\'' + options.depPath + '\'], function () {\nreturn ' + module + '\n});'; } return module; From 9ca53d50d938aa3826f491ae96303f421cce5b5a Mon Sep 17 00:00:00 2001 From: David OSTERMANN Date: Fri, 3 Apr 2015 17:39:27 +0200 Subject: [PATCH 05/13] add quotes --- lib/compile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/compile.js b/lib/compile.js index 5eb0ae1..7407015 100644 --- a/lib/compile.js +++ b/lib/compile.js @@ -21,7 +21,7 @@ var formats = { if (options.requirejs) { var modulePath = (options.modulePath) ? options.modulePath : ''; - return 'define('+modulePath+'[\'' + options.depPath + '\'], function () {\nreturn ' + module + '\n});'; + return 'define(\''+modulePath+'\',[\'' + options.depPath + '\'], function () {\nreturn ' + module + '\n});'; } return module; From 5fc218ae7f04c73fa5fc936d12897a46be0219e5 Mon Sep 17 00:00:00 2001 From: David OSTERMANN Date: Fri, 3 Apr 2015 19:11:29 +0200 Subject: [PATCH 06/13] unstick + character --- lib/compile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/compile.js b/lib/compile.js index 7407015..c7ea742 100644 --- a/lib/compile.js +++ b/lib/compile.js @@ -21,7 +21,7 @@ var formats = { if (options.requirejs) { var modulePath = (options.modulePath) ? options.modulePath : ''; - return 'define(\''+modulePath+'\',[\'' + options.depPath + '\'], function () {\nreturn ' + module + '\n});'; + return 'define(\'' + modulePath + '\',[\'' + options.depPath + '\'], function () {\nreturn ' + module + '\n});'; } return module; From fc2b1f586511389d718510774e211c8ae45a2bc1 Mon Sep 17 00:00:00 2001 From: David OSTERMANN Date: Fri, 3 Apr 2015 19:31:46 +0200 Subject: [PATCH 07/13] add options.requirejsDependencies array --- lib/compile.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/compile.js b/lib/compile.js index c7ea742..d680d00 100644 --- a/lib/compile.js +++ b/lib/compile.js @@ -20,8 +20,9 @@ var formats = { module += '}]);'; if (options.requirejs) { - var modulePath = (options.modulePath) ? options.modulePath : ''; - return 'define(\'' + modulePath + '\',[\'' + options.depPath + '\'], function () {\nreturn ' + module + '\n});'; + var modulePath = (options.requirejsModulePath) ? options.requirejsModulePath : ''; + var deps = (options.requirejsDependencies) ? options.requirejsDependencies.join[','] : ''; + return 'define(\'' + modulePath + '\',[' + deps + '], function () {\nreturn ' + module + '\n});'; } return module; From 9abf2d256777cae050db1641671d21d3f3cd5b56 Mon Sep 17 00:00:00 2001 From: David OSTERMANN Date: Fri, 3 Apr 2015 19:53:17 +0200 Subject: [PATCH 08/13] replace double quotes --- lib/compile.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/compile.js b/lib/compile.js index d680d00..21e72a7 100644 --- a/lib/compile.js +++ b/lib/compile.js @@ -21,8 +21,8 @@ var formats = { if (options.requirejs) { var modulePath = (options.requirejsModulePath) ? options.requirejsModulePath : ''; - var deps = (options.requirejsDependencies) ? options.requirejsDependencies.join[','] : ''; - return 'define(\'' + modulePath + '\',[' + deps + '], function () {\nreturn ' + module + '\n});'; + var deps = (options.requirejsDependencies) ? JSON.stringify(options.requirejsDependencies).replace(/"/gi, '\'') : ''; + return 'define(\'' + modulePath + '\',' + deps + ', function () {\nreturn ' + module + '\n});'; } return module; From e14664c50d82590fabb7cb61b5545245e63f730f Mon Sep 17 00:00:00 2001 From: David OSTERMANN Date: Fri, 3 Apr 2015 20:11:59 +0200 Subject: [PATCH 09/13] adapt test --- test/compile.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/compile.js b/test/compile.js index 89683b8..f3d2bcd 100644 --- a/test/compile.js +++ b/test/compile.js @@ -24,11 +24,11 @@ function makeEnv(mod, catalog) { } // Fake Angular environment with RequireJS module loader -function makeRequireJsEnv(mod, modPath, catalog) { +function makeRequireJsEnv(mod, name, deps, catalog) { return { - define: function (modules, callback) { - assert.equal(modules[0], 'angular'); - assert.equal(modules[1], modPath); + define: function (expliciteName, modules, callback) { + assert.equal(modules[0], deps[0]); + assert.equal(modules[1], deps[1]); var angular = { module: function (modDefined) { @@ -116,7 +116,7 @@ describe('Compile', function () { var output = testCompile(files, { module: 'myApp', requirejs: true, - modulePath: './test/fixtures/module' + modulePath: ['angular', './test/fixtures/module'] }); var catalog = { called: false, @@ -125,7 +125,7 @@ describe('Compile', function () { } }; - var context = vm.createContext(makeRequireJsEnv('myApp', './test/fixtures/module', catalog)); + var context = vm.createContext(makeRequireJsEnv('myApp', 'testName', ['angular', './test/fixtures/module'], catalog)); vm.runInContext(output, context); assert(catalog.called); }); From a151d83cae0a4cfe782d664412c55f30735b3f28 Mon Sep 17 00:00:00 2001 From: David OSTERMANN Date: Fri, 3 Apr 2015 20:43:07 +0200 Subject: [PATCH 10/13] reset test change --- test/compile.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/compile.js b/test/compile.js index f3d2bcd..0b932bc 100644 --- a/test/compile.js +++ b/test/compile.js @@ -24,11 +24,11 @@ function makeEnv(mod, catalog) { } // Fake Angular environment with RequireJS module loader -function makeRequireJsEnv(mod, name, deps, catalog) { +function makeRequireJsEnv(mod, modPath, catalog) { return { - define: function (expliciteName, modules, callback) { - assert.equal(modules[0], deps[0]); - assert.equal(modules[1], deps[1]); + define: function (modules, callback) { + assert.equal(modules[0], 'angular'); + assert.equal(modules[1], modPath); var angular = { module: function (modDefined) { @@ -116,7 +116,7 @@ describe('Compile', function () { var output = testCompile(files, { module: 'myApp', requirejs: true, - modulePath: ['angular', './test/fixtures/module'] + modulePath: './test/fixtures/module' }); var catalog = { called: false, @@ -125,7 +125,7 @@ describe('Compile', function () { } }; - var context = vm.createContext(makeRequireJsEnv('myApp', 'testName', ['angular', './test/fixtures/module'], catalog)); + var context = vm.createContext(makeRequireJsEnv('myApp', './test/fixtures/module', catalog)); vm.runInContext(output, context); assert(catalog.called); }); @@ -242,4 +242,4 @@ describe('Compile', function () { vm.runInContext(output, context); assert(catalog.called); }); -}); +}); \ No newline at end of file From 950dffafa6806b7678025dd6972305c2484a7bd5 Mon Sep 17 00:00:00 2001 From: David OSTERMANN Date: Sat, 4 Apr 2015 10:13:54 +0200 Subject: [PATCH 11/13] fix requirejs wrapping --- lib/compile.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/compile.js b/lib/compile.js index 21e72a7..4573a14 100644 --- a/lib/compile.js +++ b/lib/compile.js @@ -20,9 +20,9 @@ var formats = { module += '}]);'; if (options.requirejs) { - var modulePath = (options.requirejsModulePath) ? options.requirejsModulePath : ''; - var deps = (options.requirejsDependencies) ? JSON.stringify(options.requirejsDependencies).replace(/"/gi, '\'') : ''; - return 'define(\'' + modulePath + '\',' + deps + ', function () {\nreturn ' + module + '\n});'; + var modulePath = (options.requirejsModulePath) ? ('\'' + options.requirejsModulePath + '\',') : ''; + var deps = (options.requirejsDependencies) ? JSON.stringify(options.requirejsDependencies).replace(/"/gi, '\'') : '[]'; + return 'define( ' + modulePath + deps + ', function () {\nreturn ' + module + '\n});'; } return module; From db254f17cd79fc82129e5bf35989a87c7d65a0a5 Mon Sep 17 00:00:00 2001 From: David OSTERMANN Date: Mon, 13 Apr 2015 01:09:02 +0200 Subject: [PATCH 12/13] rewrite compile with angular dependence and adapt test --- lib/compile.js | 7 ++++--- test/compile.js | 51 ++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/lib/compile.js b/lib/compile.js index 4573a14..85f6f41 100644 --- a/lib/compile.js +++ b/lib/compile.js @@ -20,9 +20,10 @@ var formats = { module += '}]);'; if (options.requirejs) { - var modulePath = (options.requirejsModulePath) ? ('\'' + options.requirejsModulePath + '\',') : ''; - var deps = (options.requirejsDependencies) ? JSON.stringify(options.requirejsDependencies).replace(/"/gi, '\'') : '[]'; - return 'define( ' + modulePath + deps + ', function () {\nreturn ' + module + '\n});'; + var nameStr = (options.requirejsName) ? ('\'' + options.requirejsName + '\',') : ''; + var deps = (options.requirejsModule) ? ['angular', options.requirejsModule] : ['angular']; + var depsStr = JSON.stringify(deps).replace(/"/gi, '\''); + return 'define( ' + nameStr + depsStr + ', function (angular) {\nreturn ' + module + '\n});'; } return module; diff --git a/test/compile.js b/test/compile.js index 0b932bc..9dfa172 100644 --- a/test/compile.js +++ b/test/compile.js @@ -23,12 +23,37 @@ function makeEnv(mod, catalog) { }; } + // Fake Angular environment with RequireJS module loader -function makeRequireJsEnv(mod, modPath, catalog) { +function makeRequireJsExpliciteEnv(mod, name, module, catalog) { + return { + define: function (expliciteName, modules, callback) { + assert.equal(expliciteName, name); + assert.equal(modules[0], 'angular'); + assert.equal(modules[1], module); + + var angular = { + module: function (modDefined) { + assert.equal(modDefined, mod); + return { + run: function (block) { + assert.equal(block[0], 'gettextCatalog'); + block[1](catalog); + } + }; + } + }; + callback(angular); + } + }; +} + +// Fake Angular environment with RequireJS module loader +function makeRequireJsEnv(mod, module, catalog) { return { define: function (modules, callback) { assert.equal(modules[0], 'angular'); - assert.equal(modules[1], modPath); + assert.equal(modules[1], module); var angular = { module: function (modDefined) { @@ -116,7 +141,7 @@ describe('Compile', function () { var output = testCompile(files, { module: 'myApp', requirejs: true, - modulePath: './test/fixtures/module' + requirejsModule: './test/fixtures/module' }); var catalog = { called: false, @@ -130,6 +155,26 @@ describe('Compile', function () { assert(catalog.called); }); + it('Accepts a requirejs and name parameter', function () { + var files = ['test/fixtures/nl.po']; + var output = testCompile(files, { + module: 'myApp', + requirejs: true, + requirejsName: 'testName', + requirejsModule: './test/fixtures/module' + }); + var catalog = { + called: false, + setStrings: function (language, strings) { + this.called = true; + } + }; + + var context = vm.createContext(makeRequireJsExpliciteEnv('myApp', 'testName', './test/fixtures/module', catalog)); + vm.runInContext(output, context); + assert(catalog.called); + }); + it('Allows merging multiple languages', function () { var files = ['test/fixtures/nl.po', 'test/fixtures/fr.po']; var output = testCompile(files); From 072c89563c4bf7ee46d725fea74ea01c9f4a6b22 Mon Sep 17 00:00:00 2001 From: David OSTERMANN Date: Thu, 4 Jun 2015 18:28:16 +0200 Subject: [PATCH 13/13] angular in params --- lib/compile.js | 7 +++++-- test/compile.js | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/compile.js b/lib/compile.js index 85f6f41..6771ded 100644 --- a/lib/compile.js +++ b/lib/compile.js @@ -21,9 +21,12 @@ var formats = { if (options.requirejs) { var nameStr = (options.requirejsName) ? ('\'' + options.requirejsName + '\',') : ''; - var deps = (options.requirejsModule) ? ['angular', options.requirejsModule] : ['angular']; + var deps = []; + if (options.requirejsAngular) { deps.push(options.requirejsAngular); } + if (options.requirejsModule) { deps.push(options.requirejsModule); } var depsStr = JSON.stringify(deps).replace(/"/gi, '\''); - return 'define( ' + nameStr + depsStr + ', function (angular) {\nreturn ' + module + '\n});'; + var paramStr = (options.requirejsAngular) ? 'angular' : ''; + return 'define( ' + nameStr + depsStr + ', function (' + paramStr + ') {\nreturn ' + module + '\n});'; } return module; diff --git a/test/compile.js b/test/compile.js index 9dfa172..4092b18 100644 --- a/test/compile.js +++ b/test/compile.js @@ -141,6 +141,7 @@ describe('Compile', function () { var output = testCompile(files, { module: 'myApp', requirejs: true, + requirejsAngular: 'angular', requirejsModule: './test/fixtures/module' }); var catalog = { @@ -161,6 +162,7 @@ describe('Compile', function () { module: 'myApp', requirejs: true, requirejsName: 'testName', + requirejsAngular: 'angular', requirejsModule: './test/fixtures/module' }); var catalog = {