sassc-media_query_combiner 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ffca2139033f4899d98979623a6cc5da0e6686d8fdae9d9e91a9b60a6651db3d
4
+ data.tar.gz: 3da0ef2da4784bb1137b4a880fb16489279e6b29c4618ebc704ad0204572566a
5
+ SHA512:
6
+ metadata.gz: bece214e207b5dce411f74965abf01fa56098323c5dbbbba4f240ba73cab970efd6aa8cada1b3c8f72a81743323bc791e4d4aaa64438e6574986f7839ee10cbe
7
+ data.tar.gz: 7f914e7dd2e50d26664dee3638a7774026b25e68b09e5627d7a08aef66591630461acc32cd7e8df03273c818b165fd604a1049c0a8e8109eb6691c3a4878a984
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1 @@
1
+ ## 0.0.1
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sassc-media_query_combiner.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem 'coveralls', require: false
8
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Aaron Jensen
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,87 @@
1
+ # SassC::MediaQueryCombiner
2
+
3
+ Combines all matching media queries while compiling your SassC.
4
+
5
+ For example:
6
+
7
+ ```css
8
+ h3 {
9
+ color: orange
10
+ }
11
+ @media (max-width: 480px) {
12
+ h1 {
13
+ color: red
14
+ }
15
+ }
16
+ @media (max-width: 980px) {
17
+ h4 {
18
+ color: black
19
+ }
20
+ }
21
+ @media (max-width: 480px) {
22
+ h2 {
23
+ color: blue
24
+ }
25
+ }
26
+ ```
27
+
28
+ Would end up as (except the whitespace won't be so clean):
29
+
30
+ ```css
31
+ h3 {
32
+ color: orange
33
+ }
34
+ @media (max-width: 480px) {
35
+ h1 {
36
+ color: red
37
+ }
38
+ h2 {
39
+ color: blue
40
+ }
41
+ }
42
+ @media (max-width: 980px) {
43
+ h4 {
44
+ color: black
45
+ }
46
+ }
47
+ ```
48
+
49
+ ### Note
50
+
51
+ **This will change the order of your css, so be aware of that.** All the
52
+ `@media` queries will end up at the end of each css file in the order that
53
+ they are first encountered. In other words, if you're relying on only using
54
+ min-width or only using max-width in a specific order you'll want to be sure
55
+ define your media queries in the right order up front before you use them
56
+ randomly throughout your file.
57
+
58
+ ## Installation
59
+
60
+ Requires Ruby >= 1.9.2.
61
+
62
+ Add this line to your application's Gemfile:
63
+
64
+ gem 'sassc-media_query_combiner'
65
+
66
+ And then execute:
67
+
68
+ $ bundle
69
+
70
+ Or install it yourself as:
71
+
72
+ $ gem install sassc-media_query_combiner
73
+
74
+ ## Usage
75
+
76
+ In your `config.rb`
77
+
78
+ ```ruby
79
+ require 'sassc-media_query_combiner'
80
+ ```
81
+
82
+ If you're using `sassc --watch` do:
83
+
84
+ ```bash
85
+ sassc --watch -r sassc-media_query_combiner
86
+ ```
87
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => [:spec]
@@ -0,0 +1,12 @@
1
+ require "sassc/media_query_combiner/version"
2
+ require "sassc/media_query_combiner/combiner"
3
+ require "sassc"
4
+
5
+ SassC::Engine.class_eval do
6
+ def render_with_combine
7
+ SassC::MediaQueryCombiner::Combiner.combine(render_without_combine)
8
+ end
9
+ alias_method :render_without_combine, :render
10
+ alias_method :render, :render_with_combine
11
+ alias_method :to_css, :render_with_combine
12
+ end
@@ -0,0 +1,52 @@
1
+ module SassC
2
+ module MediaQueryCombiner
3
+ module Combiner
4
+ def self.combine(css)
5
+ queries = Hash.new { |hash, key| hash[key] = '' }
6
+ pretty = true
7
+
8
+ css, source_map_url = extract_source_map_url(css)
9
+
10
+ filtered_data = css.gsub(/
11
+ \n? # Optional newline
12
+ (?<query> # The media query parameters, this will be $1
13
+ @media # Start with @media
14
+ (?!\ -sass-debug-info) # Ignore sass-debug-info
15
+ [^{]+ # One to many characters that are not {, we are guaranteed to have a space
16
+ )
17
+ {
18
+ (?<body> # The actual body, this will be $2
19
+ (?<braces> # Recursive capture group
20
+ (?:
21
+ [^{}]* # Anything that is not a brace
22
+ | # OR
23
+ {\g<braces>} # Recursively capture things within braces, this allows for balanced braces
24
+ )* # As many of these as we have
25
+ )
26
+ )
27
+ }
28
+ \n? # Optional newline
29
+ /mx) do |match|
30
+ queries[$1] << $2
31
+ pretty &&= /\n$/m === match
32
+ ''
33
+ end
34
+
35
+ combined = queries.map { |query, body| "#{query}{#{body}}" }.
36
+ join(("\n\n" if pretty))
37
+ "#{filtered_data}#{"\n" if pretty}#{combined}#{source_map_url}\n"
38
+ end
39
+
40
+ def self.extract_source_map_url(css)
41
+ source_map_url = ''
42
+
43
+ css = css.gsub(/\n*\/\*# sourceMappingURL=.* \*\/$/m) do |match|
44
+ source_map_url = match
45
+ ''
46
+ end
47
+
48
+ return css, source_map_url
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,5 @@
1
+ module SassC
2
+ module MediaQueryCombiner
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sassc/media_query_combiner/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "sassc-media_query_combiner"
8
+ gem.version = SassC::MediaQueryCombiner::VERSION
9
+ gem.authors = ["Aaron Jensen"]
10
+ gem.email = ["aaronjensen@gmail.com"]
11
+ gem.description = %q{Automatically combine media queries}
12
+ gem.summary = %q{Sass plugin to combine all like media queries}
13
+ gem.homepage = ""
14
+ gem.license = "MIT"
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.required_ruby_version = '>= 1.9.2'
22
+
23
+ gem.add_runtime_dependency "sassc", ">=2.2.0"
24
+
25
+ gem.add_development_dependency "rspec"
26
+ gem.add_development_dependency "rake"
27
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+ require 'sassc/media_query_combiner/combiner'
3
+
4
+ describe SassC::MediaQueryCombiner::Combiner do
5
+ it "should handle keyframes in media queries" do
6
+ Timeout::timeout(0.5) do
7
+ SassC::MediaQueryCombiner::Combiner.combine <<CSS
8
+ @media (min-width: 40em) {
9
+ @-webkit-keyframes whatever {}
10
+ }
11
+ CSS
12
+ end
13
+ end
14
+
15
+ it "should handle debug info" do
16
+ Timeout::timeout(0.5) do
17
+ SassC::MediaQueryCombiner::Combiner.combine <<CSS
18
+ @media (max-width: 480px) {
19
+ @media -sass-debug-info {filename{}line{}}
20
+ h1 {
21
+ color: red; } }
22
+ CSS
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,103 @@
1
+ require 'spec_helper'
2
+ require 'sassc-media_query_combiner'
3
+
4
+ describe "Combiner" do
5
+ let(:sass) { <<SASS }
6
+ h3
7
+ color: orange
8
+
9
+ @media (max-width: 480px)
10
+ h1
11
+ color: red
12
+
13
+ @media (max-width: 980px)
14
+ h4
15
+ color: black
16
+
17
+ @media (max-width: 480px)
18
+ h2
19
+ color: blue
20
+
21
+ b
22
+ color: yellow
23
+ SASS
24
+
25
+
26
+ it "should work with sass" do
27
+ # NOTE: the weird interpolated space in there is required to match.
28
+ # My editor strips out trailing whitespace, so that's how I get it to stay.
29
+ expected_output = <<CSS
30
+ h3 {
31
+ color: orange; }
32
+ b {
33
+ color: yellow; }
34
+
35
+ @media (max-width: 480px) {
36
+ h1 {
37
+ color: red; }#{" "}
38
+ h2 {
39
+ color: blue; } }
40
+
41
+ @media (max-width: 980px) {
42
+ h4 {
43
+ color: black; } }
44
+ CSS
45
+
46
+ SassC::Engine.new(sass).render.should == expected_output
47
+ end
48
+
49
+ it "should work with sourcemaps" do
50
+ options = {
51
+ filename: "out.css",
52
+ sourcemap_filename: "out.css.map"
53
+ }
54
+
55
+ expected_output = <<CSS
56
+ h3 {
57
+ color: orange; }
58
+ b {
59
+ color: yellow; }
60
+
61
+ @media (max-width: 480px) {
62
+ h1 {
63
+ color: red; }#{" "}
64
+ h2 {
65
+ color: blue; } }
66
+
67
+ @media (max-width: 980px) {
68
+ h4 {
69
+ color: black; } }
70
+
71
+ /*# sourceMappingURL=out.css.map */
72
+ CSS
73
+
74
+ output, _ = SassC::Engine.new(sass, options).render_with_sourcemap("out.css.map")
75
+ output.should == expected_output
76
+ end
77
+
78
+ it "should work with debug_info: true" do
79
+ Timeout::timeout(1) do
80
+ SassC::Engine.new(sass, debug_info: true).render.should == <<CSS
81
+ @media -sass-debug-info{filename{}line{font-family:\\000031}}
82
+ h3 {
83
+ color: orange; }
84
+ @media -sass-debug-info{filename{}line{font-family:\\0000316}}
85
+ b {
86
+ color: yellow; }
87
+
88
+ @media (max-width: 480px) {
89
+ @media -sass-debug-info{filename{}line{font-family:\\000035}}
90
+ h1 {
91
+ color: red; }#{" "}
92
+ @media -sass-debug-info{filename{}line{font-family:\\0000313}}
93
+ h2 {
94
+ color: blue; } }
95
+
96
+ @media (max-width: 980px) {
97
+ @media -sass-debug-info{filename{}line{font-family:\\000039}}
98
+ h4 {
99
+ color: black; } }
100
+ CSS
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,14 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ RSpec.configure do |config|
5
+ config.treat_symbols_as_metadata_keys_with_true_values = true
6
+ config.run_all_when_everything_filtered = true
7
+ config.filter_run :focus
8
+
9
+ # Run specs in random order to surface order dependencies. If you find an
10
+ # order dependency and want to debug it, you can fix the order by providing
11
+ # the seed, which is printed after each run.
12
+ # --seed 1234
13
+ config.order = 'random'
14
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sassc-media_query_combiner
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Aaron Jensen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-06-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sassc
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 2.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 2.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Automatically combine media queries
56
+ email:
57
+ - aaronjensen@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - CHANGELOG.md
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - lib/sassc-media_query_combiner.rb
69
+ - lib/sassc/media_query_combiner/combiner.rb
70
+ - lib/sassc/media_query_combiner/version.rb
71
+ - sassc-media_query_combiner.gemspec
72
+ - spec/lib/sassc-media_query_combiner/combiner_spec.rb
73
+ - spec/sassc-media_query_combiner_spec.rb
74
+ - spec/spec_helper.rb
75
+ homepage: ''
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: 1.9.2
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubygems_version: 3.1.2
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Sass plugin to combine all like media queries
98
+ test_files:
99
+ - spec/lib/sassc-media_query_combiner/combiner_spec.rb
100
+ - spec/sassc-media_query_combiner_spec.rb
101
+ - spec/spec_helper.rb