Sha256: 45da3b545a81c004348ded4219af3a96ec9957f9cf120e242a40c57590a17d88

Contents?: true

Size: 659 Bytes

Versions: 4

Compression:

Stored size: 659 Bytes

Contents

require 'tilt'

module Sprockets
  module MediaQueryCombiner
    class Processor < Tilt::Template
      def prepare
      end

      def evaluate(context, locals, &block)
        queries = Hash.new { |hash, key| hash[key] = '' }
        pretty = true

        filtered_data = data.gsub(/\n?(?<query>@media[^{]+){(?<body>(?<braces>(?:[^{}]+)|({\g<braces>}))*)}\n?/m) do |match|
          queries[$1] << $2
          pretty &&= /\n$/m === match
          ''
        end

        combined = queries.map { |query, body| "#{query}{#{body}}" }.
          join(("\n\n" if pretty))
        "#{filtered_data}#{"\n" if pretty}#{combined}\n"
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sprockets-media_query_combiner-0.0.6 lib/sprockets/media_query_combiner/processor.rb
sprockets-media_query_combiner-0.0.5 lib/sprockets/media_query_combiner/processor.rb
sprockets-media_query_combiner-0.0.4 lib/sprockets/media_query_combiner/processor.rb
sprockets-media_query_combiner-0.0.3 lib/sprockets/media_query_combiner/processor.rb