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

Idea: add parser hook (and possibly some more) #1141

Open
gucki opened this issue Aug 2, 2023 · 0 comments
Open

Idea: add parser hook (and possibly some more) #1141

gucki opened this issue Aug 2, 2023 · 0 comments

Comments

@gucki
Copy link
Contributor

gucki commented Aug 2, 2023

I want to make haml autogenerate id attributes for all elements. The ids should be static at runtime, so my idea was to use a hash of "#{filename}:#{line}". Currently, I'm doing this using a small monkey patch (requires fix #1140):

module ParserPatch
  extend ActiveSupport::Concern

  def tag(line)
    super.tap do |node|
      node.value[:attributes]["id"] ||= Digest::MD5.hexdigest("#{@options.filename}:#{line.index}")
    end
  end
end

Haml::Parser.prepend(ParserPatch)

What about having HAML expose some hooks, which could be used to implement such a requirement without monkey-patching?

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

1 participant