graphite-sass 0.1.0 → 0.2.0
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 +4 -4
- data/README.md +8 -4
- data/lib/graphite.rb +74 -54
- data/stylesheets/graphite.scss +11 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f95802c27bf6e64aa382e06679b095db1570b79
|
4
|
+
data.tar.gz: 83b5a4d1fde1886825eccdc4fdce1cee2457d1eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c84fd5def4936d12045e4f17c4f06f48039023e71a0411cbd76ce0492c95d139bdd4d6e0e2ca7a757c12a5fdc11be314cee2c94c24f5f51857cf6753d86ae134
|
7
|
+
data.tar.gz: abf11cb1fad532e17140d6cb7cd0f0a18ba77408aecac4fcf3f1c9b9596ffa6aa6e9a8928039253ac08bb0e2ab8fcba322479e268a2e9d9ae6ea2fa8e790ecfa
|
data/README.md
CHANGED
@@ -4,12 +4,12 @@ Graphite imports a folder of fonts and automagically outputs font-face directive
|
|
4
4
|
|
5
5
|
##Requirements
|
6
6
|
|
7
|
-
* Sass
|
8
|
-
* Compass
|
7
|
+
* Sass `~> 3.3.0`
|
8
|
+
* Compass `~> 1.0.0.alpha.19`
|
9
9
|
|
10
10
|
## Installation
|
11
11
|
|
12
|
-
1. `gem install graphite-sass`
|
12
|
+
1. `gem install graphite-sass` / `bower install graphite-sass`
|
13
13
|
2. Add `require "graphite"` to your `config.rb`
|
14
14
|
3. Import into your stylesheet with `@import "graphite";`
|
15
15
|
|
@@ -17,7 +17,7 @@ Graphite imports a folder of fonts and automagically outputs font-face directive
|
|
17
17
|
|
18
18
|
### Directory tree
|
19
19
|
|
20
|
-
Each font-family should have it's own folder inside of the top-level fonts directory.
|
20
|
+
Each font-family should have it's own folder inside of the top-level fonts directory. The font-family directory name should match the name specified in the actual font filename.
|
21
21
|
|
22
22
|
```
|
23
23
|
root
|
@@ -128,6 +128,10 @@ $helvetica-neue: "helvetica-neue";
|
|
128
128
|
|
129
129
|
[Ezekiel Gabrielse](http://ezekielg.com)
|
130
130
|
|
131
|
+
## Credits
|
132
|
+
|
133
|
+
[Scott Davis, for creating Sassy Hash](https://github.com/scottdavis/sassy_hash)
|
134
|
+
|
131
135
|
## License
|
132
136
|
|
133
137
|
Graphite is available under the [MIT](http://opensource.org/licenses/MIT) license.
|
data/lib/graphite.rb
CHANGED
@@ -5,19 +5,20 @@ extension_path = File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
|
5
5
|
Compass::Frameworks.register('graphite', :path => extension_path)
|
6
6
|
|
7
7
|
module Graphite
|
8
|
-
VERSION = "0.
|
9
|
-
DATE = "2014-07-
|
8
|
+
VERSION = "0.2.0"
|
9
|
+
DATE = "2014-07-30"
|
10
10
|
end
|
11
11
|
|
12
12
|
# Graphite : import fonts from font_dir into map
|
13
13
|
# ----------------------------------------------------------------------------------------------------
|
14
14
|
# @param font_dir [string] : path to top-level font directory
|
15
15
|
# @param legacy_ie [bool] : support legacy versions of ie
|
16
|
+
# @param debug [bool] : print debug information
|
16
17
|
# ----------------------------------------------------------------------------------------------------
|
17
18
|
# @return map of fonts, variable for each font
|
18
19
|
|
19
20
|
module Sass::Script::Functions
|
20
|
-
def graphite(font_dir, legacy_ie
|
21
|
+
def graphite(font_dir, legacy_ie, debug)
|
21
22
|
|
22
23
|
def opts(value)
|
23
24
|
value.options = options
|
@@ -38,17 +39,15 @@ module Sass::Script::Functions
|
|
38
39
|
# valid styles
|
39
40
|
valid_styles = ["normal", "italic"]
|
40
41
|
# Get weights for font
|
41
|
-
valid_weights.each do |weight|
|
42
|
+
valid_weights.each do | weight |
|
42
43
|
# Check filename for weight
|
43
44
|
if font.include?(weight)
|
44
45
|
# Get styles for weight
|
45
46
|
styles = []
|
46
47
|
# Check filename for style
|
47
|
-
valid_styles.each do |style|
|
48
|
-
|
49
|
-
|
50
|
-
styles << style
|
51
|
-
end
|
48
|
+
valid_styles.each do | style |
|
49
|
+
# Save to styles
|
50
|
+
styles << style if font.include?(style)
|
52
51
|
end
|
53
52
|
# Keep hash of each weight
|
54
53
|
w = {
|
@@ -66,15 +65,15 @@ module Sass::Script::Functions
|
|
66
65
|
|
67
66
|
# Add style to passed weight
|
68
67
|
def set_font_style(font, style)
|
69
|
-
font.merge!(style) do |k,
|
68
|
+
font.merge!(style) do | k, o, n |
|
70
69
|
# Merge styles
|
71
|
-
if
|
70
|
+
if o.is_a?(Hash)
|
72
71
|
# Get key => value of old map
|
73
|
-
|
72
|
+
o.each do | key, value |
|
74
73
|
# Does new map have key?
|
75
|
-
if
|
74
|
+
if n.has_key?(key)
|
76
75
|
# Then concat values
|
77
|
-
|
76
|
+
n.each do | k, v |
|
78
77
|
value.concat(v)
|
79
78
|
end
|
80
79
|
end
|
@@ -84,53 +83,68 @@ module Sass::Script::Functions
|
|
84
83
|
end
|
85
84
|
|
86
85
|
# Check if passed dir has fonts
|
87
|
-
def dir_has_fonts?(dir)
|
86
|
+
def dir_has_fonts?(dir, debug)
|
88
87
|
# Keep hash of all fonts found
|
89
88
|
fonts = {}
|
90
89
|
# Valid font extensions
|
91
90
|
valid_extensions = ["eot", "otf", "woff", "ttf", "svg"]
|
92
|
-
#
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
Dir.
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
91
|
+
# Check if directory exists
|
92
|
+
dir_name = File.dirname(dir)
|
93
|
+
|
94
|
+
if File.exists?(dir_name)
|
95
|
+
# Print debug
|
96
|
+
puts "Fonts directory found: #{dir}" if debug
|
97
|
+
# Change dir to font_dir
|
98
|
+
Dir.chdir(dir) do
|
99
|
+
# Search each dir
|
100
|
+
Dir.glob("**/") do | d |
|
101
|
+
# Check if directory exists
|
102
|
+
dir_name = File.dirname(d)
|
103
|
+
|
104
|
+
if File.exists?(dir_name)
|
105
|
+
# Check if dir has fonts
|
106
|
+
Dir.chdir(d) do
|
107
|
+
path = d
|
108
|
+
# Clean up font name
|
109
|
+
family = d.delete("/")
|
110
|
+
# Print debug
|
111
|
+
puts "Font family found: #{family}" if debug
|
112
|
+
# Get matched extensions
|
113
|
+
extensions = []
|
114
|
+
# Get matched weights and styles
|
115
|
+
variations = {}
|
116
|
+
# Check dir for matching extensions
|
117
|
+
valid_extensions.each do | ext |
|
118
|
+
Dir.glob("*.#{ext}") do | filename |
|
119
|
+
puts "Font found: #{filename}" if debug
|
120
|
+
# Check if filename has weights
|
121
|
+
w = font_has_weights?(filename.to_s)
|
122
|
+
# Merge weights and styles
|
123
|
+
set_font_style(variations, w)
|
124
|
+
# Save extensions that don't already exist
|
125
|
+
extensions << ext if extensions.include?(ext) === false
|
116
126
|
end
|
117
127
|
end
|
128
|
+
# Build out font hash
|
129
|
+
font = {
|
130
|
+
"#{family}" => {
|
131
|
+
"path" => path,
|
132
|
+
"extensions" => extensions,
|
133
|
+
"weights" => variations
|
134
|
+
}
|
135
|
+
}
|
136
|
+
# Merge into fonts hash
|
137
|
+
fonts = fonts.merge(font)
|
138
|
+
# Set Sass variable for font family
|
139
|
+
set_sass_var(family)
|
118
140
|
end
|
141
|
+
else
|
142
|
+
puts "Directory was not found: #{dir}. Aborting mission."
|
119
143
|
end
|
120
|
-
# Build out font hash
|
121
|
-
font = {
|
122
|
-
"#{family}" => {
|
123
|
-
"path" => path,
|
124
|
-
"extensions" => extensions,
|
125
|
-
"weights" => variations
|
126
|
-
}
|
127
|
-
}
|
128
|
-
# Merge into fonts hash
|
129
|
-
fonts = fonts.merge(font)
|
130
|
-
# Set Sass variable for font family
|
131
|
-
set_sass_var(family)
|
132
144
|
end
|
133
145
|
end
|
146
|
+
else
|
147
|
+
puts "Directory was not found: #{dir}. Aborting mission."
|
134
148
|
end
|
135
149
|
# Return hash of all fonts
|
136
150
|
return fonts
|
@@ -138,6 +152,12 @@ module Sass::Script::Functions
|
|
138
152
|
|
139
153
|
# Assert types
|
140
154
|
assert_type font_dir, :String, :font_dir
|
155
|
+
assert_type legacy_ie, :Bool, :legacy_ie
|
156
|
+
assert_type debug, :Bool, :debug
|
157
|
+
|
158
|
+
# Cast to bool
|
159
|
+
legacy_ie = legacy_ie.to_bool
|
160
|
+
debug = debug.to_bool
|
141
161
|
|
142
162
|
# Define root path up to current working directory
|
143
163
|
root = Dir.pwd
|
@@ -155,13 +175,13 @@ module Sass::Script::Functions
|
|
155
175
|
# Create Sass variable for font path
|
156
176
|
set_sass_var(font_dir, 'graphite_font_dir')
|
157
177
|
|
158
|
-
# Font naming convention : name-weight
|
178
|
+
# Font naming convention : name-weight-variant.extension
|
159
179
|
fonts = {
|
160
180
|
"legacy-ie" => legacy_ie,
|
161
181
|
}
|
162
182
|
|
163
183
|
# Get all fonts in dir
|
164
|
-
f = dir_has_fonts?(dir_path)
|
184
|
+
f = dir_has_fonts?(dir_path, debug)
|
165
185
|
|
166
186
|
# Merge results into fonts
|
167
187
|
fonts = fonts.merge(f)
|
@@ -169,5 +189,5 @@ module Sass::Script::Functions
|
|
169
189
|
# Convert hash to map, return
|
170
190
|
Sass::Script::Value::Map.new(SassyHash[fonts])
|
171
191
|
end
|
172
|
-
declare :
|
192
|
+
declare :graphite, [:font_dir]
|
173
193
|
end
|
data/stylesheets/graphite.scss
CHANGED
@@ -55,8 +55,8 @@ $graphite_chdir: ".." !global;
|
|
55
55
|
// @return $fonts [map] : imports fonts from $dir and creates
|
56
56
|
// a $var for each font family containing [string] name
|
57
57
|
|
58
|
-
@mixin graphite($dir, $legacy-ie: false) {
|
59
|
-
$graphite_fonts: graphite("#{$dir}", $legacy-ie) !global;
|
58
|
+
@mixin graphite($dir, $legacy-ie: false, $debug: false) {
|
59
|
+
$graphite_fonts: graphite("#{$dir}", $legacy-ie, $debug) !global;
|
60
60
|
|
61
61
|
// Make sure it's a valid map before attempting the loop
|
62
62
|
@if graphite-is-map($graphite_fonts) {
|
@@ -120,29 +120,30 @@ $graphite_chdir: ".." !global;
|
|
120
120
|
|
121
121
|
@font-face {
|
122
122
|
// Empty list of valid extensions
|
123
|
-
$types: ();
|
123
|
+
$types: (local('☺'));
|
124
124
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
font-style: $style;
|
125
|
+
font: {
|
126
|
+
family: "#{$name}";
|
127
|
+
weight: $weight;
|
128
|
+
style: $style;
|
129
|
+
}
|
131
130
|
|
132
131
|
// IE9
|
133
|
-
@if index($extensions, "eot") {
|
132
|
+
@if index($extensions, "eot") and $legacy-ie {
|
134
133
|
src: url("#{$path + $filename}.eot");
|
135
134
|
}
|
136
135
|
|
137
136
|
// Define value for each type
|
138
137
|
$ie: if(index($extensions, "eot") and $legacy-ie, url("#{$path + $filename}.eot?#iefix") format("embedded-opentype"), null);
|
139
138
|
$woff: if(index($extensions, "woff"), url("#{$path + $filename}.woff") format("woff"), null);
|
139
|
+
$otf: if(index($extensions, "otf"), url("#{$path + $filename}.otf") format("otf"), null);
|
140
140
|
$ttf: if(index($extensions, "ttf"), url("#{$path + $filename}.ttf") format("truetype"), null);
|
141
141
|
$svg: if(index($extensions, "svg"), url("#{$path + $filename + '.svg#' + $name}") format("svg"), null);
|
142
142
|
|
143
143
|
// Append to types list if not null
|
144
144
|
$types: if($ie != null, append($types, #{$ie}, "comma"), $types);
|
145
145
|
$types: if($woff != null, append($types, #{$woff}, "comma"), $types);
|
146
|
+
$types: if($otf != null, append($types, #{$otf}, "comma"), $types);
|
146
147
|
$types: if($ttf != null, append($types, #{$ttf}, "comma"), $types);
|
147
148
|
$types: if($svg != null, append($types, #{$svg}, "comma"), $types);
|
148
149
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphite-sass
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ezekiel Gabrielse
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sass
|