mindplay-dk / php-outline

Legacy template engine archived here for historical purposes
1 stars 0 forks source link

whitespace next/before braces #11

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. create a template with the content "{ $a }"
2. create an Outline instance with the template, assing something to 'a'
3. run display() method of the outline instance

What is the expected output? What do you see instead?
i would expect to compile it, and print 'a', it instead throws a parse error

What version of the product are you using? On what operating system?
1.0.4

Please provide any additional information below.

OutlineCompiler::parse function should trim the given command, so we can put 
newlines, spaces, tabs, whatever next/before the open/close braces, so it more 
robust.
put a '$command = trim($command);' as the first statement in 
OutlineCompiler::parse method, somewhere around class/compiler.php:220

Original issue reported on code.google.com by complex...@gmail.com on 24 Oct 2011 at 2:32

GoogleCodeExporter commented 9 years ago
enhancement category may suit this issue better

Original comment by complex...@gmail.com on 24 Oct 2011 at 2:33

GoogleCodeExporter commented 9 years ago
This would make the parser less reliable, since you could have JavaScript 
blocks mistaken for commands - for example:

    <script type="text/javascript">
      var $a = 1;
      function xyz() {
        $a += 1;
      }
    </script>

The parser would see { $a += 1; } and this would look like a command. Worse, 
this particular example would probably even compile, and both the compiled 
template and the JavaScript would fail.

Original comment by ras...@mindplay.dk on 25 Oct 2011 at 1:43

GoogleCodeExporter commented 9 years ago
Shouldn't you have to wrap inline css/js blocks in {ignore} blocks anyway?

I understand that that this would not be backward compatible, I'm trying to 
migrate from templatelight, and the whitespace sensitivity really bugs me.

Original comment by complex...@gmail.com on 25 Oct 2011 at 8:16

GoogleCodeExporter commented 9 years ago
> Shouldn't you have to wrap inline css/js blocks in {ignore} blocks anyway?

You shouldn't be forced to use ignore tags - suppose you want to insert a 
template variable into a JS snippet, for example:

    <script type="text/javascript">
      var name = '{$name}';
    </script>

I suppose we could have a configuration switch to ignore whitespace. You're 
welcome to submit a patch - I haven't worked on the engine myself in almost 2 
years. Most of my work is currently in .NET, and it'll probably be another year 
before I return to PHP, at which point I'd like to integrate Outline with the 
Yii framework...

Original comment by ras...@mindplay.dk on 25 Oct 2011 at 1:34

GoogleCodeExporter commented 9 years ago
as for now, i use smarty/templatelite this way (only its called {literal} 
there), moving js variable assigns out to a "safe place" where no {ignore} 
needed (code with no braces), and everyting else goes in {ignore}-s afterward, 
so it looks like this:

<script>
  var from_php = '{$stuff}';

  {ignore}
  function a() { // code using the variable from php ... }
  {/ignore}
</script>

patch attached (diff against trunk in svn), and i want to thank you for the 
code, makes my life much simpler when objects are involved (-:

Original comment by complex...@gmail.com on 25 Oct 2011 at 1:59

Attachments:

GoogleCodeExporter commented 9 years ago
This is for the 1.0 branch, which I abandoned a long time ago. Have you looked 
the 2.0 branch?

http://code.google.com/p/php-outline/source/browse/#svn%2Fbranches%2F2

Original comment by rschu...@gorges.us on 26 Oct 2011 at 1:37

GoogleCodeExporter commented 9 years ago
I have, but as for now (rev201) there's no include support and I'm using that 
all over the place. If I understand it correctly then {block} -s could be used 
for same thing, but for layouts i need the included file run in the same scope 
(or have access the variables that its caller had), but this should go to the 
planning 2.0 discussion board.

Anyway, i attached a patch with the same ignore_whitespace_near_brackets moved 
to the config array, also one removed a call time reference warning (explicitly 
deprecated syntax since php 5.3.0 ).

Original comment by complex...@gmail.com on 26 Oct 2011 at 9:53

Attachments: