Class: Slim::CodeAttributes Private

Inherits:
Filter
  • Object
show all
Defined in:
lib/slim/code_attributes.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Methods inherited from Filter

#on_slim_control, #on_slim_embedded, #on_slim_output, #on_slim_text

Instance Method Details

#on_html_attr(name, value) ⇒ Array

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Handle attribute expression [:html, :attr, name, value]



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/slim/code_attributes.rb', line 19

def on_html_attr(name, value)
  if value[0] == :slim && value[1] == :attrvalue && !options[:merge_attrs][name]
    # We handle the attribute as a boolean attribute
    escape, code = value[2], value[3]
    case code
    when 'true'
      [:html, :attr, name, [:multi]]
    when 'false', 'nil'
      [:multi]
    else
      tmp = unique_name
      [:multi,
       [:code, "#{tmp} = #{code}"],
       [:if, tmp,
        [:if, "#{tmp} == true",
         [:html, :attr, name, [:multi]],
         [:html, :attr, name, [:escape, escape, [:dynamic, tmp]]]]]]
    end
  else
    # Attribute with merging
    @attr = name
    super
  end
end

#on_html_attrs(*attrs) ⇒ Array

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Handle attributes expression [:html, :attrs, *attrs]



10
11
12
# File 'lib/slim/code_attributes.rb', line 10

def on_html_attrs(*attrs)
  [:multi, *attrs.map {|a| compile(a) }]
end

#on_slim_attrvalue(escape, code) ⇒ Array

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Handle attribute expression [:slim, :attrvalue, escape, code]



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/slim/code_attributes.rb', line 49

def on_slim_attrvalue(escape, code)
  # We perform attribute merging on Array values
  if delimiter = options[:merge_attrs][@attr]
    tmp = unique_name
    [:multi,
     [:code, "#{tmp} = #{code}"],
     [:if, "Array === #{tmp}",
      [:multi,
       [:code, "#{tmp} = #{tmp}.flatten"],
       [:code, "#{tmp}.map!(&:to_s)"],
       [:code, "#{tmp}.reject!(&:empty?)"],
       [:escape, escape, [:dynamic, "#{tmp}.join(#{delimiter.inspect})"]]],
      [:escape, escape, [:dynamic, tmp]]]]
  else
    [:escape, escape, [:dynamic, code]]
  end
end