Class: SlimLint::Filters::StaticMerger

Inherits:
SlimLint::Filter show all
Defined in:
lib/slim_lint/filters/static_merger.rb

Overview

Merges several statics into a single static while respecting source location data. Example:

[:multi,
  [:static, "Hello "],
  [:static, "World!"]]

Compiles to:

[:static, "Hello World!"]

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_slim_control, #on_slim_output, #on_slim_text

Instance Method Details

#on_multi(*exps) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/slim_lint/filters/static_merger.rb', line 20

def on_multi(*exps)
  result = @self
  result.clear
  result.concat(@key)

  static = nil
  exps.each do |exp|
    if exp.first == :static
      if static
        static.finish = exp.finish if later_pos?(static.finish, exp.finish)
        static.last.finish = exp.finish if later_pos?(static.last.finish, exp.finish)
        static.last.value << exp.last.value
      else
        static = exp
        static[1] = exp.last.dup
        result << static
      end
    else
      result << compile(exp)
      static = nil unless exp.first == :newline
    end
  end

  result.size == 2 ? result[1] : result
end

#on_slim_embedded(*exps) ⇒ Object



16
17
18
# File 'lib/slim_lint/filters/static_merger.rb', line 16

def on_slim_embedded(*exps)
  @self
end