Skip to content

Commit

Permalink
Less hackish way to validate i18n techs
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Tatarintsev committed Aug 30, 2013
1 parent bff95c6 commit 58cbd7b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 39 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"mocha": "~1.12.0",
"chai": "~1.7.2",
"bem-smoke": "~0.3.0",
"bem": "~1.0.0",
"bem": "git://github.com/bem/bem-tools.git#77d56dd93e94",
"sinon": "~1.7.3",
"sinon-chai": "~2.4.0",
"jshint": "~2.1.10"
Expand All @@ -40,7 +40,8 @@
"dependencies": {
"ym": "0.0.9",
"bemhtml-compat": "0.0.10",
"bem-xjst": "~0.3.1"
"bem-xjst": "~0.3.1",
"dom-js": "0.0.9"
},
"directories": {
"test": "test"
Expand Down
14 changes: 7 additions & 7 deletions techs/i18n.browser.js+bemhtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,17 @@ exports.techMixin = BEM.util.extend({}, LangsMixin, {
return lang + '.' + this.getBaseTechSuffix();
},

getBuildPaths: function(decl, levels) {
var _this = this;
return Q.all([this.__base(decl, levels), QFS.lastModified(this._allJSPath)])
.spread(function(paths, allJSUpdate) {
getBuildPaths: function(decl, levels, output) {
var _this = this,
source = this.getPath(output, this.getSourceSuffix());
return Q.all([this.__base(decl, levels), QFS.lastModified(source).invoke('getTime')])
.spread(function(paths, sourceUpdate) {
Object.keys(paths).forEach(function(destSuffix) {
if (destSuffix !== _this.getBaseTechSuffix()) {
paths[destSuffix].push({
absPath: _this._allJSPath,
absPath: source,
suffix: _this.getSourceSuffix(),
lastUpdated: allJSUpdate.getTime()
lastUpdated: sourceUpdate
});
}
});
Expand All @@ -80,7 +81,6 @@ exports.techMixin = BEM.util.extend({}, LangsMixin, {
var _this = this,
source = this.getPath(output, this.getSourceSuffix()),
base = this.__base;
this._allJSPath = source;
return BEM.util.readJsonJs(source)
.then(function(data) {
opts = opts || {};
Expand Down
65 changes: 35 additions & 30 deletions techs/i18n.browser.js.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,17 @@ exports.techMixin = BEM.util.extend({}, LangsMixin, {
return lang + '.' + this.getBaseTechSuffix();
},

getBuildResults: function(decl, levels, output, opts) {

getBuildPaths: function(decl, levels, output) {
var _this = this,
source = this.getPath(output, this.getSourceSuffix()),
base = this.__base;

this._allJSPath = source;
return BEM.util.readJsonJs(source)
.then(function(data) {
_this._langData = data;
return base.call(_this, decl, levels, output, opts);
});
},

getBuildPaths: function(decl, levels) {
var _this = this;
return Q.all([this.__base(decl, levels), QFS.lastModified(this._allJSPath)])
.spread(function(paths, allJSUpdate) {
source = this.getPath(output, this.getSourceSuffix());
return Q.all([this.__base(decl, levels), QFS.lastModified(source).invoke('getTime')])
.spread(function(paths, sourceUpdate) {
Object.keys(paths).forEach(function(destSuffix) {
if (destSuffix !== _this.getBaseTechSuffix()) {
paths[destSuffix].push({
absPath: _this._allJSPath,
absPath: source,
suffix: _this.getSourceSuffix(),
lastUpdated: allJSUpdate.getTime()
lastUpdated: sourceUpdate
});
}
});
Expand All @@ -75,26 +62,44 @@ exports.techMixin = BEM.util.extend({}, LangsMixin, {
},


getBuildResults: function(decl, levels, output, opts) {
var _this = this,
source = this.getPath(output, this.getSourceSuffix()),
base = this.__base;
return BEM.util.readJsonJs(source)
.then(function(data) {
opts = opts || {};
opts.ctx = {
data: data
};

return base.call(_this, decl, levels, output, opts);

});
},

getBuildResult: function(files, suffix, output, opts) {
if (suffix === this.getBaseTechSuffix()) {
return Q.resolve(output);
}

this._lang = suffix.substr(0, 2);
return this.__base(files, suffix, output, opts);
var _this = this;
return this.__base.apply(this, arguments)
.then(function(res) {
var lang = suffix.substr(0, 2),
dataLang = _this.extendLangDecl({}, opts.ctx.data.all || {});

},
dataLang = _this.extendLangDecl(dataLang, opts.ctx.data[suffix.substr(0, 2)] || {});

getBuildResultChunk: function (relPath, path, suffix) {
if (path === this._allJSPath) {
var dataLang = this.extendLangDecl({}, this._langData.all || {});
return res.concat(dataLang? _this.serializeI18nData(dataLang, lang) : [])
.concat([_this.serializeI18nInit(lang)]);
});

dataLang = this.extendLangDecl(dataLang, this._langData[this._lang] || {});

},

return (dataLang? this.serializeI18nData(dataLang, this._lang) : [])
.concat([this.serializeI18nInit(this._lang)])
.join('');
getBuildResultChunk: function(relPath, path, suffix) {
if (suffix === this.getSourceSuffix()) {
return '';
}
return this.__base(relPath, path, suffix);
},
Expand Down

0 comments on commit 58cbd7b

Please sign in to comment.