totaljs / framework

Node.js framework
http://www.totaljs.com
Other
4.36k stars 450 forks source link

comments shouldn't be processed by view engine #639

Closed Jusys closed 6 years ago

Jusys commented 6 years ago

If I understand correctly, your view engine uses html-type comments <!-- --> and has no its own type of comments like handlebars (e.g. {{! }}). If html compression is turned off in config: allow-compile: false allow-compile-html: false allow-compile-script: false comments are still processed! that is if I have a code like: <!--@{forma._id}--> and variable forma._id is NOT initialized, I get view engine error: 500: Internal Server ErrorError: View "/admin-dealer/dealer": forma._id - Line: 17 - forma is not defined at Controller.$viewrender

petersirka commented 6 years ago

Hi, sorry for delay. Yes Total.js View Engine markup is always processed. Why do you want to use it in comments? I have to think how to update compiler, it's a bit complicated...

Jusys commented 6 years ago

There might be just need to temporarily disable some code in view file. Disabled code shouldn't be processed and shouldn't be sent to user. The best solution would be to add view engine's own comment system. I would suggest to use @{! to start comments and !} to end.

For example let's say I have such code: 1. @{!<div data-jc="textbox" data-jc-path="some.value1">@{some.other.value1}</div> 2. <div data-jc="textbox" data-jc-path="some.value2">@{some.other.value2}</div>!} 3. <div data-jc="textbox" data-jc-path="some.value3">@{some.other.value3}</div>

Here lines 1. and 2. are commented out for now. Maybe they will be enabled in the future. I think it's not hard to implement in view engine - just run some regex which deletes code between @{! and !} before compilation and that's it.

Jusys commented 6 years ago

P.S. such comment system is good for leaving comments, which user should not see

petersirka commented 6 years ago

@{! is used for disabling of escaping characters: https://docs.totaljs.com/latest/en.html#pages~View%20engine~(escaping)

I'm thinking, but I don't see any good way for it. If you will have enabled HTML complication then standard HTML comments will be removed before the view engine processes the content. I think on it, but I don't know.

Jusys commented 6 years ago

it makes harder to write code - when you develop project, you disable HTML compilation, because compiled html/js/css is very hard to debug. If @{! is already used, then just use some other comment symbols like @{* and *}. I think it's no reason to 'reinvent the wheel' - almost all (or all) other view engines have their own comment symbols and do not rely on html comments.

BTW speaking about debugging: it seems, that I cannot find uncompiled spa.js and spa.css; when I get an error in spa.min.js it's very hard to debug.

Jusys commented 6 years ago

P.S. @{-- and --} would also be a good choice.

petersirka commented 6 years ago

Here is a part of uncompiled spa.min.js: https://github.com/totaljs/jComponent

I'm thinking... All comments will be wrapped in HTML comments symbols <!-- bla bla -–> but the comments will still be removed before the view is rendered. That will be best way for handling both comments (HTML + ViewEngine).

Jusys commented 6 years ago

Today I've got one thought too - if you're removing all html comments, what about: <!--[if gte IE 8]><!--><!--<![endif]--><!--[if gte IE 9]><!--><script type="text/javascript" src="//some-src"></script><!--<![endif]--><!--[if lt IE 9]><script type="text/javascript" src="//some-src"></script><![endif]-->

petersirka commented 6 years ago

This type of comment is not removed, so you can use it without any problem.

petersirka commented 6 years ago

I have updated beta version of Total.js, so you can use it $ npm install total.js@beta. Thank you!