Sha256: 953deeb6c1b0b11ea17c8957339f27ee3b7dd3a9155f68bb4d6207b7c67ea6a4

Contents?: true

Size: 1.14 KB

Versions: 5

Compression:

Stored size: 1.14 KB

Contents

module SlimLint
  module Filters
    # Merges several statics into a single static while respecting source
    # location data.  Example:
    #
    #   [:multi,
    #     [:static, "Hello "],
    #     [:static, "World!"]]
    #
    # Compiles to:
    #
    #   [:static, "Hello World!"]
    #
    # @api public
    class StaticMerger < Filter
      def on_slim_embedded(*exps)
        @self
      end

      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
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
slim_lint_standard-0.0.2.2 lib/slim_lint/filters/static_merger.rb
slim_lint_standard-0.0.2.1 lib/slim_lint/filters/static_merger.rb
slim_lint_standard-0.0.2 lib/slim_lint/filters/static_merger.rb
slim_lint_standard-0.0.1 lib/slim_lint/filters/static_merger.rb
slim_lint_standard-0.0.0 lib/slim_lint/filters/static_merger.rb