Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HAML 5 broken #172

Open
zubietaroberto opened this issue May 22, 2017 · 3 comments
Open

HAML 5 broken #172

zubietaroberto opened this issue May 22, 2017 · 3 comments

Comments

@zubietaroberto
Copy link

Deface works until HAML 5 beta 2. If you update to HAML 5 then Deface will break all the attributes. This is what happens:

I have this layout file (summarized):

!!!
/[if IE 7] <html class="no-js ie7 oldie" lang="es">
/[if IE 8] <html class="no-js ie8 oldie" lang="es">
/[if gt IE 9]><!
%html{lang: I18n.locale}
  /<![endif]

-# Omitted for brevity

When I use Haml 5 with this file then rails throws at me this error:

ArgumentError in Spree::HomeController#index
Old attributes must start with "{" and end with "}"

haml (5.0.1) lib/haml/parser.rb:213:in `old='
  def old=(value)
        unless value =~ /\A{.*}\z/m
          raise ArgumentError.new('Old attributes must start with "{" and end with "}"')
        end
        super
      end

deface (1.2.0) lib/deface/haml_converter.rb:94:in `initialize'
        options[:compiler_class] = Compiler
        options[:parser_class]   = Parser
        super(template, options)
      end
    else

When I use the stack trace to debug value in the HAML Parser class it returns "\"data-erb-lang\" => \"<%= I18n.locale %>\"". This is wrong.

However, if I write the attributtes in the HTML element in the old ruby rocket style, like this:

%html{:lang => I18n.locale}

It outputs this:

<html>
</html>

It silently fails to parse the attributes.

@jormon
Copy link

jormon commented Oct 18, 2017

🏏 s

@meowsus
Copy link

meowsus commented Jun 26, 2019

I am having a similar issue, almost a year and a half later it looks like.

If I have a partial located at app/views/shared/_fields.html.haml that contains:

.foobar
%div{ data: { foo_bar: '' } }

And an override at app/overrides/my_fields.rb that contains:

Deface::Override.new(                                                           
  virtual_path: 'shared/_fields',                   
  name: 'my_fields',                                   
  insert_top: '.foobar',
  partial: 'shared/my_fields'
)

And the new partial at app/shared/_my_fields.html.haml that contains:

%div{ data: { baz: '' } }

The expected output should be:

<div class='foobar'>
   <div data-baz=''></div>
</div>
<div data-foo-bar=''></div>

But it is actually:

<div class='foobar'>
   <div data-baz=''></div>
</div>
<div></div>

Whatever data attributes I have already defined in the partial I want to deface are stripped, but the partial I'm inserting remains unmolested.

For what it's worth this seems to be happening before the insertion is happening. If I run bin/rails deface:get_result[shared/_fields] the BEFORE section contains no reference to data-foo-bar.

Here are the versions of as many gems as I can think of that might be related to the problem:

  • nokogiri 1.10.3
  • rails 5.2.3
  • deface 1.3.2
  • haml 5.0.4

Please let me know if I can help in any way to figure this out, as it's a total showstopper from me being able to use this in my project :|

Thanks in advance for your time!

@meowsus
Copy link

meowsus commented Jun 26, 2019

So I had some time before my day finished so I spurred up a demo to help in debugging:

https://github.com/meowsus/deface-haml5-bug

What's funny is that I'm having the same issue, but just in reverse; the data attribute of the partial being injected is losing its data attribute.

Something's going on for sure.

If you have a minute, take a peek at the repo I set up. Here's a screenshot of the compiled source:

Screenshot from 2019-06-26 15-17-23

That <h1>My Partial!</h1> should have a data-bar='' attribute on it, as per this line.

I really hope this helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants