Sha256: 9a40f460f27c771b6852b73162bcb9dbc5e4df7e5ab9149ee66a8e5d43b2422b
Contents?: true
Size: 846 Bytes
Versions: 2
Compression:
Stored size: 846 Bytes
Contents
require "sass/media_query_combiner/version" require "sass" module Sass module MediaQueryCombiner def self.combine(css) queries = Hash.new { |hash, key| hash[key] = '' } pretty = true filtered_data = css.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 Sass::Engine.class_eval do def render_with_combine Sass::MediaQueryCombiner.combine(render_without_combine) end alias_method :render_without_combine, :render alias_method :render, :render_with_combine alias_method :to_css, :render_with_combine end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
sass-media_query_combiner-0.0.2 | lib/sass-media_query_combiner.rb |
sass-media_query_combiner-0.0.1 | lib/sass-media_query_combiner.rb |