Skip to content

Commit 4098379

Browse files
committed
ui.8; sort objects by key when saving mfAll.js (closes #195)
1 parent 2a04e73 commit 4098379

File tree

9 files changed

+73
-16
lines changed

9 files changed

+73
-16
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ the stable release):
1818
```
1919
meteor add msgfmt:[email protected] # 2016-01-11
2020
meteor add msgfmt:[email protected]
21-
meteor add msgfmt:[email protected].7 # 2016-01-11
21+
meteor add msgfmt:[email protected].8 # 2016-01-27
2222
```
2323

2424
If you don't want the UI translator on production (i.e. no crowd translation),

msgfmt:ui-dev-only/.versions

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ [email protected]
4141
4242
4343
44-
45-
44+
45+
4646
nicolaslopezj:[email protected]
4747
4848

msgfmt:ui-dev-only/package.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
Package.describe({
22
name: "msgfmt:ui-dev-only",
3-
version: "2.0.0",
3+
version: "2.0.1",
44
summary: "msgfmt-ui that is never deployed",
55
git: "https://github.com/gadicc/meteor-messageformat.git",
66
debugOnly: true
77
});
88

99
Package.onUse(function (api) {
10-
api.use('msgfmt:[email protected].7');
10+
api.use('msgfmt:[email protected].8');
1111
api.imply('msgfmt:ui');
1212
});

msgfmt:ui/.versions

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jag:[email protected]
3131
3232
3333
34-
local-test:msgfmt:[email protected].7
34+
local-test:msgfmt:[email protected].8
3535
3636
3737
@@ -42,7 +42,7 @@ [email protected]
4242
4343
4444
45-
45+
4646
nicolaslopezj:[email protected]
4747
4848

msgfmt:ui/History.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
## vNEXT
22

3+
## 2.0.0-preview.8
4+
5+
* Feature: sort objects by key when saving mfAll.js (#195)
6+
Instead of natural order. This helps keeping commits of
7+
mfAll.js small, and gives better overview of changes.
8+
39
## 2.0.0-preview.7
410

511
* Feature: show/hide and sort by `key` (thanks @tomitrescak, #133,

msgfmt:ui/lib/server.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,28 @@ Meteor.publish('mfStats', function() {
7878
});
7979

8080
WebApp.connectHandlers.use('/translate/mfAll.js', function(req, res, next) {
81-
var out, meta = { exportedAt: new Date().getTime(), updatedAt: 0 };
81+
var lang, out, meta = { exportedAt: new Date().getTime(), updatedAt: 0 };
82+
8283
for (lang in mfPkg.strings)
8384
for (key in mfPkg.strings[lang])
8485
if (mfPkg.strings[lang][key].mtime > meta.updatedAt)
8586
meta.updatedAt = mfPkg.strings[lang][key].mtime;
8687

88+
/*
89+
* sort objects by key when saving mfAll.js (#195)
90+
* this helps keeping commits of mfAll.js small,
91+
* and gives better overview of changes.
92+
*/
93+
var sortedStrings = {};
94+
_.each(Object.keys(mfPkg.strings).sort(), function(lang) {
95+
sortedStrings[lang] = {};
96+
_.each(Object.keys(mfPkg.strings[lang]).sort(), function(key) {
97+
sortedStrings[lang][key] = mfPkg.strings[lang][key];
98+
});
99+
});
100+
87101
out = 'mfPkg.syncAll('
88-
+ JSON.stringify(mfPkg.strings, null, 2)
102+
+ JSON.stringify(sortedStrings, null, 2)
89103
+ ', ' + JSON.stringify(meta, null, 2) + ');';
90104
//res.writeHead(200, {'Content-Type': 'application/javascript'});
91105
res.writeHead(200, {'Content-Disposition': 'attachment; filename=mfAll.js'});

msgfmt:ui/package.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package.describe({
22
name: "msgfmt:ui",
3-
version: "2.0.0-preview.7",
3+
version: "2.0.0-preview.8",
44
summary: "messageformat: translation UI",
55
git: "https://github.com/gadicc/meteor-messageformat.git",
66
});
@@ -30,8 +30,8 @@ Package.onUse(function (api) {
3030
});
3131

3232
Package.onTest(function(api) {
33-
api.use('tinytest');
34-
api.use('msgfmt:ui');
33+
api.use(['tinytest', 'http', 'ejson', 'underscore']);
34+
api.use(['msgfmt:core', 'msgfmt:ui']);
3535

3636
api.addFiles('tests/tests-client.js', 'client');
3737
api.addFiles('tests/tests-server.js', 'server');

msgfmt:ui/tests/tests-client.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
Tinytest.add('messageformat-ui', function(test) {
1+
Tinytest.add('msgfmt:ui', function(test) {
22
test.ok(true);
33
});

msgfmt:ui/tests/tests-server.js

+40-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,40 @@
1-
Tinytest.add('messageformat-ui', function(test) {
2-
test.ok(true);
3-
});
1+
var vm = Npm.require('vm');
2+
3+
function getMfAll() {
4+
var res = HTTP.get(Meteor.absoluteUrl('/translate/mfAll.js'));
5+
//var json = res.content.match(/^mfPkg.syncAll\(([\s\S]*)\);/)[1];
6+
var sandbox = {
7+
out: {},
8+
mfPkg: {
9+
syncAll: function(strings, meta) {
10+
sandbox.out.strings = strings;
11+
sandbox.out.meta = meta;
12+
}
13+
}
14+
};
15+
16+
vm.runInNewContext(res.content, sandbox);
17+
return sandbox.out;
18+
}
19+
20+
Tinytest.add('msgfmt:ui - mfAll.js - sorted by key', function(test) {
21+
// Add some out of order stuff to whatever's already in db
22+
msgfmt.langUpdate('en', {
23+
keyOrderC: { key: 'keyOrderC', lang: 'en', text: 'keyOrderC', ctime: 1453884079148, mtime: 1453884079148, revisionId: 'c8eDxMdMJJKDfpEME', file: 'msgfmt:ui-tests', line: 0, func: 'function()' },
24+
keyOrderA: { key: 'keyOrderA', lang: 'en', text: 'keyOrderA', ctime: 1453884079148, mtime: 1453884079148, revisionId: 'c8eDxMdMJJKDfpEMF', file: 'msgfmt:ui-tests', line: 0, func: 'function()' },
25+
keyOrderB: { key: 'keyOrderB', lang: 'en', text: 'keyOrderB', ctime: 1453884079148, mtime: 1453884079148, revisionId: 'c8eDxMdMJJKDfpEMG', file: 'msgfmt:ui-tests', line: 0, func: 'function()' }
26+
}, {
27+
exportedAt: Date.now(),
28+
updatedAt: Date.now()
29+
});
30+
31+
var strings = getMfAll().strings;
32+
var keys = Object.keys(strings.en);
33+
34+
// Assert no change in EJSON's behaviour to make sure below remains true
35+
if (EJSON.stringify({c:1, a:1, b:1}) !== '{"c":1,"a":1,"b":1}')
36+
throw new Error("EJSON behaviour has changed");
37+
38+
// Must use EJSON since JSON.stringify re-orders the keys
39+
test.equal(EJSON.stringify(keys), EJSON.stringify(keys.sort()));
40+
});

0 commit comments

Comments
 (0)