quantity-queries 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +5 -0
- data/README.md +88 -0
- data/lib/quantity-queries.rb +8 -0
- data/stylesheets/_quantity-queries.scss +187 -0
- metadata +76 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 45871b8e3e5fb9423cd4442fc864fcce8862089f
|
4
|
+
data.tar.gz: f9f539ba2312ac0a423a0e66e8e38549aef3379a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8a7d72153c37f092a500831ea079db6ba52c736b3a0cf346e4a75e458f9cf9c7e4061766983a046c9753502f3c3e3d13fd2bb72bcbb4e17b15b67a2c220d8b0b
|
7
|
+
data.tar.gz: 517b3c53fde2508e30387f8482ad31f4964e5bbfe4ed7cd58d0d18a597cea91484cb5111b2fe0a86650dc3c71741c183f441a34b9d8b22964318cc140aa1e687
|
data/README.md
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
# Quantity Queries mixins
|
2
|
+
|
3
|
+
Simple item quantity queries mixins for Sass.
|
4
|
+
|
5
|
+
[![Build Status](https://travis-ci.org/danielguillan/quantity-queries.svg?branch=master)](https://travis-ci.org/danielguillan/quantity-queries)
|
6
|
+
|
7
|
+
## Install
|
8
|
+
|
9
|
+
There are 3 ways of installing the Quantity Queries mixins:
|
10
|
+
|
11
|
+
### Download
|
12
|
+
|
13
|
+
Download [_quantity-queries.scss](/stylesheets/_quantity-queries.scss) and place it in your Sass directory.
|
14
|
+
|
15
|
+
### Bower
|
16
|
+
|
17
|
+
Run the following command:
|
18
|
+
|
19
|
+
bower install --save-dev quantity-queries
|
20
|
+
|
21
|
+
### Compass extension
|
22
|
+
|
23
|
+
1. `gem install quantity-queries`
|
24
|
+
2. Add `require 'quantity-queries'` to your `config.rb`
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
Import it into your main stylesheet:
|
29
|
+
|
30
|
+
@import 'quantity-queries';
|
31
|
+
|
32
|
+
### at-least
|
33
|
+
|
34
|
+
Target the items inside elements that contain N items or more:
|
35
|
+
|
36
|
+
@include at-least($count) { ... }
|
37
|
+
|
38
|
+
|
39
|
+
### at-most
|
40
|
+
|
41
|
+
Target the items inside elements that contain N items or less:
|
42
|
+
|
43
|
+
@include nope($count) { ... }
|
44
|
+
|
45
|
+
|
46
|
+
### between
|
47
|
+
|
48
|
+
Target the items inside elements that contain between X and Y items:
|
49
|
+
|
50
|
+
@include between($at-least, $at-most) { ... }
|
51
|
+
|
52
|
+
### Example
|
53
|
+
|
54
|
+
Sass input:
|
55
|
+
|
56
|
+
```scss
|
57
|
+
ul > li {
|
58
|
+
|
59
|
+
// Color the `li` items red when there are 6 items or more
|
60
|
+
@include at-least(6) {
|
61
|
+
color: red;
|
62
|
+
}
|
63
|
+
|
64
|
+
// Color the `li` items blue when there are 4 items or less
|
65
|
+
@include at-most(4) {
|
66
|
+
color: blue;
|
67
|
+
}
|
68
|
+
|
69
|
+
// Add a green background to `li` items when there are between 5 and 8 items
|
70
|
+
@include between(5, 8) {
|
71
|
+
background-color: green;
|
72
|
+
}
|
73
|
+
}
|
74
|
+
```
|
75
|
+
|
76
|
+
### Custom selector
|
77
|
+
|
78
|
+
The quantity query mixins assume you want to use the current simple selector for
|
79
|
+
all your items by default. `li` in the previous example. If you need a diffrent
|
80
|
+
selector or want it to be selector agnostic (a.k.a. the universal selector: `*`)
|
81
|
+
you just need to pass it in the mixin:
|
82
|
+
|
83
|
+
```scss
|
84
|
+
|
85
|
+
nav div {
|
86
|
+
@include at-leat(4, '*'); // selector agnostic
|
87
|
+
@include between(4, 8, 'span'); // use span instead of div
|
88
|
+
}
|
@@ -0,0 +1,187 @@
|
|
1
|
+
// -----------------------------------------------------------------------------
|
2
|
+
// Quantity queries
|
3
|
+
// -----------------------------------------------------------------------------
|
4
|
+
// Table of contents:
|
5
|
+
// 1. Last Simple Selector
|
6
|
+
// 2. Build Quantity Selector
|
7
|
+
// 3. At least
|
8
|
+
// 4. At most
|
9
|
+
// 5. Between
|
10
|
+
|
11
|
+
|
12
|
+
// -----------------------------------------------------------------------------
|
13
|
+
// 1. Last Simple Selector
|
14
|
+
// -----------------------------------------------------------------------------
|
15
|
+
|
16
|
+
/// Find the last simple selector in a given selector
|
17
|
+
/// @access private
|
18
|
+
/// @param {list | string} $selector - A single selector
|
19
|
+
/// @return {string} - The last simple selector in $selector
|
20
|
+
/// @example scss
|
21
|
+
/// $result: _last-simple-selector(ul > li); // returns 'li'
|
22
|
+
/// @todo: check that $selector is a valid list with a single selector
|
23
|
+
|
24
|
+
@function _last-simple-selector($selector) {
|
25
|
+
$parsed: selector-parse($selector);
|
26
|
+
|
27
|
+
@if length($parsed) > 1 {
|
28
|
+
@error '`#{$selector}` contains #{length($parsed)} selectors and the `_last-simple-selector()`function accepts only 1.';
|
29
|
+
}
|
30
|
+
$last-simple-selector: nth(nth($parsed, 1), -1);
|
31
|
+
|
32
|
+
@return $last-simple-selector;
|
33
|
+
}
|
34
|
+
|
35
|
+
|
36
|
+
// -----------------------------------------------------------------------------
|
37
|
+
// 2. Build Quantity Selector
|
38
|
+
// -----------------------------------------------------------------------------
|
39
|
+
|
40
|
+
/// Builds the selector for the quantity query
|
41
|
+
/// @access private
|
42
|
+
/// @param {string} $selector-append - The selector to append
|
43
|
+
/// @param {string} $last-selector - The last selector to use (item)
|
44
|
+
/// @return {list} - The complete quantity query selector
|
45
|
+
|
46
|
+
@function _build-quantity-selector($selector-append, $last-selector) {
|
47
|
+
$quantity-selector: ();
|
48
|
+
|
49
|
+
@each $s in & {
|
50
|
+
$last-simple-selector: '~' + if($last-selector, $last-selector, _last-simple-selector($s));
|
51
|
+
$sel: selector-append($s, $selector-append);
|
52
|
+
$sel2: selector-nest($sel, $last-simple-selector);
|
53
|
+
$quantity-selector: append($quantity-selector, $sel, 'comma');
|
54
|
+
$quantity-selector: append($quantity-selector, $sel2 , 'comma');
|
55
|
+
}
|
56
|
+
|
57
|
+
@return $quantity-selector;
|
58
|
+
}
|
59
|
+
|
60
|
+
|
61
|
+
// -----------------------------------------------------------------------------
|
62
|
+
// 3. At least
|
63
|
+
// -----------------------------------------------------------------------------
|
64
|
+
|
65
|
+
/// Query when total items is at least N items
|
66
|
+
/// @param {number} $count - Quantity to match (equal or more)
|
67
|
+
/// @example scss - Make the items color red when there are 4 items or more
|
68
|
+
/// ul li {
|
69
|
+
/// @include at-least(4) { color: red; }
|
70
|
+
/// }
|
71
|
+
/// @example scss - Make the items color blue when there are 6 items or more and use '*' (element agnostic) as the item selector
|
72
|
+
/// ul li {
|
73
|
+
/// @include at-least(6, '*') { color: blue; }
|
74
|
+
/// }
|
75
|
+
|
76
|
+
@mixin at-least($count, $selector: null) {
|
77
|
+
$selector-append: ':nth-last-child(n+#{$count})';
|
78
|
+
|
79
|
+
@if type-of($count) != 'number' {
|
80
|
+
@error '`#{$count}` is not a valid number for at-least() mixin.';
|
81
|
+
}
|
82
|
+
|
83
|
+
@if $selector != null and (type-of($selector) != 'string' or length($selector) > 1) {
|
84
|
+
@error '`#{$selector}` is not a valid selector for at-least($count, $selector)';
|
85
|
+
}
|
86
|
+
|
87
|
+
$at-least-selector: _build-quantity-selector($selector-append, $selector);
|
88
|
+
|
89
|
+
|
90
|
+
@at-root #{$at-least-selector} {
|
91
|
+
@content;
|
92
|
+
}
|
93
|
+
}
|
94
|
+
|
95
|
+
|
96
|
+
// -----------------------------------------------------------------------------
|
97
|
+
// 4. At most
|
98
|
+
// -----------------------------------------------------------------------------
|
99
|
+
|
100
|
+
/// Query when total items is at most N items
|
101
|
+
/// @param {number} $count - Quantity to match (equal or less)
|
102
|
+
/// @example scss - Make the items color red when there are 4 items or less
|
103
|
+
/// ul li {
|
104
|
+
/// @include at-most(4) { color: red; }
|
105
|
+
/// }
|
106
|
+
/// @example scss - Make the items color blue when there are 6 items or less and use '*' (element agnostic) as the item selector
|
107
|
+
/// ul li {
|
108
|
+
/// @include at-most(6, '*') { color: blue; }
|
109
|
+
/// }
|
110
|
+
|
111
|
+
@mixin at-most($count, $selector: null) {
|
112
|
+
$selector-append: ':nth-last-child(-n+#{$count}):first-child';
|
113
|
+
|
114
|
+
@if type-of($count) != 'number' {
|
115
|
+
@error '`#{$count}` is not a valid number for at-least() mixin.';
|
116
|
+
}
|
117
|
+
|
118
|
+
@if $selector != null and (type-of($selector) != 'string' or length($selector) > 1) {
|
119
|
+
@error '`#{$selector}` is not a valid selector for at-least($count, $selector)';
|
120
|
+
}
|
121
|
+
|
122
|
+
$at-least-selector: _build-quantity-selector($selector-append, $selector);
|
123
|
+
|
124
|
+
|
125
|
+
@at-root #{$at-least-selector} {
|
126
|
+
@content;
|
127
|
+
}
|
128
|
+
}
|
129
|
+
|
130
|
+
|
131
|
+
// -----------------------------------------------------------------------------
|
132
|
+
// 5. Between
|
133
|
+
// -----------------------------------------------------------------------------
|
134
|
+
|
135
|
+
/// Query when total items is at least X items and at most Y items
|
136
|
+
/// @param {number} $at-least - Lower quantity of items to match
|
137
|
+
/// @param {number} $at-most - Higher quantity of items to match
|
138
|
+
/// @example scss - Make the items color red when there are at least 2 and at most 4 items
|
139
|
+
/// ul li {
|
140
|
+
/// @include between(4, 8) { color: red; }
|
141
|
+
/// }
|
142
|
+
/// @example scss - Make the items color blue when there are at least 6 items and at most 10 items and use '*' (element agnostic) as the item selector
|
143
|
+
/// ul li {
|
144
|
+
/// @include between(6, 10, '*') { color: blue; }
|
145
|
+
/// }
|
146
|
+
|
147
|
+
|
148
|
+
@mixin between($first, $last, $selector: null) {
|
149
|
+
$selector-append: ':nth-last-child(n+#{$first}):nth-last-child(-n+#{$last}):first-child';
|
150
|
+
|
151
|
+
@if $first > $last {
|
152
|
+
@error '#{$first} can´t be larger that #{$last} for in-between() mixin';
|
153
|
+
}
|
154
|
+
|
155
|
+
@if $selector != null and (type-of($selector) != 'string' or length($selector) > 1) {
|
156
|
+
@error '`#{$selector}` is not a valid selector for at-least($count, $selector)';
|
157
|
+
}
|
158
|
+
|
159
|
+
$at-least-selector: _build-quantity-selector($selector-append, $selector);
|
160
|
+
|
161
|
+
|
162
|
+
@at-root #{$at-least-selector} {
|
163
|
+
@content;
|
164
|
+
}
|
165
|
+
}
|
166
|
+
|
167
|
+
|
168
|
+
// -----------------------------------------------------------------------------
|
169
|
+
// Test
|
170
|
+
// -----------------------------------------------------------------------------
|
171
|
+
|
172
|
+
.nav > li,
|
173
|
+
.nav > div {
|
174
|
+
|
175
|
+
@include at-most(3) {
|
176
|
+
color: green;
|
177
|
+
}
|
178
|
+
|
179
|
+
@include at-least(6) {
|
180
|
+
color: red;
|
181
|
+
}
|
182
|
+
|
183
|
+
|
184
|
+
@include between(4, 6) {
|
185
|
+
background-color: rgba(blue, .1);
|
186
|
+
}
|
187
|
+
}
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: quantity-queries
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Guillan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sass
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.4'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: compass
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.0.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.0.0
|
41
|
+
description: Simple item quantity queries mixins for Sass
|
42
|
+
email:
|
43
|
+
- daniel.guillan@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- CHANGELOG.md
|
49
|
+
- README.md
|
50
|
+
- lib/quantity-queries.rb
|
51
|
+
- stylesheets/_quantity-queries.scss
|
52
|
+
homepage: https://github.com/danielguillan/quantity-queries
|
53
|
+
licenses:
|
54
|
+
- MIT
|
55
|
+
metadata: {}
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.3.6
|
70
|
+
requirements: []
|
71
|
+
rubyforge_project: quantity-queries
|
72
|
+
rubygems_version: 2.2.2
|
73
|
+
signing_key:
|
74
|
+
specification_version: 4
|
75
|
+
summary: Simple item quantity queries mixins for Sass
|
76
|
+
test_files: []
|