Class: Slim::Compiler Private
- Defined in:
- lib/slim/compiler.rb
Overview
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.
Compiles Slim expressions into Temple::HTML expressions.
Instance Method Summary collapse
-
#on_slim_attr(name, escape, code) ⇒ Array
private
Handle attribute expression ‘[:slim, :attr, escape, code]`.
-
#on_slim_condcomment(condition, content) ⇒ Array
private
Handle conditional comment expression ‘[:slim, :conditional_comment, conditional, content]`.
-
#on_slim_control(code, content) ⇒ Array
private
Handle control expression ‘[:slim, :control, code, content]`.
-
#on_slim_output(escape, code, content) ⇒ Array
private
Handle output expression ‘[:slim, :output, escape, code, content]`.
Methods inherited from Filter
Instance Method Details
#on_slim_attr(name, 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, :attr, escape, code]`
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/slim/compiler.rb', line 62 def on_slim_attr(name, escape, code) value = case code when 'true' escape = false [:static, name] when 'false', 'nil' escape = false [:multi] else tmp = unique_name [:multi, [:code, "#{tmp} = #{code}"], [:case, tmp, ['true', [:static, name]], ['false, nil', [:multi]], [:else, [:dynamic, if delimiter = [:attr_delimiter][name] "#{tmp}.respond_to?(:join) ? #{tmp}.flatten.compact.join(#{delimiter.inspect}) : #{tmp}" else code end ]]]] end [:html, :attr, name, [:escape, escape, value]] end |
#on_slim_condcomment(condition, content) ⇒ 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 conditional comment expression ‘[:slim, :conditional_comment, conditional, content]`
21 22 23 |
# File 'lib/slim/compiler.rb', line 21 def on_slim_condcomment(condition, content) [:multi, [:static, "<!--[#{condition}]>"], compile(content), [:static, '<![endif]-->']] end |
#on_slim_control(code, content) ⇒ 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 control expression ‘[:slim, :control, code, content]`
10 11 12 13 14 |
# File 'lib/slim/compiler.rb', line 10 def on_slim_control(code, content) [:multi, [:code, code], compile(content)] end |
#on_slim_output(escape, code, content) ⇒ 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 output expression ‘[:slim, :output, escape, code, content]`
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/slim/compiler.rb', line 31 def on_slim_output(escape, code, content) if empty_exp?(content) [:multi, [:escape, escape, [:dynamic, code]], content] else tmp = unique_name [:multi, # Capture the result of the code in a variable. We can't do # `[:dynamic, code]` because it's probably not a complete # expression (which is a requirement for Temple). [:block, "#{tmp} = #{code}", # Capture the content of a block in a separate buffer. This means # that `yield` will not output the content to the current buffer, # but rather return the output. # # The capturing can be disabled with the option :disable_capture. # Output code in the block writes directly to the output buffer then. # Rails handles this by replacing the output buffer for helpers. [:disable_capture] ? compile(content) : [:capture, unique_name, compile(content)]], # Output the content. [:escape, escape, [:dynamic, tmp]]] end end |