Skip to content

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

@gucki

Description

@gucki

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions