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

Issues with "smarty php templates" #75

Open
unxed opened this issue May 22, 2019 · 8 comments

Comments

Projects
None yet
3 participants
@unxed
Copy link

commented May 22, 2019

Smarty allows css/js code inside templates and not processes expressions if next character after { is space or newline.

But colorer treats {<newline> as smarty expression.

{<space> is ok, but additional space symbol is needed after }, or } will be shown as error.

Also ; inside css are shown as errors.

Снимок экрана в 2019-05-22 15-44-19

@unxed

This comment has been minimized.

Copy link
Author

commented May 23, 2019

@lazyeugene, can you please help with it?

@lazyeugene

This comment has been minimized.

Copy link
Member

commented May 23, 2019

I think, 'tpl' is not a very specific extension to use it exclusively for smarty. Currently tpl files can be highlighted as turbo prolog and as config file if first line starts with ; [ or #
Why don't you use "smarty" extension?
If there is a reason, you can select color scheme from farcolorer menu.

@lazyeugene

This comment has been minimized.

Copy link
Member

commented May 23, 2019

Anyway, a good start is to provide text content to review in addition to a picture.

@unxed

This comment has been minimized.

Copy link
Author

commented May 23, 2019

Why don't you use "smarty" extension?

Unfortunately, it's not just my choice. There is a bunch of legacy code that I’m working with and not just me. But my colleagues prefer .tpl and do not want me to rename everything as it may accidentally break something. And .tpl is ok for almost any other editor/ide supporting smarty's syntax.

May be we can assume that every .tpl file starting with { or < is a smarty template? Turbo Prolog sources will hardly ever start with those symbols.

Sample of wrongly highlighted js / css inside smarty template as you requested, mind the spaces:

<html>
<head></head>
<body>
<script>
    function sample1() {
    }
    function sample2() { 
    }
    function sample3() { 
    } 
</script>
<style>
    .sample1 {
        color: #fff;
    }
    .sample2 { 
        color: #fff;
    }
    .sample3 { 
        color: #fff;
    } 
</style>
some text {$some_smarty_var}
</body>
</html>

Smarty processes such code correctly, do not interpreting { as delimeter symbol if it is followed by space or new line.

@lazyeugene

This comment has been minimized.

Copy link
Member

commented May 24, 2019

Well, the problem is in smarty syntax - it uses the same delimiter as used in javascript/css - curly bracers. So it is pretty difficult to separate the case when it is the js function body start (or css rule start) from the bracers used for smarty tags.
Colorer uses regexps to parse, so it is pretty tricky task.
I never used smarty in my work, so this scheme was written just for fun and I don't understand smarty templates in details. Here is a patched scheme that does a quick fix for this problem. Please, test it.

PS I have no plans to develop colorer schemes, so a little quick fix is the best I can do.
smarty.hrc.zip

@unxed

This comment has been minimized.

Copy link
Author

commented May 24, 2019

Unfortunately, patched scheme introduced a new problem: smarty's tags (not variables) are not highlighted with black background now. Anyway, it is a good starting point for me to experiment with scheme development by myself. Thanks!

Btw, what about treating as smarty templates all .tpl files with first line starting with { or < symbols?

@unxed

This comment has been minimized.

Copy link
Author

commented May 24, 2019

This scheme version has almost all problems solved. Minor problems left:

  • curly bracket pairs in embed javascript code are not highlighted on cursor hit
  • embeded css is highlighted poorly
  • js inside smarty tags like {if} is not highlighted
  • css rules with @ sign (like @media) at the beginning of the line are processed wrong
  • ; separating css rules with no following space symbol shows as error

Okay, at least well-formatted code is colored (almost) correctly.

But as js/css inside smarty templates isn't a good design by itself, I think these problems may be neglected.

https://github.com/unxed/far2l-deb/blob/master/smarty.hrc

Example of complicated smarty template for testing/experiments:

appeals.zip

@AnrDaemon

This comment has been minimized.

Copy link
Contributor

commented May 25, 2019

Smarty uses configurable tag separators. In some projects, I use "$( … )" tags for example.
Speaking of selecting highlights by extension, you can change that by introducing an appropriate ~hrc/auto/ file. F.e. this is what I have for modules used in one of my projects:

<?xml version="1.0" encoding='UTF-8'?>
<!DOCTYPE hrc PUBLIC
	"-//Cail Lomecb//DTD Colorer HRC take5//EN"
	"http://colorer.sf.net/2003/hrc.dtd"
>
<hrc version="take5" xmlns="http://colorer.sf.net/2003/hrc"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://colorer.sf.net/2003/hrc http://colorer.sf.net/2003/hrc.xsd"
 >

<annotation><documentation>
  Dummy MCSC scheme.
</documentation></annotation>

<prototype name="MCSC.sh" group="scripts" description="MCSC dummy scheme">
  <filename>/\.(mcsc)$/i</filename>
</prototype>

<type name="MCSC.sh">

  <import type="shell"/>

	<scheme name="MCSC.sh">
		<inherit scheme="shell"/>
	</scheme>

</type>
</hrc>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.