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

Redefined blocks now actually work as expected #80

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions lib/ect.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
bufferStack.push('__ectTemplateContext.blocks[\'' + text.replace(/block\s+('|")([^'"]+)('|").*/, '$2') + '\']');
bufferStackPointer++;
prefix = '\'\n';
postfix = '\n' + bufferStack[bufferStackPointer] + ' += \'';
postfix = '\n' + bufferStack[bufferStackPointer] + ' = \'';
text = 'if ' + text;
buffer += prefix.replace(newlineExp, '\n' + indentation) + text;
if (indent) {
Expand Down Expand Up @@ -302,7 +302,7 @@

TemplateContext.prototype.block = function (name) {
if (!this.blocks[name]) { this.blocks[name] = ''; }
return !this.blocks[name].length;
return true || !this.blocks[name].length;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latter part of this conditional statement becomes unreachable with this change.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That to say, since this always returns true then it should likely not return anything and any code relying on it be refactored.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did that so that the previous statement would still exist there and goad someone who knows why it's there to change it. It could merely be commented out though.

};

TemplateContext.prototype.content = function (block) {
Expand Down Expand Up @@ -692,4 +692,4 @@
}());

}
}());
}());