machined 1.0.0 → 1.0.1

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.
@@ -18,7 +18,7 @@ module Machined
18
18
  end
19
19
  end
20
20
  end
21
-
21
+
22
22
  # Returns an `Array` of the child directories that
23
23
  # exist within the given +path+. If the path itself
24
24
  # does not exist, an emtpy array is returned.
@@ -1,3 +1,3 @@
1
1
  module Machined
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  end
@@ -6,7 +6,7 @@ describe Machined::Context do
6
6
  build_context.machined.should be(machined)
7
7
  end
8
8
  end
9
-
9
+
10
10
  describe '#config' do
11
11
  it "returns a reference to the Machined environment's configuration" do
12
12
  machined.config.layout = 'application'
@@ -13,24 +13,24 @@ describe Machined::Environment do
13
13
  end
14
14
  end
15
15
  end
16
-
16
+
17
17
  describe '#append_sprocket' do
18
18
  it 'creates a new Sprockets environment' do
19
19
  sprocket = machined.append_sprocket :updates
20
20
  sprocket.should be_a(Sprockets::Environment)
21
21
  end
22
-
22
+
23
23
  it 'appends the sprocket to #sprockets' do
24
24
  sprocket = machined.append_sprocket :updates
25
25
  machined.sprockets.last.should be(sprocket)
26
26
  end
27
-
27
+
28
28
  it 'adds a method with the given name which returns the sprocket' do
29
29
  sprocket = machined.append_sprocket :updates
30
30
  machined.updates.should be(sprocket)
31
31
  Machined::Environment.method_defined?(:updates).should be_false
32
32
  end
33
-
33
+
34
34
  it 'yields the sprocket for configuration' do
35
35
  yielded_sprocket = nil
36
36
  sprocket = machined.append_sprocket :updates do |updates|
@@ -38,43 +38,43 @@ describe Machined::Environment do
38
38
  end
39
39
  yielded_sprocket.should be(sprocket)
40
40
  end
41
-
41
+
42
42
  it 'initializes the sprocket with a reference to the Machined environment' do
43
43
  sprocket = machined.append_sprocket :updates
44
44
  sprocket.machined.should be(machined)
45
45
  end
46
-
46
+
47
47
  it 'initializes the sprocket with configuration' do
48
48
  sprocket = machined.append_sprocket :updates, :root => 'spec/machined'
49
49
  sprocket.root.should == File.expand_path('spec/machined')
50
50
  end
51
51
  end
52
-
52
+
53
53
  describe '#prepend_sprocket' do
54
54
  it 'creates a new Sprockets environment' do
55
55
  sprocket = machined.prepend_sprocket :updates
56
56
  sprocket.should be_a(Sprockets::Environment)
57
57
  end
58
-
58
+
59
59
  it 'prepends the sprocket to #sprockets' do
60
60
  sprocket = machined.prepend_sprocket :updates
61
61
  machined.sprockets.first.should be(sprocket)
62
62
  end
63
63
  end
64
-
64
+
65
65
  describe '#remove_sprocket' do
66
66
  it 'sets the accessor method to return nil' do
67
67
  machined.remove_sprocket :pages
68
68
  machined.pages.should be_nil
69
69
  end
70
-
70
+
71
71
  it 'removes the sprockets from the sprockets list' do
72
72
  views = machined.views
73
73
  machined.remove_sprocket :views
74
74
  machined.sprockets.should_not include(views)
75
75
  end
76
76
  end
77
-
77
+
78
78
  describe '#helpers' do
79
79
  it 'adds methods defined in the given block to the Context' do
80
80
  machined.helpers do
@@ -82,10 +82,10 @@ describe Machined::Environment do
82
82
  'world'
83
83
  end
84
84
  end
85
-
85
+
86
86
  build_context.hello.should == 'world'
87
87
  end
88
-
88
+
89
89
  it 'adds methods defined in the given module to the Context' do
90
90
  helper = Module.new do
91
91
  def hello
@@ -96,81 +96,81 @@ describe Machined::Environment do
96
96
  build_context.hello.should == 'world'
97
97
  end
98
98
  end
99
-
99
+
100
100
  describe '#reload' do
101
101
  it 'knows when helpers are changed' do
102
102
  within_construct do |c|
103
103
  c.file 'machined.rb', 'helpers do; def hello; "hello"; end; end'
104
104
  build_context.hello.should == 'hello'
105
-
105
+
106
106
  modify 'machined.rb', 'helpers do; def hello; "world"; end; end'
107
107
  machined.reload
108
108
  build_context.hello.should == 'world'
109
109
  end
110
110
  end
111
-
111
+
112
112
  it 'knows when configuration is changed' do
113
113
  within_construct do |c|
114
114
  c.file 'machined.rb'
115
115
  machined.output_path.should == c.join('public')
116
-
116
+
117
117
  modify 'machined.rb', 'config.output_path = "output"'
118
118
  machined.reload
119
119
  machined.output_path.should == c.join('output')
120
120
  end
121
121
  end
122
-
122
+
123
123
  it 'does not re-append sprockets' do
124
124
  within_construct do |c|
125
125
  c.file 'machined.rb'
126
126
  machined.sprockets.length.should == 3
127
-
127
+
128
128
  modify 'machined.rb', 'config.output_path = "output"'
129
129
  machined.reload
130
130
  machined.sprockets.length.should == 3
131
131
  end
132
132
  end
133
-
133
+
134
134
  it 're-evaluates assets when configuration changes' do
135
135
  within_construct do |c|
136
136
  c.file 'machined.rb', 'helpers do; def hello; "hello"; end; end'
137
137
  c.file 'pages/index.html.erb', '<%= hello %>'
138
138
  machined.pages['index.html'].to_s.should == 'hello'
139
-
139
+
140
140
  modify 'machined.rb', 'helpers do; def hello; "world"; end; end'
141
141
  machined.reload
142
142
  machined.pages['index.html'].to_s.should == 'world'
143
143
  end
144
144
  end
145
-
145
+
146
146
  it 'knows when a lib file changes' do
147
147
  within_construct do |c|
148
148
  c.file 'lib/hello.rb', 'module Hello; def hello; "hello"; end; end'
149
149
  c.file 'machined.rb', 'helpers Hello'
150
150
  machined :skip_autoloading => false
151
151
  build_context.hello.should == 'hello'
152
-
152
+
153
153
  modify 'lib/hello.rb', 'module Hello; def hello; "world"; end; end'
154
154
  machined.reload
155
155
  build_context.hello.should == 'world'
156
156
  end
157
157
  end
158
158
  end
159
-
159
+
160
160
  describe '#environment' do
161
161
  it 'is wrapped in String inquirer' do
162
162
  machined :environment => 'development'
163
163
  machined.environment.development?.should be_true
164
164
  machined.environment.production?.should be_false
165
165
  machined.environment.test?.should be_false
166
-
166
+
167
167
  machined :environment => 'production', :reload => true
168
168
  machined.environment.development?.should be_false
169
169
  machined.environment.production?.should be_true
170
170
  machined.environment.test?.should be_false
171
171
  end
172
172
  end
173
-
173
+
174
174
  describe 'default assets sprocket' do
175
175
  it 'appends the standard asset paths' do
176
176
  within_construct do |c|
@@ -180,7 +180,7 @@ describe Machined::Environment do
180
180
  c.directory 'vendor/assets/images'
181
181
  c.directory 'vendor/assets/javascripts'
182
182
  c.directory 'vendor/assets/stylesheets'
183
-
183
+
184
184
  machined.assets.paths.should match_paths(%w(
185
185
  assets/images
186
186
  assets/javascripts
@@ -191,14 +191,14 @@ describe Machined::Environment do
191
191
  )).with_root(c)
192
192
  end
193
193
  end
194
-
194
+
195
195
  it 'appends the available asset paths' do
196
196
  within_construct do |c|
197
197
  c.directory 'assets/css'
198
198
  c.directory 'assets/img'
199
199
  c.directory 'assets/js'
200
200
  c.directory 'assets/plugins'
201
-
201
+
202
202
  machined.assets.paths.should match_paths(%w(
203
203
  assets/css
204
204
  assets/img
@@ -207,26 +207,26 @@ describe Machined::Environment do
207
207
  )).with_root(c)
208
208
  end
209
209
  end
210
-
210
+
211
211
  # it 'appends Rails::Engine paths' do
212
212
  # require 'rails'
213
213
  # require 'jquery-rails'
214
214
  # machined.assets.paths.first.should =~ %r(/jquery-rails-[\d\.]+/vendor/assets/javascripts)
215
215
  # Rails::Engine.subclasses.delete Jquery::Rails::Engine
216
216
  # end
217
-
217
+
218
218
  it 'appends Sprockets::Plugin paths' do
219
219
  require 'sprockets-plugin'
220
-
220
+
221
221
  within_construct do |c|
222
222
  plugin_dir = c.directory 'plugin/assets'
223
223
  plugin_dir.directory 'images'
224
224
  plugin_dir.directory 'javascripts'
225
225
  plugin_dir.directory 'stylesheets'
226
-
226
+
227
227
  plugin = Class.new(Sprockets::Plugin)
228
228
  plugin.append_paths_in plugin_dir
229
-
229
+
230
230
  machined.assets.paths.should match_paths(%w(
231
231
  plugin/assets/images
232
232
  plugin/assets/javascripts
@@ -235,49 +235,64 @@ describe Machined::Environment do
235
235
  Sprockets::Plugin.plugins.delete plugin
236
236
  end
237
237
  end
238
-
238
+
239
239
  it 'compiles web assets' do
240
240
  within_construct do |c|
241
- c.file 'assets/javascripts/main.js', '//= require dep'
242
- c.file 'assets/javascripts/dep.js', 'var app = {};'
241
+ c.file 'assets/javascripts/main.js', '//= require dep'
242
+ c.file 'assets/javascripts/dep.js', 'var app = {};'
243
243
  c.file 'assets/stylesheets/main.css.scss', "@import 'dep';\nbody { color: $color; }"
244
- c.file 'assets/stylesheets/_dep.scss', '$color: red;'
245
-
244
+ c.file 'assets/stylesheets/_dep.scss', '$color: red;'
245
+
246
246
  machined.assets['main.js'].to_s.should == "var app = {};\n"
247
247
  machined.assets['main.css'].to_s.should == "body {\n color: red; }\n"
248
248
  end
249
249
  end
250
250
  end
251
-
251
+
252
252
  describe 'default pages sprocket' do
253
+ after { Sprockets.clear_paths }
254
+
253
255
  it 'appends the pages path' do
254
256
  within_construct do |c|
255
257
  c.directory 'pages'
256
258
  machined.pages.paths.should match_paths(%w(pages)).with_root(c)
257
259
  end
258
260
  end
259
-
261
+
260
262
  it 'compiles html pages' do
261
263
  within_construct do |c|
262
264
  c.file 'pages/index.html.haml', '%h1 Hello World'
263
265
  machined.pages['index.html'].to_s.should == "<h1>Hello World</h1>\n"
264
266
  end
265
267
  end
266
-
268
+
269
+ it 'does not compile other assets from additiontal paths' do
270
+ within_construct do |c|
271
+ vendor_path = c.directory 'vendor-assets'
272
+ vendor_path.file 'main.js', '//= require dep'
273
+ vendor_path.file 'dep.js', 'var app = {};'
274
+ vendor_path.file 'main.css.scss', "@import 'dep';\nbody { color: $color; }"
275
+ vendor_path.file '_dep.scss', '$color: red;'
276
+ Sprockets.append_path vendor_path
277
+
278
+ machined.pages['main.js'].to_s.should_not == "var app = {};\n"
279
+ machined.pages['main.css'].to_s.should_not == "body {\n color: red; }\n"
280
+ end
281
+ end
282
+
267
283
  context 'when :assets_only is set in constructor' do
268
284
  it 'is never created' do
269
285
  machined :assets_only => true
270
286
  machined.respond_to?(:pages).should be_false
271
287
  machined.sprockets.should == [ machined.assets, machined.views ]
272
288
  end
273
-
274
289
  end
275
-
290
+
276
291
  context 'when :assets_only is set in the config file' do
277
292
  it 'is removed' do
278
293
  within_construct do |c|
279
294
  c.file 'machined.rb', 'config.assets_only = true'
280
-
295
+
281
296
  machined
282
297
  machined.pages.should be_nil
283
298
  machined.sprockets.should == [ machined.assets, machined.views ]
@@ -285,7 +300,7 @@ describe Machined::Environment do
285
300
  end
286
301
  end
287
302
  end
288
-
303
+
289
304
  describe 'default views sprocket' do
290
305
  it 'appends the views path' do
291
306
  within_construct do |c|
@@ -293,7 +308,7 @@ describe Machined::Environment do
293
308
  machined.views.paths.should match_paths(%w(views)).with_root(c)
294
309
  end
295
310
  end
296
-
311
+
297
312
  it 'compiles html pages' do
298
313
  within_construct do |c|
299
314
  c.file 'views/layouts/main.html.haml', '%h1 Hello World'
@@ -301,7 +316,7 @@ describe Machined::Environment do
301
316
  end
302
317
  end
303
318
  end
304
-
319
+
305
320
  describe 'compression' do
306
321
  context 'with compress set to true' do
307
322
  it 'compresses javascripts and stylesheets' do
@@ -310,17 +325,17 @@ describe Machined::Environment do
310
325
  c.file 'assets/javascripts/dep.js', 'var app = {};'
311
326
  c.file 'assets/stylesheets/main.css.scss', "@import 'dep';\nbody { color: $color; }"
312
327
  c.file 'assets/stylesheets/_dep.scss', '$color: red;'
313
-
328
+
314
329
  Crush::Uglifier.should_receive(:compress).with("var app = {};\n").and_return('compressed')
315
330
  Crush::Sass::Engine.should_receive(:compress).with("body {\n color: red; }\n").and_return('compressed')
316
-
331
+
317
332
  machined :compress => true
318
333
  machined.assets['main.js'].to_s.should == 'compressed'
319
334
  machined.assets['main.css'].to_s.should == 'compressed'
320
335
  end
321
336
  end
322
337
  end
323
-
338
+
324
339
  context 'with a js_compressor set' do
325
340
  it 'compresses using that compressor' do
326
341
  within_construct do |c|
@@ -332,7 +347,7 @@ describe Machined::Environment do
332
347
  end
333
348
  end
334
349
  end
335
-
350
+
336
351
  it 'autoloads files from the lib directory' do
337
352
  within_construct do |c|
338
353
  c.file 'lib/hello.rb', 'module Hello; def hello; "hello"; end; end'
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Machined::Helpers::AssetTagHelpers do
4
4
  let(:context) { build_context }
5
-
5
+
6
6
  describe '#asset_path' do
7
7
  context 'with URIs' do
8
8
  it 'returns URIs untouched' do
@@ -14,65 +14,65 @@ describe Machined::Helpers::AssetTagHelpers do
14
14
  '//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js'
15
15
  end
16
16
  end
17
-
17
+
18
18
  context 'with regular files' do
19
19
  it 'returns absolute paths' do
20
20
  context.asset_path(:js, '/path/to/file.js').should == '/path/to/file.js'
21
21
  context.asset_path(:images, '/path/to/file.jpg').should == '/path/to/file.jpg'
22
22
  end
23
-
23
+
24
24
  it 'appends the extension for javascripts and stylesheets' do
25
25
  context.asset_path(:js, '/path/to/file').should == '/path/to/file.js'
26
26
  context.asset_path(:css, '/path/to/file').should == '/path/to/file.css'
27
27
  context.asset_path(:images, '/path/to/file').should_not == '/path/to/file.jpg'
28
28
  end
29
-
29
+
30
30
  it 'prepends a base URL if missing' do
31
31
  context.asset_path(:css, 'main').should == '/stylesheets/main.css'
32
32
  context.asset_path(:js, 'main').should == '/javascripts/main.js'
33
33
  context.asset_path(:images, 'logo.jpg').should == '/images/logo.jpg'
34
34
  end
35
-
35
+
36
36
  it 'appends a timestamp if the file exists in the output path' do
37
37
  within_construct do |c|
38
38
  c.file 'public/javascripts/main.js'
39
39
  c.file 'public/favicon.ico'
40
-
40
+
41
41
  context.asset_path(:js, 'main').should =~ %r(/javascripts/main.js\?\d+)
42
42
  context.asset_path(:images, '/favicon.ico').should =~ %r(/favicon.ico\?\d+)
43
43
  end
44
44
  end
45
45
  end
46
-
46
+
47
47
  context 'with assets' do
48
48
  it 'prepends a base URL if missing' do
49
49
  within_construct do |c|
50
50
  c.file 'assets/images/logo.jpg'
51
51
  c.file 'assets/javascripts/main.js'
52
52
  c.file 'assets/stylesheets/main.css'
53
-
53
+
54
54
  context.asset_path(:css, 'main').should == '/assets/main.css'
55
55
  context.asset_path(:js, 'main').should == '/assets/main.js'
56
56
  context.asset_path(:images, 'logo.jpg').should == '/assets/logo.jpg'
57
57
  end
58
58
  end
59
-
59
+
60
60
  it 'uses the digest path if configured' do
61
61
  within_construct do |c|
62
62
  c.file 'assets/javascrtips/main.js'
63
-
63
+
64
64
  machined :digest_assets => true
65
65
  context.asset_path(:js, 'main').should =~ %r(/assets/main-[0-9a-f]+.js)
66
66
  end
67
67
  end
68
68
  end
69
69
  end
70
-
70
+
71
71
  describe '#asset_path' do
72
72
  it 'is compatible with the Sprockets::Helpers API' do
73
73
  within_construct do |c|
74
74
  c.file 'assets/images/logo.jpg'
75
-
75
+
76
76
  context.image_path('logo.jpg', :digest => true).should =~ %r(/assets/logo-[0-9a-f]+.jpg)
77
77
  end
78
78
  end