samvincent / jekyll-haml

HAML html converter for Jekyll
MIT License
88 stars 40 forks source link

Tag attributes are not being interpolated #23

Open EvanAgee opened 7 years ago

EvanAgee commented 7 years ago

Hello! First off thanks for creating this, love it!

The issue I'm having is that when I use liquid to assign a value to a tag attribute it's not being interpolated correctly. For example:

%a.button.filled.color-yellow{ href: "{{ '/venue' | relative_url }}" }

is returning an anchor with an empty href attribute. However if I move that liquid tag into the contents of the anchor it renders correctly.

Any assistance you can provide?

afaundez commented 6 years ago

Hi,

I had trouble also with interpolations, I made a gem with a slightly different approach https://github.com/afaundez/jekyll-haml-markup.

It had a lot of work to do, but I'm willing to maintain it.

jbschrades commented 6 years ago

@EvanAgee did you ever figure this out?

astery commented 6 years ago

I assume that your string is being escaped from "{{ '/venue' | relative_url }}" to "{{ '/venue' | relative_url }}" and being ignored.

In rails it would overcome with simply adding "{{ '/venue' | relative_url }}".html_safe.

But in jekyll where is no such function for string, put this in _plugins/string_helpers.rb to obtain it:

class String
  def html_safe?
    defined?(@html_safe) && @html_safe
  end

  def html_safe
    @html_safe = true
    self
  end
end

require 'haml/helpers/xss_mods'

module Haml::Helpers
  include Haml::Helpers::XssMods
end

Credits for answer going here, look there for details.