hamlphp / HamlPHP

Yet another Haml to HTML converter written in PHP.
http://hamlphp.github.com/HamlPHP
MIT License
84 stars 15 forks source link

Silent scripts behave different #3

Closed svallory closed 13 years ago

svallory commented 13 years ago

I noticed today a difference between the behavior of HamlPHP and Haml. The silent script in haml (lines preceded by - ) is executed during the parse phase and never gets to the parsed file. In haml when you write...

- (1...5).each do |i|
  %p= i

it's compile to

<p>1</p>
<p>2</p>
<p>3</p>
<p>4</p>
<p>5</p>

In current implementation of HamlPHP, the following...

- for($i=1; $i <= 5; $i++)
  %p #{$i}

is compiled to...

<?php for($i=1; $i <= 5; $i++): ?>
  <p><?php echo $i; ?></p>
<?php endfor; ?>

I think we should make - behave like in haml. And use = for what was done above. I'm already working on the LoudScriptNode and it will support the syntax above (without having to close the for). Plus, it will accept any code, like in haml.

sniemela commented 13 years ago

OK. Should interpolations be evaluated in the place too?

svallory commented 13 years ago

Hey, sorry, I was mistaken about changing this behavior. And this is why... In Rails haml doesn't get compiled to rhtml before being rendered to html. So, when haml documentation says it gets compiled to yada yada. It really means "that's the way it goes to the browser". So, you got it right on the first place. Or almost, because silent scripts ( - ) have to accept any code. By the way, loud scripts ( = ) are like silent ones but they add an 'echo' to the beginning of the line.

sniemela commented 13 years ago

Yep, good to know. So, all we need to change is to allow any code in both scripts?

svallory commented 13 years ago

Yep! and to automatically add echo on loud scripts (=)