Class: Slim::Controls Private

Inherits:
Filter
  • Object
show all
Defined in:
lib/slim/controls.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.

Constant Summary collapse

IF_RE =

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

/\A(if|unless)\b|\bdo\s*(\|[^\|]*\|)?\s*$/

Instance Method Summary collapse

Methods inherited from Filter

#on_slim_embedded

Instance Method Details

#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]

Parameters:

  • code (String)

    Ruby code

  • content (Array)

    Temple expression

Returns:

  • (Array)

    Compiled temple expression



14
15
16
17
18
# File 'lib/slim/controls.rb', line 14

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]

Parameters:

  • escape (Boolean)

    Escape html

  • code (String)

    Ruby code

  • content (Array)

    Temple expression

Returns:

  • (Array)

    Compiled temple expression



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/slim/controls.rb', line 26

def on_slim_output(escape, code, content)
  if code =~ IF_RE
    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.
      options[:disable_capture] ? compile(content) : [:capture, unique_name, compile(content)]],

     # Output the content.
     [:escape, escape, [:dynamic, tmp]]]
  else
    [:multi, [:escape, escape, [:dynamic, code]], content]
  end
end

#on_slim_text(type, 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 text expression [:slim, :text, type, content]

Parameters:

  • type (Symbol)

    Text type

  • content (Array)

    Temple expression

Returns:

  • (Array)

    Compiled temple expression



57
58
59
# File 'lib/slim/controls.rb', line 57

def on_slim_text(type, content)
  compile(content)
end