fontcustom 1.3.0.beta3 → 1.3.0.beta4
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/TODO.md +8 -8
- data/lib/fontcustom.rb +3 -7
- data/lib/fontcustom/base.rb +13 -17
- data/lib/fontcustom/cli.rb +0 -8
- data/lib/fontcustom/generator/font.rb +17 -15
- data/lib/fontcustom/generator/template.rb +50 -32
- data/lib/fontcustom/manifest.rb +52 -19
- data/lib/fontcustom/options.rb +31 -77
- data/lib/fontcustom/utility.rb +22 -58
- data/lib/fontcustom/version.rb +1 -1
- data/spec/fontcustom/base_spec.rb +12 -24
- data/spec/fontcustom/cli_spec.rb +1 -1
- data/spec/fontcustom/generator/font_spec.rb +17 -19
- data/spec/fontcustom/generator/template_spec.rb +5 -3
- data/spec/fontcustom/manifest_spec.rb +7 -6
- data/spec/fontcustom/options_spec.rb +108 -189
- data/spec/fontcustom/utility_spec.rb +3 -84
- data/spec/spec_helper.rb +10 -13
- metadata +2 -2
@@ -5,15 +5,17 @@ describe Fontcustom::Generator::Template do
|
|
5
5
|
it "should generate templates (integration)", :integration => true do
|
6
6
|
live_test do |testdir|
|
7
7
|
FileUtils.cp_r fixture("generators/mixed-output"), "fontcustom"
|
8
|
-
|
8
|
+
test_manifest(
|
9
9
|
:input => "vectors",
|
10
10
|
:quiet => true,
|
11
11
|
:templates => %w|preview css scss scss-rails|
|
12
12
|
)
|
13
|
+
manifest = File.join testdir, ".fontcustom-manifest.json"
|
13
14
|
Fontcustom::Generator::Font.new(manifest).generate
|
14
|
-
|
15
|
+
Fontcustom::Generator::Template.new(manifest).generate
|
15
16
|
|
16
|
-
|
17
|
+
content = File.read manifest
|
18
|
+
content.should match(/fontcustom\/fontcustom-preview.html/)
|
17
19
|
end
|
18
20
|
end
|
19
21
|
end
|
@@ -2,14 +2,15 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Fontcustom::Manifest do
|
4
4
|
context "#initialize" do
|
5
|
-
it "should create a manifest file and
|
5
|
+
it "should create a manifest file and assign :options", :integration => true do
|
6
6
|
live_test do |testdir|
|
7
|
-
capture(:stdout) do
|
8
|
-
|
9
|
-
Fontcustom::
|
7
|
+
capture(:stdout) do
|
8
|
+
manifest = File.join testdir, ".fontcustom-manifest.json"
|
9
|
+
options = Fontcustom::Options.new(:manifest => manifest, :input => "vectors").options
|
10
|
+
Fontcustom::Manifest.new manifest, options
|
10
11
|
end
|
11
|
-
|
12
|
-
|
12
|
+
content = File.read File.join(testdir, ".fontcustom-manifest.json")
|
13
|
+
content.should match(/"options":.+"input":/m)
|
13
14
|
end
|
14
15
|
end
|
15
16
|
end
|
@@ -3,6 +3,7 @@ require "spec_helper"
|
|
3
3
|
|
4
4
|
describe Fontcustom::Options do
|
5
5
|
def options(args = {})
|
6
|
+
args[:manifest] = fixture(".fontcustom-manifest.json") if args[:manifest].nil?
|
6
7
|
Fontcustom::Options.new(args)
|
7
8
|
end
|
8
9
|
|
@@ -13,11 +14,11 @@ describe Fontcustom::Options do
|
|
13
14
|
|
14
15
|
context ".overwrite_examples" do
|
15
16
|
it "should overwite example defaults with real defaults" do
|
16
|
-
o = options
|
17
|
+
o = options Fontcustom::EXAMPLE_OPTIONS.dup
|
17
18
|
o.send :overwrite_examples
|
18
19
|
cli = o.instance_variable_get(:@cli_options)
|
19
20
|
Fontcustom::EXAMPLE_OPTIONS.keys.each do |key|
|
20
|
-
cli[key].should == Fontcustom::DEFAULT_OPTIONS[key]
|
21
|
+
cli[key].should == Fontcustom::DEFAULT_OPTIONS[key]
|
21
22
|
end
|
22
23
|
end
|
23
24
|
end
|
@@ -25,49 +26,52 @@ describe Fontcustom::Options do
|
|
25
26
|
context ".set_config_path" do
|
26
27
|
context "when :config is set" do
|
27
28
|
it "should use options[:config] if it's a file" do
|
28
|
-
|
29
|
-
:
|
30
|
-
:
|
31
|
-
|
32
|
-
|
33
|
-
o.instance_variable_get(:@cli_options)[:config].should == fixture("options/any-file-name.yml")
|
29
|
+
FileUtils.cd fixture do
|
30
|
+
o = options :config => "options/any-file-name.yml"
|
31
|
+
o.send :set_config_path
|
32
|
+
o.instance_variable_get(:@cli_options)[:config].should == "options/any-file-name.yml"
|
33
|
+
end
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should search for fontcustom.yml if options[:config] is a dir" do
|
37
|
-
|
38
|
-
:
|
39
|
-
:
|
40
|
-
|
41
|
-
|
42
|
-
o.instance_variable_get(:@cli_options)[:config].should == fixture("options/config-is-in-dir/fontcustom.yml")
|
37
|
+
FileUtils.cd fixture do
|
38
|
+
o = options :config => "options/config-is-in-dir"
|
39
|
+
o.send :set_config_path
|
40
|
+
o.instance_variable_get(:@cli_options)[:config].should == "options/config-is-in-dir/fontcustom.yml"
|
41
|
+
end
|
43
42
|
end
|
44
43
|
|
45
44
|
it "should raise error if :config doesn't exist" do
|
46
|
-
|
47
|
-
:
|
48
|
-
:
|
49
|
-
|
50
|
-
expect { o.send :set_config_path }.to raise_error Fontcustom::Error, /configuration file/
|
45
|
+
FileUtils.cd fixture do
|
46
|
+
o = options :config => "does-not-exist"
|
47
|
+
expect { o.send :set_config_path }.to raise_error Fontcustom::Error, /configuration file/
|
48
|
+
end
|
51
49
|
end
|
52
50
|
end
|
53
51
|
|
54
52
|
context "when :config is not set" do
|
55
|
-
it "should find fontcustom.yml
|
56
|
-
|
57
|
-
|
58
|
-
|
53
|
+
it "should find fontcustom.yml in the same dir as the manifest" do
|
54
|
+
FileUtils.cd fixture("options") do
|
55
|
+
o = options
|
56
|
+
o.send :set_config_path
|
57
|
+
o.instance_variable_get(:@cli_options)[:config].should == "fontcustom.yml"
|
58
|
+
end
|
59
59
|
end
|
60
60
|
|
61
|
-
it "should find fontcustom.yml at
|
62
|
-
|
63
|
-
|
64
|
-
|
61
|
+
it "should find fontcustom.yml at config/fontcustom.yml" do
|
62
|
+
FileUtils.cd fixture("options/rails-like") do
|
63
|
+
o = options
|
64
|
+
o.send :set_config_path
|
65
|
+
o.instance_variable_get(:@cli_options)[:config].should == "config/fontcustom.yml"
|
66
|
+
end
|
65
67
|
end
|
66
68
|
|
67
69
|
it "should be false if nothing is found" do
|
68
|
-
|
69
|
-
|
70
|
-
|
70
|
+
FileUtils.cd fixture do
|
71
|
+
o = options :manifest => "options/no-config-here/.fontcustom-manifest.json"
|
72
|
+
o.send :set_config_path
|
73
|
+
o.instance_variable_get(:@cli_options)[:config].should == false
|
74
|
+
end
|
71
75
|
end
|
72
76
|
end
|
73
77
|
end
|
@@ -75,29 +79,20 @@ describe Fontcustom::Options do
|
|
75
79
|
context ".load_config" do
|
76
80
|
it "should warn if fontcustom.yml is blank" do
|
77
81
|
o = options
|
78
|
-
o.instance_variable_set :@cli_options, {
|
79
|
-
:project_root => fixture,
|
80
|
-
:config => fixture("options/fontcustom-empty.yml")
|
81
|
-
}
|
82
|
+
o.instance_variable_set :@cli_options, {:config => fixture("options/fontcustom-empty.yml")}
|
82
83
|
o.should_receive(:say_message).with :warn, /was empty/
|
83
84
|
o.send :load_config
|
84
85
|
end
|
85
86
|
|
86
87
|
it "should raise error if fontcustom.yml isn't valid" do
|
87
88
|
o = options
|
88
|
-
o.instance_variable_set :@cli_options, {
|
89
|
-
:project_root => fixture,
|
90
|
-
:config => fixture("options/fontcustom-malformed.yml")
|
91
|
-
}
|
89
|
+
o.instance_variable_set :@cli_options, {:config => fixture("options/fontcustom-malformed.yml")}
|
92
90
|
expect { o.send :load_config }.to raise_error Fontcustom::Error, /Error parsing/
|
93
91
|
end
|
94
92
|
|
95
93
|
it "should assign empty hash :config is false" do
|
96
94
|
o = options
|
97
|
-
o.instance_variable_set :@cli_options, {
|
98
|
-
:project_root => fixture,
|
99
|
-
:config => false
|
100
|
-
}
|
95
|
+
o.instance_variable_set :@cli_options, {:config => false}
|
101
96
|
o.send :load_config
|
102
97
|
o.instance_variable_get(:@config_options).should == {}
|
103
98
|
end
|
@@ -106,7 +101,6 @@ describe Fontcustom::Options do
|
|
106
101
|
it "should report which configuration file it's using" do
|
107
102
|
o = options
|
108
103
|
o.instance_variable_set :@cli_options, {
|
109
|
-
:project_root => fixture,
|
110
104
|
:config => fixture("options/any-file-name.yml"),
|
111
105
|
:debug => true
|
112
106
|
}
|
@@ -143,125 +137,93 @@ describe Fontcustom::Options do
|
|
143
137
|
end
|
144
138
|
end
|
145
139
|
|
146
|
-
context ".set_manifest_path" do
|
147
|
-
it "should set :manifest in the config dir by default" do
|
148
|
-
o = options
|
149
|
-
o.options = { :config => "path/to/config/fontcustom.yml" }
|
150
|
-
o.send :set_manifest_path
|
151
|
-
o.options[:manifest].should == "path/to/config/.fontcustom-manifest.json"
|
152
|
-
end
|
153
|
-
|
154
|
-
it "should set :manifest in :project_root if :config doesn't exist" do
|
155
|
-
o = options
|
156
|
-
o.options = { :project_root => "project/root" }
|
157
|
-
o.send :set_manifest_path
|
158
|
-
o.options[:manifest].should == "project/root/.fontcustom-manifest.json"
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
140
|
context ".set_input_paths" do
|
163
141
|
it "should raise error if input[:vectors] doesn't contain SVGs" do
|
164
|
-
|
165
|
-
|
166
|
-
:
|
167
|
-
:
|
168
|
-
|
169
|
-
expect { o.send :set_input_paths }.to raise_error Fontcustom::Error, /doesn't contain any SVGs/
|
142
|
+
FileUtils.cd fixture("shared") do
|
143
|
+
o = options
|
144
|
+
o.options = { :input => "vectors-empty" }
|
145
|
+
expect { o.send :set_input_paths }.to raise_error Fontcustom::Error, /doesn't contain any SVGs/
|
146
|
+
end
|
170
147
|
end
|
171
148
|
|
172
149
|
context "when :input is a hash" do
|
173
150
|
it "should set :templates as :vectors if :templates isn't set" do
|
174
|
-
|
175
|
-
|
176
|
-
:
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
o.options[:input][:templates].should == fixture("shared/vectors")
|
151
|
+
FileUtils.cd fixture("shared") do
|
152
|
+
o = options
|
153
|
+
o.options = { :input => { :vectors => "vectors" } }
|
154
|
+
o.send :set_input_paths
|
155
|
+
o.options[:input][:templates].should == "vectors"
|
156
|
+
end
|
181
157
|
end
|
182
158
|
|
183
159
|
it "should preserve :templates if it's set" do
|
184
|
-
|
185
|
-
|
186
|
-
:
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
o.options[:input][:templates].should == fixture("shared/templates")
|
160
|
+
FileUtils.cd fixture("shared") do
|
161
|
+
o = options
|
162
|
+
o.options = { :input => { :vectors => "vectors", :templates => "templates" } }
|
163
|
+
o.send :set_input_paths
|
164
|
+
o.options[:input][:templates].should == "templates"
|
165
|
+
end
|
191
166
|
end
|
192
167
|
|
193
168
|
it "should raise an error if :vectors isn't set" do
|
194
|
-
|
195
|
-
|
196
|
-
:
|
197
|
-
:
|
198
|
-
|
199
|
-
}
|
200
|
-
expect { o.send :set_input_paths }.to raise_error Fontcustom::Error, /have a :vectors key/
|
169
|
+
FileUtils.cd fixture("shared") do
|
170
|
+
o = options
|
171
|
+
o.options = { :input => { :templates => "templates" } }
|
172
|
+
expect { o.send :set_input_paths }.to raise_error Fontcustom::Error, /have a :vectors key/
|
173
|
+
end
|
201
174
|
end
|
202
175
|
|
203
176
|
it "should raise an error if :vectors doesn't point to an existing directory" do
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
177
|
+
FileUtils.cd fixture("shared") do
|
178
|
+
o = options
|
179
|
+
o.options = {
|
180
|
+
:config => "fontcustom.yml",
|
181
|
+
:input => { :vectors => "not-a-dir" }
|
182
|
+
}
|
183
|
+
expect { o.send :set_input_paths }.to raise_error Fontcustom::Error, /isn't a directory/
|
184
|
+
end
|
211
185
|
end
|
212
186
|
end
|
213
187
|
|
214
188
|
context "when :input is a string" do
|
215
189
|
it "should return a hash of locations" do
|
216
|
-
|
217
|
-
|
218
|
-
:
|
219
|
-
:
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
o.options[:input].should have_key(:templates)
|
190
|
+
FileUtils.cd fixture("shared") do
|
191
|
+
o = options
|
192
|
+
o.options = { :input => "vectors" }
|
193
|
+
o.send :set_input_paths
|
194
|
+
o.options[:input].should have_key(:vectors)
|
195
|
+
o.options[:input].should have_key(:templates)
|
196
|
+
end
|
224
197
|
end
|
225
198
|
|
226
199
|
it "should set :templates to match :vectors" do
|
227
|
-
|
228
|
-
|
229
|
-
:
|
230
|
-
:
|
231
|
-
|
232
|
-
|
233
|
-
o.options[:input][:templates].should == fixture("shared/vectors")
|
200
|
+
FileUtils.cd fixture("shared") do
|
201
|
+
o = options
|
202
|
+
o.options = { :input => "vectors" }
|
203
|
+
o.send :set_input_paths
|
204
|
+
o.options[:input][:templates].should == "vectors"
|
205
|
+
end
|
234
206
|
end
|
235
207
|
|
236
208
|
it "should raise an error if :vectors doesn't point to a directory" do
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
209
|
+
FileUtils.cd fixture("shared") do
|
210
|
+
o = options
|
211
|
+
o.options = {
|
212
|
+
:config => "fontcustom.yml",
|
213
|
+
:input => "not-a-dir"
|
214
|
+
}
|
215
|
+
expect { o.send :set_input_paths }.to raise_error Fontcustom::Error, /isn't a directory/
|
216
|
+
end
|
244
217
|
end
|
245
218
|
end
|
246
219
|
end
|
247
220
|
|
248
221
|
context ".set_output_paths" do
|
249
222
|
context "when :output is nil" do
|
250
|
-
it "should default to :project_root/:font_name" do
|
251
|
-
o = options
|
252
|
-
o.options = {
|
253
|
-
:project_root => fixture,
|
254
|
-
:font_name => "Test-Font"
|
255
|
-
}
|
256
|
-
o.send :set_output_paths
|
257
|
-
o.options[:output][:fonts].should == fixture("Test-Font")
|
258
|
-
end
|
259
|
-
|
260
223
|
context "when :debug is true" do
|
261
224
|
it "should print a warning" do
|
262
225
|
o = options
|
263
226
|
o.options = {
|
264
|
-
:project_root => fixture,
|
265
227
|
:debug => true,
|
266
228
|
:font_name => "Test-Font"
|
267
229
|
}
|
@@ -274,19 +236,15 @@ describe Fontcustom::Options do
|
|
274
236
|
context "when :output is a hash" do
|
275
237
|
it "should set :css and :preview to match :fonts if either aren't set" do
|
276
238
|
o = options
|
277
|
-
o.options = {
|
278
|
-
:project_root => fixture,
|
279
|
-
:output => { :fonts => "output/fonts" }
|
280
|
-
}
|
239
|
+
o.options = { :output => { :fonts => "output/fonts" } }
|
281
240
|
o.send :set_output_paths
|
282
|
-
o.options[:output][:css].should ==
|
283
|
-
o.options[:output][:preview].should ==
|
241
|
+
o.options[:output][:css].should == "output/fonts"
|
242
|
+
o.options[:output][:preview].should == "output/fonts"
|
284
243
|
end
|
285
244
|
|
286
245
|
it "should preserve :css and :preview if they do exist" do
|
287
246
|
o = options
|
288
247
|
o.options = {
|
289
|
-
:project_root => fixture,
|
290
248
|
:output => {
|
291
249
|
:fonts => "output/fonts",
|
292
250
|
:css => "output/styles",
|
@@ -294,27 +252,25 @@ describe Fontcustom::Options do
|
|
294
252
|
}
|
295
253
|
}
|
296
254
|
o.send :set_output_paths
|
297
|
-
o.options[:output][:css].should ==
|
298
|
-
o.options[:output][:preview].should ==
|
255
|
+
o.options[:output][:css].should == "output/styles"
|
256
|
+
o.options[:output][:preview].should == "output/preview"
|
299
257
|
end
|
300
258
|
|
301
259
|
it "should create additional paths if they are given" do
|
302
260
|
o = options
|
303
261
|
o.options = {
|
304
|
-
:project_root => fixture,
|
305
262
|
:output => {
|
306
263
|
:fonts => "output/fonts",
|
307
264
|
"special.js" => "assets/javascripts"
|
308
265
|
}
|
309
266
|
}
|
310
267
|
o.send :set_output_paths
|
311
|
-
o.options[:output][:"special.js"].should ==
|
268
|
+
o.options[:output][:"special.js"].should == "assets/javascripts"
|
312
269
|
end
|
313
270
|
|
314
271
|
it "should raise an error if :fonts isn't set" do
|
315
272
|
o = options
|
316
273
|
o.options = {
|
317
|
-
:project_root => fixture,
|
318
274
|
:config => "fontcustom.yml",
|
319
275
|
:output => { :css => "output/styles" }
|
320
276
|
}
|
@@ -325,10 +281,7 @@ describe Fontcustom::Options do
|
|
325
281
|
context "when :output is a string" do
|
326
282
|
it "should return a hash of output locations" do
|
327
283
|
o = options
|
328
|
-
o.options = {
|
329
|
-
:project_root => fixture,
|
330
|
-
:output => "output/fonts"
|
331
|
-
}
|
284
|
+
o.options = { :output => "output/fonts" }
|
332
285
|
o.send :set_output_paths
|
333
286
|
o.options[:output].should be_a(Hash)
|
334
287
|
o.options[:output].should have_key(:fonts)
|
@@ -338,67 +291,33 @@ describe Fontcustom::Options do
|
|
338
291
|
|
339
292
|
it "should set :css and :preview to match :fonts" do
|
340
293
|
o = options
|
341
|
-
o.options = {
|
342
|
-
:project_root => fixture,
|
343
|
-
:output => "output/fonts"
|
344
|
-
}
|
294
|
+
o.options = { :output => "output/fonts" }
|
345
295
|
o.send :set_output_paths
|
346
|
-
o.options[:output][:css].should ==
|
347
|
-
o.options[:output][:preview].should ==
|
296
|
+
o.options[:output][:css].should == "output/fonts"
|
297
|
+
o.options[:output][:preview].should == "output/fonts"
|
348
298
|
end
|
349
299
|
|
350
300
|
it "should raise an error if :fonts exists but isn't a directory" do
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
301
|
+
FileUtils.cd fixture("shared") do
|
302
|
+
o = options
|
303
|
+
o.options = {
|
304
|
+
:config => "fontcustom.yml",
|
305
|
+
:output => "not-a-dir"
|
306
|
+
}
|
307
|
+
expect { o.send :set_output_paths }.to raise_error Fontcustom::Error, /isn't a directory/
|
308
|
+
end
|
358
309
|
end
|
359
310
|
end
|
360
311
|
end
|
361
312
|
|
362
|
-
context ".
|
363
|
-
it "should expand shorthand for packaged templates" do
|
364
|
-
o = options
|
365
|
-
o.options = {
|
366
|
-
:project_root => fixture,
|
367
|
-
:input => { :templates => "shared/templates" },
|
368
|
-
:templates => %w|preview css scss scss-rails bootstrap bootstrap-scss bootstrap-ie7 bootstrap-ie7-scss|
|
369
|
-
}
|
370
|
-
o.send :set_template_paths
|
371
|
-
o.options[:templates].should =~ [
|
372
|
-
File.join(Fontcustom.gem_lib, "templates", "fontcustom-preview.html"),
|
373
|
-
File.join(Fontcustom.gem_lib, "templates", "fontcustom.css"),
|
374
|
-
File.join(Fontcustom.gem_lib, "templates", "_fontcustom.scss"),
|
375
|
-
File.join(Fontcustom.gem_lib, "templates", "_fontcustom-rails.scss"),
|
376
|
-
File.join(Fontcustom.gem_lib, "templates", "fontcustom-bootstrap.css"),
|
377
|
-
File.join(Fontcustom.gem_lib, "templates", "_fontcustom-bootstrap.scss"),
|
378
|
-
File.join(Fontcustom.gem_lib, "templates", "fontcustom-bootstrap-ie7.css"),
|
379
|
-
File.join(Fontcustom.gem_lib, "templates", "_fontcustom-bootstrap-ie7.scss")
|
380
|
-
]
|
381
|
-
end
|
382
|
-
|
383
|
-
it "should find custom templates in :template_path" do
|
384
|
-
o = options
|
385
|
-
o.options = {
|
386
|
-
:project_root => fixture,
|
387
|
-
:input => { :templates => fixture("shared/templates") },
|
388
|
-
:templates => %w|custom.css|
|
389
|
-
}
|
390
|
-
o.send :set_template_paths
|
391
|
-
o.options[:templates].should =~ [fixture("shared/templates/custom.css")]
|
392
|
-
end
|
393
|
-
|
313
|
+
context ".check_template_paths" do
|
394
314
|
it "should raise an error if a template does not exist" do
|
395
315
|
o = options
|
396
316
|
o.options = {
|
397
|
-
:project_root => fixture,
|
398
317
|
:input => { :templates => fixture("shared/templates") },
|
399
318
|
:templates => %w|fake-template.txt|
|
400
319
|
}
|
401
|
-
expect { o.send :
|
320
|
+
expect { o.send :check_template_paths }.to raise_error Fontcustom::Error, /doesn't exist/
|
402
321
|
end
|
403
322
|
end
|
404
323
|
end
|