haml / haml-contrib

Addons to Haml (Ruby)
MIT License
7 stars 7 forks source link

Inline filters #6

Closed ezekg closed 10 years ago

ezekg commented 10 years ago

Is there some way that HAML could allow inline filters? Or is there a way for me to do this right now that I'm missing?

%a{:href => "#{:php => $user}" }
-# Equivalent to '= $user' within the filter
-#   which would be parsed to '<?php echo $user; ?>'

Right now, HAML thinks I'm passing the entire line ":php => $user" as the filter name.

mattwildig commented 10 years ago

Perhaps you could use a helper, something like:

def php text
  "<?php echo #{text}; %>"
end

Then you could use it like this:

%a{:href => php("$user") }

which would then generate (you will need to turn off attribute escaping):

<a href='<?php echo $user; %>'></a>
ezekg commented 10 years ago

Good idea. I ended up creating a custom Guard/shell script to compile Haml from the command line using PHamlP. Much nicer, as I can write vanilla Haml and have it compile to PHP instead of Ruby.