sinatra-assetpack 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.md +14 -0
- data/README.md +203 -12
- data/Rakefile +8 -0
- data/example/app.rb +7 -1
- data/lib/sinatra/assetpack/helpers.rb +18 -5
- data/lib/sinatra/assetpack/options.rb +44 -11
- data/lib/sinatra/assetpack/version.rb +1 -1
- data/test/app/app.rb +7 -0
- data/test/arity_test.rb +27 -0
- data/test/helpers_test.rb +16 -9
- data/test/options_test.rb +7 -1
- data/test/redundant_test.rb +11 -0
- data/test/sqwish_test.rb +7 -4
- metadata +21 -19
data/HISTORY.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
v0.0.6 - Aug 30, 2011
|
2
|
+
---------------------
|
3
|
+
|
4
|
+
### Fixed:
|
5
|
+
* Redundant entries are now suppressed. (eg, when specifying
|
6
|
+
`['vendor/jquery.js', 'vendor/*.js']`)
|
7
|
+
|
8
|
+
### Added:
|
9
|
+
* Allow a parameter to the block in the `assets` configuration block.
|
10
|
+
* Update README with lots of info.
|
11
|
+
* Allow multiple packages in the js and css helpers. (eg, `css :base, :login`)
|
12
|
+
* Allow setting options for `js_compression` by passing a hash after it.
|
13
|
+
* Make the path parameter in `js` and `css` in the `assets` block optional.
|
14
|
+
|
1
15
|
v0.0.5 - Aug 30, 2011
|
2
16
|
---------------------
|
3
17
|
|
data/README.md
CHANGED
@@ -5,17 +5,19 @@ This is *the* most convenient way to set up your CSS/JS (and images) in a
|
|
5
5
|
Sinatra app. Seriously. No need for crappy routes to render Sass or whatever.
|
6
6
|
No-siree!
|
7
7
|
|
8
|
-
1. Drop your
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
1. Drop your assets into `/app` like so (you can configure directories don't worry):
|
9
|
+
* JavaScript/CoffeeScript files in `/app/js`
|
10
|
+
* CSS/Sass/Less/CSS files in `/app/css`
|
11
|
+
* Images into `/app/images`
|
12
|
+
3. Add `register Sinatra::AssetPack` and set up options to your app (see below)
|
13
|
+
4. Use `<%= css :application %>` to your layouts. Use this instead of
|
14
|
+
messy *script* and *link* tags
|
13
15
|
5. BOOM! You're in business baby!
|
14
16
|
|
15
17
|
Setup
|
16
18
|
-----
|
17
19
|
|
18
|
-
* Bundler
|
20
|
+
* Bundler? Add to *Gemfile*: `gem 'sinatra-assetpack', :require => 'sinatra/assetpack'`
|
19
21
|
* Else: `$ gem install sinatra-assetpack`
|
20
22
|
|
21
23
|
Install the plugin and add some options. (Feel free to omit the *Optional*
|
@@ -24,7 +26,7 @@ Install the plugin and add some options. (Feel free to omit the *Optional*
|
|
24
26
|
``` ruby
|
25
27
|
require 'sinatra/assetpack'
|
26
28
|
|
27
|
-
class
|
29
|
+
class App < Sinatra::Base
|
28
30
|
set :root, File.dirname(__FILE__)
|
29
31
|
register Sinatra::AssetPack
|
30
32
|
|
@@ -33,6 +35,8 @@ class Main < Sinatra::Base
|
|
33
35
|
serve '/css', from: 'app/css' # Optional
|
34
36
|
serve '/images', from: 'app/images' # Optional
|
35
37
|
|
38
|
+
# The second parameter defines where the compressed version will be served.
|
39
|
+
# (Note: that parameter is optional, AssetPack will figure it out.)
|
36
40
|
js :app, '/js/app.js', [
|
37
41
|
'/js/vendor/**/*.js',
|
38
42
|
'/js/app/**/*.js'
|
@@ -110,7 +114,7 @@ Compressors
|
|
110
114
|
-----------
|
111
115
|
|
112
116
|
By default, AssetPack uses [JSMin](http://rubygems.org/gems/jsmin) for JS
|
113
|
-
|
117
|
+
compression, and simple regexes for CSS compression. You can specify other
|
114
118
|
compressors in the `assets` block:
|
115
119
|
|
116
120
|
``` ruby
|
@@ -121,13 +125,16 @@ assets {
|
|
121
125
|
```
|
122
126
|
|
123
127
|
|
128
|
+
----
|
129
|
+
|
124
130
|
### YUI Compressor
|
125
131
|
|
126
132
|
``` ruby
|
127
133
|
assets {
|
128
134
|
js_compression :yui
|
135
|
+
js_compression :yui, :munge => true # Munge variable names
|
136
|
+
|
129
137
|
css_compression :yui
|
130
|
-
js_compression_options { :munge => true } # Munge variable names
|
131
138
|
}
|
132
139
|
```
|
133
140
|
|
@@ -136,6 +143,8 @@ For YUI compression, you need the YUI compressor gem.
|
|
136
143
|
* Bundler? Add to *Gemfile*: `gem 'yui-compressor', :require => 'yui/compressor'`
|
137
144
|
* Else, `gem install yui-compressor`
|
138
145
|
|
146
|
+
----
|
147
|
+
|
139
148
|
### SASS compression
|
140
149
|
|
141
150
|
``` ruby
|
@@ -149,12 +158,14 @@ For SASS compression, you need the Sass gem.
|
|
149
158
|
* Bundler? Add to *Gemfile*: `gem 'sass'`
|
150
159
|
* Else, `gem install sass`
|
151
160
|
|
161
|
+
----
|
162
|
+
|
152
163
|
### Sqwish CSS compression
|
153
164
|
|
154
165
|
``` ruby
|
155
166
|
assets {
|
156
167
|
css_compression :sqwish
|
157
|
-
|
168
|
+
css_compression :sqwish, :strict => true
|
158
169
|
}
|
159
170
|
```
|
160
171
|
|
@@ -162,12 +173,14 @@ assets {
|
|
162
173
|
Sqwish with AssetPack, install it using `npm install -g sqwish`. You need NodeJS
|
163
174
|
and NPM installed.
|
164
175
|
|
176
|
+
----
|
177
|
+
|
165
178
|
### Google Closure compression
|
166
179
|
|
167
180
|
``` ruby
|
168
181
|
assets {
|
169
182
|
js_compression :closure
|
170
|
-
|
183
|
+
js_compression :closure, :level => "SIMPLE_OPTIMIZATIONS"
|
171
184
|
}
|
172
185
|
```
|
173
186
|
|
@@ -209,7 +222,7 @@ Actually, you don't need to--this is optional! But add this to your Rakefile:
|
|
209
222
|
|
210
223
|
``` ruby
|
211
224
|
APP_FILE = 'app.rb'
|
212
|
-
APP_CLASS = '
|
225
|
+
APP_CLASS = 'App'
|
213
226
|
|
214
227
|
require 'sinatra/assetpack/rake'
|
215
228
|
```
|
@@ -220,6 +233,182 @@ Now:
|
|
220
233
|
|
221
234
|
This will create files in `/public`.
|
222
235
|
|
236
|
+
API reference: assets block
|
237
|
+
---------------------------
|
238
|
+
|
239
|
+
All configuration happens in the `assets` block. You may invoke it in 2 ways:
|
240
|
+
|
241
|
+
``` ruby
|
242
|
+
class App < Sinatra::Base
|
243
|
+
register Sinatra::AssetPack
|
244
|
+
|
245
|
+
# Style 1
|
246
|
+
assets do
|
247
|
+
css :hello, [ '/css/*.css' ]
|
248
|
+
js_compression :yui
|
249
|
+
end
|
250
|
+
|
251
|
+
# Style 2
|
252
|
+
assets do |a|
|
253
|
+
a.css :hello, ['/css/*.css' ]
|
254
|
+
a.js_compression :yui
|
255
|
+
end
|
256
|
+
end
|
257
|
+
```
|
258
|
+
|
259
|
+
Invoking it without a block allows you to access the options.
|
260
|
+
|
261
|
+
``` ruby
|
262
|
+
App.assets
|
263
|
+
App.assets.js_compression #=> :yui
|
264
|
+
```
|
265
|
+
|
266
|
+
----
|
267
|
+
|
268
|
+
### assets.serve
|
269
|
+
|
270
|
+
__Usage:__ `serve 'PATH', :from => 'LOCALPATH'`
|
271
|
+
|
272
|
+
Serves files from `LOCALPATH` in the URI path `PATH`. Both parameters are
|
273
|
+
required.
|
274
|
+
|
275
|
+
``` ruby
|
276
|
+
# ..This makes /app/javascripts/vendor/jquery.js
|
277
|
+
# available as http://localhost:4567/js/vendor/jquery.js
|
278
|
+
serve '/js', from: '/app/javascripts'
|
279
|
+
```
|
280
|
+
|
281
|
+
----
|
282
|
+
|
283
|
+
### assets.js_compression
|
284
|
+
### assets.css_compression
|
285
|
+
|
286
|
+
__Usage:__ `js_compression :ENGINE`
|
287
|
+
__Usage:__ `js_compression :ENGINE, OPTIONS_HASH`
|
288
|
+
__Usage:__ `css_compression :ENGINE`
|
289
|
+
__Usage:__ `css_compression :ENGINE, OPTIONS_HASH`
|
290
|
+
|
291
|
+
Sets the compression engine to use for JavaScript or CSS. This defaults to
|
292
|
+
`:jsmin` and `:simple`, respectively.
|
293
|
+
|
294
|
+
If `OPTIONS_HASH` is given as a hash, it sets options for the engine to use.
|
295
|
+
|
296
|
+
__Example 1:__ `css_compression :sqwish`
|
297
|
+
__Example 2:__ `css_compression :sqwish, :strict => true`
|
298
|
+
|
299
|
+
----
|
300
|
+
|
301
|
+
### assets.js_compression_options
|
302
|
+
### assets.css_compression_options
|
303
|
+
|
304
|
+
__Usage:__ `js_compression_options HASH`
|
305
|
+
__Usage:__ `css_compression_options HASH`
|
306
|
+
|
307
|
+
Sets the options for the compression engine to use. This is usually not needed
|
308
|
+
as you can already set options using `js_compression` and `css_compression`.
|
309
|
+
|
310
|
+
__Example:__ `js_compression_options :munge => true`
|
311
|
+
|
312
|
+
----
|
313
|
+
|
314
|
+
### assets.css
|
315
|
+
### assets.js
|
316
|
+
|
317
|
+
__Usage:__ `css :NAME, [ PATH1, PATH2, ... ]`
|
318
|
+
__Usage:__ `css :NAME, 'URI', [ PATH1, PATH2, ... ]`
|
319
|
+
__Usage:__ `js :NAME, [ PATH1, PATH2, ... ]`
|
320
|
+
__Usage:__ `js :NAME, 'URI', [ PATH1, PATH2, ... ]`
|
321
|
+
|
322
|
+
Adds packages to be used.
|
323
|
+
|
324
|
+
The `NAME` is a symbol defines the ID for that given package that you can use
|
325
|
+
for the helpers. That is, If a CSS package was defined as `css :main, [ ... ]`,
|
326
|
+
then you will need to use `<%= css :main %>` to render it in views.
|
327
|
+
|
328
|
+
the `URI` is a string that defines where the compressed version will be served.
|
329
|
+
It is optional. If not provided, it will default to `"/type/name.type"` (eg:
|
330
|
+
`/css/main.css`).
|
331
|
+
|
332
|
+
the `PATHs` is an array that defines files that will be served. Take note that
|
333
|
+
this is an array of URI paths, not local paths.
|
334
|
+
|
335
|
+
If a `PATH` contains wildcards, it will be expanded in alphabetical order.
|
336
|
+
Redundancies will be taken care of.
|
337
|
+
|
338
|
+
__Examples:__
|
339
|
+
|
340
|
+
In this example, JavaScript files will be served compressed as
|
341
|
+
`/js/application.js` (default since no `URI` is given). The files will be taken
|
342
|
+
from `./app/javascripts/vendor/jquery*.js`.
|
343
|
+
|
344
|
+
``` ruby
|
345
|
+
class App < Sinatra::Base
|
346
|
+
serve '/js', from: '/app/javascripts'
|
347
|
+
assets {
|
348
|
+
js :application, [
|
349
|
+
'/js/vendor/jquery.*.js',
|
350
|
+
'/js/vendor/jquery.js'
|
351
|
+
]
|
352
|
+
}
|
353
|
+
end
|
354
|
+
|
355
|
+
# In views: <%= js :application %>
|
356
|
+
```
|
357
|
+
|
358
|
+
API reference: helpers
|
359
|
+
----------------------
|
360
|
+
|
361
|
+
These are helpers you can use in your views.
|
362
|
+
|
363
|
+
----
|
364
|
+
|
365
|
+
### css
|
366
|
+
|
367
|
+
__Usage:__ `css :PACKAGE`
|
368
|
+
__Usage:__ `css :PACKAGE_1, :PACKAGE_2, ... :PACKAGE_N, OPTIONS_HASH`
|
369
|
+
__Usage:__ `css :PACKAGE, OPTIONS_HASH`
|
370
|
+
|
371
|
+
Shows a CSS package named `PACKAGE`. If `OPTIONS_HASH` is given, they will we
|
372
|
+
passed onto the `<link>` tag to be generated as attributes.
|
373
|
+
|
374
|
+
You may specify as many packages as you need, as shown in the second usage line.
|
375
|
+
|
376
|
+
__Example 1:__ `css :main, media: 'screen'`
|
377
|
+
__Output:__ `<link rel='stylesheet' type='text/css' href='/css/main.873984.css'
|
378
|
+
media='screen' />`
|
379
|
+
|
380
|
+
__Example 2:__ `css :base, :app, :main, media: 'screen'`
|
381
|
+
|
382
|
+
----
|
383
|
+
|
384
|
+
### js
|
385
|
+
|
386
|
+
__Usage:__ `js :PACKAGE`
|
387
|
+
__Usage:__ `js :PACKAGE, OPTIONS_HASH`
|
388
|
+
|
389
|
+
Same as `css`, but obviously for JavaScript.
|
390
|
+
|
391
|
+
You may also specify as many packages as you need.
|
392
|
+
|
393
|
+
__Example:__ `js :main, id: 'main_script'`
|
394
|
+
__Output:__ `<script type='text/javascript' src='/js/main.783439.js' id='main_script'></script>`
|
395
|
+
|
396
|
+
----
|
397
|
+
|
398
|
+
### img
|
399
|
+
|
400
|
+
__Usage:__ `img 'SRC'`
|
401
|
+
__Usage:__ `img 'SRC', OPTIONS_HASH`
|
402
|
+
|
403
|
+
Shows an `<img>` tag from the given `SRC`. If the images is found in the asset
|
404
|
+
directories, `width` and `height` attributes will be added.
|
405
|
+
|
406
|
+
If `OPTIONS_HASH` is given, they will we passed onto the `<img>` tag to be
|
407
|
+
generated as attributes.
|
408
|
+
|
409
|
+
__Example:__ `img '/images/icon.png', alt: 'Icon'`
|
410
|
+
__Output:__ `<img src='/images/icon.834782.png' width='24' height='24' alt='Icon' />`
|
411
|
+
|
223
412
|
Need Compass support?
|
224
413
|
---------------------
|
225
414
|
|
@@ -241,6 +430,8 @@ To do
|
|
241
430
|
|
242
431
|
AssetPack will eventually have:
|
243
432
|
|
433
|
+
* Nested packages
|
434
|
+
* Ignored files (to ignore included sass files and such)
|
244
435
|
* `rake assetpack:build` should be able to output to another folder
|
245
436
|
* Cache folder support (best if your app has many workers)
|
246
437
|
* Refactor *Compressor* module
|
data/Rakefile
CHANGED
data/example/app.rb
CHANGED
@@ -13,9 +13,15 @@ class App < Sinatra::Base
|
|
13
13
|
'/js/app.js'
|
14
14
|
]
|
15
15
|
|
16
|
-
css :main,
|
16
|
+
css :main, [
|
17
17
|
'/css/*.css'
|
18
18
|
]
|
19
|
+
|
20
|
+
# The second parameter here is optional (see above).
|
21
|
+
# It will default to '/css/#{name}.css'.
|
22
|
+
css :more, '/css/more.css', [
|
23
|
+
'/css/more/*.css'
|
24
|
+
]
|
19
25
|
end
|
20
26
|
|
21
27
|
get '/' do
|
@@ -1,12 +1,12 @@
|
|
1
1
|
module Sinatra
|
2
2
|
module AssetPack
|
3
3
|
module Helpers
|
4
|
-
def css(
|
5
|
-
show_asset_pack :css,
|
4
|
+
def css(*args)
|
5
|
+
show_asset_pack :css, *args
|
6
6
|
end
|
7
7
|
|
8
|
-
def js(
|
9
|
-
show_asset_pack :js,
|
8
|
+
def js(*args)
|
9
|
+
show_asset_pack :js, *args
|
10
10
|
end
|
11
11
|
|
12
12
|
def img(src, options={})
|
@@ -25,7 +25,20 @@ module Sinatra
|
|
25
25
|
"<img#{HtmlHelpers.kv attrs} />"
|
26
26
|
end
|
27
27
|
|
28
|
-
def show_asset_pack(type,
|
28
|
+
def show_asset_pack(type, *args)
|
29
|
+
names = Array.new
|
30
|
+
while args.first.is_a?(Symbol)
|
31
|
+
names << args.shift
|
32
|
+
end
|
33
|
+
|
34
|
+
options = args.shift if args.first.is_a?(Hash)
|
35
|
+
|
36
|
+
names.map { |name|
|
37
|
+
show_one_asset_pack type, name, (options || Hash.new)
|
38
|
+
}.join "\n"
|
39
|
+
end
|
40
|
+
|
41
|
+
def show_one_asset_pack(type, name, options={})
|
29
42
|
pack = settings.assets.packages["#{name}.#{type}"]
|
30
43
|
return "" unless pack
|
31
44
|
|
@@ -56,7 +56,7 @@ module Sinatra
|
|
56
56
|
serve '/js', :from => 'app/js'
|
57
57
|
serve '/images', :from => 'app/images'
|
58
58
|
|
59
|
-
instance_eval
|
59
|
+
blk.arity <= 0 ? instance_eval(&blk) : yield(self) if block_given?
|
60
60
|
end
|
61
61
|
|
62
62
|
# =====================================================================
|
@@ -77,18 +77,37 @@ module Sinatra
|
|
77
77
|
|
78
78
|
# Adds some JS packages.
|
79
79
|
#
|
80
|
-
# js :foo,
|
80
|
+
# js :foo, [ '/js/vendor/jquery.*.js', ... ]
|
81
|
+
# js :foo, '/js/foo.js', [ '/js/vendor/jquery.*.js', ... ]
|
81
82
|
#
|
82
|
-
def js(name,
|
83
|
-
|
83
|
+
def js(name, *args)
|
84
|
+
js_or_css :js, name, *args
|
84
85
|
end
|
85
86
|
|
86
87
|
# Adds some CSS packages.
|
87
88
|
#
|
88
|
-
# css :app,
|
89
|
+
# css :app, [ '/css/screen.css', ... ]
|
90
|
+
# css :app, '/css/app.css', [ '/css/screen.css', ... ]
|
89
91
|
#
|
90
|
-
def css(name, path, files=[])
|
91
|
-
|
92
|
+
def css(name, *args) #path, files=[])
|
93
|
+
js_or_css :css, name, *args
|
94
|
+
end
|
95
|
+
|
96
|
+
def js_or_css(type, name, *args)
|
97
|
+
# Account for "css :name, '/path/to/css', [ files ]"
|
98
|
+
if args[0].is_a?(String) && args[1].respond_to?(:each)
|
99
|
+
path, files = args
|
100
|
+
|
101
|
+
# Account for "css :name, [ files ]"
|
102
|
+
elsif args[0].respond_to?(:each)
|
103
|
+
path = "/#{type}/#{name}.#{type}" # /css/foobar.css by default
|
104
|
+
files = args[0]
|
105
|
+
|
106
|
+
else
|
107
|
+
raise ArgumentError
|
108
|
+
end
|
109
|
+
|
110
|
+
@packages["#{name}.#{type}"] = Package.new(self, name, type, path, files)
|
92
111
|
end
|
93
112
|
|
94
113
|
attr_reader :app # Sinatra::Base instance
|
@@ -102,6 +121,18 @@ module Sinatra
|
|
102
121
|
|
103
122
|
attrib :js_compression_options # Hash
|
104
123
|
attrib :css_compression_options # Hash
|
124
|
+
|
125
|
+
def js_compression(name=nil, options=nil)
|
126
|
+
@js_compression = name unless name.nil?
|
127
|
+
@js_compression_options = options if options.is_a?(Hash)
|
128
|
+
@js_compression
|
129
|
+
end
|
130
|
+
|
131
|
+
def css_compression(name=nil, options=nil)
|
132
|
+
@css_compression = name unless name.nil?
|
133
|
+
@css_compression_options = options if options.is_a?(Hash)
|
134
|
+
@css_compression
|
135
|
+
end
|
105
136
|
|
106
137
|
# =====================================================================
|
107
138
|
# Stuff
|
@@ -186,10 +217,12 @@ module Sinatra
|
|
186
217
|
|
187
218
|
# Returns an array of URI paths of those matching given globs.
|
188
219
|
def glob(*match)
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
220
|
+
paths = match.map { |spec|
|
221
|
+
files.keys.select { |f| File.fnmatch?(spec, f) }.sort
|
222
|
+
}.flatten
|
223
|
+
|
224
|
+
paths = paths.uniq
|
225
|
+
tuples = paths.map { |key| [key, files[key]] }
|
193
226
|
|
194
227
|
HashArray[*tuples.flatten]
|
195
228
|
end
|
data/test/app/app.rb
CHANGED
data/test/arity_test.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class ArityTest < UnitTest
|
4
|
+
class App < Sinatra::Base
|
5
|
+
set :root, File.expand_path('../app', __FILE__)
|
6
|
+
register Sinatra::AssetPack
|
7
|
+
|
8
|
+
assets do |a|
|
9
|
+
a.css :a, '/css/a.css', [
|
10
|
+
'/css/s*.css',
|
11
|
+
'/css/j*.css'
|
12
|
+
]
|
13
|
+
|
14
|
+
a.js_compression :closure
|
15
|
+
a.css_compression = :yui
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
test "arity in #assets" do
|
20
|
+
paths = App.assets.packages['a.css'].paths
|
21
|
+
assert paths ==
|
22
|
+
["/css/screen.css", "/css/sqwishable.css", "/css/style.css", "/css/js2c.css"]
|
23
|
+
|
24
|
+
assert App.assets.js_compression == :closure
|
25
|
+
assert App.assets.css_compression == :yui
|
26
|
+
end
|
27
|
+
end
|
data/test/helpers_test.rb
CHANGED
@@ -1,23 +1,30 @@
|
|
1
1
|
require File.expand_path('../test_helper', __FILE__)
|
2
2
|
|
3
3
|
class HelpersTest < UnitTest
|
4
|
-
Main.get
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
Main.get
|
9
|
-
img '/images/email.png'
|
10
|
-
end
|
4
|
+
Main.get('/helper/foo') { img '/images/foo.jpg' }
|
5
|
+
Main.get('/helper/email') { img '/images/email.png' }
|
6
|
+
Main.get('/helper/css/all') { css :application, :sq }
|
7
|
+
Main.get('/helper/css/app') { css :application }
|
8
|
+
Main.get('/helper/css/sq') { css :sq }
|
11
9
|
|
12
10
|
test "img non-existing" do
|
13
|
-
get '/
|
11
|
+
get '/helper/foo'
|
14
12
|
assert body == "<img src='/images/foo.jpg' />"
|
15
13
|
end
|
16
14
|
|
17
15
|
test "img existing" do
|
18
|
-
get '/
|
16
|
+
get '/helper/email'
|
19
17
|
assert body =~ %r{src='/images/email.[0-9]+.png'}
|
20
18
|
assert body =~ %r{width='16'}
|
21
19
|
assert body =~ %r{height='16'}
|
22
20
|
end
|
21
|
+
|
22
|
+
test "css" do
|
23
|
+
re = Array.new
|
24
|
+
get '/helper/css/app'; re << body
|
25
|
+
get '/helper/css/sq'; re << body
|
26
|
+
|
27
|
+
get '/helper/css/all'
|
28
|
+
assert body.gsub(/[\r\n]*/m, '') == re.join('')
|
29
|
+
end
|
23
30
|
end
|
data/test/options_test.rb
CHANGED
@@ -3,15 +3,21 @@ require File.expand_path('../test_helper', __FILE__)
|
|
3
3
|
|
4
4
|
class OptionsTest < UnitTest
|
5
5
|
class App < Sinatra::Base
|
6
|
-
set :root, File.
|
6
|
+
set :root, File.expand_path('../app', __FILE__)
|
7
7
|
register Sinatra::AssetPack
|
8
8
|
|
9
9
|
assets {
|
10
|
+
css :application, [ '/css/*.css' ]
|
10
11
|
js_compression :closure
|
11
12
|
}
|
12
13
|
end
|
13
14
|
|
15
|
+
def app
|
16
|
+
App
|
17
|
+
end
|
18
|
+
|
14
19
|
test "options" do
|
15
20
|
assert App.assets.js_compression == :closure
|
21
|
+
assert App.assets.packages['application.css'].path == "/css/application.css"
|
16
22
|
end
|
17
23
|
end
|
data/test/sqwish_test.rb
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
require File.expand_path('../test_helper', __FILE__)
|
2
2
|
|
3
|
-
class
|
3
|
+
class SqwishTest < UnitTest
|
4
4
|
setup do
|
5
|
-
app.assets.css_compression
|
6
|
-
app.assets.css_compression_options[:strict] = true
|
5
|
+
app.assets.css_compression :sqwish, :strict => true
|
7
6
|
end
|
8
7
|
|
9
8
|
teardown do
|
10
|
-
app.assets.css_compression
|
9
|
+
app.assets.css_compression :simple
|
11
10
|
app.assets.css_compression_options.delete :strict
|
12
11
|
end
|
13
12
|
|
@@ -15,6 +14,10 @@ class Sqwish < UnitTest
|
|
15
14
|
`which sqwish` && true rescue false
|
16
15
|
end
|
17
16
|
|
17
|
+
test "css compression options" do
|
18
|
+
assert app.assets.css_compression_options[:strict] == true
|
19
|
+
end
|
20
|
+
|
18
21
|
if sqwish?
|
19
22
|
test "build" do
|
20
23
|
Sinatra::AssetPack::Compressor.expects(:`).with() { |cmd|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-assetpack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -14,7 +14,7 @@ default_executable:
|
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: sinatra
|
17
|
-
requirement: &
|
17
|
+
requirement: &2157093660 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *2157093660
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: jsmin
|
28
|
-
requirement: &
|
28
|
+
requirement: &2157093240 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *2157093240
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: rack-test
|
39
|
-
requirement: &
|
39
|
+
requirement: &2153355700 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :runtime
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *2153355700
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: yui-compressor
|
50
|
-
requirement: &
|
50
|
+
requirement: &2153355280 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *2153355280
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: sass
|
61
|
-
requirement: &
|
61
|
+
requirement: &2153354860 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ! '>='
|
@@ -66,10 +66,10 @@ dependencies:
|
|
66
66
|
version: '0'
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *2153354860
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: haml
|
72
|
-
requirement: &
|
72
|
+
requirement: &2153354440 !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
75
|
- - ! '>='
|
@@ -77,10 +77,10 @@ dependencies:
|
|
77
77
|
version: '0'
|
78
78
|
type: :development
|
79
79
|
prerelease: false
|
80
|
-
version_requirements: *
|
80
|
+
version_requirements: *2153354440
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
82
|
name: coffee-script
|
83
|
-
requirement: &
|
83
|
+
requirement: &2153354020 !ruby/object:Gem::Requirement
|
84
84
|
none: false
|
85
85
|
requirements:
|
86
86
|
- - ! '>='
|
@@ -88,10 +88,10 @@ dependencies:
|
|
88
88
|
version: '0'
|
89
89
|
type: :development
|
90
90
|
prerelease: false
|
91
|
-
version_requirements: *
|
91
|
+
version_requirements: *2153354020
|
92
92
|
- !ruby/object:Gem::Dependency
|
93
93
|
name: contest
|
94
|
-
requirement: &
|
94
|
+
requirement: &2153353600 !ruby/object:Gem::Requirement
|
95
95
|
none: false
|
96
96
|
requirements:
|
97
97
|
- - ! '>='
|
@@ -99,10 +99,10 @@ dependencies:
|
|
99
99
|
version: '0'
|
100
100
|
type: :development
|
101
101
|
prerelease: false
|
102
|
-
version_requirements: *
|
102
|
+
version_requirements: *2153353600
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
104
|
name: mocha
|
105
|
-
requirement: &
|
105
|
+
requirement: &2153353180 !ruby/object:Gem::Requirement
|
106
106
|
none: false
|
107
107
|
requirements:
|
108
108
|
- - ! '>='
|
@@ -110,7 +110,7 @@ dependencies:
|
|
110
110
|
version: '0'
|
111
111
|
type: :development
|
112
112
|
prerelease: false
|
113
|
-
version_requirements: *
|
113
|
+
version_requirements: *2153353180
|
114
114
|
description: Package your assets for Sinatra.
|
115
115
|
email:
|
116
116
|
- rico@sinefunc.com
|
@@ -160,6 +160,7 @@ files:
|
|
160
160
|
- test/app/app/js/hello.js
|
161
161
|
- test/app/app/js/hi.coffee
|
162
162
|
- test/app/app/views/index.haml
|
163
|
+
- test/arity_test.rb
|
163
164
|
- test/build_test.rb
|
164
165
|
- test/cache_test.rb
|
165
166
|
- test/helpers_test.rb
|
@@ -167,6 +168,7 @@ files:
|
|
167
168
|
- test/options_test.rb
|
168
169
|
- test/order_test.rb
|
169
170
|
- test/preproc_test.rb
|
171
|
+
- test/redundant_test.rb
|
170
172
|
- test/simplecss_test.rb
|
171
173
|
- test/sqwish_test.rb
|
172
174
|
- test/test_helper.rb
|