fontcustom 1.1.0.pre2 → 1.1.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/CHANGELOG.md +18 -0
- data/CONTRIBUTING.md +2 -3
- data/README.md +37 -12
- data/Rakefile +3 -3
- data/fontcustom.gemspec +11 -10
- data/lib/fontcustom.rb +18 -22
- data/lib/fontcustom/cli.rb +29 -30
- data/lib/fontcustom/generator/font.rb +23 -34
- data/lib/fontcustom/generator/template.rb +26 -24
- data/lib/fontcustom/options.rb +51 -48
- data/lib/fontcustom/scripts/generate.py +2 -2
- data/lib/fontcustom/templates/_fontcustom-bootstrap.scss +5 -5
- data/lib/fontcustom/templates/_fontcustom-rails.scss +5 -5
- data/lib/fontcustom/templates/_fontcustom.scss +8 -5
- data/lib/fontcustom/templates/fontcustom-bootstrap-ie7.css +1 -1
- data/lib/fontcustom/templates/fontcustom-bootstrap.css +1 -1
- data/lib/fontcustom/templates/fontcustom-preview.html +67 -22
- data/lib/fontcustom/templates/fontcustom.css +4 -1
- data/lib/fontcustom/templates/fontcustom.yml +14 -14
- data/lib/fontcustom/util.rb +18 -8
- data/lib/fontcustom/version.rb +1 -1
- data/lib/fontcustom/watcher.rb +24 -22
- data/spec/fixtures/shared/templates/custom.css +6 -0
- data/spec/fixtures/shared/templates/regular.css +3 -0
- data/spec/fontcustom/generator/font_spec.rb +14 -14
- data/spec/fontcustom/generator/template_spec.rb +34 -21
- data/spec/fontcustom/options_spec.rb +45 -69
- data/spec/fontcustom/util_spec.rb +26 -5
- data/spec/fontcustom/watcher_spec.rb +6 -6
- data/spec/spec_helper.rb +8 -8
- metadata +11 -11
- data/TODO.md +0 -21
@@ -1,4 +1,4 @@
|
|
1
|
-
/*
|
1
|
+
/*
|
2
2
|
Icon Font: <%= @opts.font_name %>
|
3
3
|
*/
|
4
4
|
|
@@ -13,6 +13,9 @@
|
|
13
13
|
font-style: normal;
|
14
14
|
}
|
15
15
|
|
16
|
+
[data-icon]:before { content: attr(data-icon); }
|
17
|
+
|
18
|
+
[data-icon]:before,
|
16
19
|
<%= @glyphs.map {|name| ".#{@opts.css_prefix + name}:before"}.join(",\n") %> {
|
17
20
|
font-family: "<%= @opts.font_name %>";
|
18
21
|
font-style: normal;
|
@@ -1,30 +1,30 @@
|
|
1
1
|
# ---------------------------------------------------------------------------- #
|
2
2
|
# Project Info
|
3
|
-
# Learn more about these options by running
|
4
|
-
# <http://fontcustom.com>.
|
3
|
+
# Default values shown. Learn more about these options by running
|
4
|
+
# `fontcustom help` or visit <http://fontcustom.com>.
|
5
5
|
# ---------------------------------------------------------------------------- #
|
6
6
|
|
7
|
-
#font_name:
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#debug:
|
12
|
-
#
|
7
|
+
#font_name: fontcustom
|
8
|
+
#css_prefix: icon-
|
9
|
+
#preprocessor_path: ""
|
10
|
+
#no_hash: false
|
11
|
+
#debug: false
|
12
|
+
#quiet: false
|
13
13
|
|
14
14
|
|
15
15
|
# ---------------------------------------------------------------------------- #
|
16
16
|
# Project Paths
|
17
|
-
#
|
18
|
-
#
|
19
|
-
# For finer control, assign INPUT and OUTPUT as hashes instead of a strings.
|
17
|
+
# Relative paths are expanded from PROJECT_ROOT (default: working directory).
|
18
|
+
# INPUT and OUTPUT can be assigned as hashes instead of a strings.
|
20
19
|
# The OUPUT hash can route custom templates according to their filename.
|
21
20
|
# ---------------------------------------------------------------------------- #
|
22
21
|
|
23
22
|
#project_root: some/other/place
|
23
|
+
#data_cache: tmp/fontcustom
|
24
24
|
|
25
25
|
#input:
|
26
|
-
# vectors: app/assets/fontcustom/vectors
|
27
|
-
# templates: app/assets/fontcustom/templates
|
26
|
+
# vectors: app/assets/fonts/fontcustom/vectors
|
27
|
+
# templates: app/assets/fonts/fontcustom/templates
|
28
28
|
|
29
29
|
#output:
|
30
30
|
# fonts: app/assets/fonts
|
@@ -36,7 +36,7 @@
|
|
36
36
|
# ---------------------------------------------------------------------------- #
|
37
37
|
# Templates
|
38
38
|
# Included in Font Custom:
|
39
|
-
# preview, css, scss, bootstrap, bootstrap-scss, bootstrap-ie7,
|
39
|
+
# preview, css, scss, scss-rails, bootstrap, bootstrap-scss, bootstrap-ie7,
|
40
40
|
# bootstrap-ie7-scss
|
41
41
|
# Custom templates should be saved in the INPUT[:templates] directory.
|
42
42
|
# ---------------------------------------------------------------------------- #
|
data/lib/fontcustom/util.rb
CHANGED
@@ -1,35 +1,45 @@
|
|
1
1
|
##
|
2
|
-
# Needs access to @shell and an Options instance
|
2
|
+
# Needs access to @shell and an Options instance
|
3
3
|
# (@opts in thor, @cli_options or self in Options)
|
4
4
|
module Fontcustom
|
5
5
|
module Util
|
6
6
|
def check_fontforge
|
7
7
|
fontforge = `which fontforge`
|
8
8
|
if fontforge == "" || fontforge == "fontforge not found"
|
9
|
-
raise Fontcustom::Error, "Please install fontforge. Visit http://fontcustom.com for instructions."
|
9
|
+
raise Fontcustom::Error, "Please install fontforge. Visit <http://fontcustom.com> for instructions."
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
def say_changed(status, changed)
|
14
|
-
return
|
14
|
+
return if base(:quiet)
|
15
15
|
message = changed.map { |file| relative_to_root(file) }
|
16
|
-
@shell.say_status status, message.join(" ")
|
16
|
+
@shell.say_status status, message.join("\n#{" " * 14}"), :green # magic number
|
17
17
|
end
|
18
18
|
|
19
|
-
def say_message(status, message)
|
20
|
-
return
|
21
|
-
@shell.say_status status, message
|
19
|
+
def say_message(status, message, color = :yellow)
|
20
|
+
return if base(:quiet) && status != :error
|
21
|
+
@shell.say_status status, message, color
|
22
|
+
end
|
23
|
+
|
24
|
+
def expand_path(path)
|
25
|
+
return path if path[0] == "/"
|
26
|
+
File.expand_path File.join(base(:project_root), path)
|
22
27
|
end
|
23
28
|
|
24
29
|
def relative_to_root(path)
|
25
30
|
path = path.sub(base(:project_root), "")
|
26
31
|
path = path[1..-1] if path[0] == "/"
|
32
|
+
path = "." if path.empty?
|
27
33
|
path
|
28
34
|
end
|
29
35
|
|
30
36
|
def overwrite_file(file, content = "")
|
31
37
|
File.open(file, "w") { |f| f.write(content) }
|
32
|
-
say_changed :update, [ file ]
|
38
|
+
# say_changed :update, [ file ]
|
39
|
+
end
|
40
|
+
|
41
|
+
def symbolize_hash(hash)
|
42
|
+
hash.inject({}) { |memo, (k, v)| memo[k.to_sym] = v; memo }
|
33
43
|
end
|
34
44
|
|
35
45
|
private
|
data/lib/fontcustom/version.rb
CHANGED
data/lib/fontcustom/watcher.rb
CHANGED
@@ -3,6 +3,8 @@ require "listen"
|
|
3
3
|
|
4
4
|
module Fontcustom
|
5
5
|
class Watcher
|
6
|
+
include Util
|
7
|
+
|
6
8
|
def initialize(opts)
|
7
9
|
@opts = opts
|
8
10
|
@vector_listener = Listen.to(@opts.input[:vectors]).relative_paths(true).filter(/\.(eps|svg)$/).change(&callback)
|
@@ -27,56 +29,56 @@ module Fontcustom
|
|
27
29
|
end
|
28
30
|
|
29
31
|
def watch
|
30
|
-
puts "Font Custom is watching your icons at #{@opts.input[:vectors]}. Press Ctrl + C to stop."
|
31
32
|
compile unless @opts.skip_first
|
33
|
+
start
|
34
|
+
rescue SignalException # Catches Ctrl + C
|
35
|
+
stop
|
36
|
+
end
|
32
37
|
|
33
|
-
|
34
|
-
|
38
|
+
private
|
39
|
+
|
40
|
+
def start
|
41
|
+
if @is_test # Non-blocking listener
|
35
42
|
@vector_listener.start
|
36
43
|
@template_listener.start if @template_listener
|
37
44
|
else
|
38
45
|
@vector_listener.start!
|
39
46
|
@template_listener.start! if @template_listener
|
40
47
|
end
|
41
|
-
|
42
|
-
rescue Fontcustom::Error => e
|
43
|
-
show_error e
|
44
|
-
|
45
|
-
# Catches Ctrl + C
|
46
|
-
rescue SignalException
|
47
|
-
stop
|
48
48
|
end
|
49
49
|
|
50
50
|
def stop
|
51
51
|
@vector_listener.stop
|
52
52
|
@template_listener.stop if @template_listener
|
53
|
-
|
53
|
+
say "\nFont Custom is signing off. Good night and good luck.", :yellow
|
54
54
|
end
|
55
55
|
|
56
|
-
private
|
57
|
-
|
58
56
|
def callback
|
59
57
|
Proc.new do |modified, added, removed|
|
60
58
|
begin
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
59
|
+
say_message :changed, modified.join(", ") unless modified.empty?
|
60
|
+
say_message :added, added.join(", ") unless added.empty?
|
61
|
+
say_message :removed, removed.join(", ") unless removed.empty?
|
65
62
|
changed = modified + added + removed
|
66
63
|
compile unless changed.empty?
|
67
64
|
rescue Fontcustom::Error => e
|
68
|
-
|
65
|
+
say_message :error, e.message, :red
|
69
66
|
end
|
70
67
|
end
|
71
68
|
end
|
72
69
|
|
73
70
|
def compile
|
74
|
-
|
75
|
-
|
71
|
+
Generator::Font.start [@opts]
|
72
|
+
Generator::Template.start [@opts]
|
73
|
+
end
|
74
|
+
|
75
|
+
def say(*args)
|
76
|
+
return if @opts.quiet
|
77
|
+
@opts.instance_variable_get(:@shell).say *args
|
76
78
|
end
|
77
79
|
|
78
|
-
def
|
79
|
-
|
80
|
+
def say_message(*args)
|
81
|
+
@opts.say_message *args
|
80
82
|
end
|
81
83
|
end
|
82
84
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Fontcustom::Generator::Font do
|
4
|
-
# Silence messages without passing :
|
4
|
+
# Silence messages without passing :quiet => true to everything
|
5
5
|
before(:each) do
|
6
6
|
Fontcustom::Options.any_instance.stub :say_message
|
7
7
|
end
|
@@ -45,7 +45,7 @@ describe Fontcustom::Generator::Font do
|
|
45
45
|
options = {
|
46
46
|
:project_root => fixture,
|
47
47
|
:input => "shared/vectors",
|
48
|
-
:
|
48
|
+
:quiet => true
|
49
49
|
}
|
50
50
|
gen = generator options
|
51
51
|
gen.get_data
|
@@ -59,7 +59,7 @@ describe Fontcustom::Generator::Font do
|
|
59
59
|
:config => "generators",
|
60
60
|
:input => "shared/vectors",
|
61
61
|
:output => "mixed-output",
|
62
|
-
:
|
62
|
+
:quiet => true
|
63
63
|
}
|
64
64
|
gen = generator options
|
65
65
|
gen.get_data
|
@@ -74,7 +74,7 @@ describe Fontcustom::Generator::Font do
|
|
74
74
|
:data_cache => "generators/.fontcustom-data-corrupted",
|
75
75
|
:input => "shared/vectors",
|
76
76
|
:output => "mixed-output",
|
77
|
-
:
|
77
|
+
:quiet => true
|
78
78
|
}
|
79
79
|
gen = generator options
|
80
80
|
expect { gen.get_data }.to raise_error Fontcustom::Error, /corrupted/
|
@@ -87,7 +87,7 @@ describe Fontcustom::Generator::Font do
|
|
87
87
|
:project_root => fixture,
|
88
88
|
:input => "shared/vectors",
|
89
89
|
:output => "mixed-output",
|
90
|
-
:
|
90
|
+
:quiet => true
|
91
91
|
}
|
92
92
|
gen = generator options
|
93
93
|
gen.stub :remove_file
|
@@ -131,19 +131,19 @@ describe Fontcustom::Generator::Font do
|
|
131
131
|
:project_root => fixture,
|
132
132
|
:input => "shared/vectors",
|
133
133
|
:output => "mixed-output",
|
134
|
-
:
|
134
|
+
:quiet => true
|
135
135
|
)
|
136
|
-
gen.stub(:
|
136
|
+
gen.stub(:execute_and_clean).and_return [fontforge_stdout.split("\n"), fontforge_stderr, double(:status, :success? => true)]
|
137
137
|
gen
|
138
138
|
end
|
139
139
|
|
140
140
|
it "should call fontforge" do
|
141
|
-
subject.should_receive(:
|
141
|
+
subject.should_receive(:execute_and_clean).with(/fontforge -script/)
|
142
142
|
subject.generate
|
143
143
|
end
|
144
144
|
|
145
145
|
it "should pass options to fontforge" do
|
146
|
-
subject.should_receive(:
|
146
|
+
subject.should_receive(:execute_and_clean).with(/#{fixture("shared/vectors")}.+#{fixture("mixed-output")}/)
|
147
147
|
subject.generate
|
148
148
|
end
|
149
149
|
|
@@ -160,7 +160,7 @@ describe Fontcustom::Generator::Font do
|
|
160
160
|
:output => "fake-dir-should-cause-failure",
|
161
161
|
:debug => true
|
162
162
|
)
|
163
|
-
expect { capture(:stdout) { gen.generate } }.to raise_error Fontcustom::Error, /failed
|
163
|
+
expect { capture(:stdout) { gen.generate } }.to raise_error Fontcustom::Error, /failed/
|
164
164
|
end
|
165
165
|
end
|
166
166
|
|
@@ -197,12 +197,12 @@ describe Fontcustom::Generator::Font do
|
|
197
197
|
stdout.should =~ /create.+\.(woff|ttf|eot|svg)/
|
198
198
|
end
|
199
199
|
|
200
|
-
it "should print nothing if
|
200
|
+
it "should print nothing if :quiet is set" do
|
201
201
|
gen = generator(
|
202
202
|
:project_root => fixture,
|
203
203
|
:input => "shared/vectors",
|
204
204
|
:output => "output",
|
205
|
-
:
|
205
|
+
:quiet => true
|
206
206
|
)
|
207
207
|
gen.instance_variable_set :@data, data_file_contents
|
208
208
|
stdout = capture(:stdout) { gen.announce_files }
|
@@ -228,12 +228,12 @@ describe Fontcustom::Generator::Font do
|
|
228
228
|
gen.save_data
|
229
229
|
end
|
230
230
|
|
231
|
-
it "should be silent if
|
231
|
+
it "should be silent if :quiet is set" do
|
232
232
|
gen = generator(
|
233
233
|
:project_root => fixture,
|
234
234
|
:input => "shared/vectors",
|
235
235
|
:output => "output",
|
236
|
-
:
|
236
|
+
:quiet => true
|
237
237
|
)
|
238
238
|
gen.stub :overwrite_file
|
239
239
|
gen.instance_variable_set(:@data, data_file_contents)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Fontcustom::Generator::Template do
|
4
|
-
# Silence messages without passing :
|
4
|
+
# Silence messages without passing :quiet => true to everything
|
5
5
|
before(:each) do
|
6
6
|
Fontcustom::Options.any_instance.stub :say_message
|
7
7
|
end
|
@@ -16,17 +16,16 @@ describe Fontcustom::Generator::Template do
|
|
16
16
|
gen = generator(
|
17
17
|
:project_root => fixture,
|
18
18
|
:input => "shared/vectors",
|
19
|
-
:
|
19
|
+
:quiet => true
|
20
20
|
)
|
21
|
-
expect { gen.get_data }.to raise_error Fontcustom::Error, /\.fontcustom-data
|
21
|
+
expect { gen.get_data }.to raise_error Fontcustom::Error, /\.fontcustom-data/
|
22
22
|
end
|
23
23
|
|
24
|
-
# TODO ensure data file is correct
|
25
24
|
it "should assign @data from data file" do
|
26
25
|
gen = generator(
|
27
26
|
:project_root => fixture("generators"),
|
28
27
|
:input => "../shared/vectors",
|
29
|
-
:
|
28
|
+
:quiet => true
|
30
29
|
)
|
31
30
|
gen.get_data
|
32
31
|
gen.instance_variable_get(:@data)[:templates].should =~ data_file_contents[:templates]
|
@@ -39,7 +38,7 @@ describe Fontcustom::Generator::Template do
|
|
39
38
|
:project_root => fixture("generators"),
|
40
39
|
:input => "../shared/vectors",
|
41
40
|
:output => "mixed-output",
|
42
|
-
:
|
41
|
+
:quiet => true
|
43
42
|
)
|
44
43
|
gen.stub :remove_file
|
45
44
|
gen.stub :overwrite_file
|
@@ -77,21 +76,20 @@ describe Fontcustom::Generator::Template do
|
|
77
76
|
end
|
78
77
|
|
79
78
|
context "#make_relative_paths" do
|
80
|
-
it "should assign
|
79
|
+
it "should assign @font_path, @font_path_alt, and @font_path_preview" do
|
81
80
|
gen = generator(
|
82
81
|
:project_root => fixture,
|
83
82
|
:input => "shared/vectors",
|
84
83
|
:output => {:fonts => "foo/fonts", :css => "output/css", :preview => "views/"}
|
85
84
|
)
|
86
|
-
gen.instance_variable_set
|
85
|
+
gen.instance_variable_set :@data, data_file_contents
|
87
86
|
gen.make_relative_paths
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
data[:paths][:preprocessor_to_fonts].should eq(data[:paths][:css_to_fonts])
|
87
|
+
gen.instance_variable_get(:@font_path).should match("../../foo/fonts")
|
88
|
+
gen.instance_variable_get(:@font_path_alt).should match("../../foo/fonts")
|
89
|
+
gen.instance_variable_get(:@font_path_preview).should match("../foo/fonts")
|
92
90
|
end
|
93
91
|
|
94
|
-
it "should assign
|
92
|
+
it "should assign @font_path_alt if :preprocessor_font_path is set" do
|
95
93
|
gen = generator(
|
96
94
|
:project_root => fixture,
|
97
95
|
:preprocessor_font_path => "fonts/fontcustom",
|
@@ -100,8 +98,7 @@ describe Fontcustom::Generator::Template do
|
|
100
98
|
)
|
101
99
|
gen.instance_variable_set "@data", data_file_contents
|
102
100
|
gen.make_relative_paths
|
103
|
-
|
104
|
-
data[:paths][:preprocessor_to_fonts].should match("fonts/fontcustom")
|
101
|
+
gen.instance_variable_get(:@font_path_alt).should match("fonts/fontcustom")
|
105
102
|
end
|
106
103
|
|
107
104
|
it "should assign '.' when paths are the same" do
|
@@ -112,8 +109,7 @@ describe Fontcustom::Generator::Template do
|
|
112
109
|
)
|
113
110
|
gen.instance_variable_set "@data", data_file_contents
|
114
111
|
gen.make_relative_paths
|
115
|
-
|
116
|
-
data[:paths][:css_to_fonts].should match("./")
|
112
|
+
gen.instance_variable_get(:@font_path).should match("./")
|
117
113
|
end
|
118
114
|
end
|
119
115
|
|
@@ -124,7 +120,7 @@ describe Fontcustom::Generator::Template do
|
|
124
120
|
:input => {:vectors => "../shared/vectors", :templates => "../shared/templates"},
|
125
121
|
:output => "mixed-output",
|
126
122
|
:templates => %W|scss css custom.css|,
|
127
|
-
:
|
123
|
+
:quiet => true
|
128
124
|
)
|
129
125
|
gen.instance_variable_set :@data, data_file_contents
|
130
126
|
gen.stub :template
|
@@ -150,11 +146,28 @@ describe Fontcustom::Generator::Template do
|
|
150
146
|
subject.generate
|
151
147
|
end
|
152
148
|
|
153
|
-
it "should be silent if
|
149
|
+
it "should be silent if :quiet is set" do
|
154
150
|
stdout = capture(:stdout) { subject.generate }
|
155
151
|
stdout.should == ""
|
156
152
|
end
|
157
153
|
|
154
|
+
it "should rename stock templates according to opts.font_name" do
|
155
|
+
gen = generator(
|
156
|
+
:project_root => fixture("generators"),
|
157
|
+
:font_name => "Test Font",
|
158
|
+
:input => {:vectors => "../shared/vectors", :templates => "../shared/templates"},
|
159
|
+
:templates => %W|scss css|,
|
160
|
+
:quiet => true
|
161
|
+
)
|
162
|
+
gen.instance_variable_set :@data, data_file_contents
|
163
|
+
gen.stub :template
|
164
|
+
gen.stub :overwrite_file
|
165
|
+
gen.should_receive(:template).exactly(2).times do |*args|
|
166
|
+
args[1].should match(/(Test-Font\.css|_Test-Font\.scss)/)
|
167
|
+
end
|
168
|
+
gen.generate
|
169
|
+
end
|
170
|
+
|
158
171
|
context "when various output locations are given" do
|
159
172
|
subject do
|
160
173
|
gen = generator(
|
@@ -162,7 +175,7 @@ describe Fontcustom::Generator::Template do
|
|
162
175
|
:input => {:vectors => "shared/vectors", :templates => "shared/templates"},
|
163
176
|
:output => {:fonts => "output/fonts", :css => "output/css", :preview => "output/views", "custom.css" => "output/custom"},
|
164
177
|
:templates => %W|scss preview css custom.css regular.css|,
|
165
|
-
:
|
178
|
+
:quiet => true
|
166
179
|
)
|
167
180
|
gen.instance_variable_set :@data, data_file_contents
|
168
181
|
gen.stub :template
|
@@ -173,7 +186,7 @@ describe Fontcustom::Generator::Template do
|
|
173
186
|
# 6 times because preview also includes preview-css
|
174
187
|
it "should output custom templates to their matching :output paths" do
|
175
188
|
subject.should_receive(:template).exactly(5).times do |*args|
|
176
|
-
if File.basename(args[0]) == "custom.css"
|
189
|
+
if File.basename(args[0]) == :"custom.css"
|
177
190
|
args[1].should == fixture("output/custom/custom.css")
|
178
191
|
end
|
179
192
|
end
|