Sha256: 4ffa7a34cbfe45860965c1dbc2439ee0e7d077e2f1d7a977bda24bd1d4314fbb

Contents?: true

Size: 860 Bytes

Versions: 2

Compression:

Stored size: 860 Bytes

Contents

# frozen_string_literal: true

module Slim
  class Embedded < Filter
    class JavaScriptEngine < TagEngine
      alias original_on_slim_embedded on_slim_embedded

      def on_slim_embedded(engine, body, attrs)
        minified_body = minify(body)
        super(engine, [:html, :js, minified_body], attrs)
      end

      private

      def minify(body)
        multiline_comment = false
        body.filter do |line|
          if line.instance_of?(Array) && line.first == :slim
            if line.last.match?(%r{\A/\*})
              multiline_comment = true
              next false
            elsif multiline_comment
              multiline_comment = false if line.last.match?(%r{\*/})
              next false
            end
            !line.last.match?(%r{\A//})
          else
            true
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
slim-embedded-minify-0.1.1 lib/slim/embedded/minify/java_script_engine.rb
slim-embedded-minify-0.1.0 lib/slim/embedded/minify/java_script_engine.rb