Class: SlimLint::Filters::DoInserter Private

Inherits:
SlimLint::Filter show all
Defined in:
lib/slim_lint/filters/do_inserter.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.

In Slim you don’t need the do keyword sometimes. This filter adds the missing keyword.

- 10.times
  | Hello

Constant Summary collapse

BLOCK_REGEX =

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|else|elsif|when|begin|rescue|ensure|case)\b)|\bdo\s*(\|[^|]*\|\s*)?\Z/

Instance Method Summary collapse

Methods included from SlimLint::Filter::Overrides

#on_escape, #on_html_attr, #on_html_attrs, #on_html_comment, #on_html_condcomment, #on_html_js, #on_html_tag, #on_multi, #on_slim_embedded, #on_slim_text

Instance Method Details

#on_slim_control(code, content) ⇒ Sexp

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 (Sexp)

    Ruby code

  • content (Sexp)

    Temple expression

Returns:

  • (Sexp)

    Compiled temple expression



18
19
20
21
22
23
# File 'lib/slim_lint/filters/do_inserter.rb', line 18

def on_slim_control(code, content)
  _, lines = code
  lines.last.value.concat(" do") unless lines.last.value =~ BLOCK_REGEX || empty_exp?(content)
  @self[3] = compile(content)
  @self
end

#on_slim_output(escape, code, content) ⇒ Sexp

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 (Sexp)

    Ruby code

  • content (Sexp)

    Temple expression

Returns:

  • (Sexp)

    Compiled temple expression



31
32
33
34
35
36
# File 'lib/slim_lint/filters/do_inserter.rb', line 31

def on_slim_output(escape, code, content)
  _, lines = code
  lines.last.value.concat(" do") unless lines.last.value =~ BLOCK_REGEX || empty_exp?(content)
  @self[4] = compile(content)
  @self
end