Sha256: b6ac4273de217d1596f469a773421744ab2b9416ad9509df88bb2a7bab50641e

Contents?: true

Size: 1.31 KB

Versions: 19

Compression:

Stored size: 1.31 KB

Contents

module SlimLint::Filters
  # A dumbed-down version of {Slim::Controls} which doesn't introduce temporary
  # variables and other cruft (which in the context of extracting Ruby code,
  # results in a lot of weird cops reported by RuboCop).
  class ControlProcessor < Slim::Filter
    BLOCK_RE = /\A(if|unless)\b|\bdo\s*(\|[^\|]*\|)?\s*$/

    # Handle control expression `[:slim, :control, code, content]`
    #
    # @param code [String]
    # @param content [Array]
    def on_slim_control(code, content)
      [:multi,
        [:code, code],
        compile(content)]
    end

    # Handle output expression `[:slim, :output, escape, code, content]`
    #
    # @param _escape [Boolean]
    # @param code [String]
    # @param content [Array]
    # @return [Array
    def on_slim_output(_escape, code, content)
      if code[BLOCK_RE]
        [:multi,
          [:code, code, compile(content)],
          [:code, 'end']]
      else
        [:multi, [:dynamic, code], compile(content)]
      end
    end

    # Handle text expression `[:slim, :text, type, content]`
    #
    # @param _type [Symbol]
    # @param content [Array]
    # @return [Array]
    def on_slim_text(_type, content)
      # Ensures :newline expressions from static output are still represented in
      # the final expression
      compile(content)
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
slim_lint-0.15.1 lib/slim_lint/filters/control_processor.rb
slim_lint-0.15.0 lib/slim_lint/filters/control_processor.rb
slim_lint-0.14.0 lib/slim_lint/filters/control_processor.rb
slim_lint-0.13.0 lib/slim_lint/filters/control_processor.rb
slim_lint-0.12.0 lib/slim_lint/filters/control_processor.rb
slim_lint-0.11.0 lib/slim_lint/filters/control_processor.rb
slim_lint-0.10.0 lib/slim_lint/filters/control_processor.rb
slim_lint-0.9.0 lib/slim_lint/filters/control_processor.rb
slim_lint-0.8.3 lib/slim_lint/filters/control_processor.rb
slim_lint-0.8.2 lib/slim_lint/filters/control_processor.rb
slim_lint-0.8.1 lib/slim_lint/filters/control_processor.rb
slim_lint-0.8.0 lib/slim_lint/filters/control_processor.rb
slim_lint-0.7.2 lib/slim_lint/filters/control_processor.rb
slim_lint-0.7.1 lib/slim_lint/filters/control_processor.rb
slim_lint-0.7.0 lib/slim_lint/filters/control_processor.rb
slim_lint-0.6.1 lib/slim_lint/filters/control_processor.rb
slim_lint-0.6.0 lib/slim_lint/filters/control_processor.rb
slim_lint-0.5.0 lib/slim_lint/filters/control_processor.rb
slim_lint-0.4.0 lib/slim_lint/filters/control_processor.rb