Class: Skim::CodeAttributes
- Inherits:
-
Slim::Filter
- Object
- Slim::Filter
- Skim::CodeAttributes
- Defined in:
- lib/skim/code_attributes.rb
Instance Method Summary collapse
-
#on_html_attr(name, value) ⇒ Array
Handle attribute expression ‘[:html, :attr, name, value]`.
-
#on_html_attrs(*attrs) ⇒ Array
Handle attributes expression ‘[:html, :attrs, *attrs]`.
-
#on_slim_attrvalue(escape, code) ⇒ Array
Handle attribute expression ‘[:slim, :attrvalue, escape, code]`.
Instance Method Details
#on_html_attr(name, value) ⇒ Array
Handle attribute expression ‘[:html, :attr, name, value]`
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/skim/code_attributes.rb', line 18 def on_html_attr(name, value) if value[0] == :slim && value[1] == :attrvalue && ![:merge_attrs][name] # We handle the attribute as a boolean attribute escape, code = value[2], value[3] case code when 'true' [:html, :attr, name, [:static, name]] when 'false', 'null' [:multi] else tmp = unique_name [:multi, [:code, "#{tmp} = #{code}"], [:case, tmp, ['true', [:html, :attr, name, [:static, name]]], ['false, null', [:multi]], [:else, [:html, :attr, name, [:escape, escape, [:dynamic, tmp]]]]]] end else # Attribute with merging @attr = name return super end end |
#on_html_attrs(*attrs) ⇒ Array
Handle attributes expression ‘[:html, :attrs, *attrs]`
9 10 11 |
# File 'lib/skim/code_attributes.rb', line 9 def on_html_attrs(*attrs) [:multi, *attrs.map {|a| compile(a) }] end |
#on_slim_attrvalue(escape, code) ⇒ Array
Handle attribute expression ‘[:slim, :attrvalue, escape, code]`
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/skim/code_attributes.rb', line 48 def on_slim_attrvalue(escape, code) # We perform attribute merging on Array values if delimiter = [:merge_attrs][@attr] tmp = unique_name [:multi, [:code, "#{tmp} = #{code}"], [:if, "@isArray(#{tmp})", [:multi, [:code, "#{tmp} = @flatten(#{tmp})"], [:code, "#{tmp} = item.toString() for item in #{tmp} when item"], [:code, "#{tmp} = item for item in #{tmp} when item.length > 0"], [:escape, escape, [:dynamic, "#{tmp}.join(#{delimiter.inspect})"]]], [:escape, escape, [:dynamic, tmp]]]] else [:escape, escape, [:dynamic, code]] end end |