Sha256: 2d880b68aeb888ace9852228f4a556f996db6002a9a52d39c2bf1b98165fffcb

Contents?: true

Size: 845 Bytes

Versions: 33

Compression:

Stored size: 845 Bytes

Contents

# frozen_string_literal: true
module Haml
  module ObjectRef
    class << self
      def parse(args)
        object, prefix = args
        return {} unless object

        suffix =
          if object.respond_to?(:haml_object_ref)
            object.haml_object_ref
          else
            underscore(object.class)
          end
        {
          'class' => [prefix, suffix].compact.join('_'),
          'id'    => [prefix, suffix, object.id || 'new'].compact.join('_'),
        }
      end

      private

      # Haml::Buffer.underscore
      def underscore(camel_cased_word)
        word = camel_cased_word.to_s.dup
        word.gsub!(/::/, '_')
        word.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
        word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
        word.tr!('-', '_')
        word.downcase!
        word
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
haml-6.3.0 lib/haml/object_ref.rb
haml-6.2.5 lib/haml/object_ref.rb
haml-6.2.4 lib/haml/object_ref.rb
haml-6.2.3 lib/haml/object_ref.rb
haml-6.2.2 lib/haml/object_ref.rb
haml-6.2.1 lib/haml/object_ref.rb
haml-6.2.0 lib/haml/object_ref.rb
haml-6.1.4-java lib/haml/object_ref.rb
haml-6.1.4 lib/haml/object_ref.rb
haml-6.1.3-java lib/haml/object_ref.rb
haml-6.1.3 lib/haml/object_ref.rb
haml-6.1.2-java lib/haml/object_ref.rb
haml-6.1.2 lib/haml/object_ref.rb
haml-6.1.1-java lib/haml/object_ref.rb
haml-6.1.1 lib/haml/object_ref.rb
haml-6.1.0-java lib/haml/object_ref.rb
haml-6.1.0 lib/haml/object_ref.rb
haml-6.0.12-java lib/haml/object_ref.rb
haml-6.0.12 lib/haml/object_ref.rb
haml-6.0.11-java lib/haml/object_ref.rb