Skip to content
This repository has been archived by the owner on Jan 13, 2018. It is now read-only.

Commit

Permalink
Add shortcut for deps by same tech
Browse files Browse the repository at this point in the history
closes #413
  • Loading branch information
Sergey Tatarintsev authored and Vladimir Alaev committed Sep 10, 2013
1 parent 72d86b2 commit c0a2f97
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/techs/deps.js.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,16 +359,21 @@ var DepsItem = exports.DepsItem = INHERIT({
this.item = {};
this.extendByCtx({ item: item });
this.extendByCtx(ctx);

},

extendByCtx: function(ctx) {
if(ctx && (ctx = ctx.item)) {
var ks = ['tech', 'block', 'elem', 'mod', 'val'],
k;
var keys = ['block', 'elem', 'mod', 'val'],
key;

while(k = ks.shift())
if(this.item[k]) break;
else ctx[k] && (this.item[k] = ctx[k]);
if (!this.item.tech && ctx.tech) {
this.item.tech = ctx.tech;
}
while (key = keys.shift()) {
if(this.item[key]) break;
else ctx[key] && (this.item[key] = ctx[key]);
}
}
return this;
},
Expand Down
9 changes: 9 additions & 0 deletions test/deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,15 @@ describe('Deps', function() {
} }
));

it('block with tech shortcut', assertDepsParse(
{block: 'b1', tech: 't1', shouldDeps: {tech: 't2'}},
{ 't1': {
't1': [ { block: 'b1', tech: 't1'} ],
't2': [ { block: 'b1', tech: 't2'} ]
}
}
));

it('block with and without tech', assertDepsParse(
{ block: 'b1', shouldDeps: { block: 'b2', tech: 't2', shouldDeps: { block: 'b3' } } },
{ '': {
Expand Down

0 comments on commit c0a2f97

Please sign in to comment.