class Skim::CodeAttributes
Public Instance Methods
on_html_attr(name, value)
click to toggle source
Handle attribute expression `[:html, :attr, name, value]`
@param [String] name Attribute name @param [Array] value Value expression @return [Array] Compiled temple expression
Calls superclass method
# File lib/skim/code_attributes.rb, line 18 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, [: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)
click to toggle source
Handle attributes expression `[:html, :attrs, *attrs]`
@param [Array] attrs Array of temple expressions @return [Array] Compiled temple expression
# 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)
click to toggle source
Handle attribute expression `[:slim, :attrvalue, escape, code]`
@param [Boolean] escape Escape html @param [String] code Ruby code @return [Array] Compiled temple expression
# File lib/skim/code_attributes.rb, line 48 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, "@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