sundawg-sinatra-assetpack-fork 0.0.12.pre1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +2 -0
- data/HISTORY.md +131 -0
- data/README.md +656 -0
- data/Rakefile +31 -0
- data/docsrc/style.css +32 -0
- data/examples/basic/.gitignore +1 -0
- data/examples/basic/Rakefile +7 -0
- data/examples/basic/app/css/test.sass +11 -0
- data/examples/basic/app/images/icon.png +0 -0
- data/examples/basic/app/js/app.js +4 -0
- data/examples/basic/app/js/vendor/jquery.js +2 -0
- data/examples/basic/app/js/vendor/jquery.plugin.js +2 -0
- data/examples/basic/app/js/vendor/underscore.js +2 -0
- data/examples/basic/app.rb +39 -0
- data/examples/basic/views/index.erb +26 -0
- data/examples/classic/app.rb +24 -0
- data/examples/classic/css/screen.scss +1 -0
- data/examples/compass/.gitignore +1 -0
- data/examples/compass/Rakefile +7 -0
- data/examples/compass/app/css/main.scss +64 -0
- data/examples/compass/app/images/icon/mail.png +0 -0
- data/examples/compass/app/images/icon/refresh.png +0 -0
- data/examples/compass/app/images/icon-scfd8d7d404.png +0 -0
- data/examples/compass/app/images/junk/mail.png +0 -0
- data/examples/compass/app/images/junk/refresh.png +0 -0
- data/examples/compass/app/js/app.js +3 -0
- data/examples/compass/app/js/vendor/jquery.js +2 -0
- data/examples/compass/app/js/vendor/jquery.plugin.js +2 -0
- data/examples/compass/app/js/vendor/underscore.js +2 -0
- data/examples/compass/app.rb +45 -0
- data/examples/compass/config.ru +3 -0
- data/examples/compass/views/index.erb +15 -0
- data/lib/sinatra/assetpack/buster_helpers.rb +36 -0
- data/lib/sinatra/assetpack/class_methods.rb +82 -0
- data/lib/sinatra/assetpack/compressor.rb +54 -0
- data/lib/sinatra/assetpack/configurator.rb +21 -0
- data/lib/sinatra/assetpack/css.rb +36 -0
- data/lib/sinatra/assetpack/engine.rb +20 -0
- data/lib/sinatra/assetpack/engines/closure.rb +19 -0
- data/lib/sinatra/assetpack/engines/jsmin.rb +10 -0
- data/lib/sinatra/assetpack/engines/sass.rb +11 -0
- data/lib/sinatra/assetpack/engines/simple.rb +11 -0
- data/lib/sinatra/assetpack/engines/sqwish.rb +21 -0
- data/lib/sinatra/assetpack/engines/uglify.rb +12 -0
- data/lib/sinatra/assetpack/engines/yui.rb +22 -0
- data/lib/sinatra/assetpack/hasharray.rb +66 -0
- data/lib/sinatra/assetpack/helpers.rb +62 -0
- data/lib/sinatra/assetpack/html_helpers.rb +17 -0
- data/lib/sinatra/assetpack/image.rb +59 -0
- data/lib/sinatra/assetpack/options.rb +329 -0
- data/lib/sinatra/assetpack/package.rb +126 -0
- data/lib/sinatra/assetpack/rake.rb +29 -0
- data/lib/sinatra/assetpack/version.rb +7 -0
- data/lib/sinatra/assetpack.rb +61 -0
- data/sinatra-assetpack.gemspec +26 -0
- data/test/app/.gitignore +1 -0
- data/test/app/Rakefile +7 -0
- data/test/app/app/css/behavior.htc +1 -0
- data/test/app/app/css/js2c.css +494 -0
- data/test/app/app/css/screen.sass +9 -0
- data/test/app/app/css/sqwishable.css +7 -0
- data/test/app/app/css/style.css +3 -0
- data/test/app/app/css/stylus.styl +3 -0
- data/test/app/app/css_stylus/stylus.styl +3 -0
- data/test/app/app/images/background.jpg +1 -0
- data/test/app/app/images/email.png +0 -0
- data/test/app/app/js/_ignoreme.js +1 -0
- data/test/app/app/js/hello.2.js +1 -0
- data/test/app/app/js/hello.js +1 -0
- data/test/app/app/js/helloe.js +1 -0
- data/test/app/app/js/hi.coffee +2 -0
- data/test/app/app/js/ugly.js +7 -0
- data/test/app/app/js/yoe.coffee +2 -0
- data/test/app/app/js_glob/a/b/c1/hello.js +1 -0
- data/test/app/app/js_glob/a/b/c2/hi.js +1 -0
- data/test/app/app/js_glob/a/b/c2/hola.js +1 -0
- data/test/app/app/views/index.haml +1 -0
- data/test/app/app.rb +67 -0
- data/test/arity_test.rb +26 -0
- data/test/build_test.rb +31 -0
- data/test/cache_test.rb +9 -0
- data/test/combined_test.rb +8 -0
- data/test/compressed_test.rb +30 -0
- data/test/glob_test.rb +42 -0
- data/test/helpers_test.rb +30 -0
- data/test/ignore_test.rb +30 -0
- data/test/img_test.rb +31 -0
- data/test/local_file_test.rb +21 -0
- data/test/mime_type_test.rb +33 -0
- data/test/non_existent_test.rb +45 -0
- data/test/options_test.rb +21 -0
- data/test/order_test.rb +20 -0
- data/test/preproc_test.rb +28 -0
- data/test/redundant_test.rb +11 -0
- data/test/simplecss_test.rb +16 -0
- data/test/sqwish_test.rb +31 -0
- data/test/stylus_test.rb +23 -0
- data/test/template_cache_test.rb +29 -0
- data/test/test_helper.rb +46 -0
- data/test/tilt_test.rb +11 -0
- data/test/uglifier_test.rb +23 -0
- data/test/unit_test.rb +106 -0
- data/test/yui_test.rb +22 -0
- metadata +341 -0
data/test/app/app.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
$:.unshift File.expand_path('../../../lib', __FILE__)
|
2
|
+
|
3
|
+
require 'sinatra/base'
|
4
|
+
require 'sinatra/assetpack'
|
5
|
+
require 'coffee-script'
|
6
|
+
|
7
|
+
class Main < Sinatra::Base
|
8
|
+
set :root, File.dirname(__FILE__)
|
9
|
+
set :views, "#{root}/app/views"
|
10
|
+
|
11
|
+
register Sinatra::AssetPack
|
12
|
+
|
13
|
+
enable :raise_errors
|
14
|
+
disable :show_exceptions
|
15
|
+
|
16
|
+
assets {
|
17
|
+
#serve '/js', :from => 'app/js'
|
18
|
+
serve '/css', :from => 'app/css'
|
19
|
+
serve '/images', :from => 'app/images'
|
20
|
+
|
21
|
+
js :skitch, '/skitch.js', [
|
22
|
+
'/js/hi.js',
|
23
|
+
]
|
24
|
+
|
25
|
+
js :app, '/js/app.js', [
|
26
|
+
'/js/vendor/**/*.js',
|
27
|
+
'/js/assets/**/*.js',
|
28
|
+
'/js/hi.js',
|
29
|
+
'/js/hell*.js'
|
30
|
+
]
|
31
|
+
|
32
|
+
js :encoding, '/js/encoding.js', [
|
33
|
+
'/js/yoe.js',
|
34
|
+
'/js/helloe.js'
|
35
|
+
]
|
36
|
+
|
37
|
+
css :application, '/css/application.css', [
|
38
|
+
'/css/screen.css'
|
39
|
+
]
|
40
|
+
|
41
|
+
css :js2, '/css/js2.css', [
|
42
|
+
'/css/js2c.css'
|
43
|
+
]
|
44
|
+
|
45
|
+
css :sq, '/css/sq.css', [
|
46
|
+
'/css/sqwishable.css'
|
47
|
+
]
|
48
|
+
|
49
|
+
css :redundant, [
|
50
|
+
'/css/scre*.css',
|
51
|
+
'/css/scre*.css',
|
52
|
+
'/css/scre*.css',
|
53
|
+
'/css/screen.css'
|
54
|
+
]
|
55
|
+
}
|
56
|
+
|
57
|
+
get '/index.html' do
|
58
|
+
haml :index
|
59
|
+
end
|
60
|
+
|
61
|
+
get '/helpers/css' do
|
62
|
+
haml %{
|
63
|
+
!= css :application, :media => 'screen'
|
64
|
+
}.strip
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
data/test/arity_test.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class ArityTest < UnitTest
|
4
|
+
class App < UnitTest::App
|
5
|
+
register Sinatra::AssetPack
|
6
|
+
|
7
|
+
assets do |a|
|
8
|
+
a.css :a, '/css/a.css', [
|
9
|
+
'/css/s*.css',
|
10
|
+
'/css/j*.css'
|
11
|
+
]
|
12
|
+
|
13
|
+
a.js_compression :closure
|
14
|
+
a.css_compression = :yui
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
test "arity in #assets" do
|
19
|
+
paths = App.assets.packages['a.css'].paths
|
20
|
+
assert_equal paths,
|
21
|
+
[ "/css/screen.css", "/css/sqwishable.css", "/css/style.css", "/css/stylus.css", "/css/js2c.css" ]
|
22
|
+
|
23
|
+
assert App.assets.js_compression == :closure
|
24
|
+
assert App.assets.css_compression == :yui
|
25
|
+
end
|
26
|
+
end
|
data/test/build_test.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class BuildTest < UnitTest
|
4
|
+
teardown do
|
5
|
+
FileUtils.rm_rf File.join(app.root, 'public')
|
6
|
+
end
|
7
|
+
|
8
|
+
test "build" do
|
9
|
+
Stylus.expects(:compile).returns("body{background:#f00;color:#00f;}")
|
10
|
+
app.assets.css_compression = :simple
|
11
|
+
app.assets.build!
|
12
|
+
|
13
|
+
assert File.file? File.join(app.root, 'public/js/app.js')
|
14
|
+
assert File.mtime(File.join(app.root, 'public/js/app.js')).to_i == app.assets.packages['app.js'].mtime.to_i
|
15
|
+
|
16
|
+
assert Dir[File.join(app.root, 'public/js/app.*.js')].first
|
17
|
+
|
18
|
+
assert File.read(File.join(app.root, 'public/js/app.js')).include?('function(){alert("Hello");')
|
19
|
+
|
20
|
+
assert Dir["#{app.root}/public/images/background.*.jpg"].first
|
21
|
+
assert Dir["#{app.root}/public/images/email.*.png"].first
|
22
|
+
|
23
|
+
assert \
|
24
|
+
File.mtime(Dir["#{app.root}/public/images/background.*.jpg"].first).to_i ==
|
25
|
+
File.mtime(Dir["#{app.root}/public/images/background.jpg"].first).to_i
|
26
|
+
|
27
|
+
assert \
|
28
|
+
File.mtime(Dir["#{app.root}/public/images/background.*.jpg"].first).to_i ==
|
29
|
+
File.mtime(Dir["#{app.root}/app/images/background.jpg"].first).to_i
|
30
|
+
end
|
31
|
+
end
|
data/test/cache_test.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class CompressedTest < UnitTest
|
4
|
+
class App < UnitTest::App
|
5
|
+
register Sinatra::AssetPack
|
6
|
+
|
7
|
+
assets {
|
8
|
+
js :app, '/app.js', [ '/js/*.js' ]
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
def app
|
13
|
+
App
|
14
|
+
end
|
15
|
+
|
16
|
+
test "ha" do
|
17
|
+
get '/x/y/z/app.js'
|
18
|
+
assert last_response.status == 404
|
19
|
+
end
|
20
|
+
|
21
|
+
test "right" do
|
22
|
+
get '/app.js'
|
23
|
+
assert last_response.status == 200
|
24
|
+
end
|
25
|
+
|
26
|
+
test "lol" do
|
27
|
+
get '/app.4872837.js'
|
28
|
+
assert last_response.status == 200
|
29
|
+
end
|
30
|
+
end
|
data/test/glob_test.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class GlobTest < UnitTest
|
4
|
+
class App < UnitTest::App
|
5
|
+
register Sinatra::AssetPack
|
6
|
+
|
7
|
+
assets {
|
8
|
+
serve '/js', :from => 'app/js_glob'
|
9
|
+
js :a, '/a.js', [ '/js/**/*.js' ]
|
10
|
+
js :b, '/b.js', [ '/js/a/b/c2/*.js' ]
|
11
|
+
js :c, '/c.js', [ '/js/a/b/*/*.js' ]
|
12
|
+
}
|
13
|
+
|
14
|
+
get('/a') { js :a }
|
15
|
+
get('/b') { js :b }
|
16
|
+
get('/c') { js :c }
|
17
|
+
end
|
18
|
+
|
19
|
+
def app
|
20
|
+
App
|
21
|
+
end
|
22
|
+
|
23
|
+
should "match double-star globs recursively" do
|
24
|
+
get '/a'
|
25
|
+
assert body.include?("a/b/c1/hello.")
|
26
|
+
assert body.include?("a/b/c2/hi.")
|
27
|
+
assert body.include?("a/b/c2/hola.")
|
28
|
+
end
|
29
|
+
|
30
|
+
should "match single-star globs in filenames" do
|
31
|
+
get '/b'
|
32
|
+
assert body.include?("a/b/c2/hi.")
|
33
|
+
assert body.include?("a/b/c2/hola.")
|
34
|
+
end
|
35
|
+
|
36
|
+
should "match single-star globs in paths" do
|
37
|
+
get '/c'
|
38
|
+
assert body.include?("a/b/c1/hello.")
|
39
|
+
assert body.include?("a/b/c2/hi.")
|
40
|
+
assert body.include?("a/b/c2/hola.")
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class HelpersTest < UnitTest
|
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 }
|
9
|
+
|
10
|
+
test "img non-existing" do
|
11
|
+
get '/helper/foo'
|
12
|
+
assert body == "<img src='/images/foo.jpg' />"
|
13
|
+
end
|
14
|
+
|
15
|
+
test "img existing" do
|
16
|
+
get '/helper/email'
|
17
|
+
assert body =~ %r{src='/images/email.[0-9]+.png'}
|
18
|
+
assert body =~ %r{width='16'}
|
19
|
+
assert body =~ %r{height='16'}
|
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
|
30
|
+
end
|
data/test/ignore_test.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class IgnoreTest < UnitTest
|
4
|
+
class App < UnitTest::App
|
5
|
+
register Sinatra::AssetPack
|
6
|
+
|
7
|
+
assets do
|
8
|
+
js :main, '/main.js', %w[/js/*.js]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def app
|
13
|
+
App
|
14
|
+
end
|
15
|
+
|
16
|
+
test "ignore as individual file" do
|
17
|
+
get '/js/_ignoreme.js'
|
18
|
+
assert last_response.status == 404
|
19
|
+
end
|
20
|
+
|
21
|
+
test "ignore in package" do
|
22
|
+
get '/main.js'
|
23
|
+
assert body.size > 0
|
24
|
+
assert !body.include?("BUMBLEBEE")
|
25
|
+
end
|
26
|
+
|
27
|
+
test "package files" do
|
28
|
+
assert !app.assets.packages['main.js'].files.any? { |s| s.include? '_ignoreme.js' }
|
29
|
+
end
|
30
|
+
end
|
data/test/img_test.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class ImgTest < UnitTest
|
4
|
+
Image = Sinatra::AssetPack::Image
|
5
|
+
|
6
|
+
test "get img" do
|
7
|
+
get '/images/email.png'
|
8
|
+
assert_equal last_response.headers['Content-Length'], File.size(r("/app/images/email.png")).to_s
|
9
|
+
end
|
10
|
+
|
11
|
+
test "get img with cache buster" do
|
12
|
+
get '/images/email.893748.png'
|
13
|
+
assert_equal last_response.headers['Content-Length'], File.size(r("/app/images/email.png")).to_s
|
14
|
+
end
|
15
|
+
|
16
|
+
test "Image[]" do
|
17
|
+
i = Image['/app/images/email.png']
|
18
|
+
j = Image['/app/images/email.png']
|
19
|
+
|
20
|
+
assert j === i
|
21
|
+
end
|
22
|
+
|
23
|
+
test "Image[]" do
|
24
|
+
i = Image['/app/images/email.png']
|
25
|
+
j = Image['/app/images/email.png']
|
26
|
+
|
27
|
+
Image.any_instance.expects(:`).times(1)
|
28
|
+
j.dimensions
|
29
|
+
i.dimensions
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class LocalFileTest < UnitTest
|
4
|
+
class App < UnitTest::App
|
5
|
+
register Sinatra::AssetPack
|
6
|
+
|
7
|
+
assets {
|
8
|
+
css :application, [ '/css/*.css' ]
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
test "local file for (in existing files)" do
|
13
|
+
fn = App.assets.local_file_for '/images/background.jpg'
|
14
|
+
assert_equal r('app/images/background.jpg'), fn
|
15
|
+
end
|
16
|
+
|
17
|
+
test "local file for (in nonexisting files)" do
|
18
|
+
fn = App.assets.local_file_for '/images/404.jpg'
|
19
|
+
assert fn.nil?
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class AppTest < UnitTest
|
4
|
+
test 'htc' do
|
5
|
+
get '/css/behavior.htc'
|
6
|
+
assert last_response.content_type =~ %r[^text/x-component]
|
7
|
+
end
|
8
|
+
|
9
|
+
test 'css - sass' do
|
10
|
+
get '/css/screen.css'
|
11
|
+
assert last_response.content_type =~ %r[^text/css]
|
12
|
+
end
|
13
|
+
|
14
|
+
test 'js' do
|
15
|
+
get '/js/hello.js'
|
16
|
+
assert last_response.content_type =~ %r[^.*?/javascript]
|
17
|
+
end
|
18
|
+
|
19
|
+
test 'js - coffee' do
|
20
|
+
get '/js/hi.js'
|
21
|
+
assert last_response.content_type =~ %r[^.*?/javascript]
|
22
|
+
end
|
23
|
+
|
24
|
+
test 'css - compressed' do
|
25
|
+
get '/css/application.css'
|
26
|
+
assert last_response.content_type =~ %r[^text/css]
|
27
|
+
end
|
28
|
+
|
29
|
+
test 'js - compressed' do
|
30
|
+
get '/skitch.js'
|
31
|
+
assert last_response.content_type =~ %r[^.*?/javascript]
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class NonExistentTest < UnitTest
|
4
|
+
class App < UnitTest::App
|
5
|
+
register Sinatra::AssetPack
|
6
|
+
|
7
|
+
assets do |a|
|
8
|
+
a.js :script, '/script.min.js', [
|
9
|
+
'/js/h*.js',
|
10
|
+
'/js/combine.js'
|
11
|
+
]
|
12
|
+
|
13
|
+
a.js_compression :closure
|
14
|
+
a.css_compression = :yui
|
15
|
+
end
|
16
|
+
|
17
|
+
get '/js/combine.js' do
|
18
|
+
"alert('Spin spin sugar');"
|
19
|
+
end
|
20
|
+
|
21
|
+
get '/' do
|
22
|
+
js :script
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def app
|
27
|
+
App
|
28
|
+
end
|
29
|
+
|
30
|
+
test "non-existent files in js helper" do
|
31
|
+
get '/'
|
32
|
+
assert body.include?('combine.js')
|
33
|
+
end
|
34
|
+
|
35
|
+
test "dev non-existent files in js helper" do
|
36
|
+
App.expects(:environment).returns(:development).times(1..100)
|
37
|
+
get '/'
|
38
|
+
assert body.include?('combine.js')
|
39
|
+
end
|
40
|
+
|
41
|
+
test "non-existent files in js minifier" do
|
42
|
+
get '/script.min.js'
|
43
|
+
assert body.include?('Spin spin sugar')
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class OptionsTest < UnitTest
|
4
|
+
class App < UnitTest::App
|
5
|
+
register Sinatra::AssetPack
|
6
|
+
|
7
|
+
assets {
|
8
|
+
css :application, [ '/css/*.css' ]
|
9
|
+
js_compression :closure
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
def app
|
14
|
+
App
|
15
|
+
end
|
16
|
+
|
17
|
+
test "options" do
|
18
|
+
assert App.assets.js_compression == :closure
|
19
|
+
assert App.assets.packages['application.css'].path == "/assets/application.css"
|
20
|
+
end
|
21
|
+
end
|
data/test/order_test.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class OrderTest < UnitTest
|
4
|
+
class App < UnitTest::App
|
5
|
+
register Sinatra::AssetPack
|
6
|
+
|
7
|
+
assets {
|
8
|
+
css :a, '/css/a.css', [
|
9
|
+
'/css/s*.css',
|
10
|
+
'/css/j*.css'
|
11
|
+
]
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
test "order" do
|
16
|
+
paths = App.assets.packages['a.css'].paths
|
17
|
+
assert_equal paths.sort,
|
18
|
+
[ "/css/screen.css", "/css/sqwishable.css", "/css/style.css", "/css/stylus.css", "/css/js2c.css" ].sort
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class PreprocTest < UnitTest
|
4
|
+
test "preproc" do
|
5
|
+
get '/css/screen.css'
|
6
|
+
assert body =~ %r{email.[0-9]+.png}
|
7
|
+
end
|
8
|
+
|
9
|
+
test "preproc static files" do
|
10
|
+
get '/css/style.css'
|
11
|
+
assert body =~ %r{background.[0-9]+.jpg}
|
12
|
+
end
|
13
|
+
|
14
|
+
test "no cache-busting number for non-existent images" do
|
15
|
+
get '/css/style.css'
|
16
|
+
assert body.include?('background: url(/images/404.png)')
|
17
|
+
end
|
18
|
+
|
19
|
+
test "preproc on minify" do
|
20
|
+
get '/css/application.css'
|
21
|
+
assert body =~ %r{email.[0-9]+.png}
|
22
|
+
end
|
23
|
+
|
24
|
+
test "embed" do
|
25
|
+
get '/css/screen.css'
|
26
|
+
assert body =~ %r{data:image/png;base64,[A-Za-z0-9=/]{100,}}
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class SimplecssTest < UnitTest
|
4
|
+
setup do
|
5
|
+
app.assets.css_compression = :simple
|
6
|
+
end
|
7
|
+
|
8
|
+
teardown do
|
9
|
+
app.assets.css_compression = :simple
|
10
|
+
end
|
11
|
+
|
12
|
+
test "build" do
|
13
|
+
get '/css/js2.css'
|
14
|
+
assert body.include? "op:solid 1px #ddd;padding-top:20px;margin-top:20px;font-size:1em;}#info code{background"
|
15
|
+
end
|
16
|
+
end
|
data/test/sqwish_test.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class SqwishTest < UnitTest
|
4
|
+
setup do
|
5
|
+
app.assets.css_compression :sqwish, :strict => true
|
6
|
+
end
|
7
|
+
|
8
|
+
teardown do
|
9
|
+
app.assets.css_compression :simple
|
10
|
+
app.assets.css_compression_options.delete :strict
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.sqwish?
|
14
|
+
`which sqwish` && true rescue false
|
15
|
+
end
|
16
|
+
|
17
|
+
test "css compression options" do
|
18
|
+
assert app.assets.css_compression_options[:strict] == true
|
19
|
+
end
|
20
|
+
|
21
|
+
if sqwish?
|
22
|
+
test "build" do
|
23
|
+
Sinatra::AssetPack::Compressor
|
24
|
+
Sinatra::AssetPack::SqwishEngine.any_instance.expects(:css)
|
25
|
+
|
26
|
+
get '/css/sq.css'
|
27
|
+
end
|
28
|
+
else
|
29
|
+
puts "(No Sqwish found; skipping sqwish tests)"
|
30
|
+
end
|
31
|
+
end
|
data/test/stylus_test.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class StylusTest < UnitTest
|
4
|
+
class App < UnitTest::App
|
5
|
+
register Sinatra::AssetPack
|
6
|
+
|
7
|
+
assets do |a|
|
8
|
+
a.css :a, '/css/a.css', [
|
9
|
+
'/css/stylus.css'
|
10
|
+
]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def app
|
15
|
+
App
|
16
|
+
end
|
17
|
+
|
18
|
+
test "build" do
|
19
|
+
Stylus.expects(:compile).returns("body{background:#f00;color:#00f;}")
|
20
|
+
get '/css/stylus.css'
|
21
|
+
assert body.gsub(/[ \t\r\n]/, '') == "body{background:#f00;color:#00f;}"
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class TemplateCacheTest < UnitTest
|
4
|
+
class App < UnitTest::App
|
5
|
+
register Sinatra::AssetPack
|
6
|
+
|
7
|
+
set :reload_templates, false
|
8
|
+
assets do |a|
|
9
|
+
a.css :a, '/a.css', %w[/css/screen.css]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def app() App; end
|
14
|
+
|
15
|
+
test "cache dynamic files when reload templates is false" do
|
16
|
+
App.any_instance.expects(:asset_filter_css).times(1).returns "OK"
|
17
|
+
10.times { get '/css/screen.css' }
|
18
|
+
end
|
19
|
+
|
20
|
+
test "cache static css files when reload templates is false" do
|
21
|
+
App.any_instance.expects(:asset_filter_css).times(1).returns "OK"
|
22
|
+
10.times { get '/css/style.css' }
|
23
|
+
end
|
24
|
+
|
25
|
+
test "cache packages when reload templates is false" do
|
26
|
+
Sinatra::AssetPack::Package.any_instance.expects(:minify).times(1).returns "OK"
|
27
|
+
10.times { get '/a.css' }
|
28
|
+
end
|
29
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'contest'
|
2
|
+
require 'jsmin'
|
3
|
+
require 'tilt'
|
4
|
+
require 'stylus'
|
5
|
+
require 'rack/test'
|
6
|
+
require 'yaml'
|
7
|
+
require 'mocha'
|
8
|
+
|
9
|
+
require File.expand_path('../app/app.rb', __FILE__)
|
10
|
+
|
11
|
+
class UnitTest < Test::Unit::TestCase
|
12
|
+
include Rack::Test::Methods
|
13
|
+
|
14
|
+
class App < Sinatra::Base
|
15
|
+
set :root, File.expand_path('../app', __FILE__)
|
16
|
+
enable :raise_errors
|
17
|
+
disable :show_exceptions
|
18
|
+
end
|
19
|
+
|
20
|
+
def app
|
21
|
+
Main
|
22
|
+
end
|
23
|
+
|
24
|
+
def d
|
25
|
+
puts "-"*80
|
26
|
+
puts "#{last_response.status}"
|
27
|
+
y last_response.original_headers
|
28
|
+
puts "-"*80
|
29
|
+
puts ""
|
30
|
+
puts last_response.body.gsub(/^/m, ' ')
|
31
|
+
puts ""
|
32
|
+
end
|
33
|
+
|
34
|
+
def body
|
35
|
+
last_response.body.strip
|
36
|
+
end
|
37
|
+
|
38
|
+
def r(*a)
|
39
|
+
File.join app.root, *a
|
40
|
+
end
|
41
|
+
|
42
|
+
def assert_includes(haystack, needle)
|
43
|
+
assert haystack.include?(needle), "Expected #{haystack.inspect} to include #{needle.inspect}."
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
data/test/tilt_test.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class OptionsTest < UnitTest
|
4
|
+
test "tilt mappings" do
|
5
|
+
@formats = Sinatra::AssetPack.tilt_formats
|
6
|
+
assert @formats['sass'] == 'css'
|
7
|
+
assert @formats['scss'] == 'css'
|
8
|
+
assert @formats['coffee'] == 'js'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|