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 AST Scanner #465

Open
cantin opened this issue Aug 2, 2022 · 4 comments
Open

HAML AST Scanner #465

cantin opened this issue Aug 2, 2022 · 4 comments

Comments

@cantin
Copy link
Contributor

cantin commented Aug 2, 2022

The HAML provides a method to return the precompiled content which is literally Ruby code. We can use it with the Ruby AST scanner to parse the HAML templates.

module I18n::Tasks::Scanners
  class HamlAstScanner < RubyAstScanner
    protected

    def make_buffer(path, contents = read_file(path))
      contents = Haml::Engine.new(contents).precompiled
      super(path, contents)
    end
  end
end

Does it make sense to you?
Is it good to merge in as a default HAML scanner? Or put it on the Wiki?

@glebm
Copy link
Owner

glebm commented Aug 2, 2022

Neat, but does this approach provide the correct line numbers and support i18n-tasks-use comments?

@davidwessman
Copy link
Collaborator

@cantin can you try to add tests similar to https://github.com/glebm/i18n-tasks/blob/main/spec/used_keys_erb_spec.rb which I added for the AST-scanner for ERB?

@cantin
Copy link
Contributor Author

cantin commented Aug 2, 2022

Neat, but does this approach provide the correct line numbers and support i18n-tasks-use comments?

Hey, @glebm, thanks for the reply. So far in my test the line numbers are correct because the compiled content contains exact same line breaks.
Unfortunately the i18n-task-use comment is not. it got removed in the compiled content. I guess we need to extend the Haml::Compiler#compile_haml_comment to retain the comment.

@cantin
Copy link
Contributor Author

cantin commented Aug 2, 2022

Hey @davidwessman ,thanks for the reply. Nice spec, I'll look into it.

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