Skip to content

Commit

Permalink
feat(token templates): Added simple value translation.
Browse files Browse the repository at this point in the history
  • Loading branch information
David Diers committed Feb 14, 2017
1 parent 845beb8 commit 4d3a09d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
8 changes: 6 additions & 2 deletions lib/plugins/transform/tokenTemplateValues.js
Expand Up @@ -40,6 +40,10 @@ module.exports = superclass => class extends superclass {
["error", { "exceptMethods": ["getTraceIndex"] }]
*/
transform(value) {
let tmpValue = value;
if (typeof tmpValue !== 'object') {
tmpValue = {value: value};// eslint-disable-line object-shorthand
}
// Set up variables.
// Are we using named values?
let tokens = {}; // eslint-disable-line no-unused-vars
Expand All @@ -53,13 +57,13 @@ module.exports = superclass => class extends superclass {
// We are using tokens, which are reassignments of values to new names.
for (let i = 0; i < Object.keys(tmpTokens).length; i += 1) {
// We need to get the values and assign them to their new names.
tmpTokens[Object.keys(tmpTokens)[i]] = value[tmpTokens[Object.keys(tmpTokens)[i]]];
tmpTokens[Object.keys(tmpTokens)[i]] = tmpValue[tmpTokens[Object.keys(tmpTokens)[i]]];
}
tokens = Object.assign({}, tokens, tmpTokens);
}
else {
// we are not using tokens.
tokens = Object.assign({}, tokens, value);
tokens = Object.assign({}, tokens, tmpValue);
}
const templatePath = this.getTemplatePath(this.options.origin);

Expand Down
1 change: 1 addition & 0 deletions test/helpers/templateFive.tpl
@@ -0,0 +1 @@
this is a {{value}}
15 changes: 14 additions & 1 deletion test/tokenTemplateValues.js
Expand Up @@ -73,6 +73,7 @@ const options5 = {
}
};

const value2 = 'testBoogie';

const testClass = new Implemented(options, {});

Expand All @@ -84,6 +85,8 @@ const testClass4 = new Implemented(options4, {monkey: 'toofer'});

const testClass5 = new Implemented(options5, {monkey: 'toofer'});

const testClass6 = new Implemented(options, {});

module.exports = {
tokenOnlyValues: (test) => {
test.expect(1);
Expand Down Expand Up @@ -148,6 +151,16 @@ module.exports = {
'Dust template "one" name is: testName, test has the value of \"testKey2: item1.' // eslint-disable-line no-useless-escape
);
test.done();
}
},
tokenSimpleValue: (test) => {
test.expect(1);
testClass6.options.origin = 'test/helpers/templateFive.tpl';
testClass.transform(value2);
test.deepEqual(
testClass.value,
'this is a testBoogie'
);
test.done();
},

};

0 comments on commit 4d3a09d

Please sign in to comment.