Class: Slim::Compiler Private

Inherits:
Filter
  • Object
show all
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

Methods inherited from Filter

#tmp_var

Instance Method Details

#on_slim_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 tag attributes expression ‘[:slim, :attrs, *attrs]`

Parameters:

  • attrs (Array)

    Attributes

Returns:

  • (Array)

    Compiled temple expression



96
97
98
# File 'lib/slim/compiler.rb', line 96

def on_slim_attrs(*attrs)
  [:html, :staticattrs, *attrs.map {|k, v| [k.to_s, compile!(v)] }]
end

#on_slim_comment(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 comment expression ‘[:slim, :comment, content]`

Parameters:

  • content (Array)

    Temple expression

Returns:

  • (Array)

    Compiled temple expression



22
23
24
# File 'lib/slim/compiler.rb', line 22

def on_slim_comment(content)
  [:html, :comment, compile!(content)]
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]`

Parameters:

  • ruby (String)

    code

  • content (Array)

    Temple expression

Returns:

  • (Array)

    Compiled temple expression



12
13
14
15
16
# File 'lib/slim/compiler.rb', line 12

def on_slim_control(code, content)
  [:multi,
    [:block, code],
    compile!(content)]
end

#on_slim_directive(type, args) ⇒ 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 directive expression ‘[:slim, :directive, type, args]`

Parameters:

  • type (String)

    Directive type

Returns:

  • (Array)

    Compiled temple expression



76
77
78
79
80
# File 'lib/slim/compiler.rb', line 76

def on_slim_directive(type, args)
  if type == 'doctype'
    [:html, :doctype, args]
  end
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



32
33
34
35
36
37
38
# File 'lib/slim/compiler.rb', line 32

def on_slim_output(escape, code, content)
  if empty_exp?(content)
    [:multi, escape && options[:auto_escape] ? [:escape, :dynamic, code] : [:dynamic, code], content]
  else
    on_slim_output_block(escape, code, content)
  end
end

#on_slim_output_block(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]` if content is not empty.

Parameters:

  • escape (Boolean)

    Escape html

  • code (String)

    Ruby code

  • content (Array)

    Temple expression

Returns:

  • (Array)

    Compiled temple expression



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/slim/compiler.rb', line 47

def on_slim_output_block(escape, code, content)
  tmp = tmp_var('capture')

  [: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 (with_output_buffer - braindead!).
    options[:disable_capture] ? compile!(content) : [:capture, tmp_var('capture'), compile!(content)],

    # Close the block.
    [:block, 'end'],

    # Output the content.
    on_slim_output(escape, tmp, [:multi])]
end

#on_slim_tag(name, attrs, closed, 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 tag expression ‘[:slim, :tag, name, attrs, closed, content]`

Parameters:

  • name (String)

    Tag name

  • attrs (Array)

    Attributes

  • content (Array)

    Temple expression

Returns:

  • (Array)

    Compiled temple expression



88
89
90
# File 'lib/slim/compiler.rb', line 88

def on_slim_tag(name, attrs, closed, content)
  [:html, :tag, name, compile!(attrs), closed, compile!(content)]
end