Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix double handlebars
  • Loading branch information
Kevin Yang committed Aug 16, 2016
commit 8da67a0bfc1f6174a026a0d721fffa4aa79a71d6
8 changes: 6 additions & 2 deletions lib/htmlbars-plugin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ ClassTransformPlugin.prototype.localToPath = function(node) {
};

ClassTransformPlugin.prototype.dynamicLocalPath = function(node) {
var getPath = this.builders.path('lookup-module-styles');
var lookupModuleStylesPath = this.builders.path('lookup-module-styles');
var unboundPath = this.builders.path('unbound');
var stylePath = this.builders.path('styles');

Expand All @@ -121,9 +121,13 @@ ClassTransformPlugin.prototype.dynamicLocalPath = function(node) {
}
if (node.type === 'MustacheStatement') {
builder = 'mustache';
node = this.builders.sexpr(node.path, node.params, node.hash);
}

return [this.builders[builder](getPath, [this.builders['sexpr'](unboundPath, [stylePath]), node])];
var unbound = this.builders['sexpr'](unboundPath, [stylePath]);
var lookupModuleStyles = this.builders[builder](lookupModuleStylesPath, [unbound, node]);

return [lookupModuleStyles];
}

ClassTransformPlugin.prototype.divide = function(parts) {
Expand Down
27 changes: 10 additions & 17 deletions tests-node/htmlbars-plugin-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ testTransformation('appending to an unquoted class attribute with multiple class

testTransformationElement('creating a class attribute with dynamic value on element', {
input: 'local-class={{if true foo}}',
elementOutput: 'class="{{lookup-module-styles (unbound styles) {{if true foo}}}}"'
elementOutput: 'class="{{lookup-module-styles (unbound styles) (if true foo)}}"'
});

testTransformationStatement('creating a class attribute with dynamic value on statement', {
Expand All @@ -50,7 +50,7 @@ testTransformationStatement('creating a class attribute with dynamic value on st

testTransformationElement('appending a class attribute with dynamic value on element', {
input: 'class="x" local-class={{if true foo}}',
elementOutput: 'class="x {{lookup-module-styles (unbound styles) {{if true foo}}}}"'
elementOutput: 'class="x {{lookup-module-styles (unbound styles) (if true foo)}}"'
});

testTransformationStatement('appending a class attribute with dynamic value on statement', {
Expand All @@ -61,40 +61,33 @@ testTransformationStatement('appending a class attribute with dynamic value on s
function testTransformation(title, options) {
test('ClassTransformPlugin: ' + title, function(assert) {
assert.plan(3);
assertElementTransforms('<div [ATTRS]></div>', 'ElementNode', options.input, options.elementOutput, assert);
assertStatementTransforms('{{x-div [ATTRS]}}', 'MustacheStatement', options.input, options.statementOutput, assert);
assertStatementTransforms('{{#x-div [ATTRS]}}content{{/x-div}}', 'BlockStatement', options.input, options.statementOutput, assert);
assertTransforms('<div [ATTRS]></div>', 'ElementNode', options.input, options.elementOutput, assert);
assertTransforms('{{x-div [ATTRS]}}', 'MustacheStatement', options.input, options.statementOutput, assert);
assertTransforms('{{#x-div [ATTRS]}}content{{/x-div}}', 'BlockStatement', options.input, options.statementOutput, assert);
});
}

function testTransformationElement(title, options) {
test('ClassTransformPlugin: ' + title, function(assert) {
assert.plan(1);
assertElementTransforms('<div [ATTRS]></div>', 'ElementNode', options.input, options.elementOutput, assert);
assertTransforms('<div [ATTRS]></div>', 'ElementNode', options.input, options.elementOutput, assert);
});
}

function testTransformationStatement(title, options) {
test('ClassTransformPlugin: ' + title, function(assert) {
assert.plan(2);
assertStatementTransforms('{{x-div [ATTRS]}}', 'MustacheStatement', options.input, options.statementOutput, assert);
assertStatementTransforms('{{#x-div [ATTRS]}}content{{/x-div}}', 'BlockStatement', options.input, options.statementOutput, assert);
assertTransforms('{{x-div [ATTRS]}}', 'MustacheStatement', options.input, options.statementOutput, assert);
assertTransforms('{{#x-div [ATTRS]}}content{{/x-div}}', 'BlockStatement', options.input, options.statementOutput, assert);
});
}

function assertElementTransforms(template, type, input, output, assert) {
var input = template.replace('[ATTRS]', input);
var output = template.replace('[ATTRS]', output);

var actual = htmlbars.print(htmlbars.parse(input, { plugins: { ast: [ClassTransformPlugin] } }));
assert.equal(actual, output, 'works for ' + type);
}

function assertStatementTransforms(template, type, input, output, assert) {
function assertTransforms(template, type, input, output, assert) {
var input = template.replace('[ATTRS]', input);
var output = template.replace('[ATTRS]', output);

var actual = htmlbars.print(htmlbars.parse(input, { plugins: { ast: [ClassTransformPlugin] } }));
var expected = htmlbars.print(htmlbars.parse(output));

assert.equal(actual, expected, 'works for ' + type);
}