Comparing version 0.0.43 to 0.0.44
@@ -15,3 +15,3 @@ const RazorError = require('./RazorError'); | ||
unexpectedCharacter(ch, lineNum, posNum, line) { | ||
var message = `unexpected '${ch}' character at line ${lineNum + 1} pos ${posNum + 1} after '${line}'`; | ||
var message = `Unexpected '${ch}' character at line ${lineNum + 1} pos ${posNum + 1} after '${line}'`; | ||
return RazorError.new({ message, info: this.info, line: lineNum, pos: posNum, capture: this.unexpectedCharacter }); | ||
@@ -21,4 +21,4 @@ } | ||
unexpectedAtCharacter(lineNum, posNum) { | ||
var message = `unexpected '@' character at line ${lineNum + 1} pos ${posNum + 1}. Once inside the body of a code block (@if {}, @{}, etc.) or a section (@section{}) you do not need to use "@{" to switch to code.`; | ||
return RazorError.new({ message, info: this.info, line: lineNum, pos: posNum, capture: this.unexpectedCharacter }); | ||
var message = `Unexpected '@' character at line ${lineNum + 1} pos ${posNum + 1}. Once inside the body of a code block (@if {}, @{}, etc.) or a section (@section{}) you do not need to use "@" character to switch to code.`; | ||
return RazorError.new({ message, info: this.info, line: lineNum, pos: posNum, capture: this.unexpectedAtCharacter }); | ||
} | ||
@@ -25,0 +25,0 @@ |
@@ -214,3 +214,4 @@ 'use strict'; | ||
this.partial = function (viewName, viewModel) { | ||
args.html += this.getPartial(viewName, viewModel); | ||
var partialHtml = this.getPartial(viewName, viewModel); | ||
this.raw(partialHtml) | ||
}; | ||
@@ -353,3 +354,6 @@ } | ||
catch (exc) { | ||
throw toParserError(exc, this.er); | ||
if (this.args.root) | ||
throw toParserError(exc, this.er); | ||
else | ||
throw exc; | ||
} | ||
@@ -632,3 +636,3 @@ | ||
// In contrast to a base-HTML-block, here it can only start with an HTML-tag. | ||
throw this.er.unexpectedCharacter(ch, this.lineNum, this.linePos(), this.line); // Tests: "Section 1". | ||
throw this.er.unexpectedCharacter(ch, this.lineNum, this.linePos(), this.line); // Cannot be tested. | ||
} | ||
@@ -638,3 +642,3 @@ if (this.pickNextChar() === '@') { // checking for '@@' that means just text '@' | ||
} | ||
else { | ||
else if (openTagName || tag) { // it must be an expression somewhere inside HTML | ||
this.fetchChar(); // skip current '@' | ||
@@ -649,2 +653,5 @@ this.parseCode(blocks); | ||
} | ||
else{ | ||
throw this.er.unexpectedAtCharacter(this.lineNum, this.linePos()); // [Section 0] | ||
} | ||
} | ||
@@ -1068,3 +1075,3 @@ else if (quotes.length) { // In Quotes.. | ||
else if (ch === '@' && (!lastLiteral || Char.isWhiteSpace(lastLiteral))) { | ||
throw this.er.unexpectedAtCharacter(this.lineNum, this.linePos(), this.line); | ||
throw this.er.unexpectedAtCharacter(this.lineNum, this.linePos(), this.line); // [Invalid-HTML 9], [Section 1] | ||
} | ||
@@ -1374,2 +1381,5 @@ else if (ch === '<') { | ||
if (err instanceof RazorError) { | ||
// it could be the 2-nd or most time here from the stack | ||
// Error.captureStackTrace(err, toParserError); | ||
// cut everything above (excessive information from the VM in debug mode), for example this: | ||
@@ -1386,3 +1396,3 @@ // d:\Projects\NodeJS\RazorExpressFullExample\node_modules\raz\core\Razor.js:117 | ||
let parserError = errorFactory.customError(err.message || err); | ||
let parserError = errorFactory.customError(err.message || err, toParserError); | ||
@@ -1389,0 +1399,0 @@ if (err.stack) |
{ | ||
"name": "raz", | ||
"description": "Razor-like syntax for templating views in Express framework by mixing HTML with JavaScript.", | ||
"version": "0.0.43", | ||
"description": "Razor-like syntax for templating views in NodeJS Express framework by mixing HTML with JavaScript.", | ||
"version": "0.0.44", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Sergey", |
@@ -5,2 +5,3 @@ # RAZ: Razor-Express view template engine | ||
- [**Intro**](#intro) | ||
- [A brief comparison of syntax of Node.JS layout engines](#a-brief-comparison-of-syntax-of-nodejs-layout-engines) | ||
- [**Quick Start**](#quick-start) | ||
@@ -13,2 +14,3 @@ - [Node.js example](#nodejs-example) | ||
- [What is Razor-Express](https://github.com/DevelAx/RazorExpress/blob/master/docs/overview.md#what-is-razor-express) | ||
- Razor syntax | ||
- [**Razor-Express View API**](#razor-express-view-api) | ||
@@ -19,4 +21,6 @@ - [Analogues of ASP.NET MVC Razor HtmlHelper methods](#analogues-of-aspnet-mvc-razor-htmlhelper-methods) | ||
- [Missing semicolon](#missing-semicolon) | ||
- [**Errors handling**](https://github.com/DevelAx/RazorExpress/blob/master/docs/ErrorsHandling.md) | ||
- [Custom error handler](https://github.com/DevelAx/RazorExpress/blob/master/docs/ErrorsHandling.md#custom-error-handler) | ||
- [**Debugging & Errors handling in Razor-Express**](https://github.com/DevelAx/RazorExpress/blob/master/docs/Debugging.md) | ||
- **Debugging view templates** | ||
- [**Errors handling**](https://github.com/DevelAx/RazorExpress/blob/master/docs/Debugging.md#errors-handling) | ||
- [Custom error handler](https://github.com/DevelAx/RazorExpress/blob/master/docs/Debugging.md#custom-error-handler) | ||
@@ -33,6 +37,6 @@ ----------------------- | ||
A brief comparison of Node.JS layout engines | ||
A brief comparison of syntax of Node.JS layout engines | ||
--- | ||
I may be exaggerating the merits of *ASP.NET MVC Razor* and maybe it's all just a matter of habit, but let's look at a few examples that I found on the web: | ||
I may be exaggerating the merits of *ASP.NET MVC Razor* and maybe it's all just a matter of habit, but let's look at a few examples that I found on the web ([the question on Quora](https://www.quora.com/What-is-the-best-Node-js-template-engine)): | ||
@@ -273,5 +277,5 @@ This is our **data model** represented via a JavaScript object: | ||
Html.partial | Html.RenderPartial & Html.Partial | renders the content of the partial view | ||
Html.raw | Html.Raw | renders string without encoding | ||
Html.getPartial | -- | returns a partial view as string (not encoded) | ||
Html.getEncoded | -- | returns encoded string | ||
Html.raw | Html.Raw | renders a string without encoding | ||
Html.getPartial | -- | returns a partial view as a string (not encoded) | ||
Html.getEncoded | -- | returns an encoded string | ||
@@ -278,0 +282,0 @@ |
@@ -392,7 +392,7 @@ (function () { | ||
<div> | ||
@Html.raw("H") | ||
@Html.raw("H"); | ||
@Html.raw("C") | ||
</div> | ||
`, | ||
expected: '\n<div>\nH\nC\n</div>\n' | ||
expected: '\n<div>\nH;\nC\n</div>\n' | ||
}, | ||
@@ -399,0 +399,0 @@ { |
@@ -83,3 +83,3 @@ (function () { | ||
}`, | ||
error: "unexpected '<' character at line 3 pos 6 after ' <<'" | ||
error: "Unexpected '<' character at line 3 pos 6 after ' <<'" | ||
}, | ||
@@ -94,3 +94,3 @@ { | ||
</div>`, | ||
error: "unexpected '@' character at line 4 pos 9." | ||
error: "Unexpected '@' character at line 4 pos 9." | ||
}, | ||
@@ -97,0 +97,0 @@ { |
(function () { | ||
var cases = [ | ||
{ | ||
name: "Section 0", | ||
template: ` | ||
@section Test{ | ||
<div style="background-color: greenyellow">SECTION TEST</div> | ||
@Html.raw("123"); | ||
@Html.raw("456"); | ||
}`, | ||
error: "Unexpected '@' character at line 4 pos 5." | ||
}, | ||
{ | ||
name: "Section 1", | ||
@@ -13,3 +23,3 @@ template: ` | ||
</div>`, | ||
error: "unexpected '@' character at line 4 pos 5." | ||
error: "Unexpected '@' character at line 4 pos 5." | ||
}, | ||
@@ -16,0 +26,0 @@ { |
@@ -96,3 +96,10 @@ console.log("STARTED: server.test.js"); | ||
expect(sharedTests, "views shared data test").to.have.lengthOf(3); | ||
// Check rendering partials from section with different path styles (they should be siblings). | ||
let sectionTest = $('#section-test'); | ||
expect(sectionTest, '#section-test').to.have.lengthOf(1); | ||
let partial1 = sectionTest.next(); | ||
expect(partial1.attr('id'), '#partial_1').to.be.equal('partial_1'); | ||
let partial2 = partial1.next(); | ||
expect(partial2.attr('id'), '#partial_2').to.be.equal('partial_2'); | ||
for (var i = 0; i < layouts.length; i++) { | ||
@@ -99,0 +106,0 @@ let layout = layouts[i]; |
Sorry, the diff of this file is not supported yet
180832
74
3958
356