compass-fontcustom 1.0.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +17 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +22 -0
- data/README.md +54 -0
- data/Rakefile +11 -0
- data/compass-fontcustom.gemspec +27 -0
- data/lib/compass/fontcustom/configurable.rb +33 -0
- data/lib/compass/fontcustom/font_importer.rb +176 -0
- data/lib/compass/fontcustom/glyph_map.rb +71 -0
- data/lib/compass/fontcustom/sass_extensions.rb +89 -0
- data/lib/compass/fontcustom/templates/stylesheet.scss.erb +14 -0
- data/lib/compass/fontcustom/version.rb +5 -0
- data/lib/compass/fontcustom.rb +20 -0
- data/stylesheets/_fontcustom.scss +29 -0
- data/test/fixtures/myfont/C.svg +4 -0
- data/test/fixtures/myfont/D.svg +3 -0
- data/test/test_helper.rb +3 -0
- data/test/unit/font_importer_test.rb +74 -0
- data/test/unit/glyph_map_test.rb +19 -0
- metadata +139 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 33c354b92ccccb62776079d49fd0edab33aee28b
|
4
|
+
data.tar.gz: 97fd9f1564a4180e3a03756c91ced0f30d9a83c1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 78fc310f732d0fef8eae33ddb604cac414aee7f228f502470f4e13385def8f0079e63ffdc8848df8e4aeea6e3562ee793f4122113b35e06b31893787b4bafd3c
|
7
|
+
data.tar.gz: fb41b7770a5f977d2565455adb60a7993607d80b9c06a70e177642dd36ce01381ec3ad59444858b559e840c3d79c269252e259c926982afc9d2f7149a21dae25
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
**1.0.0.pre**
|
4
|
+
|
5
|
+
- Designed to work with fontcustom 1.0.0.pre
|
6
|
+
- Leveraging fontcustom's new `Fontcustom::Generator::Font` to generate font without stylesheets
|
7
|
+
- Generating custom stylesheet (see `lib/compass/fontcustom/templates/stylesheet.scss.erb) via mixins
|
8
|
+
- After `@import`ing your font you now need to `@include all-font-name-glyphs` to have classes available
|
9
|
+
- Font glyph class names follow this naming scheme: `.icon-<font>-<glyph>`
|
10
|
+
- New Sass function: `glyph(index)` which yields `:before` styles with proper index pointing at a specific glyph
|
11
|
+
Example:
|
12
|
+
`&:before { content: "\<index>"; }`
|
13
|
+
|
14
|
+
**0.0.1**
|
15
|
+
|
16
|
+
- obsolete. doesn't matter anymore.
|
17
|
+
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 glaszig
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# Compass::Fontcustom [![Build Status](https://travis-ci.org/glaszig/compass-fontcustom.png?branch=experimental)](https://travis-ci.org/glaszig/compass-fontcustom)
|
2
|
+
|
3
|
+
This is my attempt of integrating [Font Custom](http://fontcustom.com) with [Compass](http://compass-style.org).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'compass-fontcustom'
|
10
|
+
|
11
|
+
or:
|
12
|
+
|
13
|
+
gem 'compass-fontcustom', :github => 'glaszig/compass-fontcustom'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Syntactically it works like Compass' sprites feature.
|
22
|
+
You can let Font Custom generate your fonts upon Compass' css compilation:
|
23
|
+
|
24
|
+
```css
|
25
|
+
@import "myfont/*.svg";
|
26
|
+
@include all-myfont-glyphs;
|
27
|
+
```
|
28
|
+
|
29
|
+
This will import `fontcustom.css` into your stylesheet so that you can use the font `myfont` and the generated classes.
|
30
|
+
|
31
|
+
The font files will be searched in `images_path/myfont` and be written to Compass' `fonts_path`.
|
32
|
+
|
33
|
+
## Disabling file name hashes
|
34
|
+
|
35
|
+
You can choose to disable file name hashes if you're already using an asset pipeline that handles this for you:
|
36
|
+
Use the `fontcustom_hash` compass option in `config.rb`
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
compass_config do |config|
|
40
|
+
config.fontcustom_hash = false
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
## Contributing
|
45
|
+
|
46
|
+
1. Fork it
|
47
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
48
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
49
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
50
|
+
5. Create new Pull Request
|
51
|
+
|
52
|
+
## License
|
53
|
+
|
54
|
+
[MIT](https://raw.github.com/glaszig/compass-fontcustom/master/LICENSE)
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'compass/fontcustom/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "compass-fontcustom"
|
8
|
+
spec.version = Compass::Fontcustom::VERSION
|
9
|
+
spec.authors = ["glaszig"]
|
10
|
+
spec.email = ["glaszig@gmail.com"]
|
11
|
+
spec.description = %q{Fontcustom for Compass}
|
12
|
+
spec.summary = %q{Integrates Fontcustom with Compass}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/).reject { |f| f =~ /^(demo|\.)/ }
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "compass"
|
22
|
+
spec.add_dependency "fontcustom", "~> 1.0.0.pre"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "pry"
|
27
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Compass
|
2
|
+
module Fontcustom
|
3
|
+
|
4
|
+
# A simple configuration store like the one known from ActiveSupport.
|
5
|
+
module Configurable
|
6
|
+
|
7
|
+
def self.included(base)
|
8
|
+
base.class_eval do
|
9
|
+
def self.configure(&block)
|
10
|
+
yield config
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.config
|
14
|
+
@_config ||= Configuration.new
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class Configuration
|
20
|
+
def method_missing(meth, *args)
|
21
|
+
@config ||= {}
|
22
|
+
if meth.to_s =~ /=$/
|
23
|
+
sym = meth.to_s[0...-1].to_sym
|
24
|
+
@config[sym] = args.first
|
25
|
+
else
|
26
|
+
@config[meth]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,176 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'tempfile'
|
3
|
+
require 'fontcustom/error'
|
4
|
+
require 'fontcustom/options'
|
5
|
+
require 'fontcustom/util'
|
6
|
+
require 'fontcustom/generator/font'
|
7
|
+
|
8
|
+
module Compass
|
9
|
+
module Fontcustom
|
10
|
+
|
11
|
+
# Just an `OpenStruct` to contain template variables.
|
12
|
+
# @see FontImporter#content_for_font
|
13
|
+
class TemplateData < OpenStruct
|
14
|
+
# Returns the intance's internal `binding`.
|
15
|
+
def expose_binding; binding end
|
16
|
+
end
|
17
|
+
|
18
|
+
# The Sass Importer responsible to find svg and eps files
|
19
|
+
# and to start the Fontcustom font generator.
|
20
|
+
class FontImporter < ::Sass::Importers::Base
|
21
|
+
|
22
|
+
# Regexp matching uri's of svg and eps files.
|
23
|
+
# Matching group `$1` contains the path, `$3` the file name.
|
24
|
+
GLYPH_FILE_REGEX = %r{((.+/)?([^\*.]+))/(.+?)\.(svg|eps)}
|
25
|
+
|
26
|
+
# class methods
|
27
|
+
class << self
|
28
|
+
|
29
|
+
# Returns an array with two elements.
|
30
|
+
# First the path, second the file name of the `uri`.
|
31
|
+
# @param uri [String] an uri to match glyph image
|
32
|
+
# @return [Array] a two-element array containing the path and file name components
|
33
|
+
def path_and_name(uri)
|
34
|
+
if uri =~ GLYPH_FILE_REGEX
|
35
|
+
[$1, $3]
|
36
|
+
else
|
37
|
+
raise Compass::Error, "Invalid glyph image uri"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Returns only the file name component of `uri`.
|
42
|
+
# @see path_and_name
|
43
|
+
# @return [String]
|
44
|
+
def font_name(uri)
|
45
|
+
_, name = path_and_name(uri)
|
46
|
+
name
|
47
|
+
end
|
48
|
+
|
49
|
+
# Returns only the path component of `uri`
|
50
|
+
# @see path_and_name
|
51
|
+
# @return [String]
|
52
|
+
def path(uri)
|
53
|
+
path, _ = path_and_name(uri)
|
54
|
+
path
|
55
|
+
end
|
56
|
+
|
57
|
+
# Returns all glyph names inside the folder at `uri`.
|
58
|
+
# @param uri [String] the uri to glob files from
|
59
|
+
# @return [Array]
|
60
|
+
def glyph_names(uri)
|
61
|
+
folder = Compass.configuration.images_path.to_s
|
62
|
+
files = Dir[File.join(folder, uri)].sort
|
63
|
+
|
64
|
+
if files.empty?
|
65
|
+
raise Compass::SpriteException, %Q{No glyph images were found matching "#{uri}" in the images path. Your current images path is: #{folder}}
|
66
|
+
end
|
67
|
+
|
68
|
+
files.map { |f| File.basename(f)[0..-5] }
|
69
|
+
end
|
70
|
+
|
71
|
+
# Returns `Sass::Engine` options with defaults
|
72
|
+
# @param uri [String] the uri to glob files from
|
73
|
+
# @param importer [Sass::Importers::Base] the importer to use (in this case `self`)
|
74
|
+
# @param options [Hash] options to merge with
|
75
|
+
# @return [Hash]
|
76
|
+
def sass_options(uri, importer, options)
|
77
|
+
options.merge!(:filename => uri.gsub(%r{\*/},"*\\/"), :syntax => :scss, :importer => importer)
|
78
|
+
end
|
79
|
+
|
80
|
+
# Returns a `Sass::Engine`
|
81
|
+
# @param uri [String] the uri to glob files from
|
82
|
+
# @param name [String] the font's name
|
83
|
+
# @param importer [Sass::Importers::Base] the importer to use (in this case `self`)
|
84
|
+
# @param options [Hash] options to merge with
|
85
|
+
# @return [Sass::Engine]
|
86
|
+
def sass_engine(uri, name, importer, options)
|
87
|
+
content = content_for_font(uri, name)
|
88
|
+
Sass::Engine.new(content, sass_options(uri, importer, options))
|
89
|
+
end
|
90
|
+
|
91
|
+
# Renders the stylesheet for font `name` at `uri`
|
92
|
+
# @param uri [String] the uri to glob files from
|
93
|
+
# @param name [String] the font's name
|
94
|
+
# @return [String]
|
95
|
+
def content_for_font(uri, name)
|
96
|
+
erb = File.read File.join(template_path, 'stylesheet.scss.erb')
|
97
|
+
binder = TemplateData.new(uri: uri, name: name, path: fonts_path, glyph_names: glyph_names(uri))
|
98
|
+
ERB.new(erb).result(binder.expose_binding)
|
99
|
+
end
|
100
|
+
|
101
|
+
# Returns the fonts path
|
102
|
+
# @return [String]
|
103
|
+
def fonts_path
|
104
|
+
Compass.configuration.fonts_dir.to_s
|
105
|
+
end
|
106
|
+
|
107
|
+
# Returns the gems' internal template path.
|
108
|
+
# @return [String]
|
109
|
+
def template_path
|
110
|
+
File.expand_path('../templates', __FILE__)
|
111
|
+
end
|
112
|
+
|
113
|
+
# Returns an array of font files.
|
114
|
+
# @param uri [String] the uri to glob files from
|
115
|
+
# @return [Array]
|
116
|
+
def files(uri)
|
117
|
+
folder = Compass.configuration.images_path.to_s
|
118
|
+
files = Dir[File.join(folder, uri)]
|
119
|
+
files
|
120
|
+
end
|
121
|
+
|
122
|
+
end # end class methods
|
123
|
+
|
124
|
+
# Resolves incoming uri from an `@import "..."` directive.
|
125
|
+
# @param uri [String] the uri from the import directive
|
126
|
+
# @param options [Hash] options for the returned Sass::Engine`
|
127
|
+
# @return [Sass::Engine]
|
128
|
+
def find(uri, options)
|
129
|
+
if uri =~ GLYPH_FILE_REGEX
|
130
|
+
return self.class.sass_engine(uri, self.class.font_name(uri), self, options)
|
131
|
+
end
|
132
|
+
nil
|
133
|
+
end
|
134
|
+
|
135
|
+
# Unused. Just returns nil.
|
136
|
+
def find_relative(uri, base, options)
|
137
|
+
nil
|
138
|
+
end
|
139
|
+
|
140
|
+
# Returns the string representation of this instance.
|
141
|
+
# @return [String]
|
142
|
+
def to_s
|
143
|
+
self.class.name
|
144
|
+
end
|
145
|
+
|
146
|
+
# Returns the hash of this instance.
|
147
|
+
# @return [String]
|
148
|
+
def hash
|
149
|
+
self.class.name.hash
|
150
|
+
end
|
151
|
+
|
152
|
+
# Compares this instance with another object.
|
153
|
+
# @param other [Object] another object
|
154
|
+
# @return [Boolean]
|
155
|
+
def eql?(other)
|
156
|
+
other.class == self.class
|
157
|
+
end
|
158
|
+
|
159
|
+
def mtime(uri, options)
|
160
|
+
self.class.files(uri).sort.inject(Time.at(0)) do |max_time, file|
|
161
|
+
(t = File.mtime(file)) > max_time ? t : max_time
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
# This instance's Compass cache key
|
166
|
+
# @param uri [String] the uri to glob files from
|
167
|
+
# @param options [Hash] hash of options
|
168
|
+
# @return [Array]
|
169
|
+
def key(uri, options={})
|
170
|
+
[self.class.name + ":fontcustom:" + File.dirname(File.expand_path(uri)), File.basename(uri)]
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
176
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'fontcustom/generator/font'
|
2
|
+
require 'compass/fontcustom/configurable'
|
3
|
+
|
4
|
+
module Compass
|
5
|
+
module Fontcustom
|
6
|
+
class GlyphMap < Sass::Script::Literal
|
7
|
+
include Configurable
|
8
|
+
|
9
|
+
attr_reader :name, :path
|
10
|
+
|
11
|
+
# @param context [Object] usually an instance of FontImporter
|
12
|
+
def self.from_uri(uri, context)
|
13
|
+
path, name = FontImporter.path_and_name uri
|
14
|
+
glyphs = FontImporter.files(uri).sort.map { |file| File.basename(file)[0..-5] }
|
15
|
+
new glyphs, path, name, context
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(glyphs, path, name, context)
|
19
|
+
raise StandardError, "No glyphs found at '#{path}'" if glyphs.empty?
|
20
|
+
@glyphs = glyphs
|
21
|
+
@path = path
|
22
|
+
@name = name
|
23
|
+
@context = context
|
24
|
+
end
|
25
|
+
|
26
|
+
def index_for_glyph(name)
|
27
|
+
@glyphs.index name
|
28
|
+
end
|
29
|
+
|
30
|
+
# Starts the Fontcustom font generator to write font files to disk.
|
31
|
+
def generate
|
32
|
+
unless exists?
|
33
|
+
args = self.class.config.generator_options || {}
|
34
|
+
args.merge!(
|
35
|
+
:input => File.join(Compass.configuration.images_path.to_s, self.path),
|
36
|
+
:output => output_dir,
|
37
|
+
:font_name => @name,
|
38
|
+
:file_hash => Compass.configuration.fontcustom_hash,
|
39
|
+
:verbose => false
|
40
|
+
)
|
41
|
+
::Fontcustom::Generator::Font.start [args]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def filename
|
46
|
+
file = glob.first
|
47
|
+
File.basename file, File.extname(file)
|
48
|
+
end
|
49
|
+
|
50
|
+
def exists?
|
51
|
+
not glob.empty?
|
52
|
+
end
|
53
|
+
|
54
|
+
def output_dir
|
55
|
+
Compass.configuration.fonts_path.to_s
|
56
|
+
end
|
57
|
+
|
58
|
+
def to_s
|
59
|
+
@name.to_s
|
60
|
+
end
|
61
|
+
|
62
|
+
protected
|
63
|
+
|
64
|
+
def glob
|
65
|
+
glob = File.join output_dir, "#{self.name}*"
|
66
|
+
Dir[glob]
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module Compass
|
2
|
+
module Fontcustom
|
3
|
+
# Declares extensions for the Sass interpreter
|
4
|
+
module SassExtensions
|
5
|
+
|
6
|
+
# Sass function extensions
|
7
|
+
module Functions
|
8
|
+
|
9
|
+
# Font type format mappings used in css font-face declarations.
|
10
|
+
# @see #glyph_font_sources
|
11
|
+
FONT_TYPE_FORMATS = {
|
12
|
+
'eot?#iefix' => 'embedded-opentype',
|
13
|
+
'woff' => 'woff',
|
14
|
+
'ttf' => 'truetype',
|
15
|
+
"svg#%{font_name}" => 'svg'
|
16
|
+
}
|
17
|
+
|
18
|
+
# Returns `:before` pseudo class styles for the letter at `index` of the font.
|
19
|
+
#
|
20
|
+
# @param index [FixNum] the font's index
|
21
|
+
# @return [Sass::Script::String]
|
22
|
+
def glyph(index)
|
23
|
+
idx = (61696+index.value-1).to_s(16)
|
24
|
+
css = %Q[&:before { content: "\\#{idx}"; }]
|
25
|
+
Sass::Script::String.new %Q["\\#{idx}"]
|
26
|
+
end
|
27
|
+
Sass::Script::Functions.declare :letter, [:index]
|
28
|
+
|
29
|
+
# Returns a `GlyphMap` representing a font.
|
30
|
+
#
|
31
|
+
# @param uri [String] the uri to glob files from
|
32
|
+
# @return [Compass::Fontcustom::GlyphMap] a glyph map
|
33
|
+
def glyph_map(uri)
|
34
|
+
GlyphMap.from_uri uri.value, self
|
35
|
+
end
|
36
|
+
Sass::Script::Functions.declare :glyph_map, [:uri]
|
37
|
+
|
38
|
+
# Returns all `url(...) format(...)` definitions for the font files of the `map`.
|
39
|
+
#
|
40
|
+
# @param map [Compass::Fontcustom::GlyphMap] a glyph map
|
41
|
+
# @return [Sass::Script::String]
|
42
|
+
def glyph_font_sources(map)
|
43
|
+
map.generate
|
44
|
+
src = []
|
45
|
+
FONT_TYPE_FORMATS.each do |type, format|
|
46
|
+
url = glyph_font_type_url map, type
|
47
|
+
src << "#{url} format('#{format}')"
|
48
|
+
end
|
49
|
+
Sass::Script::String.new src.join ", "
|
50
|
+
end
|
51
|
+
Sass::Script::Functions.declare :glyph_font_sources, [:map]
|
52
|
+
|
53
|
+
# Retuns the font name of `map`.
|
54
|
+
#
|
55
|
+
# @param map [Compass::Fontcustom::GlyphMap] a glyph map
|
56
|
+
# @return [Sass::Script::String]
|
57
|
+
def glyph_font_name(map)
|
58
|
+
Sass::Script::String.new map.name
|
59
|
+
end
|
60
|
+
Sass::Script::Functions.declare :glyph_font_name, [:map]
|
61
|
+
|
62
|
+
# Returns the font name of `map in quotes
|
63
|
+
#
|
64
|
+
# @param map [Compass::Fontcustom::GlyphMap] a glyph map
|
65
|
+
# @return [Sass::Script::String]
|
66
|
+
def glyph_font_name_quoted(map)
|
67
|
+
Sass::Script::String.new %Q{"#{map.name}"}
|
68
|
+
end
|
69
|
+
Sass::Script::Functions.declare :glyph_font_name_quoted, [:map]
|
70
|
+
|
71
|
+
# Helper method. Returns a `Sass::Script::Functions#font_url for the font of `type` in `map`.
|
72
|
+
#
|
73
|
+
# @return [String]
|
74
|
+
def glyph_font_type_url(map, type)
|
75
|
+
type = type % {font_name: map.name}
|
76
|
+
file_name = "#{map.filename}.#{type}"
|
77
|
+
font_file = Sass::Script::String.new file_name
|
78
|
+
font_url(font_file).value
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
module Sass::Script::Functions
|
88
|
+
include Compass::Fontcustom::SassExtensions::Functions
|
89
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
@import "fontcustom.scss";
|
2
|
+
|
3
|
+
$<%= name %>-font-base-class: ".<%= name %>-font" !default;
|
4
|
+
|
5
|
+
#{$<%= name %>-font-base-class} {
|
6
|
+
font-family: "<%= name %>";
|
7
|
+
}
|
8
|
+
|
9
|
+
$<%= name %>-glyphs: glyph-map("<%= uri %>");
|
10
|
+
|
11
|
+
@mixin all-<%= name %>-glyphs {
|
12
|
+
@include fontcustom-font-face($<%= name %>-glyphs);
|
13
|
+
@include glyphs($<%= name %>-glyphs, <%= glyph_names.join " " %>, $<%= name %>-font-base-class)
|
14
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "compass"
|
2
|
+
require "compass/fontcustom/version"
|
3
|
+
require "compass/fontcustom/sass_extensions"
|
4
|
+
require "compass/fontcustom/glyph_map"
|
5
|
+
require "compass/fontcustom/font_importer"
|
6
|
+
|
7
|
+
module Compass
|
8
|
+
# This module registers the gem as a Compass framework source,
|
9
|
+
# adds config properties to Compass and extends Sass' `load_paths`.
|
10
|
+
module Fontcustom
|
11
|
+
base_directory = File.expand_path('../../../', __FILE__)
|
12
|
+
Compass::Frameworks.register('fontcustom', :path => base_directory)
|
13
|
+
|
14
|
+
Compass::Configuration.add_configuration_property(:fontcustom_hash, "enables/disables fontcustom file name hashing") do
|
15
|
+
true
|
16
|
+
end
|
17
|
+
|
18
|
+
Sass.load_paths << FontImporter.new
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
@mixin fontcustom-font-face($map) {
|
2
|
+
@font-face {
|
3
|
+
font-family: glyph-font-name-quoted($map);
|
4
|
+
src: glyph-font-sources($map);
|
5
|
+
font-weight: normal;
|
6
|
+
font-style: normal;
|
7
|
+
}
|
8
|
+
}
|
9
|
+
|
10
|
+
// generates icon classes in the format icon-<font-name>-<glyph-name>
|
11
|
+
// for each glyph in the font.
|
12
|
+
//
|
13
|
+
// $map must be a glyph map
|
14
|
+
// $glyph-names must be a space-separated list of glyph names
|
15
|
+
// $base-class should be the css class to @extend
|
16
|
+
@mixin glyphs($map, $glyph-names, $base-class: false) {
|
17
|
+
$name: glyph-font-name($map);
|
18
|
+
@each $glyph-name in $glyph-names {
|
19
|
+
|
20
|
+
$index: index($glyph-names, $glyph-name);
|
21
|
+
$class_name: "icon-#{$name}-#{$glyph-name}";
|
22
|
+
|
23
|
+
.#{$class_name} {
|
24
|
+
@if $base-class { @extend #{$base-class}; }
|
25
|
+
&:before { content: glyph($index); }
|
26
|
+
}
|
27
|
+
|
28
|
+
}
|
29
|
+
}
|
@@ -0,0 +1,4 @@
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Layer_1" x="0px" y="0px" width="100px" height="100px" viewBox="0 0 100 100" enable-background="new 0 0 100 100" xml:space="preserve">
|
2
|
+
<path d="M50,0C22.389,0,0,22.383,0,49.994V100h100V49.994C100,22.383,77.617,0,50,0z M96.667,96.667H3.333V49.994 c0-25.729,20.938-46.66,46.667-46.66c25.729,0,46.667,20.931,46.667,46.66V96.667z"/>
|
3
|
+
<path d="M50,10c-22.083,0-40,17.91-40,39.994V90l30-30V50c0-5.521,4.479-10,10-10c5.521,0,10,4.479,10,10v10l30,30V49.994 C90,27.91,72.09,10,50,10z"/>
|
4
|
+
</svg>
|
@@ -0,0 +1,3 @@
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Layer_1" x="0px" y="0px" width="100px" height="100px" viewBox="0 0 100 100" style="enable-background:new 0 0 100 100;" xml:space="preserve">
|
2
|
+
<path style="fill:#010101;" d="M87.5,75c-3.039,0-5.725,1.221-7.886,3.016l-19.056-13.6c1.209-2.49,1.941-5.225,1.941-8.166 c0-4.041-1.318-7.775-3.491-10.828l22.29-22.302C83.154,24.207,85.193,25,87.5,25c6.909,0,12.5-5.591,12.5-12.5S94.409,0,87.5,0 S75,5.591,75,12.5c0,2.307,0.793,4.346,1.88,6.201L54.59,41.004c-3.076-2.197-6.787-3.504-10.84-3.504 c-7.153,0-13.306,4.064-16.467,9.973l-15.052-5.029C11.621,39.637,9.24,37.5,6.25,37.5C2.795,37.5,0,40.295,0,43.75 S2.795,50,6.25,50c1.574,0,2.979-0.635,4.077-1.6l14.966,4.993C25.146,54.334,25,55.273,25,56.25C25,66.602,33.398,75,43.75,75 c5.151,0,9.826-2.088,13.221-5.457l18.933,13.514C75.366,84.448,75,85.926,75,87.5c0,6.896,5.591,12.5,12.5,12.5 S100,94.396,100,87.5S94.409,75,87.5,75z"/>
|
3
|
+
</svg>
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'stringio'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
class FontImporterTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
Compass.reset_configuration!
|
9
|
+
@project_path = File.expand_path('../../', __FILE__)
|
10
|
+
@output_path = File.join(@project_path, '.output')
|
11
|
+
@fonts_path = File.join(@output_path, 'fonts')
|
12
|
+
FileUtils.mkdir_p @fonts_path
|
13
|
+
|
14
|
+
config = StringIO.new <<-SCSS
|
15
|
+
project_path = #{@project_path.inspect}
|
16
|
+
images_dir = #{"fixtures".inspect}
|
17
|
+
css_dir = #{".output".inspect}
|
18
|
+
SCSS
|
19
|
+
Compass.add_configuration(config, "fontcustom_config")
|
20
|
+
|
21
|
+
Compass::Fontcustom::GlyphMap.configure do |config|
|
22
|
+
config.generator_options = { :debug => true }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def teardown
|
27
|
+
Compass.reset_configuration!
|
28
|
+
FileUtils.rm_r @output_path
|
29
|
+
end
|
30
|
+
|
31
|
+
def render(scss)
|
32
|
+
scss = %Q(@import "compass"; #{scss})
|
33
|
+
options = Compass.sass_engine_options
|
34
|
+
options[:line_comments] = false
|
35
|
+
options[:style] = :expanded
|
36
|
+
options[:syntax] = :scss
|
37
|
+
options[:compass] ||= {}
|
38
|
+
options[:compass][:logger] ||= Compass::NullLogger.new
|
39
|
+
Sass::Engine.new(scss, options).render
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_should_generate_font_classes
|
43
|
+
fontname = 'myfont'
|
44
|
+
|
45
|
+
css = render <<-SCSS
|
46
|
+
@import "#{fontname}/*.svg";
|
47
|
+
@include all-myfont-glyphs;
|
48
|
+
SCSS
|
49
|
+
|
50
|
+
assert css =~ %r{.#{fontname}-font}, "base font class missing"
|
51
|
+
assert css =~ %r{.icon-#{fontname}-c}i, "icon c css class missing"
|
52
|
+
assert css =~ %r{.icon-#{fontname}-d}i, "icon d css class missing"
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_should_skip_file_name_hashes_if_option_is_set
|
56
|
+
fontname = 'myfont'
|
57
|
+
|
58
|
+
Compass.configuration.fontcustom_hash = false
|
59
|
+
|
60
|
+
css = render <<-SCSS
|
61
|
+
@import "#{fontname}/*.svg";
|
62
|
+
@include all-myfont-glyphs;
|
63
|
+
SCSS
|
64
|
+
|
65
|
+
assert File.exists? File.join(Compass.configuration.fonts_path, 'myfont.svg')
|
66
|
+
assert File.exists? File.join(Compass.configuration.fonts_path, 'myfont.ttf')
|
67
|
+
assert File.exists? File.join(Compass.configuration.fonts_path, 'myfont.woff')
|
68
|
+
|
69
|
+
assert css =~ %r{.#{fontname}-font}, "base font class missing"
|
70
|
+
assert css =~ %r{.icon-#{fontname}-c}i, "icon c css class missing"
|
71
|
+
assert css =~ %r{.icon-#{fontname}-d}i, "icon d css class missing"
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class GlyphMapTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
font_path = File.expand_path('../../fixtures/myfont', __FILE__) + '/*.svg'
|
7
|
+
@glyph_map = Compass::Fontcustom::GlyphMap.from_uri font_path, nil
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_glyph_map
|
11
|
+
map = @glyph_map.instance_variable_get(:@glyphs)
|
12
|
+
assert !map.empty?
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_glyph_index_access
|
16
|
+
assert_equal 0, @glyph_map.index_for_glyph('C')
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: compass-fontcustom
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0.pre
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- glaszig
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-04-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: compass
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: fontcustom
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.0.0.pre
|
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.pre
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Fontcustom for Compass
|
84
|
+
email:
|
85
|
+
- glaszig@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- CHANGELOG.md
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- compass-fontcustom.gemspec
|
96
|
+
- lib/compass/fontcustom.rb
|
97
|
+
- lib/compass/fontcustom/configurable.rb
|
98
|
+
- lib/compass/fontcustom/font_importer.rb
|
99
|
+
- lib/compass/fontcustom/glyph_map.rb
|
100
|
+
- lib/compass/fontcustom/sass_extensions.rb
|
101
|
+
- lib/compass/fontcustom/templates/stylesheet.scss.erb
|
102
|
+
- lib/compass/fontcustom/version.rb
|
103
|
+
- stylesheets/_fontcustom.scss
|
104
|
+
- test/fixtures/myfont/C.svg
|
105
|
+
- test/fixtures/myfont/D.svg
|
106
|
+
- test/test_helper.rb
|
107
|
+
- test/unit/font_importer_test.rb
|
108
|
+
- test/unit/glyph_map_test.rb
|
109
|
+
homepage: ''
|
110
|
+
licenses:
|
111
|
+
- MIT
|
112
|
+
metadata: {}
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - '>='
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - '>'
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: 1.3.1
|
127
|
+
requirements: []
|
128
|
+
rubyforge_project:
|
129
|
+
rubygems_version: 2.0.0
|
130
|
+
signing_key:
|
131
|
+
specification_version: 4
|
132
|
+
summary: Integrates Fontcustom with Compass
|
133
|
+
test_files:
|
134
|
+
- test/fixtures/myfont/C.svg
|
135
|
+
- test/fixtures/myfont/D.svg
|
136
|
+
- test/test_helper.rb
|
137
|
+
- test/unit/font_importer_test.rb
|
138
|
+
- test/unit/glyph_map_test.rb
|
139
|
+
has_rdoc:
|