Skip to content
Browse files

fixed bad example of initialization in blockMain instead of init

  • Loading branch information...
1 parent ba8b81d commit 5bedb71c9f9d2bcd9545e2bf28d0e2a2d6fb183c @dimsmol committed
View
6 error_examples/results/generation_errors.txt
@@ -1,6 +1,3 @@
-File "error_examples/generation/no_template.ojst" compilation failed:
-Template token not found
-
File "error_examples/generation/generation.ojst" compilation failed:
4: <% @inherits ojster.Template %>
^
@@ -30,3 +27,6 @@ File "error_examples/generation/generation.ojst" compilation failed:
File "error_examples/generation/inherits_token_not_found.ojst" compilation failed:
Inherits token not found
+File "error_examples/generation/no_template.ojst" compilation failed:
+Template token not found
+
View
121 examples/universal/compiled/goog_scope/person.js
@@ -35,6 +35,7 @@ Person.prototype.init = function() { // @10:1
goog.base(this, 'init');
this.baseCssName = 'basecss';
+ vars.score = this.calculateScore(d); // vars is right place for template-level variables
};
@@ -57,86 +58,76 @@ Person.prototype.calculateScore = function(person) {
return twistScore(person.score);
};
-Person.prototype.renderBlockMain = function() { // @34:1
- var self = this;
- var d = this.data, vars = this.vars;
-
- // TODO bad example, need 'init' function instead
- vars.score = this.calculateScore(d); // vars is right place for template-level variables
-
- goog.base(this, 'renderBlockMain'); // @39:5
-}; // @40:1
-
// code could be here too, almost anywhere
-Person.prototype.renderBlockTitle = function() { // @44:1
+Person.prototype.renderBlockTitle = function() { // @37:1
var self = this;
var d = this.data, vars = this.vars;
self.writer.write(
'Person #',
- self.escape(d.id) // @44:29
+ self.escape(d.id) // @37:29
);
-}; // @44:40
+}; // @37:40
-Person.prototype.renderBlockScript = function() { // @46:1
+Person.prototype.renderBlockScript = function() { // @39:1
var self = this;
var d = this.data, vars = this.vars;
self.writer.write(
'<script>'
- ); // @48:1
+ ); // @41:1
// seems like jslint tries to check code within 'script' tags even if it's part of string constant, so avoid it
self.writer.write(
'(function() {\n\t// TODO good for node, but bad for goog\n\tvar settings = ',
- JSON.stringify(this.ctx.pageSettings), // @51:20
+ JSON.stringify(this.ctx.pageSettings), // @44:20
'; // inserting JSON unescaped\n\tojster.example.page.initPage(settings);\n})();</script>'
);
-}; // @55:1
+}; // @48:1
-Person.prototype.renderBlockContent = function() { // @57:1
+Person.prototype.renderBlockContent = function() { // @50:1
var self = this;
var d = this.data, vars = this.vars;
self.writer.write(
'<span class="',
- self.baseCssName, // @58:18
+ self.baseCssName, // @51:18
'">base css</span><br /><span class="',
- goog.getCssName('abc'), // @59:18
+ goog.getCssName('abc'), // @52:18
'">\'abc\'</span><br /><span class="',
- goog.getCssName(d.css, 'abc'), // @60:18
+ goog.getCssName(d.css, 'abc'), // @53:18
'">d.css with \'abc\'</span><br /><span class="',
- goog.getCssName(/** @type {string} */ (self.baseCssName), 'abc'), // @61:18
+ goog.getCssName(/** @type {string} */ (self.baseCssName), 'abc'), // @54:18
'">base with \'abc\'</span><br /><br /><span>A</span><span>B</span>',
' ',
'<span>C</span><br />'
- ); // @66:5
- self.renderBlockEcho('Hey there!'); // @66:5
+ ); // @59:5
+ self.renderBlockEcho('Hey there!'); // @59:5
self.writer.write(
'<div>Hello, '
- ); // @67:17
- self.renderBlockFullName(); // @67:17
+ ); // @60:17
+ self.renderBlockFullName(); // @60:17
self.writer.write(
'!</div><div>Your score: ',
- self.escape(vars.score), // @68:22
+ self.escape(vars.score), // @61:22
'</div><div>Your skills:</div>'
- ); // @70:5
- self.renderBlockSkills(); // @70:5
+ ); // @63:5
+ self.renderBlockSkills(); // @63:5
if (d.events && d.events.length) {
self.writer.write(
'<div>Your events:</div>'
- ); // @73:9
+ ); // @66:9
d.events.forEach(function(event) {
- self.renderBlockBeforeEvent(); // @74:13
+ self.renderBlockBeforeEvent(); // @67:13
self.writer.write(
'<div>',
- self.escape(event.Name), // @75:18
+ self.escape(event.Name), // @68:18
'</div>'
- ); // @76:13
- self.renderBlockAfterEvent(); // @76:13
+ ); // @69:13
+ self.renderBlockAfterEvent(); // @69:13
});
@@ -147,44 +138,44 @@ Person.prototype.renderBlockContent = function() { // @57:1
// checking whitespaces compaction:
self.writer.write(
- '<div>-', // @81:5
+ '<div>-', // @74:5
' ',
- '-</div>' // @81:19
- ); // @83:5
- new Hobbies(d, this.ctx).renderTo(self); // @83:5
+ '-</div>' // @74:19
+ ); // @76:5
+ new Hobbies(d, this.ctx).renderTo(self); // @76:5
new SomeTool(d).setup(function() { var d = this.data, vars = this.vars;
this.baseCssName = 'basecss1';
- }).renderTo(self); // @85:5
+ }).renderTo(self); // @78:5
new SomeOtherTool({
parentData: d,
someMoreData: 5
- }).renderTo(self); // @88:5
-}; // @92:1
+ }).renderTo(self); // @81:5
+}; // @85:1
-Person.prototype.renderBlockFullName = function() { // @67:17
+Person.prototype.renderBlockFullName = function() { // @60:17
var self = this;
var d = this.data, vars = this.vars;
self.writer.write(
- self.escape(d.firstName), // @67:40
+ self.escape(d.firstName), // @60:40
' ',
- self.escape(d.lastName) // @67:59
+ self.escape(d.lastName) // @60:59
);
-}; // @67:76
+}; // @60:76
-Person.prototype.renderBlockBeforeEvent = function() { // @74:13
+Person.prototype.renderBlockBeforeEvent = function() { // @67:13
var self = this;
var d = this.data, vars = this.vars;
};
-Person.prototype.renderBlockEcho = function(msg) { // @94:1
+Person.prototype.renderBlockEcho = function(msg) { // @87:1
var self = this;
var d = this.data, vars = this.vars;
self.writer.write(
- self.escape(msg) // @95:5
+ self.escape(msg) // @88:5
);
-}; // @96:1
+}; // @89:1
-Person.prototype.renderBlockSkills = function() { // @98:1
+Person.prototype.renderBlockSkills = function() { // @91:1
var self = this;
var d = this.data, vars = this.vars;
@@ -202,51 +193,51 @@ Person.prototype.renderBlockSkills = function() { // @98:1
for (var i=0, l=d.skills.length; i < l; i++) {
var skill = d.skills[i];
- self.renderBlockParametrized(i, l, skill); // @114:9
+ self.renderBlockParametrized(i, l, skill); // @107:9
self.writer.write(
'<div>',
- self.escape(skill.name), // @117:14
+ self.escape(skill.name), // @110:14
': ',
- self.escape(skill.value), // @117:33
+ self.escape(skill.value), // @110:33
'</div>'
- ); // @118:1
+ ); // @111:1
}
-}; // @121:1
+}; // @114:1
-Person.prototype.renderBlockParametrized = function(i, l, skill) { // @114:9
+Person.prototype.renderBlockParametrized = function(i, l, skill) { // @107:9
var self = this;
var d = this.data, vars = this.vars;
self.writer.write(
'<div>',
- self.escape(i + 1), // @115:18
+ self.escape(i + 1), // @108:18
' of ',
- self.escape(l), // @115:34
+ self.escape(l), // @108:34
' is &quot;',
- self.escape(skill.name), // @115:52
+ self.escape(skill.name), // @108:52
'&quot;</div>'
);
-}; // @116:9
+}; // @109:9
-Person.prototype.renderBlockNoSkills = function() { // @123:1
+Person.prototype.renderBlockNoSkills = function() { // @116:1
var self = this;
var d = this.data, vars = this.vars;
self.writer.write(
'<div>You have no skills :(</div>'
);
-}; // @125:1
+}; // @118:1
-Person.prototype.renderBlockAfterEvent = function() { // @127:1
+Person.prototype.renderBlockAfterEvent = function() { // @120:1
var self = this;
var d = this.data, vars = this.vars;
};
-Person.prototype.testFunc = function() { // @129:1
+Person.prototype.testFunc = function() { // @122:1
var self = this;
var d = this.data, vars = this.vars;
return 'testValue';
-}; // @131:1
+}; // @124:1
}); // goog.scope
View
121 examples/universal/compiled/node/person.js
@@ -19,6 +19,7 @@ Person.prototype.init = function() { // @10:1
Base.prototype.init.call(this);
this.baseCssName = 'basecss';
+ vars.score = this.calculateScore(d); // vars is right place for template-level variables
};
@@ -41,86 +42,76 @@ Person.prototype.calculateScore = function(person) {
return twistScore(person.score);
};
-Person.prototype.renderBlockMain = function() { // @34:1
- var self = this;
- var d = this.data, vars = this.vars;
-
- // TODO bad example, need 'init' function instead
- vars.score = this.calculateScore(d); // vars is right place for template-level variables
-
- Base.prototype.renderBlockMain.call(this); // @39:5
-}; // @40:1
-
// code could be here too, almost anywhere
-Person.prototype.renderBlockTitle = function() { // @44:1
+Person.prototype.renderBlockTitle = function() { // @37:1
var self = this;
var d = this.data, vars = this.vars;
self.writer.write(
'Person #',
- self.escape(d.id) // @44:29
+ self.escape(d.id) // @37:29
);
-}; // @44:40
+}; // @37:40
-Person.prototype.renderBlockScript = function() { // @46:1
+Person.prototype.renderBlockScript = function() { // @39:1
var self = this;
var d = this.data, vars = this.vars;
self.writer.write(
'<script>'
- ); // @48:1
+ ); // @41:1
// seems like jslint tries to check code within 'script' tags even if it's part of string constant, so avoid it
self.writer.write(
'(function() {\n\t// TODO good for node, but bad for goog\n\tvar settings = ',
- JSON.stringify(this.ctx.pageSettings), // @51:20
+ JSON.stringify(this.ctx.pageSettings), // @44:20
'; // inserting JSON unescaped\n\tojster.example.page.initPage(settings);\n})();</script>'
);
-}; // @55:1
+}; // @48:1
-Person.prototype.renderBlockContent = function() { // @57:1
+Person.prototype.renderBlockContent = function() { // @50:1
var self = this;
var d = this.data, vars = this.vars;
self.writer.write(
'<span class="',
- self.baseCssName, // @58:18
+ self.baseCssName, // @51:18
'">base css</span><br /><span class="',
- self.getCssName('abc'), // @59:18
+ self.getCssName('abc'), // @52:18
'">\'abc\'</span><br /><span class="',
- self.getCssName(d.css, 'abc'), // @60:18
+ self.getCssName(d.css, 'abc'), // @53:18
'">d.css with \'abc\'</span><br /><span class="',
- self.getCssName(self.baseCssName, 'abc'), // @61:18
+ self.getCssName(self.baseCssName, 'abc'), // @54:18
'">base with \'abc\'</span><br /><br /><span>A</span><span>B</span>',
' ',
'<span>C</span><br />'
- ); // @66:5
- self.renderBlockEcho('Hey there!'); // @66:5
+ ); // @59:5
+ self.renderBlockEcho('Hey there!'); // @59:5
self.writer.write(
'<div>Hello, '
- ); // @67:17
- self.renderBlockFullName(); // @67:17
+ ); // @60:17
+ self.renderBlockFullName(); // @60:17
self.writer.write(
'!</div><div>Your score: ',
- self.escape(vars.score), // @68:22
+ self.escape(vars.score), // @61:22
'</div><div>Your skills:</div>'
- ); // @70:5
- self.renderBlockSkills(); // @70:5
+ ); // @63:5
+ self.renderBlockSkills(); // @63:5
if (d.events && d.events.length) {
self.writer.write(
'<div>Your events:</div>'
- ); // @73:9
+ ); // @66:9
d.events.forEach(function(event) {
- self.renderBlockBeforeEvent(); // @74:13
+ self.renderBlockBeforeEvent(); // @67:13
self.writer.write(
'<div>',
- self.escape(event.Name), // @75:18
+ self.escape(event.Name), // @68:18
'</div>'
- ); // @76:13
- self.renderBlockAfterEvent(); // @76:13
+ ); // @69:13
+ self.renderBlockAfterEvent(); // @69:13
});
@@ -131,44 +122,44 @@ Person.prototype.renderBlockContent = function() { // @57:1
// checking whitespaces compaction:
self.writer.write(
- '<div>-', // @81:5
+ '<div>-', // @74:5
' ',
- '-</div>' // @81:19
- ); // @83:5
- new Hobbies(d, this.ctx).renderTo(self); // @83:5
+ '-</div>' // @74:19
+ ); // @76:5
+ new Hobbies(d, this.ctx).renderTo(self); // @76:5
new SomeTool(d).setup(function() { var d = this.data, vars = this.vars;
this.baseCssName = 'basecss1';
- }).renderTo(self); // @85:5
+ }).renderTo(self); // @78:5
new SomeOtherTool({
parentData: d,
someMoreData: 5
- }).renderTo(self); // @88:5
-}; // @92:1
+ }).renderTo(self); // @81:5
+}; // @85:1
-Person.prototype.renderBlockFullName = function() { // @67:17
+Person.prototype.renderBlockFullName = function() { // @60:17
var self = this;
var d = this.data, vars = this.vars;
self.writer.write(
- self.escape(d.firstName), // @67:40
+ self.escape(d.firstName), // @60:40
' ',
- self.escape(d.lastName) // @67:59
+ self.escape(d.lastName) // @60:59
);
-}; // @67:76
+}; // @60:76
-Person.prototype.renderBlockBeforeEvent = function() { // @74:13
+Person.prototype.renderBlockBeforeEvent = function() { // @67:13
var self = this;
var d = this.data, vars = this.vars;
};
-Person.prototype.renderBlockEcho = function(msg) { // @94:1
+Person.prototype.renderBlockEcho = function(msg) { // @87:1
var self = this;
var d = this.data, vars = this.vars;
self.writer.write(
- self.escape(msg) // @95:5
+ self.escape(msg) // @88:5
);
-}; // @96:1
+}; // @89:1
-Person.prototype.renderBlockSkills = function() { // @98:1
+Person.prototype.renderBlockSkills = function() { // @91:1
var self = this;
var d = this.data, vars = this.vars;
@@ -186,51 +177,51 @@ Person.prototype.renderBlockSkills = function() { // @98:1
for (var i=0, l=d.skills.length; i < l; i++) {
var skill = d.skills[i];
- self.renderBlockParametrized(i, l, skill); // @114:9
+ self.renderBlockParametrized(i, l, skill); // @107:9
self.writer.write(
'<div>',
- self.escape(skill.name), // @117:14
+ self.escape(skill.name), // @110:14
': ',
- self.escape(skill.value), // @117:33
+ self.escape(skill.value), // @110:33
'</div>'
- ); // @118:1
+ ); // @111:1
}
-}; // @121:1
+}; // @114:1
-Person.prototype.renderBlockParametrized = function(i, l, skill) { // @114:9
+Person.prototype.renderBlockParametrized = function(i, l, skill) { // @107:9
var self = this;
var d = this.data, vars = this.vars;
self.writer.write(
'<div>',
- self.escape(i + 1), // @115:18
+ self.escape(i + 1), // @108:18
' of ',
- self.escape(l), // @115:34
+ self.escape(l), // @108:34
' is &quot;',
- self.escape(skill.name), // @115:52
+ self.escape(skill.name), // @108:52
'&quot;</div>'
);
-}; // @116:9
+}; // @109:9
-Person.prototype.renderBlockNoSkills = function() { // @123:1
+Person.prototype.renderBlockNoSkills = function() { // @116:1
var self = this;
var d = this.data, vars = this.vars;
self.writer.write(
'<div>You have no skills :(</div>'
);
-}; // @125:1
+}; // @118:1
-Person.prototype.renderBlockAfterEvent = function() { // @127:1
+Person.prototype.renderBlockAfterEvent = function() { // @120:1
var self = this;
var d = this.data, vars = this.vars;
};
-Person.prototype.testFunc = function() { // @129:1
+Person.prototype.testFunc = function() { // @122:1
var self = this;
var d = this.data, vars = this.vars;
return 'testValue';
-}; // @131:1
+}; // @124:1
module.exports = Person;
View
9 examples/universal/templates/person.ojst
@@ -9,6 +9,7 @@
<% @init {
this.baseCssName = 'basecss';
+ vars.score = this.calculateScore(d); // vars is right place for template-level variables
} %>
<%
@@ -31,14 +32,6 @@ Person.prototype.calculateScore = function(person) {
return twistScore(person.score);
};
-<% @block main { %>
-<%
- // TODO bad example, need 'init' function instead
- vars.score = this.calculateScore(d); // vars is right place for template-level variables
-%>
- <% @base %>
-<% @block main } %>
-
// code could be here too, almost anywhere
<% @block title { %>Person #<%= d.id %><% @block title } %>

0 comments on commit 5bedb71

Please sign in to comment.
Something went wrong with that request. Please try again.