Sha256: 6f878ad2103d550c9731a54590c140f72caa3159df89ec261de977cdc281d057

Contents?: true

Size: 691 Bytes

Versions: 18

Compression:

Stored size: 691 Bytes

Contents

module Hamlit
  module ObjectRef
    class << self
      def parse(args)
        object, prefix = args
        return {} unless object

        suffix = underscore(object.class)
        {
          '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

18 entries across 18 versions & 1 rubygems

Version Path
hamlit-2.2.4 lib/hamlit/object_ref.rb
hamlit-2.6.1 lib/hamlit/object_ref.rb
hamlit-2.6.0 lib/hamlit/object_ref.rb
hamlit-2.5.0 lib/hamlit/object_ref.rb
hamlit-2.4.2 lib/hamlit/object_ref.rb
hamlit-2.4.1 lib/hamlit/object_ref.rb
hamlit-2.4.0 lib/hamlit/object_ref.rb
hamlit-2.3.1 lib/hamlit/object_ref.rb
hamlit-2.3.0 lib/hamlit/object_ref.rb
hamlit-2.2.3 lib/hamlit/object_ref.rb
hamlit-2.2.2 lib/hamlit/object_ref.rb
hamlit-2.2.1 lib/hamlit/object_ref.rb
hamlit-2.2.0 lib/hamlit/object_ref.rb
hamlit-2.1.2 lib/hamlit/object_ref.rb
hamlit-2.1.1 lib/hamlit/object_ref.rb
hamlit-2.1.0 lib/hamlit/object_ref.rb
hamlit-2.0.2 lib/hamlit/object_ref.rb
hamlit-2.0.1 lib/hamlit/object_ref.rb