fontcustom 1.1.0.pre → 1.1.0.pre2
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 +20 -5
- data/lib/fontcustom.rb +42 -4
- data/lib/fontcustom/cli.rb +65 -25
- data/lib/fontcustom/generator/font.rb +26 -26
- data/lib/fontcustom/generator/template.rb +29 -30
- data/lib/fontcustom/options.rb +207 -23
- data/lib/fontcustom/templates/_fontcustom-bootstrap-ie7.scss +9 -9
- data/lib/fontcustom/templates/_fontcustom-bootstrap.scss +19 -19
- data/lib/fontcustom/templates/_fontcustom-rails.scss +28 -0
- data/lib/fontcustom/templates/_fontcustom.scss +11 -11
- data/lib/fontcustom/templates/fontcustom-bootstrap-ie7.css +9 -9
- data/lib/fontcustom/templates/fontcustom-bootstrap.css +19 -19
- data/lib/fontcustom/templates/fontcustom-preview.html +34 -7
- data/lib/fontcustom/templates/fontcustom.css +11 -11
- data/lib/fontcustom/templates/fontcustom.yml +11 -6
- data/lib/fontcustom/util.rb +38 -159
- data/lib/fontcustom/version.rb +1 -1
- data/lib/fontcustom/watcher.rb +16 -14
- data/spec/fixtures/generators/.fontcustom-data-corrupted +18 -0
- data/spec/fixtures/generators/fontcustom.yml +1 -0
- data/spec/fixtures/{util/fontcustom.yml → options/any-file-name.yml} +0 -0
- data/spec/fixtures/{util → options}/config-is-in-dir/fontcustom.yml +0 -0
- data/spec/fixtures/options/fontcustom-empty.yml +1 -0
- data/spec/fixtures/{util → options}/fontcustom-malformed.yml +0 -0
- data/spec/fixtures/options/fontcustom.yml +1 -0
- data/spec/fixtures/options/no-config-here/.gitkeep +0 -0
- data/spec/fixtures/{util → options}/rails-like/config/fontcustom.yml +0 -0
- data/spec/fontcustom/generator/font_spec.rb +31 -15
- data/spec/fontcustom/generator/template_spec.rb +20 -18
- data/spec/fontcustom/options_spec.rb +428 -0
- data/spec/fontcustom/util_spec.rb +38 -336
- data/spec/fontcustom/watcher_spec.rb +7 -2
- data/spec/spec_helper.rb +1 -2
- metadata +23 -13
- data/lib/fontcustom/actions.rb +0 -28
- data/spec/fontcustom/actions_spec.rb +0 -22
data/lib/fontcustom/version.rb
CHANGED
data/lib/fontcustom/watcher.rb
CHANGED
@@ -5,36 +5,38 @@ module Fontcustom
|
|
5
5
|
class Watcher
|
6
6
|
def initialize(opts)
|
7
7
|
@opts = opts
|
8
|
-
@vector_listener = Listen.to(@opts
|
8
|
+
@vector_listener = Listen.to(@opts.input[:vectors]).relative_paths(true).filter(/\.(eps|svg)$/).change(&callback)
|
9
9
|
|
10
|
-
templates = @opts
|
10
|
+
templates = @opts.templates.dup
|
11
11
|
templates.delete_if do |template|
|
12
|
-
template.match
|
12
|
+
template.match Fontcustom.gem_lib
|
13
13
|
end
|
14
14
|
unless templates.empty?
|
15
15
|
templates = templates.map do |template|
|
16
16
|
File.basename template
|
17
17
|
end
|
18
|
-
@template_listener = Listen.to(@opts
|
18
|
+
@template_listener = Listen.to(@opts.input[:templates]).relative_paths(true).filter(/(#{templates.join("|")})/).change(&callback)
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
@
|
21
|
+
# Modified to allow testing
|
22
|
+
@is_test = @opts.instance_variable_get :@is_test
|
23
|
+
if @is_test
|
24
|
+
@vector_listener = @vector_listener.polling_fallback_message(false)
|
25
|
+
@template_listener = @template_listener.polling_fallback_message(false) if @template_listener
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
28
29
|
def watch
|
29
|
-
puts "Font Custom is watching your icons at #{@opts
|
30
|
-
compile unless @opts
|
30
|
+
puts "Font Custom is watching your icons at #{@opts.input[:vectors]}. Press Ctrl + C to stop."
|
31
|
+
compile unless @opts.skip_first
|
31
32
|
|
32
|
-
if
|
33
|
-
|
34
|
-
@template_listener.start! if @template_listener
|
35
|
-
else
|
33
|
+
# Non-blocking if test
|
34
|
+
if @is_test
|
36
35
|
@vector_listener.start
|
37
36
|
@template_listener.start if @template_listener
|
37
|
+
else
|
38
|
+
@vector_listener.start!
|
39
|
+
@template_listener.start! if @template_listener
|
38
40
|
end
|
39
41
|
|
40
42
|
rescue Fontcustom::Error => e
|
@@ -0,0 +1,18 @@
|
|
1
|
+
'Totally invalid JSON.'
|
2
|
+
{
|
3
|
+
'fonts": [
|
4
|
+
"fontcustom_cc5ce52f2ae4f9ce2e7ee8131bbfee1e.woff",
|
5
|
+
"fontcustom_cc5ce52f2ae4f9ce2e7ee8131bbfee1e.ttf",
|
6
|
+
"fontcustom_cc5ce52f2ae4f9ce2e7ee8131bbfee1e.eot",
|
7
|
+
"fontcustom_cc5ce52f2ae4f9ce2e7ee8131bbfee1e.svg"
|
8
|
+
],
|
9
|
+
"templates": [
|
10
|
+
"fontcustom.css"
|
11
|
+
],
|
12
|
+
"file_name": "fontcustom_cc5ce52f2ae4f9ce2e7ee8131bbfee1e",
|
13
|
+
"glyphs": [
|
14
|
+
"a_r3ally-exotic-f1le-name",
|
15
|
+
"c",
|
16
|
+
"d"
|
17
|
+
]
|
18
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
# noop
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
# nothing
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
font_name: Custom Name From Config
|
File without changes
|
File without changes
|
@@ -1,8 +1,13 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Fontcustom::Generator::Font do
|
4
|
+
# Silence messages without passing :verbose => false to everything
|
5
|
+
before(:each) do
|
6
|
+
Fontcustom::Options.any_instance.stub :say_message
|
7
|
+
end
|
8
|
+
|
4
9
|
def generator(options)
|
5
|
-
opts = Fontcustom::
|
10
|
+
opts = Fontcustom::Options.new(options)
|
6
11
|
Fontcustom::Generator::Font.new([opts])
|
7
12
|
end
|
8
13
|
|
@@ -39,7 +44,8 @@ describe Fontcustom::Generator::Font do
|
|
39
44
|
it "should assign empty data model if data file is empty or missing" do
|
40
45
|
options = {
|
41
46
|
:project_root => fixture,
|
42
|
-
:input => "shared/vectors"
|
47
|
+
:input => "shared/vectors",
|
48
|
+
:verbose => false
|
43
49
|
}
|
44
50
|
gen = generator options
|
45
51
|
gen.get_data
|
@@ -50,13 +56,28 @@ describe Fontcustom::Generator::Font do
|
|
50
56
|
it "should assign @data from data file" do
|
51
57
|
options = {
|
52
58
|
:project_root => fixture,
|
59
|
+
:config => "generators",
|
53
60
|
:input => "shared/vectors",
|
54
|
-
:output => "mixed-output"
|
61
|
+
:output => "mixed-output",
|
62
|
+
:verbose => false
|
55
63
|
}
|
56
64
|
gen = generator options
|
57
65
|
gen.get_data
|
58
66
|
data = gen.instance_variable_get("@data")
|
59
|
-
data
|
67
|
+
data.should_not == Fontcustom::DATA_MODEL
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should throw an error if the data file is corrupted." do
|
71
|
+
options = {
|
72
|
+
:project_root => fixture,
|
73
|
+
:config => "generators",
|
74
|
+
:data_cache => "generators/.fontcustom-data-corrupted",
|
75
|
+
:input => "shared/vectors",
|
76
|
+
:output => "mixed-output",
|
77
|
+
:verbose => false
|
78
|
+
}
|
79
|
+
gen = generator options
|
80
|
+
expect { gen.get_data }.to raise_error Fontcustom::Error, /corrupted/
|
60
81
|
end
|
61
82
|
end
|
62
83
|
|
@@ -70,8 +91,7 @@ describe Fontcustom::Generator::Font do
|
|
70
91
|
}
|
71
92
|
gen = generator options
|
72
93
|
gen.stub :remove_file
|
73
|
-
gen.stub :
|
74
|
-
gen.stub :clear_file
|
94
|
+
gen.stub :overwrite_file
|
75
95
|
gen.instance_variable_set(:@data, data_file_contents)
|
76
96
|
gen
|
77
97
|
end
|
@@ -95,8 +115,7 @@ describe Fontcustom::Generator::Font do
|
|
95
115
|
|
96
116
|
it "should update the data file" do
|
97
117
|
file = fixture(".fontcustom-data")
|
98
|
-
subject.should_receive(:
|
99
|
-
subject.should_receive(:append_to_file).once.with(file, /"fonts":/, :verbose => false)
|
118
|
+
subject.should_receive(:overwrite_file).once.with(file, /"fonts":/)
|
100
119
|
subject.reset_output
|
101
120
|
end
|
102
121
|
|
@@ -175,7 +194,7 @@ describe Fontcustom::Generator::Font do
|
|
175
194
|
)
|
176
195
|
gen.instance_variable_set :@data, data_file_contents
|
177
196
|
stdout = capture(:stdout) { gen.announce_files }
|
178
|
-
stdout.should =~ /
|
197
|
+
stdout.should =~ /create.+\.(woff|ttf|eot|svg)/
|
179
198
|
end
|
180
199
|
|
181
200
|
it "should print nothing if verbose is false" do
|
@@ -198,12 +217,10 @@ describe Fontcustom::Generator::Font do
|
|
198
217
|
:input => "shared/vectors",
|
199
218
|
:output => "output"
|
200
219
|
)
|
201
|
-
gen.stub :
|
202
|
-
gen.stub :append_to_file
|
220
|
+
gen.stub :overwrite_file
|
203
221
|
gen.instance_variable_set(:@data, data_file_contents)
|
204
222
|
file = File.join fixture(".fontcustom-data")
|
205
|
-
gen.should_receive(:
|
206
|
-
gen.should_receive(:append_to_file).once.with do |path, content|
|
223
|
+
gen.should_receive(:overwrite_file).once.with do |path, content|
|
207
224
|
path.should == file
|
208
225
|
content.should match(/"fonts":/)
|
209
226
|
content.should match(/"glyphs":/)
|
@@ -218,8 +235,7 @@ describe Fontcustom::Generator::Font do
|
|
218
235
|
:output => "output",
|
219
236
|
:verbose => false
|
220
237
|
)
|
221
|
-
gen.stub :
|
222
|
-
gen.stub :append_to_file
|
238
|
+
gen.stub :overwrite_file
|
223
239
|
gen.instance_variable_set(:@data, data_file_contents)
|
224
240
|
stdout = capture(:stdout) { gen.save_data }
|
225
241
|
stdout.should == ""
|
@@ -1,8 +1,13 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Fontcustom::Generator::Template do
|
4
|
+
# Silence messages without passing :verbose => false to everything
|
5
|
+
before(:each) do
|
6
|
+
Fontcustom::Options.any_instance.stub :say_message
|
7
|
+
end
|
8
|
+
|
4
9
|
def generator(options)
|
5
|
-
opts = Fontcustom::
|
10
|
+
opts = Fontcustom::Options.new(options)
|
6
11
|
Fontcustom::Generator::Template.new([opts])
|
7
12
|
end
|
8
13
|
|
@@ -10,16 +15,18 @@ describe Fontcustom::Generator::Template do
|
|
10
15
|
it "should raise error if data file doesn't exist" do
|
11
16
|
gen = generator(
|
12
17
|
:project_root => fixture,
|
13
|
-
:input => "shared/vectors"
|
18
|
+
:input => "shared/vectors",
|
19
|
+
:verbose => false
|
14
20
|
)
|
15
|
-
expect { gen.get_data }.to raise_error Fontcustom::Error,
|
21
|
+
expect { gen.get_data }.to raise_error Fontcustom::Error, /\.fontcustom-data is required/
|
16
22
|
end
|
17
23
|
|
18
24
|
# TODO ensure data file is correct
|
19
25
|
it "should assign @data from data file" do
|
20
26
|
gen = generator(
|
21
27
|
:project_root => fixture("generators"),
|
22
|
-
:input => "../shared/vectors"
|
28
|
+
:input => "../shared/vectors",
|
29
|
+
:verbose => false
|
23
30
|
)
|
24
31
|
gen.get_data
|
25
32
|
gen.instance_variable_get(:@data)[:templates].should =~ data_file_contents[:templates]
|
@@ -35,8 +42,7 @@ describe Fontcustom::Generator::Template do
|
|
35
42
|
:verbose => false
|
36
43
|
)
|
37
44
|
gen.stub :remove_file
|
38
|
-
gen.stub :
|
39
|
-
gen.stub :append_to_file
|
45
|
+
gen.stub :overwrite_file
|
40
46
|
gen.instance_variable_set(:@data, data_file_contents)
|
41
47
|
gen
|
42
48
|
end
|
@@ -60,8 +66,7 @@ describe Fontcustom::Generator::Template do
|
|
60
66
|
|
61
67
|
it "should update the data file" do
|
62
68
|
file = fixture("generators/.fontcustom-data")
|
63
|
-
subject.should_receive(:
|
64
|
-
subject.should_receive(:append_to_file).once.with(file, /"templates":/, :verbose => false)
|
69
|
+
subject.should_receive(:overwrite_file).once.with(file, /"templates":/)
|
65
70
|
subject.reset_output
|
66
71
|
end
|
67
72
|
|
@@ -72,17 +77,17 @@ describe Fontcustom::Generator::Template do
|
|
72
77
|
end
|
73
78
|
|
74
79
|
context "#make_relative_paths" do
|
75
|
-
it "should assign :css_to_fonts and :
|
80
|
+
it "should assign :css_to_fonts, :preview_to_fonts, and :preprocessor_to_fonts" do
|
76
81
|
gen = generator(
|
77
82
|
:project_root => fixture,
|
78
83
|
:input => "shared/vectors",
|
79
|
-
:output => {:fonts => "foo/fonts", :css => "output/css", :preview => ""}
|
84
|
+
:output => {:fonts => "foo/fonts", :css => "output/css", :preview => "views/"}
|
80
85
|
)
|
81
86
|
gen.instance_variable_set "@data", data_file_contents
|
82
87
|
gen.make_relative_paths
|
83
88
|
data = gen.instance_variable_get("@data")
|
84
89
|
data[:paths][:css_to_fonts].should match("../../foo/fonts")
|
85
|
-
data[:paths][:
|
90
|
+
data[:paths][:preview_to_fonts].should match("../foo/fonts")
|
86
91
|
data[:paths][:preprocessor_to_fonts].should eq(data[:paths][:css_to_fonts])
|
87
92
|
end
|
88
93
|
|
@@ -109,7 +114,6 @@ describe Fontcustom::Generator::Template do
|
|
109
114
|
gen.make_relative_paths
|
110
115
|
data = gen.instance_variable_get("@data")
|
111
116
|
data[:paths][:css_to_fonts].should match("./")
|
112
|
-
data[:paths][:preview_to_css].should match("./")
|
113
117
|
end
|
114
118
|
end
|
115
119
|
|
@@ -124,8 +128,7 @@ describe Fontcustom::Generator::Template do
|
|
124
128
|
)
|
125
129
|
gen.instance_variable_set :@data, data_file_contents
|
126
130
|
gen.stub :template
|
127
|
-
gen.stub :
|
128
|
-
gen.stub :append_to_file
|
131
|
+
gen.stub :overwrite_file
|
129
132
|
gen
|
130
133
|
end
|
131
134
|
|
@@ -138,8 +141,7 @@ describe Fontcustom::Generator::Template do
|
|
138
141
|
|
139
142
|
it "should update data file with generated templates" do
|
140
143
|
file = fixture("generators/.fontcustom-data")
|
141
|
-
subject.should_receive(:
|
142
|
-
subject.should_receive(:append_to_file).once.with do |path, content|
|
144
|
+
subject.should_receive(:overwrite_file).once.with do |path, content|
|
143
145
|
path.should == file
|
144
146
|
content.should match(/fontcustom\.css/)
|
145
147
|
content.should match(/_fontcustom\.scss/)
|
@@ -164,11 +166,11 @@ describe Fontcustom::Generator::Template do
|
|
164
166
|
)
|
165
167
|
gen.instance_variable_set :@data, data_file_contents
|
166
168
|
gen.stub :template
|
167
|
-
gen.stub :
|
168
|
-
gen.stub :append_to_file
|
169
|
+
gen.stub :overwrite_file
|
169
170
|
gen
|
170
171
|
end
|
171
172
|
|
173
|
+
# 6 times because preview also includes preview-css
|
172
174
|
it "should output custom templates to their matching :output paths" do
|
173
175
|
subject.should_receive(:template).exactly(5).times do |*args|
|
174
176
|
if File.basename(args[0]) == "custom.css"
|
@@ -0,0 +1,428 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Fontcustom::Options do
|
4
|
+
def options(args = {})
|
5
|
+
Fontcustom::Options.new(args)
|
6
|
+
end
|
7
|
+
|
8
|
+
def silent
|
9
|
+
Fontcustom::Options.any_instance.stub :say_message
|
10
|
+
end
|
11
|
+
|
12
|
+
before(:each) { Fontcustom::Options.any_instance.stub(:set_options) }
|
13
|
+
|
14
|
+
context "#initialize" do
|
15
|
+
it "should overwite example defaults with real defaults" do
|
16
|
+
# imitates the default hash passed by thor
|
17
|
+
options = Fontcustom::Options.new(Fontcustom::EXAMPLE_OPTIONS.dup)
|
18
|
+
options = options.instance_variable_get(:@cli_options)
|
19
|
+
Fontcustom::EXAMPLE_OPTIONS.keys.each do |key|
|
20
|
+
options[key].should == Fontcustom::DEFAULT_OPTIONS[key]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context ".set_config_path" do
|
26
|
+
context "when :config is set" do
|
27
|
+
# TODO abstract this into Util?
|
28
|
+
it "should follow ../../ relative paths" do
|
29
|
+
args = {
|
30
|
+
:project_root => fixture("shared/vectors"),
|
31
|
+
:config => "../../options"
|
32
|
+
}
|
33
|
+
o = options args
|
34
|
+
o.send :set_config_path
|
35
|
+
o.instance_variable_get(:@config).should == fixture("options/fontcustom.yml")
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should use options[:config] if it's a file" do
|
39
|
+
args = {
|
40
|
+
:project_root => fixture,
|
41
|
+
:config => "options/any-file-name.yml"
|
42
|
+
}
|
43
|
+
o = options args
|
44
|
+
o.send :set_config_path
|
45
|
+
o.instance_variable_get(:@config).should == fixture("options/any-file-name.yml")
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should search for fontcustom.yml if options[:config] is a dir" do
|
49
|
+
args = {
|
50
|
+
:project_root => fixture,
|
51
|
+
:config => "options/config-is-in-dir"
|
52
|
+
}
|
53
|
+
o = options args
|
54
|
+
o.send :set_config_path
|
55
|
+
o.instance_variable_get(:@config).should == fixture("options/config-is-in-dir/fontcustom.yml")
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should raise error if :config doesn't exist" do
|
59
|
+
args = {
|
60
|
+
:project_root => fixture,
|
61
|
+
:config => "does-not-exist"
|
62
|
+
}
|
63
|
+
o = options args
|
64
|
+
expect { o.send :set_config_path }.to raise_error Fontcustom::Error, /configuration file was not found/
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "when :config is not set" do
|
69
|
+
it "should find fontcustom.yml at :project_root/fontcustom.yml" do
|
70
|
+
args = { :project_root => fixture("options") }
|
71
|
+
o = options args
|
72
|
+
o.send :set_config_path
|
73
|
+
o.instance_variable_get(:@config).should == fixture("options/fontcustom.yml")
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should find fontcustom.yml at :project_root/config/fontcustom.yml" do
|
77
|
+
args = { :project_root => fixture("options/rails-like") }
|
78
|
+
o = options args
|
79
|
+
o.send :set_config_path
|
80
|
+
o.instance_variable_get(:@config).should == fixture("options/rails-like/config/fontcustom.yml")
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should be false if nothing is found" do
|
84
|
+
args = { :project_root => fixture("options/no-config-here") }
|
85
|
+
o = options args
|
86
|
+
o.send :set_config_path
|
87
|
+
o.instance_variable_get(:@config).should == false
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context ".load_config" do
|
93
|
+
def args
|
94
|
+
{ :project_root => fixture, :verbose => false }
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should raise error if fontcustom.yml isn't valid" do
|
98
|
+
o = options args
|
99
|
+
o.instance_variable_set :@config, fixture("options/fontcustom-malformed.yml")
|
100
|
+
expect { o.send :load_config }.to raise_error Fontcustom::Error, /failed to load/
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should assign empty hash :config is false" do
|
104
|
+
o = options args
|
105
|
+
o.instance_variable_set :@config, false
|
106
|
+
o.send :load_config
|
107
|
+
o.instance_variable_get(:@config_options).should == {}
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should assign empty hash if fontcustom.yml is blank" do
|
111
|
+
o = options args
|
112
|
+
o.instance_variable_set :@config, fixture("options/fontcustom-empty.yml")
|
113
|
+
o.send :load_config
|
114
|
+
o.instance_variable_get(:@config_options).should == {}
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context ".merge_options" do
|
119
|
+
before(:each) { silent }
|
120
|
+
|
121
|
+
it "should set instance variables for each option key" do
|
122
|
+
o = options
|
123
|
+
o.instance_variable_set :@config_options, {}
|
124
|
+
o.send :merge_options
|
125
|
+
o.instance_variables.length.should == Fontcustom::DEFAULT_OPTIONS.length + 2 # @shell, @mock_proxy (rspec)
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should overwrite defaults with config file" do
|
129
|
+
o = options
|
130
|
+
o.instance_variable_set :@config_options, { :input => "config" }
|
131
|
+
o.send :merge_options
|
132
|
+
o.instance_variable_get(:@input).should == "config"
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should overwrite config file and defaults with CLI options" do
|
136
|
+
o = options
|
137
|
+
cli = o.instance_variable_get :@cli_options
|
138
|
+
o.instance_variable_set :@config_options, { :input => "config", :output => "output" }
|
139
|
+
o.instance_variable_set :@cli_options, cli.merge( :input => "cli" )
|
140
|
+
o.send :merge_options
|
141
|
+
o.instance_variable_get(:@input).should == "cli"
|
142
|
+
o.instance_variable_get(:@output).should == "output"
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should normalize the font name" do
|
146
|
+
o = options
|
147
|
+
o.instance_variable_set :@config_options, { :input => "config", :font_name => " A_stR4nG3 nAm3 Ø& " }
|
148
|
+
o.send :merge_options
|
149
|
+
o.instance_variable_get(:@font_name).should == "A_stR4nG3--nAm3---"
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
context ".set_data_path" do
|
154
|
+
it "should set :data_cache in the config dir by default" do
|
155
|
+
silent
|
156
|
+
o = options
|
157
|
+
o.instance_variable_set :@config, "path/to/config/fontcustom.yml"
|
158
|
+
o.instance_variable_set :@data_cache, nil
|
159
|
+
o.send :set_data_path
|
160
|
+
o.instance_variable_get(:@data_cache).should == "path/to/config/.fontcustom-data"
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
context "#send :set_input_paths" do
|
165
|
+
it "should raise error if input[:vectors] doesn't contain vectors" do
|
166
|
+
o = options
|
167
|
+
o.instance_variable_set :@project_root, fixture
|
168
|
+
o.instance_variable_set :@input, "shared/vectors-empty"
|
169
|
+
expect { o.send :set_input_paths }.to raise_error Fontcustom::Error, /doesn't contain any vectors/
|
170
|
+
end
|
171
|
+
|
172
|
+
context "when @input is a hash" do
|
173
|
+
it "should set :templates as :vectors if :templates isn't set" do
|
174
|
+
hash = { :vectors => "shared/vectors" }
|
175
|
+
o = options
|
176
|
+
o.instance_variable_set :@project_root, fixture
|
177
|
+
o.instance_variable_set :@input, hash
|
178
|
+
o.send :set_input_paths
|
179
|
+
input = o.instance_variable_get :@input
|
180
|
+
input[:templates].should == fixture("shared/vectors")
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should preserve :templates if it's set" do
|
184
|
+
hash = { :vectors => "shared/vectors", :templates => "shared/templates" }
|
185
|
+
o = options
|
186
|
+
o.instance_variable_set :@project_root, fixture
|
187
|
+
o.instance_variable_set :@input, hash
|
188
|
+
o.send :set_input_paths
|
189
|
+
input = o.instance_variable_get :@input
|
190
|
+
input[:templates].should == fixture("shared/templates")
|
191
|
+
end
|
192
|
+
|
193
|
+
it "should raise an error if :vectors isn't set" do
|
194
|
+
hash = { :templates => "shared/templates" }
|
195
|
+
o = options
|
196
|
+
o.instance_variable_set :@project_root, fixture
|
197
|
+
o.instance_variable_set :@input, hash
|
198
|
+
expect { o.send :set_input_paths }.to raise_error Fontcustom::Error, /contain a "vectors" key/
|
199
|
+
end
|
200
|
+
|
201
|
+
it "should raise an error if :vectors doesn't point to an existing directory" do
|
202
|
+
hash = { :vectors => "shared/not-a-dir" }
|
203
|
+
o = options
|
204
|
+
o.instance_variable_set :@project_root, fixture
|
205
|
+
o.instance_variable_set :@input, hash
|
206
|
+
expect { o.send :set_input_paths }.to raise_error Fontcustom::Error, /should be a directory/
|
207
|
+
end
|
208
|
+
|
209
|
+
it "should follow ../../ relative paths" do
|
210
|
+
hash = { :vectors => "../../shared/vectors", :templates => "../../shared/templates" }
|
211
|
+
o = options
|
212
|
+
o.instance_variable_set :@project_root, fixture("generators/mixed-output")
|
213
|
+
o.instance_variable_set :@input, hash
|
214
|
+
o.send :set_input_paths
|
215
|
+
input = o.instance_variable_get(:@input)
|
216
|
+
input[:vectors].should == fixture("shared/vectors")
|
217
|
+
input[:templates].should == fixture("shared/templates")
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
context "when @input is a string" do
|
222
|
+
it "should return a hash of locations" do
|
223
|
+
o = options
|
224
|
+
o.instance_variable_set :@project_root, fixture
|
225
|
+
o.instance_variable_set :@input, "shared/vectors"
|
226
|
+
o.send :set_input_paths
|
227
|
+
input = o.instance_variable_get :@input
|
228
|
+
input.should have_key("vectors")
|
229
|
+
input.should have_key("templates")
|
230
|
+
end
|
231
|
+
|
232
|
+
it "should set :templates to match :vectors" do
|
233
|
+
o = options
|
234
|
+
o.instance_variable_set :@project_root, fixture
|
235
|
+
o.instance_variable_set :@input, "shared/vectors"
|
236
|
+
o.send :set_input_paths
|
237
|
+
input = o.instance_variable_get :@input
|
238
|
+
input[:templates].should == fixture("shared/vectors")
|
239
|
+
end
|
240
|
+
|
241
|
+
it "should raise an error if :vectors doesn't point to a directory" do
|
242
|
+
o = options
|
243
|
+
o.instance_variable_set :@project_root, fixture
|
244
|
+
o.instance_variable_set :@input, "shared/not-a-dir"
|
245
|
+
expect { o.send :set_input_paths }.to raise_error Fontcustom::Error, /should be a directory/
|
246
|
+
end
|
247
|
+
|
248
|
+
it "should follow ../../ relative paths" do
|
249
|
+
o = options
|
250
|
+
o.instance_variable_set :@project_root, fixture("generators/mixed-output")
|
251
|
+
o.instance_variable_set :@input, "../../shared/vectors"
|
252
|
+
o.send :set_input_paths
|
253
|
+
input = o.instance_variable_get(:@input)
|
254
|
+
input[:vectors].should == fixture("shared/vectors")
|
255
|
+
input[:templates].should == fixture("shared/vectors")
|
256
|
+
end
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
context ".set_output_paths" do
|
261
|
+
context "when @output is nil" do
|
262
|
+
it "should default to :project_root/:font_name" do
|
263
|
+
silent
|
264
|
+
o = options
|
265
|
+
o.instance_variable_set :@project_root, fixture
|
266
|
+
o.instance_variable_set :@font_name, "Test-Font"
|
267
|
+
o.instance_variable_set :@output, nil
|
268
|
+
o.send :set_output_paths
|
269
|
+
output = o.instance_variable_get :@output
|
270
|
+
output[:fonts].should == fixture("Test-Font")
|
271
|
+
end
|
272
|
+
|
273
|
+
it "should print a warning" do
|
274
|
+
o = options
|
275
|
+
o.instance_variable_set :@project_root, fixture
|
276
|
+
o.instance_variable_set :@font_name, "Test-Font"
|
277
|
+
o.instance_variable_set :@output, nil
|
278
|
+
stdout = capture(:stdout) { o.send :set_output_paths }
|
279
|
+
stdout.should match("Test-Font")
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
context "when @output is a hash" do
|
284
|
+
it "should set :css and :preview to match :fonts if either aren't set" do
|
285
|
+
hash = { :fonts => "output/fonts" }
|
286
|
+
o = options
|
287
|
+
o.instance_variable_set :@project_root, fixture
|
288
|
+
o.instance_variable_set :@output, hash
|
289
|
+
o.send :set_output_paths
|
290
|
+
output = o.instance_variable_get :@output
|
291
|
+
output[:css].should == fixture("output/fonts")
|
292
|
+
output[:preview].should == fixture("output/fonts")
|
293
|
+
end
|
294
|
+
|
295
|
+
it "should preserve :css and :preview if they do exist" do
|
296
|
+
hash = {
|
297
|
+
:fonts => "output/fonts",
|
298
|
+
:css => "output/styles",
|
299
|
+
:preview => "output/preview"
|
300
|
+
}
|
301
|
+
o = options
|
302
|
+
o.instance_variable_set :@project_root, fixture
|
303
|
+
o.instance_variable_set :@output, hash
|
304
|
+
o.send :set_output_paths
|
305
|
+
output = o.instance_variable_get :@output
|
306
|
+
output[:css].should == fixture("output/styles")
|
307
|
+
output[:preview].should == fixture("output/preview")
|
308
|
+
end
|
309
|
+
|
310
|
+
it "should create additional paths if they are given" do
|
311
|
+
hash = {
|
312
|
+
:fonts => "output/fonts",
|
313
|
+
"special.js" => "assets/javascripts"
|
314
|
+
}
|
315
|
+
o = options
|
316
|
+
o.instance_variable_set :@project_root, fixture
|
317
|
+
o.instance_variable_set :@output, hash
|
318
|
+
o.send :set_output_paths
|
319
|
+
output = o.instance_variable_get :@output
|
320
|
+
output["special.js"].should == fixture("assets/javascripts")
|
321
|
+
end
|
322
|
+
|
323
|
+
it "should raise an error if :fonts isn't set" do
|
324
|
+
hash = { :css => "output/styles" }
|
325
|
+
o = options
|
326
|
+
o.instance_variable_set :@project_root, fixture
|
327
|
+
o.instance_variable_set :@output, hash
|
328
|
+
expect { o.send :set_output_paths }.to raise_error Fontcustom::Error, /contain a "fonts" key/
|
329
|
+
end
|
330
|
+
|
331
|
+
it "should follow ../../ relative paths" do
|
332
|
+
hash = {
|
333
|
+
:fonts => "../../output/fonts",
|
334
|
+
:css => "../../output/css",
|
335
|
+
:preview => "../../output/views"
|
336
|
+
}
|
337
|
+
o = options
|
338
|
+
o.instance_variable_set :@project_root, fixture("generators/mixed-output")
|
339
|
+
o.instance_variable_set :@output, hash
|
340
|
+
o.send :set_output_paths
|
341
|
+
output = o.instance_variable_get :@output
|
342
|
+
output[:fonts].should == fixture("output/fonts")
|
343
|
+
output[:css].should == fixture("output/css")
|
344
|
+
output[:preview].should == fixture("output/views")
|
345
|
+
end
|
346
|
+
end
|
347
|
+
|
348
|
+
context "when @output is a string" do
|
349
|
+
it "should return a hash of output locations" do
|
350
|
+
o = options
|
351
|
+
o.instance_variable_set :@project_root, fixture
|
352
|
+
o.instance_variable_set :@output, "output/fonts"
|
353
|
+
o.send :set_output_paths
|
354
|
+
output = o.instance_variable_get :@output
|
355
|
+
output.should be_a(Hash)
|
356
|
+
output.should have_key("fonts")
|
357
|
+
output.should have_key("css")
|
358
|
+
output.should have_key("preview")
|
359
|
+
end
|
360
|
+
|
361
|
+
it "should set :css and :preview to match :fonts" do
|
362
|
+
o = options
|
363
|
+
o.instance_variable_set :@project_root, fixture
|
364
|
+
o.instance_variable_set :@output, "output/fonts"
|
365
|
+
o.send :set_output_paths
|
366
|
+
output = o.instance_variable_get :@output
|
367
|
+
output[:css].should == fixture("output/fonts")
|
368
|
+
output[:preview].should == fixture("output/fonts")
|
369
|
+
end
|
370
|
+
|
371
|
+
it "should raise an error if :fonts exists but isn't a directory" do
|
372
|
+
o = options
|
373
|
+
o.instance_variable_set :@project_root, fixture
|
374
|
+
o.instance_variable_set :@output, "shared/not-a-dir"
|
375
|
+
expect { o.send :set_output_paths }.to raise_error Fontcustom::Error, /directory, not a file/
|
376
|
+
end
|
377
|
+
|
378
|
+
it "should follow ../../ relative paths" do
|
379
|
+
o = options
|
380
|
+
o.instance_variable_set :@project_root, fixture("generators/mixed-output")
|
381
|
+
o.instance_variable_set :@output, "../../something/else"
|
382
|
+
o.send :set_output_paths
|
383
|
+
output = o.instance_variable_get :@output
|
384
|
+
output[:fonts].should == fixture("something/else")
|
385
|
+
output[:css].should == fixture("something/else")
|
386
|
+
output[:preview].should == fixture("something/else")
|
387
|
+
end
|
388
|
+
end
|
389
|
+
end
|
390
|
+
|
391
|
+
context ".set_template_paths" do
|
392
|
+
it "should expand shorthand for packaged templates" do
|
393
|
+
o = options
|
394
|
+
o.instance_variable_set :@project_root, fixture
|
395
|
+
o.instance_variable_set :@input, { :templates => "shared/templates" }
|
396
|
+
o.instance_variable_set :@templates, %w|preview css scss bootstrap bootstrap-scss bootstrap-ie7 bootstrap-ie7-scss|
|
397
|
+
o.send :set_template_paths
|
398
|
+
templates = o.instance_variable_get :@templates
|
399
|
+
templates.should =~ [
|
400
|
+
File.join(Fontcustom.gem_lib, "templates", "fontcustom-preview.html"),
|
401
|
+
File.join(Fontcustom.gem_lib, "templates", "fontcustom.css"),
|
402
|
+
File.join(Fontcustom.gem_lib, "templates", "_fontcustom.scss"),
|
403
|
+
File.join(Fontcustom.gem_lib, "templates", "fontcustom-bootstrap.css"),
|
404
|
+
File.join(Fontcustom.gem_lib, "templates", "_fontcustom-bootstrap.scss"),
|
405
|
+
File.join(Fontcustom.gem_lib, "templates", "fontcustom-bootstrap-ie7.css"),
|
406
|
+
File.join(Fontcustom.gem_lib, "templates", "_fontcustom-bootstrap-ie7.scss")
|
407
|
+
]
|
408
|
+
end
|
409
|
+
|
410
|
+
it "should find custom templates in :template_path" do
|
411
|
+
o = options
|
412
|
+
o.instance_variable_set :@project_root, fixture
|
413
|
+
o.instance_variable_set :@input, { :templates => fixture("shared/templates") }
|
414
|
+
o.instance_variable_set :@templates, %w|custom.css|
|
415
|
+
o.send :set_template_paths
|
416
|
+
templates = o.instance_variable_get :@templates
|
417
|
+
templates.should =~ [fixture("shared/templates/custom.css")]
|
418
|
+
end
|
419
|
+
|
420
|
+
it "should raise an error if a template does not exist" do
|
421
|
+
o = options
|
422
|
+
o.instance_variable_set :@project_root, fixture
|
423
|
+
o.instance_variable_set :@input, { :templates => "shared/templates" }
|
424
|
+
o.instance_variable_set :@templates, %w|fake-template.txt|
|
425
|
+
expect { o.send :set_template_paths }.to raise_error Fontcustom::Error, /does not exist/
|
426
|
+
end
|
427
|
+
end
|
428
|
+
end
|