Class: Haml::Buffer

Inherits:
Object
  • Object
show all
Includes:
Espresso::View
Defined in:
lib/espresso/extensions/haml.rb

Instance Method Summary collapse

Methods included from Espresso::View

block_classes

Methods included from Espresso::Concern

#append_features, extended, #included

Instance Method Details

#parse_object_ref(ref) ⇒ Object

Takes an array of objects and uses the class and id of the first one to create an attributes hash. The second object, if present, is used as a prefix, just like you can do with ‘dom_id()` and `dom_class()` in Rails



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/espresso/extensions/haml.rb', line 11

def parse_object_ref(ref)
  prefix = ref[1]
  ref = ref[0]
  # Let's make sure the value isn't nil. If it is, return the default Hash.
  return {} if ref.nil?
  class_name = underscore(ref.class)
  id = "#{class_name}_#{ref.id || 'new'}"

  if ref.respond_to?(:model_modifiers)
    class_name = model_classes(ref)
  elsif prefix
    class_name = "#{prefix}_#{class_name}"
    id = "#{prefix}_#{id}"
  end

  {'id' => id, 'class' => class_name}
end