fontcustom 1.2.0 → 1.3.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +16 -0
  3. data/CONTRIBUTING.md +35 -15
  4. data/TODO.md +20 -0
  5. data/lib/fontcustom.rb +11 -24
  6. data/lib/fontcustom/base.rb +56 -0
  7. data/lib/fontcustom/cli.rb +13 -12
  8. data/lib/fontcustom/generator/font.rb +63 -65
  9. data/lib/fontcustom/generator/template.rb +81 -52
  10. data/lib/fontcustom/manifest.rb +42 -0
  11. data/lib/fontcustom/options.rb +93 -80
  12. data/lib/fontcustom/scripts/generate.py +116 -127
  13. data/lib/fontcustom/templates/_fontcustom-rails.scss +13 -18
  14. data/lib/fontcustom/templates/_fontcustom.scss +10 -18
  15. data/lib/fontcustom/templates/fontcustom-preview.html +17 -24
  16. data/lib/fontcustom/templates/fontcustom.css +10 -18
  17. data/lib/fontcustom/templates/fontcustom.yml +3 -3
  18. data/lib/fontcustom/utility.rb +145 -0
  19. data/lib/fontcustom/version.rb +1 -1
  20. data/lib/fontcustom/watcher.rb +1 -1
  21. data/spec/fixtures/generators/.fontcustom-manifest-corrupted.json +12 -5
  22. data/spec/fixtures/generators/.fontcustom-manifest-empty.json +0 -0
  23. data/spec/fixtures/generators/.fontcustom-manifest.json +49 -14
  24. data/spec/fixtures/generators/mixed-output/fontcustom_82a59e769bc60192484f2620570bbb59.eot +0 -0
  25. data/spec/fixtures/generators/mixed-output/fontcustom_82a59e769bc60192484f2620570bbb59.svg +56 -0
  26. data/spec/fixtures/generators/mixed-output/fontcustom_82a59e769bc60192484f2620570bbb59.ttf +0 -0
  27. data/spec/fixtures/generators/mixed-output/fontcustom_82a59e769bc60192484f2620570bbb59.woff +0 -0
  28. data/spec/fixtures/sandbox/.gitkeep +0 -0
  29. data/spec/fontcustom/base_spec.rb +58 -0
  30. data/spec/fontcustom/cli_spec.rb +15 -0
  31. data/spec/fontcustom/generator/font_spec.rb +50 -220
  32. data/spec/fontcustom/generator/template_spec.rb +30 -194
  33. data/spec/fontcustom/generator/template_spec.rb.off +215 -0
  34. data/spec/fontcustom/manifest_spec.rb +16 -0
  35. data/spec/fontcustom/options_spec.rb +206 -208
  36. data/spec/fontcustom/utility_spec.rb +163 -0
  37. data/spec/fontcustom/{watcher_spec.rb → watcher_spec.rb.off} +0 -0
  38. data/spec/spec_helper.rb +77 -19
  39. metadata +44 -54
  40. data/lib/fontcustom/templates/_fontcustom-bootstrap-ie7.scss +0 -22
  41. data/lib/fontcustom/templates/_fontcustom-bootstrap.scss +0 -63
  42. data/lib/fontcustom/templates/fontcustom-bootstrap-ie7.css +0 -22
  43. data/lib/fontcustom/templates/fontcustom-bootstrap.css +0 -63
  44. data/lib/fontcustom/util.rb +0 -62
  45. data/spec/fixtures/generators/mixed-output/fontcustom_cc5ce52f2ae4f9ce2e7ee8131bbfee1e.eot +0 -0
  46. data/spec/fixtures/generators/mixed-output/fontcustom_cc5ce52f2ae4f9ce2e7ee8131bbfee1e.svg +0 -102
  47. data/spec/fixtures/generators/mixed-output/fontcustom_cc5ce52f2ae4f9ce2e7ee8131bbfee1e.ttf +0 -0
  48. data/spec/fixtures/generators/mixed-output/fontcustom_cc5ce52f2ae4f9ce2e7ee8131bbfee1e.woff +0 -0
  49. data/spec/fontcustom/util_spec.rb +0 -82
@@ -1,216 +1,52 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Fontcustom::Generator::Template do
4
- # Silence messages without passing :quiet => true to everything
5
- before(:each) do
6
- Fontcustom::Options.any_instance.stub :say_message
7
- end
8
-
9
- def generator(options)
10
- opts = Fontcustom::Options.new(options)
11
- Fontcustom::Generator::Template.new([opts])
12
- end
13
-
14
- context "#get_manifest" do
15
- it "should raise error if data file doesn't exist" do
16
- gen = generator(
17
- :project_root => fixture,
18
- :input => "shared/vectors",
19
- :quiet => true
20
- )
21
- expect { gen.get_manifest }.to raise_error Fontcustom::Error, /\.fontcustom-manifest\.json/
22
- end
23
-
24
- it "should assign @data from data file" do
25
- gen = generator(
26
- :project_root => fixture("generators"),
27
- :input => "../shared/vectors",
28
- :quiet => true
29
- )
30
- gen.get_manifest
31
- gen.instance_variable_get(:@data)[:templates].should =~ data_file_contents[:templates]
32
- end
33
- end
34
-
35
- context "#reset_output" do
36
- subject do
37
- gen = generator(
38
- :project_root => fixture("generators"),
39
- :input => "../shared/vectors",
40
- :output => "mixed-output",
41
- :quiet => true
42
- )
43
- gen.stub :remove_file
44
- gen.stub :overwrite_file
45
- gen.instance_variable_set(:@data, data_file_contents)
46
- gen
47
- end
48
-
49
- it "should delete files from @data[:templates]" do
50
- subject.should_receive(:remove_file).once.with(/fontcustom\.css/, anything)
51
- subject.reset_output
52
- end
53
-
54
- it "should not delete non-template files" do
55
- subject.should_not_receive(:remove_file).with("dont-delete-me.bro")
56
- subject.should_not_receive(:remove_file).with("another-font.ttf")
57
- subject.should_not_receive(:remove_file).with(/fontcustom_cc5ce52f2ae4f9ce2e7ee8131bbfee1e/)
58
- subject.reset_output
59
- end
60
-
61
- it "should empty @data[:fonts]" do
62
- subject.reset_output
63
- subject.instance_variable_get(:@data)[:templates].should be_empty
64
- end
65
-
66
- it "should update the data file" do
67
- file = fixture("generators/.fontcustom-manifest.json")
68
- subject.should_receive(:overwrite_file).once.with(file, /"templates":/)
69
- subject.reset_output
70
- end
4
+ context "#generate" do
5
+ it "should generate templates (integration)", :integration => true do
6
+ live_test do |testdir|
7
+ FileUtils.cp_r fixture("generators/mixed-output"), "fontcustom"
8
+ manifest = test_manifest(
9
+ :input => "vectors",
10
+ :quiet => true,
11
+ :templates => %w|preview css scss scss-rails|
12
+ )
13
+ Fontcustom::Generator::Font.new(manifest).generate
14
+ gen = Fontcustom::Generator::Template.new manifest
71
15
 
72
- it "should be silent" do
73
- stdout = capture(:stdout) { subject.reset_output }
74
- stdout.should == ""
16
+ gen.generate
17
+ end
75
18
  end
76
19
  end
77
20
 
78
- context "#make_relative_paths" do
21
+ context ".set_relative_paths" do
79
22
  it "should assign @font_path, @font_path_alt, and @font_path_preview" do
80
- gen = generator(
81
- :project_root => fixture,
82
- :input => "shared/vectors",
83
- :output => {:fonts => "foo/fonts", :css => "output/css", :preview => "views/"}
84
- )
85
- gen.instance_variable_set :@data, data_file_contents
86
- gen.make_relative_paths
23
+ gen = Fontcustom::Generator::Template.new fixture("generators/.fontcustom-manifest.json")
24
+ options = gen.instance_variable_get :@options
25
+ options[:output] = {:fonts => fixture("foo/fonts"), :css => fixture("output/css"), :preview => fixture("views/")}
26
+
27
+ gen.send :set_relative_paths
87
28
  gen.instance_variable_get(:@font_path).should match("../../foo/fonts")
88
29
  gen.instance_variable_get(:@font_path_alt).should match("../../foo/fonts")
89
30
  gen.instance_variable_get(:@font_path_preview).should match("../foo/fonts")
90
31
  end
91
32
 
92
33
  it "should assign @font_path_alt if :preprocessor_font_path is set" do
93
- gen = generator(
94
- :project_root => fixture,
95
- :preprocessor_font_path => "fonts/fontcustom",
96
- :input => "shared/vectors",
97
- :output => {:fonts => "foo/bar/fonts", :css => "output/css", :preview => ""}
98
- )
99
- gen.instance_variable_set "@data", data_file_contents
100
- gen.make_relative_paths
34
+ gen = Fontcustom::Generator::Template.new fixture("generators/.fontcustom-manifest.json")
35
+ options = gen.instance_variable_get :@options
36
+ options[:preprocessor_font_path] = "fonts/fontcustom"
37
+ options[:output] = {:fonts => fixture("foo/fonts"), :css => fixture("output/css"), :preview => fixture("views/")}
38
+
39
+ gen.send :set_relative_paths
101
40
  gen.instance_variable_get(:@font_path_alt).should match("fonts/fontcustom")
102
41
  end
103
42
 
104
43
  it "should assign '.' when paths are the same" do
105
- gen = generator(
106
- :project_root => fixture,
107
- :input => "shared/vectors",
108
- :output => "output"
109
- )
110
- gen.instance_variable_set "@data", data_file_contents
111
- gen.make_relative_paths
112
- gen.instance_variable_get(:@font_path).should match("./")
113
- end
114
- end
115
-
116
- context "#generate" do
117
- subject do
118
- gen = generator(
119
- :project_root => fixture("generators"),
120
- :input => {:vectors => "../shared/vectors", :templates => "../shared/templates"},
121
- :output => "mixed-output",
122
- :templates => %W|scss css custom.css|,
123
- :quiet => true
124
- )
125
- gen.instance_variable_set :@data, data_file_contents
126
- gen.stub :template
127
- gen.stub :overwrite_file
128
- gen
129
- end
130
-
131
- it "should call #template for each template" do
132
- subject.should_receive(:template).exactly(3).times do |*args|
133
- args[1].should match(/(fontcustom\.css|_fontcustom\.scss|custom\.css)/)
134
- end
135
- subject.generate
136
- end
137
-
138
- it "should update data file with generated templates" do
139
- file = fixture("generators/.fontcustom-manifest.json")
140
- subject.should_receive(:overwrite_file).once.with do |path, content|
141
- path.should == file
142
- content.should match(/fontcustom\.css/)
143
- content.should match(/_fontcustom\.scss/)
144
- content.should match(/custom\.css/)
145
- end
146
- subject.generate
147
- end
148
-
149
- it "should be silent if :quiet is set" do
150
- stdout = capture(:stdout) { subject.generate }
151
- stdout.should == ""
152
- end
44
+ gen = Fontcustom::Generator::Template.new fixture("generators/.fontcustom-manifest.json")
45
+ options = gen.instance_variable_get :@options
46
+ options[:output] = {:fonts => fixture("foo/fonts"), :css => fixture("foo/fonts"), :preview => fixture("foo/fonts")}
153
47
 
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
-
171
- context "when various output locations are given" do
172
- subject do
173
- gen = generator(
174
- :project_root => fixture,
175
- :input => {:vectors => "shared/vectors", :templates => "shared/templates"},
176
- :output => {:fonts => "output/fonts", :css => "output/css", :preview => "output/views", "custom.css" => "output/custom"},
177
- :templates => %W|scss preview css custom.css regular.css|,
178
- :quiet => true
179
- )
180
- gen.instance_variable_set :@data, data_file_contents
181
- gen.stub :template
182
- gen.stub :overwrite_file
183
- gen
184
- end
185
-
186
- # 6 times because preview also includes preview-css
187
- it "should output custom templates to their matching :output paths" do
188
- subject.should_receive(:template).exactly(5).times do |*args|
189
- if File.basename(args[0]) == :"custom.css"
190
- args[1].should == fixture("output/custom/custom.css")
191
- end
192
- end
193
- subject.generate
194
- end
195
-
196
- it "should output css templates into :css" do
197
- subject.should_receive(:template).exactly(5).times do |*args|
198
- name = File.basename(args[0])
199
- if %w|_fontcustom.scss fontcustom.css regular.css|.include? name
200
- args[1].should match(/output\/css\/#{name}/)
201
- end
202
- end
203
- subject.generate
204
- end
205
-
206
- it "should output fontcustom-preview.html into :preview" do
207
- subject.should_receive(:template).exactly(5).times do |*args|
208
- if File.basename(args[0]) == "fontcustom-preview.html"
209
- args[1].should == fixture("output/views/fontcustom-preview.html")
210
- end
211
- end
212
- subject.generate
213
- end
48
+ gen.send :set_relative_paths
49
+ gen.instance_variable_get(:@font_path).should match("./")
214
50
  end
215
51
  end
216
52
  end
@@ -0,0 +1,215 @@
1
+ require "spec_helper"
2
+
3
+ describe Fontcustom::Generator::Template do
4
+ before(:each) do
5
+ Fontcustom::Options.any_instance.stub :say_message
6
+ end
7
+
8
+ def generator(options)
9
+ opts = Fontcustom::Options.new(options)
10
+ Fontcustom::Generator::Template.new([opts])
11
+ end
12
+
13
+ context "#get_manifest" do
14
+ it "should raise error if data file doesn't exist" do
15
+ gen = generator(
16
+ :project_root => fixture,
17
+ :input => "shared/vectors",
18
+ :quiet => true
19
+ )
20
+ expect { gen.get_manifest }.to raise_error Fontcustom::Error, /\.fontcustom-manifest\.json/
21
+ end
22
+
23
+ it "should assign @data from data file" do
24
+ gen = generator(
25
+ :project_root => fixture("generators"),
26
+ :input => "../shared/vectors",
27
+ :quiet => true
28
+ )
29
+ gen.get_manifest
30
+ gen.instance_variable_get(:@data)[:templates].should =~ data_file_contents[:templates]
31
+ end
32
+ end
33
+
34
+ context "#reset_output" do
35
+ subject do
36
+ gen = generator(
37
+ :project_root => fixture("generators"),
38
+ :input => "../shared/vectors",
39
+ :output => "mixed-output",
40
+ :quiet => true
41
+ )
42
+ gen.stub :remove_file
43
+ gen.stub :overwrite_file
44
+ gen.instance_variable_set(:@data, data_file_contents)
45
+ gen
46
+ end
47
+
48
+ it "should delete files from @data[:templates]" do
49
+ subject.should_receive(:remove_file).once.with(/fontcustom\.css/, anything)
50
+ subject.reset_output
51
+ end
52
+
53
+ it "should not delete non-template files" do
54
+ subject.should_not_receive(:remove_file).with("dont-delete-me.bro")
55
+ subject.should_not_receive(:remove_file).with("another-font.ttf")
56
+ subject.should_not_receive(:remove_file).with(/fontcustom_cc5ce52f2ae4f9ce2e7ee8131bbfee1e/)
57
+ subject.reset_output
58
+ end
59
+
60
+ it "should empty @data[:fonts]" do
61
+ subject.reset_output
62
+ subject.instance_variable_get(:@data)[:templates].should be_empty
63
+ end
64
+
65
+ it "should update the data file" do
66
+ file = fixture("generators/.fontcustom-manifest.json")
67
+ subject.should_receive(:overwrite_file).once.with(file, /"templates":/)
68
+ subject.reset_output
69
+ end
70
+
71
+ it "should be silent" do
72
+ stdout = capture(:stdout) { subject.reset_output }
73
+ stdout.should == ""
74
+ end
75
+ end
76
+
77
+ context "#make_relative_paths" do
78
+ it "should assign @font_path, @font_path_alt, and @font_path_preview" do
79
+ gen = generator(
80
+ :project_root => fixture,
81
+ :input => "shared/vectors",
82
+ :output => {:fonts => "foo/fonts", :css => "output/css", :preview => "views/"}
83
+ )
84
+ gen.instance_variable_set :@data, data_file_contents
85
+ gen.make_relative_paths
86
+ gen.instance_variable_get(:@font_path).should match("../../foo/fonts")
87
+ gen.instance_variable_get(:@font_path_alt).should match("../../foo/fonts")
88
+ gen.instance_variable_get(:@font_path_preview).should match("../foo/fonts")
89
+ end
90
+
91
+ it "should assign @font_path_alt if :preprocessor_font_path is set" do
92
+ gen = generator(
93
+ :project_root => fixture,
94
+ :preprocessor_font_path => "fonts/fontcustom",
95
+ :input => "shared/vectors",
96
+ :output => {:fonts => "foo/bar/fonts", :css => "output/css", :preview => ""}
97
+ )
98
+ gen.instance_variable_set "@data", data_file_contents
99
+ gen.make_relative_paths
100
+ gen.instance_variable_get(:@font_path_alt).should match("fonts/fontcustom")
101
+ end
102
+
103
+ it "should assign '.' when paths are the same" do
104
+ gen = generator(
105
+ :project_root => fixture,
106
+ :input => "shared/vectors",
107
+ :output => "output"
108
+ )
109
+ gen.instance_variable_set "@data", data_file_contents
110
+ gen.make_relative_paths
111
+ gen.instance_variable_get(:@font_path).should match("./")
112
+ end
113
+ end
114
+
115
+ context "#generate" do
116
+ subject do
117
+ gen = generator(
118
+ :project_root => fixture("generators"),
119
+ :input => {:vectors => "../shared/vectors", :templates => "../shared/templates"},
120
+ :output => "mixed-output",
121
+ :templates => %W|scss css custom.css|,
122
+ :quiet => true
123
+ )
124
+ gen.instance_variable_set :@data, data_file_contents
125
+ gen.stub :template
126
+ gen.stub :overwrite_file
127
+ gen
128
+ end
129
+
130
+ it "should call #template for each template" do
131
+ subject.should_receive(:template).exactly(3).times do |*args|
132
+ args[1].should match(/(fontcustom\.css|_fontcustom\.scss|custom\.css)/)
133
+ end
134
+ subject.generate
135
+ end
136
+
137
+ it "should update data file with generated templates" do
138
+ file = fixture("generators/.fontcustom-manifest.json")
139
+ subject.should_receive(:overwrite_file).once.with do |path, content|
140
+ path.should == file
141
+ content.should match(/fontcustom\.css/)
142
+ content.should match(/_fontcustom\.scss/)
143
+ content.should match(/custom\.css/)
144
+ end
145
+ subject.generate
146
+ end
147
+
148
+ it "should be silent if :quiet is set" do
149
+ stdout = capture(:stdout) { subject.generate }
150
+ stdout.should == ""
151
+ end
152
+
153
+ it "should rename stock templates according to opts.font_name" do
154
+ gen = generator(
155
+ :project_root => fixture("generators"),
156
+ :font_name => "Test Font",
157
+ :input => {:vectors => "../shared/vectors", :templates => "../shared/templates"},
158
+ :templates => %W|scss css|,
159
+ :quiet => true
160
+ )
161
+ gen.instance_variable_set :@data, data_file_contents
162
+ gen.stub :template
163
+ gen.stub :overwrite_file
164
+ gen.should_receive(:template).exactly(2).times do |*args|
165
+ args[1].should match(/(Test-Font\.css|_Test-Font\.scss)/)
166
+ end
167
+ gen.generate
168
+ end
169
+
170
+ context "when various output locations are given" do
171
+ subject do
172
+ gen = generator(
173
+ :project_root => fixture,
174
+ :input => {:vectors => "shared/vectors", :templates => "shared/templates"},
175
+ :output => {:fonts => "output/fonts", :css => "output/css", :preview => "output/views", "custom.css" => "output/custom"},
176
+ :templates => %W|scss preview css custom.css regular.css|,
177
+ :quiet => true
178
+ )
179
+ gen.instance_variable_set :@data, data_file_contents
180
+ gen.stub :template
181
+ gen.stub :overwrite_file
182
+ gen
183
+ end
184
+
185
+ # 6 times because preview also includes preview-css
186
+ it "should output custom templates to their matching :output paths" do
187
+ subject.should_receive(:template).exactly(5).times do |*args|
188
+ if File.basename(args[0]) == :"custom.css"
189
+ args[1].should == fixture("output/custom/custom.css")
190
+ end
191
+ end
192
+ subject.generate
193
+ end
194
+
195
+ it "should output css templates into :css" do
196
+ subject.should_receive(:template).exactly(5).times do |*args|
197
+ name = File.basename(args[0])
198
+ if %w|_fontcustom.scss fontcustom.css regular.css|.include? name
199
+ args[1].should match(/output\/css\/#{name}/)
200
+ end
201
+ end
202
+ subject.generate
203
+ end
204
+
205
+ it "should output fontcustom-preview.html into :preview" do
206
+ subject.should_receive(:template).exactly(5).times do |*args|
207
+ if File.basename(args[0]) == "fontcustom-preview.html"
208
+ args[1].should == fixture("output/views/fontcustom-preview.html")
209
+ end
210
+ end
211
+ subject.generate
212
+ end
213
+ end
214
+ end
215
+ end