arnaud-lb / MtHaml

Multi target HAML (HAML for PHP, Twig, <your language here>)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

whitespace removal syntax not working with php-statements

stmh opened this issue · comments

Hi,

the php-renderer does not respect the whitespace-removal-settings of parent-nodes, which will introduce unwanted whitespaces.

Here's an example:

  %a<>
    - foreach(array(1,2,3) as $ndx)
      %span<>
        =$ndx

should render to something like

<a><span>1</span><span>2</span><span>3</span></a>

It looks not that easy to fix the underlying problem, so I replaced all write with raw in my fork. Is there an easy way to fix this?

Same thing in Haml/TWIG when using if/for/macros/etc.

White space removal is really useful when using inline or inline-block positioning for horizontal layouts, i.e. this is not just cosmetic. See: http://css-tricks.com/fighting-the-space-between-inline-block-elements/, stmh's issue above is the same thing.

Whitespace removal won't work for me at all.

This MtHaml:

    %span.text-small><
      (
      = $no_reviews
      )

produces this HTML:

<span class="text-small">(
    16    )</span>

Please mark this a a bug.

PS Haml docs: http://haml.info/docs/yardoc/file.REFERENCE.html#whitespace_removal__and_

From your example, it works as documented: it removes whitespace just after <span class="text-small">, and just before </span>, but not in the content (which is what it's expected to do).

See the example from HAML/Ruby documentation:

%img
%pre><
  foo
  bar
%img

is compiled to:

<img /><pre>foo
bar</pre><img />

Note that you can make use of interpolations, for this use-case:

%span.text-small (#{$no_reviews})

(#{...} works like it works in Ruby, mostly like {$...} in PHP)

@arnaud-lb, i'm quoting the documentation:

> will remove all whitespace surrounding a tag, while < will remove all whitespace immediately within a tag.

Neither works for me. From my excerpt, you can only tell about the latter, but surrounding whitespace is also not removed.

Oh, i'm also inside a foreach, as the OP. Anyway, why is this not marked as a bug?

One difference, though, is that in HAML/Ruby, < also eats indentation, whereas in MtHaml it doesn't.

Marked as bug

One difference, though, is that in HAML/Ruby, < also eats indentation, whereas in MtHaml it doesn't.

The only reason to use whitespace removal for me is the inline-block grid technique. Whitespace adds to row width, ruining the grid. If MtHaml can't properly remove indentation, then whitespace removal is not working and thus useless.

I hacked in some changes in my fork that enable me to remove whitespace using <> where I need to. It ruins pretty printing because it's not possible to determine the right thing to do in some cases (macros/conditionals output in first and last node? memory is getting fuzzy...).  From: lolmausSent: Thursday, July 10, 2014 12:45 PMTo: arnaud-lb/MtHamlReply To: arnaud-lb/MtHamlCc: chrisrichardSubject: Re: [MtHaml] whitespace removal syntax not working with php-statements (#53)
One difference, though, is that in HAML/Ruby, < also eats indentation, whereas in MtHaml it doesn't.

The only reason to use whitespace removal for me is the inline-block grid technique. Whitespace adds to row width, ruining the grid. If MtHaml can't properly remove indentation, then whitespace removal is not working and thus useless.

—Reply to this email directly or view it on GitHub.

I've tried the > and < whitespace removal outside any PHP statements, and it won't work properly:

  • > removes whitespace only after the element, while it should remove whitespace before and after the element.
  • < removes whitespace only before the content of the element, while it should remove whitespace before, between and after the containing elements.

Putting this inside a in if (true) PHP statement makes it a bit worse. The < removes linebreaks but adds space characters.

@arnaud-lb, any progress on this one?

Any update?

Bump, it would be nice to have this fixed.

Not being able to control the white-space causes major problems with text in HTML textarea form elements.