Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed core priority #77

Merged
merged 1 commit into from
Sep 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions lib/keysets.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ function read(filename, cache, root) {
* @returns {{ core: Function|String, keysets: (Object.<String, String>|Object.<String, String, Function>) }}
*/
function parse(keysets) {
var core,
data = {},
version = 'bem-core';
var core1, core2,
data = {};

// Pull core from source keysets
keysets && Object.keys(keysets).forEach(function (scope) {
Expand All @@ -52,28 +51,29 @@ function parse(keysets) {
var keyset = keysets[scope];

if (keyset && typeof keyset.i18n === 'function') {
core = keyset.i18n;
core2 = keyset.i18n;
}
// Search deprecated core in `all` scope
} else if (scope === 'all') {
var possibleCore = keysets[scope][''];
if (possibleCore && (typeof possibleCore === 'string') && possibleCore.match(/BEM\.I18N/g)) {
version = 'bem-bl';
core = possibleCore;
core1 = possibleCore;
}
} else {
data[scope] = keysets[scope];
}
});

var core = core2 || core1;

if (!core) {
throw new Error('Core of i18n is not found!');
}

return {
core: core,
keysets: data,
version: version
version: core2 ? 'bem-core' : 'bem-bl'
};
}

Expand Down
60 changes: 60 additions & 0 deletions test/techs/i18n/mix.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
var fs = require('fs'),
path = require('path'),
mock = require('mock-fs'),
serializeJS = require('serialize-javascript'),
MockNode = require('mock-enb/lib/mock-node'),
Tech = require('../../../techs/i18n'),
bemCoreI18nCore = require('../../fixtures/bem-core-v3/common.blocks/i18n/i18n.i18n.js').i18n.i18n,
bemBLI18NCore;

describe('i18n for bem-bl + bem-core', function () {
before(function () {
var bemBLI18NPath = './test/fixtures/bem-core/common.blocks/i-bem/__i18n/i-bem__i18n.i18n/core.js';

bemBLI18NCore = fs.readFileSync(path.resolve(bemBLI18NPath), { encoding: 'utf-8' });
});

afterEach(function () {
mock.restore();
});

it('must use bem-core', function () {
var keysets = {
i18n: {
i18n: bemCoreI18nCore
},
all: {
'': bemBLI18NCore
},
scope: {
key: function (params) {
return params.join();
}
}
};

return build(keysets)
.then(function (i18n) {
i18n('scope', 'key', ['p1', 'p2']).must.be('p1,p2');
});
});
});

function build(keysets) {
mock({
bundle: {
'bundle.keysets.lang.js': serialize(keysets)
}
});

var bundle = new MockNode('bundle');

return bundle.runTechAndRequire(Tech, { lang: 'lang' })
.spread(function (i18n) {
return i18n;
});
}

function serialize(js) {
return 'module.exports = ' + serializeJS(js) + ';';
}