SassyIcons 0.0.9

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6f4c1c8e9074524b9d0148f46c81521eef54c9ee
4
+ data.tar.gz: e94a5b47498dc428049e5b147f586ab435c06c5c
5
+ SHA512:
6
+ metadata.gz: 3166dd2c0271ac184fcbd6a64a125d43ffa7df60ee622efac13c504ffa968130098265d47d82fecce12f02fae5d7098becff2847c015bf7128f4597da4b7d292
7
+ data.tar.gz: 052a9973e22c2370c163a5d83a5ad814371c33bde140b90c7abd7869e8c5d91bdf53abf4ee1360c4cb41c3435a8703dda83a84678e29a6dc11c2e1da91476f13
data/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ # SassyIcons changelog
2
+
3
+ ## 0.0.9 <span style="font-size: .8em">(2014-05-24)</span>
4
+
5
+ ### Refactor
6
+
7
+ * made `spacing` a per sprite-map configurable item.
8
+ Default value is now 0.
9
+ ([aa2f225b45](https://github.com/pascalduez/SassyIcons/commit/e1e4812cab824368c9a0bdc6b3355fab32e0c5b5),
10
+ [#1](https://github.com/pascalduez/SassyIcons/issues/1))
11
+
12
+ ## 0.0.8 <span style="font-size: .8em">(2014-05-23)</span>
13
+
14
+ ### Features
15
+
16
+ * Added new configuration items `format` and `legacy`.
data/README.md ADDED
@@ -0,0 +1,175 @@
1
+ # SassyIcons
2
+
3
+ Flexible system to manipulate icons, SVG, PNG, sprites.
4
+
5
+ Works on top of compass sprite API.
6
+ It was designed to easily switch between SVG and PNG while working with icons as background-images.
7
+ So you have more granular control over which icons to use as SVG or PNG.
8
+ SVG first with PNG sprite fallback, or PNG first with hidpi sprite support.
9
+
10
+ Also managing several "thematic" sprites a breeze.
11
+
12
+
13
+ *Best workflow used in conjunction with [grunt-svg2png](https://github.com/pascalduez/grunt-svg2png)*
14
+
15
+
16
+ ## Mixins
17
+
18
+ `sprite-map-create($name [, $spacing])`
19
+ `icon($name, $sprite [, $offset, $format])`
20
+ `icon-single($name, $sprite [, $format])`
21
+ `icon-generated($name, $sprite [, $pos, $centered, $format])`
22
+
23
+
24
+ ## Documentation
25
+
26
+ **sprite-map-create($name)**
27
+ Create a new sprite map from folder.
28
+
29
+ **icon($name, $sprite [, $offset, $format])**
30
+ Main icon mixin.
31
+
32
+ **icon-single($name, $sprite [, $format])**
33
+ Embed a single icon as inline-image (no sprite).
34
+ Should be used sporadically.
35
+
36
+ **icon-generated($name, $sprite [, $pos, $centered, $format])**
37
+ Include the icon in a generated "pseudo-element". Default to :before.
38
+ Allows for easier positioning or centering.
39
+
40
+
41
+ ## Configuration
42
+
43
+ ```scss
44
+ // Default settings.
45
+ $icons-defaults: (
46
+
47
+ // Space around sprites in generated sprite map.
48
+ // Useful with `$offset` parameter.
49
+ // This setting is global for all sprite-maps.
50
+ // Can be set per sprite-map with the `$spacing` parameter.
51
+ spacing: 0,
52
+
53
+ // Main icons directory. sprite-map-create() allows to use sub dirs.
54
+ dir: "icons",
55
+
56
+ // Name of the png sub-folders.
57
+ dir-png: "png",
58
+
59
+ // Name of the hidpi png sub-folders.
60
+ dir-hidpi: "png_2x",
61
+
62
+ // Scale of the hidpi pngs.
63
+ hidpi-scale: 2,
64
+
65
+ // Minimum resolution ratio used in the hidpi media query.
66
+ hidpi-ratio: 1.3,
67
+
68
+ // Whether to embed icons as data URI in the icon-single() mixin.
69
+ single-embed: true,
70
+
71
+ // Default file format unless overridden by parameter, svg | png.
72
+ format: "svg",
73
+
74
+ // Whether to support legacy browsers, svg fallback.
75
+ legacy: true
76
+
77
+ );
78
+ ```
79
+ Override default values in a new `$icons-settings` map.
80
+
81
+
82
+ ## Requirements
83
+
84
+ * Sass ~> 3.3.0
85
+ * Compass ~> 1.0.0.alpha.19
86
+
87
+
88
+ ## Install
89
+
90
+ #### Git
91
+
92
+ ```
93
+ git clone git@github.com:pascalduez/SassyIcons.git
94
+ ```
95
+
96
+ #### npm
97
+
98
+ ```
99
+ npm install sassyicons --save
100
+ ```
101
+
102
+ #### Bower
103
+
104
+ ```
105
+ bower install SassyIcons --save
106
+ ```
107
+
108
+
109
+ ## Usage
110
+
111
+ *Provided that [path] = path to SassyIcons*
112
+
113
+ #### Example usage with [Compass](http://compass-style.org/help/tutorials/command-line)
114
+ ```css
115
+ @import 'SassyIcons';
116
+ ```
117
+ ```
118
+ bundle exec compass watch --import-path [path]/dist
119
+ ```
120
+
121
+ #### Example config with [grunt-contrib-sass](https://github.com/gruntjs/grunt-contrib-sass)
122
+
123
+ ```js
124
+ sass: {
125
+ options: {
126
+ bundleExec: true, // Optional usage of Bundler, but recommended.
127
+ compass: true,
128
+ loadPath: ['[path]/dist/_SassyIcons.scss']
129
+ }
130
+ }
131
+ ```
132
+
133
+
134
+ ## Roadmap
135
+
136
+ * More documentation
137
+ * `icon-generated()` and `generated()` Don't force absolute positioning.
138
+ * Rewrite `generated()` mixin
139
+ * `icon-generated()` configurable `calc()` fallback
140
+ * Helper mixin to work with `background-size`
141
+ * Support for SVG sprites ?
142
+ * Support for SVG stacks ?
143
+ * Try to further improve output CSS
144
+ * More control over print position in the stylesheet ?
145
+ * Abstract and move away from compass sprites ?
146
+ * Move away from Modernizr classes ? Or make it an option.
147
+ * Clarify or remove the `@content` thing to pass additional rules to `.svg`.
148
+
149
+
150
+ ## Development
151
+
152
+ ### You need
153
+
154
+ * [Node.js](http://nodejs.org)
155
+ * [Ruby](https://www.ruby-lang.org)
156
+ * [Bundler](http://bundler.io) via `gem install bundler`
157
+ * `grunt-cli` via `npm install -g grunt-cli`
158
+
159
+ ### How to
160
+
161
+ 1. Fork this repository
162
+ 2. Run `npm install`
163
+ 3. Make your changes + write tests
164
+ 4. `grunt test`
165
+ 5. Commit + Pull request
166
+
167
+
168
+ ## Authors
169
+
170
+ [Pascal Duez](http://pascalduez.me)
171
+
172
+
173
+ ## Licence
174
+
175
+ SassyIcons is available under the [MIT](http://opensource.org/licenses/MIT) license.
data/lib/SassyIcons.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'compass'
2
+
3
+ extension_path = File.expand_path(File.join(File.dirname(__FILE__), ".."))
4
+ Compass::Frameworks.register('SassyIcons', :path => extension_path)
5
+
6
+ # Version is a number. If a version contains alphas, it will be created as a prerelease version
7
+ # Date is in the form of YYYY-MM-DD
8
+ module SassyIcons
9
+ VERSION = "0.0.9"
10
+ DATE = "2014-06-09"
11
+ end
12
+
13
+ module Sass::Script::Functions
14
+
15
+ end
@@ -0,0 +1,29 @@
1
+ // -------------------------------------------------------------------------------
2
+ // SassyIcons - Flexible icons system.
3
+ // -------------------------------------------------------------------------------
4
+ // Repository: https://github.com/pascalduez/SassyIcons
5
+ // -------------------------------------------------------------------------------
6
+
7
+ // A bit of terminology:
8
+ // sprite = a single image/icon
9
+ // "sprite sheet" or "sprite map" == all sprites combined together
10
+
11
+ //
12
+ // Import configuration
13
+ //
14
+ @import "config/config";
15
+
16
+ //
17
+ // Import helpers
18
+ //
19
+ @import "helpers/helpers";
20
+
21
+
22
+ //
23
+ // Import icons
24
+ //
25
+ @import "icons/sprite-map-create";
26
+ @import "icons/icon";
27
+ @import "icons/icon-single";
28
+ @import "icons/generated";
29
+ @import "icons/icon-generated";
@@ -0,0 +1,53 @@
1
+ //
2
+ // SassyIcons
3
+ //
4
+
5
+ // Configuration
6
+
7
+ // Default settings.
8
+ $icons-defaults: (
9
+
10
+ // Space around sprites in generated sprite map.
11
+ // Useful with `$offset` parameter.
12
+ // This setting is global for all sprite-maps.
13
+ // Can be set per sprite-map with the `$spacing` parameter.
14
+ spacing: 0,
15
+
16
+ // Main icons directory. sprite-map-create() allows to use sub dirs.
17
+ dir: "icons",
18
+
19
+ // Name of the png sub-folders.
20
+ dir-png: "png",
21
+
22
+ // Name of the hidpi png sub-folders.
23
+ dir-hidpi: "png_2x",
24
+
25
+ // Scale of the hidpi pngs.
26
+ hidpi-scale: 2,
27
+
28
+ // Minimum resolution ratio used in the hidpi media query.
29
+ hidpi-ratio: 1.3,
30
+
31
+ // Whether to embed icons as data URI in the icon-single() mixin.
32
+ single-embed: true,
33
+
34
+ // Default file format unless overridden by parameter, svg | png.
35
+ format: "svg",
36
+
37
+ // Whether to support legacy browsers, svg fallback.
38
+ legacy: true
39
+
40
+ );
41
+
42
+ // User settings.
43
+ $icons-settings: () !default;
44
+
45
+ // Retreive a configuration item.
46
+ @function conf($key) {
47
+ @if not map-has-key($icons-defaults, $key) {
48
+ @warn "No item `#{$key}` found in configuration.";
49
+ @return false;
50
+ }
51
+
52
+ @return map-get(map-merge($icons-defaults, $icons-settings), $key);
53
+ }
@@ -0,0 +1,88 @@
1
+
2
+ // Push new entry to `$map`
3
+ // -----------------------------------------------------------------------------
4
+ // @param [map] $map
5
+ // @param $key
6
+ // @param $value
7
+ // -----------------------------------------------------------------------------
8
+ // @return [map]
9
+
10
+ @function _map-set($map, $key, $value) {
11
+ @return map-merge($map, ($key: $value));
12
+ }
13
+
14
+
15
+
16
+ // Join `$list` into a string
17
+ // -----------------------------------------------------------------------------
18
+ // @param [list] $list
19
+ // @param [string] $glue
20
+ // -----------------------------------------------------------------------------
21
+ // @return [string]
22
+
23
+ @function _join($list, $glue: "") {
24
+ $result: "";
25
+ $length: length($list);
26
+
27
+ @if $length < 1 {
28
+ @return $result;
29
+ }
30
+
31
+ @for $i from 1 through $length {
32
+ $result: $result
33
+ + nth($list, $i)
34
+ + if($i != $length, $glue, "");
35
+ }
36
+
37
+ @return $result;
38
+ }
39
+
40
+
41
+
42
+ // Helper: retreive a sprite map.
43
+ // -----------------------------------------------------------------------------
44
+ // @param [string] $name
45
+ // @param [string] $factor
46
+ // -----------------------------------------------------------------------------
47
+ // @return [spritemap]
48
+
49
+ @function _sprite-map-get($name, $factor: 1x) {
50
+ @return map-get(map-get($icons-maps, $name), $factor);
51
+ }
52
+
53
+
54
+
55
+ // Helper: return correct sprites-map `background-position`.
56
+ // -----------------------------------------------------------------------------
57
+ // @param [spritemap] $map
58
+ // @param [string] $sprite
59
+ // @param [number] $offset-x
60
+ // @param [number] $offset-y
61
+ // @param [number] $scale
62
+ // -----------------------------------------------------------------------------
63
+ // @return [list]
64
+
65
+ @function _sprite-position($map, $sprite, $offset-x: 0, $offset-y: 0, $scale: 1) {
66
+ $pos: sprite-position($map, $sprite, $offset-x, $offset-y * $scale);
67
+ @return (nth($pos, 1) nth($pos, 2) / $scale);
68
+ }
69
+
70
+
71
+
72
+ // Hidpi media query builder.
73
+ // -----------------------------------------------------------------------------
74
+ // http://bjango.com/articles/min-device-pixel-ratio/
75
+ // http://brettjankord.com/2012/11/28/cross-browser-retinahigh-resolution-media-queries
76
+ // http://w3.org/blog/CSS/2012/06/14/unprefix-webkit-device-pixel-ratio
77
+ // -----------------------------------------------------------------------------
78
+
79
+ @mixin hidpi-mq() {
80
+ $hidpi-ratio: conf(hidpi-ratio);
81
+
82
+ @media (-webkit-min-device-pixel-ratio: $hidpi-ratio),
83
+ (min-resolution: round($hidpi-ratio * 96dpi)),
84
+ (min-resolution: $hidpi-ratio * 1dppx)
85
+ {
86
+ @content;
87
+ }
88
+ }
@@ -0,0 +1,21 @@
1
+
2
+ //
3
+ // Generated content.
4
+ //
5
+ @mixin generated($width: false, $height: false, $top: false, $right: false, $bottom: false, $left: false) {
6
+ //
7
+ // Boilerplate styles for generated content .before :after
8
+ //
9
+ @if ($width) { width: $width };
10
+ @if ($height) { height: $height };
11
+ content: "";
12
+ display: block;
13
+ position: absolute;
14
+ @if($top) { top: $top; }
15
+ @if($right) { right: $right; }
16
+ @if($bottom) { bottom: $bottom; }
17
+ @if($left) { left: $left; }
18
+ z-index: 1;
19
+
20
+ @content;
21
+ }
@@ -0,0 +1,38 @@
1
+ //
2
+ // SassyIcons
3
+ //
4
+
5
+ //
6
+ // Include the icon in a generated "pseudo-element".
7
+ // Default to :before
8
+ // Allows for easier positioning or centering.
9
+ //
10
+ @mixin icon-generated(
11
+ $name,
12
+ $sprite,
13
+ $pos: "before",
14
+ $centered: false,
15
+ $format: conf(format)
16
+ ) {
17
+ position: relative;
18
+
19
+ &:#{$pos} {
20
+ $sprite-file: sprite-file(_sprite-map-get($name), $sprite);
21
+
22
+ $width: image-width($sprite-file);
23
+ $height: image-height($sprite-file);
24
+
25
+ @include generated($width, $height);
26
+
27
+ @if ($centered) {
28
+ top: 35%;
29
+ top: calc(50% - #{$height} / 2);
30
+ left: 35%;
31
+ left: calc(50% - #{$width} / 2);
32
+ }
33
+
34
+ @include icon($name: $name, $sprite: $sprite, $format: $format);
35
+
36
+ @content;
37
+ }
38
+ }
@@ -0,0 +1,63 @@
1
+ //
2
+ // SassyIcons
3
+ //
4
+
5
+ //
6
+ // Embed a single icon as inline-image (no sprite).
7
+ // Should be used sporadically.
8
+ //
9
+ @mixin icon-single(
10
+ $name,
11
+ $sprite,
12
+ $format: conf(format)
13
+ ) {
14
+
15
+ // sprite-file() and inline-image() no work.
16
+ // @see https://github.com/chriseppstein/compass/issues/951
17
+
18
+ $dir: conf(dir);
19
+ $svg-file: _join(($dir, $name, "#{$sprite}.svg"), "/");
20
+ $png-file-1x: _join(($dir, $name, conf(dir-png), "#{$sprite}.png"), "/");
21
+ $png-file-2x: _join(($dir, $name, conf(dir-hidpi), "#{$sprite}.png"), "/");
22
+
23
+ $function: if(conf(single-embed), inline-image, image-url);
24
+ $svg-url: call($function, $svg-file);
25
+ $png-url-1x: call($function, $png-file-1x);
26
+ $png-url-2x: call($function, $png-file-2x);
27
+
28
+ $legacy-support: conf(legacy);
29
+
30
+ @if $format == "svg" {
31
+
32
+ background: {
33
+ image: $svg-url;
34
+ repeat: no-repeat;
35
+ }
36
+
37
+ .svg & {
38
+ @content;
39
+ }
40
+
41
+ @if $legacy-support {
42
+ .no-svg &,
43
+ .no-js & {
44
+ background-image: $png-url-1x;
45
+ }
46
+ }
47
+
48
+ }
49
+ @else if $format == "png" {
50
+
51
+ background: {
52
+ image: $png-url-1x;
53
+ repeat: no-repeat;
54
+ }
55
+
56
+ @include hidpi-mq {
57
+ background: {
58
+ image: $png-url-2x;
59
+ size: ceil(image-width($png-file-2x) / conf(hidpi-scale)) auto;
60
+ }
61
+ }
62
+ }
63
+ }
@@ -0,0 +1,59 @@
1
+ //
2
+ // SassyIcons
3
+ //
4
+
5
+ //
6
+ // Main icon mixin.
7
+ //
8
+ @mixin icon(
9
+ $name,
10
+ $sprite,
11
+ $offset: 0 0,
12
+ $format: conf(format)
13
+ ) {
14
+ $map-1x: _sprite-map-get($name);
15
+ $map-2x: _sprite-map-get($name, 2x);
16
+
17
+ // Shorter mixin calls.
18
+ $offset-x: nth($offset, 1);
19
+ $offset-y: nth($offset, length($offset));
20
+
21
+ $legacy-support: conf(legacy);
22
+
23
+ @if $format == "svg" {
24
+
25
+ $svg-file: _join((conf(dir), $name, "#{$sprite}.svg"), "/");
26
+
27
+ background: {
28
+ image: inline-image($svg-file);
29
+ repeat: no-repeat;
30
+ }
31
+
32
+ .svg & {
33
+ @content;
34
+ }
35
+
36
+ @if $legacy-support {
37
+ .no-svg &,
38
+ .no-js & {
39
+
40
+ @extend %sprite-map-#{$name}-image-map;
41
+
42
+ background-position: _sprite-position($map-1x, $sprite, $offset-x, $offset-y);
43
+ }
44
+ }
45
+
46
+ }
47
+ @else if $format == "png" {
48
+
49
+ @extend %sprite-map-#{$name}-image-map;
50
+
51
+ background-position: _sprite-position($map-1x, $sprite, $offset-x, $offset-y);
52
+
53
+ @extend %sprite-map-#{$name}-2x-image-map;
54
+
55
+ @include hidpi-mq {
56
+ background-position: _sprite-position($map-2x, $sprite, $offset-x, $offset-y, conf(hidpi-scale));
57
+ }
58
+ }
59
+ }
@@ -0,0 +1,38 @@
1
+ //
2
+ // SassyIcons
3
+ //
4
+
5
+ // Storage
6
+ $icons-maps: ();
7
+
8
+ //
9
+ // Create a new sprite map from folder.
10
+ //
11
+ @mixin sprite-map-create(
12
+ $name,
13
+ $spacing: conf(spacing)
14
+ ) {
15
+
16
+ $sprites-1x: _join((conf(dir), $name, conf(dir-png), "*.png"), "/");
17
+ $sprites-2x: _join((conf(dir), $name, conf(dir-hidpi), "*.png"), "/");
18
+
19
+ $map-1x: sprite-map($sprites-1x, $spacing: $spacing);
20
+ $map-2x: sprite-map($sprites-2x, $spacing: $spacing);
21
+
22
+ $icons-maps: _map-set($icons-maps, $name, (1x: $map-1x, 2x: $map-2x)) !global;
23
+
24
+ @at-root %sprite-map-#{$name}-image-map {
25
+ background: {
26
+ image: $map-1x;
27
+ repeat: no-repeat;
28
+ }
29
+ }
30
+ @at-root %sprite-map-#{$name}-2x-image-map {
31
+ @include hidpi-mq {
32
+ background: {
33
+ image: $map-2x;
34
+ size: ceil(image-width(sprite-path($map-2x)) / conf(hidpi-scale)) auto;
35
+ }
36
+ }
37
+ }
38
+ }
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: SassyIcons
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.9
5
+ platform: ruby
6
+ authors:
7
+ - Pascal Duez
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-09 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.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '3.3'
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.alpha.19
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.alpha.19
41
+ description: Flexible icons system.
42
+ email:
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - README.md
48
+ - CHANGELOG.md
49
+ - lib/SassyIcons.rb
50
+ - stylesheets/_SassyIcons.scss
51
+ - stylesheets/config/_config.scss
52
+ - stylesheets/helpers/_helpers.scss
53
+ - stylesheets/icons/_generated.scss
54
+ - stylesheets/icons/_icon-generated.scss
55
+ - stylesheets/icons/_icon-single.scss
56
+ - stylesheets/icons/_icon.scss
57
+ - stylesheets/icons/_sprite-map-create.scss
58
+ homepage: http://github.com/pascalduez/SassyIcons
59
+ licenses: []
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: 1.3.6
75
+ requirements: []
76
+ rubyforge_project: SassyIcons
77
+ rubygems_version: 2.0.14
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: Flexible system to manipulate icons, SVG, PNG, sprites.
81
+ test_files: []