sinatra-assetpack 0.1.7 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- checksums.yaml.gz.sig +1 -0
- data.tar.gz.sig +2 -2
- data/CONTRIBUTING.md +1 -1
- data/Gemfile.lock +9 -7
- data/HISTORY.md +12 -0
- data/README.md +1 -8
- data/lib/sinatra/assetpack.rb +6 -0
- data/lib/sinatra/assetpack/buster_helpers.rb +3 -4
- data/lib/sinatra/assetpack/class_methods.rb +18 -3
- data/lib/sinatra/assetpack/engines/simple.rb +5 -0
- data/lib/sinatra/assetpack/html_helpers.rb +7 -3
- data/lib/sinatra/assetpack/options.rb +1 -1
- data/lib/sinatra/assetpack/package.rb +3 -3
- data/lib/sinatra/assetpack/version.rb +1 -1
- data/sinatra-assetpack.gemspec +2 -3
- data/test/app/app/js/{jquery-1.8.0.min.js → lib-3.2.1.min.js} +0 -0
- data/test/app/app/js/vendor/jquery-1.8.0.min.js +1 -0
- data/test/asset_host_test.rb +77 -0
- data/test/buster_helpers_test.rb +27 -0
- data/test/cache_test.rb +4 -0
- data/test/compressed_test.rb +1 -1
- data/test/helpers_test.rb +13 -2
- data/test/img_test.rb +1 -1
- data/test/non_existent_test.rb +6 -0
- data/test/preproc_test.rb +12 -3
- data/test/simplejs_test.rb +17 -0
- data/test/unit_test.rb +29 -20
- metadata +24 -36
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZmU3MmU3YTlhMzhjZDYzZGZhMzRjMTY3YTA1MjUxNTFkYzVjMGQ1Yg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NTBlNDcyMGJlMzc5MmFkZjc4NzAxMTljODI1OThkMGJjOTliOWY5Nw==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MjIxZWJlMzQzMmFlOGI4MTdhNmJhNDhkYTkxMjU3YWM1NzdjOTQxZTc2ZjVh
|
10
|
+
YjEzMTMyZTAyNmFhNDIzMTRhZjIyYWRiYmQ3OWIwNDZhMDljMjg1MWVhYjE0
|
11
|
+
M2UyNTRkY2U2NzQ4YWUyOWEyZmM2YmY2MjdkNWY2NTc1YTdjMmI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MjFjN2EyZmQ4YjY0MWM1ZWI4OWIyMjlhNzY5MzJlNjEzMzhiOTNhNmEzM2Zl
|
14
|
+
NGY5NzBjYTgwZGI3ZTY0OTgxNDI3MzY1NDFmYWUzYTE0YTgyNWZjMDI1MDll
|
15
|
+
OTQyZDIxMWZiZjMxYTk1NWUyYmVhMTU5NGMwNTAzYTA1MjcyN2M=
|
checksums.yaml.gz.sig
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
v��o�������-n�eS�d��|����Fa��=g>��:Z�%���(�Z���^r�s�#�y����{�S�cr-/A�C�߯/�[J���`B��{D�YZ~M���W-':F�^���<���~؎�\nnn3�/��9MC �iTy���:}T�Qz�x}Oj�p�]*+�=����bC��J&���@�O �v)0��ɾ^�Ly���+,�-;7E�t%�_!��[_�"@���y��V�ڭ%�
|
data.tar.gz.sig
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
�?�g�y,㉾�q|����U��96[�g����,�%%B�I\�?��e��?}���;^������5m����M�����^�ɧ�q���v�&xA�<$��*��)�zK<��m���al<��@���>}�J+���Ic百ڀ-jY�
|
2
|
+
�7ɐ5�%��=�+[�-<bYM��T����GjS�����i��'2��!�
|
data/CONTRIBUTING.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
sinatra-assetpack (0.
|
4
|
+
sinatra-assetpack (0.2.0)
|
5
|
+
backports
|
5
6
|
jsmin
|
6
7
|
rack-test
|
7
8
|
sinatra
|
@@ -14,6 +15,7 @@ GEM
|
|
14
15
|
Platform (>= 0.4.0)
|
15
16
|
open4
|
16
17
|
Platform (0.4.0)
|
18
|
+
backports (3.3.0)
|
17
19
|
coffee-script (2.2.0)
|
18
20
|
coffee-script-source
|
19
21
|
execjs
|
@@ -30,19 +32,19 @@ GEM
|
|
30
32
|
metaclass (0.0.1)
|
31
33
|
mocha (0.13.3)
|
32
34
|
metaclass (~> 0.0.1)
|
33
|
-
multi_json (1.
|
35
|
+
multi_json (1.7.0)
|
34
36
|
open4 (1.3.0)
|
35
37
|
rack (1.5.2)
|
36
|
-
rack-protection (1.
|
38
|
+
rack-protection (1.5.0)
|
37
39
|
rack
|
38
40
|
rack-test (0.6.2)
|
39
41
|
rack (>= 1.0)
|
40
42
|
rake (10.0.3)
|
41
43
|
sass (3.2.7)
|
42
|
-
sinatra (1.
|
43
|
-
rack (~> 1.
|
44
|
-
rack-protection (~> 1.
|
45
|
-
tilt (~> 1.3, >= 1.3.
|
44
|
+
sinatra (1.4.2)
|
45
|
+
rack (~> 1.5, >= 1.5.2)
|
46
|
+
rack-protection (~> 1.4)
|
47
|
+
tilt (~> 1.3, >= 1.3.4)
|
46
48
|
stylus (0.7.1)
|
47
49
|
execjs
|
48
50
|
stylus-source
|
data/HISTORY.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
v0.2.0 - April 20, 2013
|
2
|
+
----------------------
|
3
|
+
|
4
|
+
### Changed
|
5
|
+
* Using MD5 for cache busting URI. (#91, #71)
|
6
|
+
|
7
|
+
### Added
|
8
|
+
* Add :simple compression for javascript. (#87)
|
9
|
+
|
10
|
+
### Fixed
|
11
|
+
* Added backports correctly for 1.8.7 support.
|
12
|
+
|
1
13
|
v0.1.7 - March 11, 2013
|
2
14
|
----------------------
|
3
15
|
|
data/README.md
CHANGED
@@ -26,14 +26,7 @@ render Sass or whatever. No-siree!
|
|
26
26
|
Installation
|
27
27
|
------------
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
``` console
|
32
|
-
$ gem install sinatra-assetpack
|
33
|
-
```
|
34
|
-
|
35
|
-
#### Bundler users
|
36
|
-
If you use Bundler, you will need to add it to your *Gemfile*.
|
29
|
+
Add to your `Gemfile` :
|
37
30
|
|
38
31
|
``` ruby
|
39
32
|
gem 'sinatra-assetpack', :require => 'sinatra/assetpack'
|
data/lib/sinatra/assetpack.rb
CHANGED
@@ -35,6 +35,12 @@ module Sinatra
|
|
35
35
|
out
|
36
36
|
end
|
37
37
|
|
38
|
+
# Clear Tilt::Cache (used for primarily for tests)
|
39
|
+
def self.clear_tilt_cache!(cache, app)
|
40
|
+
cache.clear
|
41
|
+
#app.clear_tilt_cache = false # Maybe it can be an option on app we can enable/disable?
|
42
|
+
end
|
43
|
+
|
38
44
|
PREFIX = File.dirname(__FILE__)
|
39
45
|
|
40
46
|
autoload :ClassMethods, "#{PREFIX}/assetpack/class_methods"
|
@@ -2,11 +2,10 @@ module Sinatra
|
|
2
2
|
module AssetPack
|
3
3
|
module BusterHelpers
|
4
4
|
extend self
|
5
|
-
# Returns the
|
6
|
-
# This implementation somewhat obfuscates the mtime to not reveal deployment dates.
|
5
|
+
# Returns the MD5 for all of the files concatenated together
|
7
6
|
def cache_buster_hash(*files)
|
8
|
-
|
9
|
-
(
|
7
|
+
content = files.sort.map { |f| File.read(f).to_s if f.is_a?(String) && File.file?(f) }.compact
|
8
|
+
Digest::MD5.hexdigest(content.join) if content.any?
|
10
9
|
end
|
11
10
|
|
12
11
|
# Returns the maximum mtime for a given list of files.
|
@@ -24,6 +24,10 @@ module Sinatra
|
|
24
24
|
def add_compressed_routes!
|
25
25
|
assets.packages.each do |name, package|
|
26
26
|
get package.route_regex do
|
27
|
+
if defined?(settings.assets.app.clear_tilt_cache) && settings.assets.app.clear_tilt_cache
|
28
|
+
AssetPack.clear_tilt_cache!(@template_cache, settings.assets.app)
|
29
|
+
end
|
30
|
+
|
27
31
|
mtime, contents = @template_cache.fetch(package.path) {
|
28
32
|
[ package.mtime, package.minify ]
|
29
33
|
}
|
@@ -42,11 +46,19 @@ module Sinatra
|
|
42
46
|
get %r{#{"^/#{path}/".squeeze('/')}(.*)$} do |file|
|
43
47
|
fmt = File.extname(file)[1..-1]
|
44
48
|
|
49
|
+
if file =~ /(.*)\.([a-f0-9]{32})\.(.*)/
|
50
|
+
clean_file = "#{$1}.#{$3}"
|
51
|
+
requested_hash = $2
|
52
|
+
else
|
53
|
+
clean_file = file
|
54
|
+
end
|
55
|
+
|
45
56
|
# Sanity checks
|
46
57
|
pass unless AssetPack.supported_formats.include?(fmt)
|
47
|
-
fn = asset_path_for(file, from) or pass
|
48
58
|
|
49
|
-
|
59
|
+
fn = asset_path_for(clean_file, from) or pass
|
60
|
+
|
61
|
+
pass if settings.assets.ignored?("#{path}/#{clean_file}")
|
50
62
|
|
51
63
|
# Send headers
|
52
64
|
content_type fmt.to_sym
|
@@ -55,6 +67,10 @@ module Sinatra
|
|
55
67
|
|
56
68
|
format = File.extname(fn)[1..-1]
|
57
69
|
|
70
|
+
if defined?(settings.assets.app.clear_tilt_cache) && settings.assets.app.clear_tilt_cache
|
71
|
+
AssetPack.clear_tilt_cache!(@template_cache, settings.assets.app)
|
72
|
+
end
|
73
|
+
|
58
74
|
if AssetPack.supported_formats.include?(format)
|
59
75
|
# Static file
|
60
76
|
if fmt == 'css'
|
@@ -77,7 +93,6 @@ module Sinatra
|
|
77
93
|
end
|
78
94
|
end
|
79
95
|
end
|
80
|
-
|
81
96
|
end
|
82
97
|
end
|
83
98
|
end
|
@@ -18,10 +18,14 @@ module Sinatra
|
|
18
18
|
|
19
19
|
local = assets.local_file_for file
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
hosts = assets.asset_hosts
|
22
|
+
dev = assets.app.settings.development?
|
23
|
+
file = dev ? file : BusterHelpers.add_cache_buster(file, local)
|
24
|
+
|
25
|
+
if assets.asset_hosts.nil? || dev
|
26
|
+
file
|
23
27
|
else
|
24
|
-
|
28
|
+
hosts[Digest::MD5.hexdigest(file).to_i(16) % hosts.length]+file
|
25
29
|
end
|
26
30
|
end
|
27
31
|
end
|
@@ -252,7 +252,7 @@ module Sinatra
|
|
252
252
|
# Remove extension
|
253
253
|
file.gsub!(/#{extension}$/, "")
|
254
254
|
# Remove cache-buster (/js/app.28389 => /js/app)
|
255
|
-
file.gsub!(/\.[
|
255
|
+
file.gsub!(/\.[a-f0-9]{32}$/, "")
|
256
256
|
matches = Dir[File.join(app.root, from, "#{file}.*")]
|
257
257
|
|
258
258
|
# Fix for filenames with dots (can't do this with glob)
|
@@ -54,15 +54,15 @@ module Sinatra
|
|
54
54
|
BusterHelpers.mtime_for(files)
|
55
55
|
end
|
56
56
|
|
57
|
-
# Returns the regex for the route, including cache buster
|
57
|
+
# Returns the regex for the route, including cache buster.
|
58
58
|
def route_regex
|
59
|
-
re = @path.gsub(/(.[^.]+)$/) { |ext| "(?:\.[
|
59
|
+
re = @path.gsub(/(.[^.]+)$/) { |ext| "(?:\.[a-f0-9]{32})?#{ext}" }
|
60
60
|
/^#{re}$/
|
61
61
|
end
|
62
62
|
|
63
63
|
def to_development_html(options={})
|
64
64
|
paths_and_files.map { |path, file|
|
65
|
-
path = add_cache_buster(path, file)
|
65
|
+
path = add_cache_buster(path, file)
|
66
66
|
link_tag(path, options)
|
67
67
|
}.join("\n")
|
68
68
|
end
|
data/sinatra-assetpack.gemspec
CHANGED
@@ -17,9 +17,8 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.add_dependency "sinatra"
|
18
18
|
s.add_dependency "jsmin"
|
19
19
|
s.add_dependency "rack-test"
|
20
|
-
|
21
|
-
|
22
|
-
end
|
20
|
+
s.add_dependency "backports"
|
21
|
+
|
23
22
|
s.add_development_dependency "yui-compressor"
|
24
23
|
s.add_development_dependency "sass"
|
25
24
|
s.add_development_dependency "haml"
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
$(function() { alert("Hello"); });
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class AssetHostTest < UnitTest
|
4
|
+
class TestApp < UnitTest::App
|
5
|
+
register Sinatra::AssetPack
|
6
|
+
|
7
|
+
set :root, File.join(File.dirname(__FILE__), "app")
|
8
|
+
|
9
|
+
assets {
|
10
|
+
serve '/css', :from => 'app/css'
|
11
|
+
serve '/js', :from => 'app/js'
|
12
|
+
serve '/images', :from => 'app/images'
|
13
|
+
|
14
|
+
asset_hosts [
|
15
|
+
'//cdn-0.example.org',
|
16
|
+
'//cdn-1.example.org'
|
17
|
+
]
|
18
|
+
|
19
|
+
css :a, ["/css/style.css"]
|
20
|
+
js :b, ["/js/hello.js"]
|
21
|
+
}
|
22
|
+
|
23
|
+
get('/helper/img') { img '/images/background.jpg' }
|
24
|
+
end
|
25
|
+
|
26
|
+
def app
|
27
|
+
TestApp
|
28
|
+
end
|
29
|
+
|
30
|
+
test "hosts sets option" do
|
31
|
+
assert app.assets.asset_hosts.include? '//cdn-0.example.org'
|
32
|
+
assert app.assets.asset_hosts.include? '//cdn-1.example.org'
|
33
|
+
end
|
34
|
+
|
35
|
+
test "host gets added to css source path" do
|
36
|
+
app.stubs(:development?).returns(false)
|
37
|
+
assert TestApp.assets.packages['a.css'].to_production_html =~ %r{href='//cdn-[0|1].example.org/assets/a.[a-f0-9]{32}.css'}
|
38
|
+
end
|
39
|
+
|
40
|
+
test "host gets added to js source path" do
|
41
|
+
app.stubs(:development?).returns(false)
|
42
|
+
assert TestApp.assets.packages['b.js'].to_production_html =~ %r{src='//cdn-[0|1].example.org/assets/b.[a-f0-9]{32}.js'}
|
43
|
+
end
|
44
|
+
|
45
|
+
test "host gets added to image helper path in production" do
|
46
|
+
app.stubs(:development?).returns(false)
|
47
|
+
get '/helper/img'
|
48
|
+
assert body =~ /<img src='\/\/cdn-[0|1].example.org\/images\/background.[a-f0-9]{32}.jpg' \/>/
|
49
|
+
end
|
50
|
+
|
51
|
+
test "host doesn't get added to image helper path in development" do
|
52
|
+
app.stubs(:development?).returns(true)
|
53
|
+
get '/helper/img'
|
54
|
+
assert body =~ /<img src='\/images\/background.jpg' \/>/
|
55
|
+
end
|
56
|
+
|
57
|
+
test "host gets added to css image path in production" do
|
58
|
+
app.stubs(:development?).returns(false)
|
59
|
+
get '/css/style.css'
|
60
|
+
assert body.include?('background: url(//cdn-1.example.org/images/background.b1946ac92492d2347c6235b4d2611184.jpg)')
|
61
|
+
|
62
|
+
# does not alter non-existing files (design or flaw???)
|
63
|
+
assert body.include?('background: url(/images/404.png)')
|
64
|
+
end
|
65
|
+
|
66
|
+
test "do not add asset host to filename in dev mode" do
|
67
|
+
app.stubs(:development?).returns(true)
|
68
|
+
file = '/js/hello.js'
|
69
|
+
assert !(Sinatra::AssetPack::HtmlHelpers.get_file_uri(file, TestApp.assets) =~ /cdn-[0|1].example.org/)
|
70
|
+
end
|
71
|
+
|
72
|
+
test "add asset host to filename in production/qa mode" do
|
73
|
+
app.stubs(:development?).returns(false)
|
74
|
+
file = '/js/hello.js'
|
75
|
+
assert Sinatra::AssetPack::HtmlHelpers.get_file_uri(file, TestApp.assets) =~ /cdn-[0|1].example.org/
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class BusterHelpersTest < UnitTest
|
4
|
+
include Sinatra::AssetPack
|
5
|
+
|
6
|
+
test "adds md5 to name for one file" do
|
7
|
+
filename = BusterHelpers.add_cache_buster '/css/style.css', asset('css/style.css')
|
8
|
+
assert_equal '/css/style.7a1b92c3f56ab5cfa73c1aa8222961cf.css', filename
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
test "adds md5 to name for multiple files" do
|
13
|
+
filename = BusterHelpers.add_cache_buster '/css/style.css', asset('css/style.css'), asset('css/js2c.css')
|
14
|
+
assert_equal '/css/style.4400cb67aeffa49b8fe18bc4e0187f86.css', filename
|
15
|
+
end
|
16
|
+
|
17
|
+
test "doesn't add md5 for non-existent file" do
|
18
|
+
assert_equal '/css/style.css', BusterHelpers.add_cache_buster('/css/style.css', 'asdf')
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def asset(file)
|
24
|
+
File.expand_path(File.dirname(__FILE__)) + '/app/app/' + file
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
data/test/cache_test.rb
CHANGED
@@ -19,6 +19,10 @@ class CacheTest < UnitTest
|
|
19
19
|
def app() App; end
|
20
20
|
|
21
21
|
test "Compressed js caching" do
|
22
|
+
app.set :reload_templates, false
|
23
|
+
app.stubs(:clear_tilt_cache).returns(false) # return false each time it calls after the first time.
|
24
|
+
app.expects(:clear_tilt_cache).returns(true).times(1) # clear cache one time.
|
25
|
+
|
22
26
|
JSMin.expects(:minify).times(1).returns ""
|
23
27
|
3.times { get '/js/app.js' }
|
24
28
|
end
|
data/test/compressed_test.rb
CHANGED
data/test/helpers_test.rb
CHANGED
@@ -12,9 +12,20 @@ class HelpersTest < UnitTest
|
|
12
12
|
assert body == "<img src='/images/foo.jpg' />"
|
13
13
|
end
|
14
14
|
|
15
|
-
test "img existing" do
|
15
|
+
test "img existing (development)" do
|
16
|
+
app.stubs(:development?).returns(true)
|
16
17
|
get '/helper/email'
|
17
|
-
|
18
|
+
|
19
|
+
assert body =~ %r{src='/images/email.png'}
|
20
|
+
assert body =~ %r{width='16'}
|
21
|
+
assert body =~ %r{height='16'}
|
22
|
+
end
|
23
|
+
|
24
|
+
test "img existing (production)" do
|
25
|
+
app.stubs(:development?).returns(false)
|
26
|
+
get '/helper/email'
|
27
|
+
|
28
|
+
assert body =~ %r{src='/images/email.[a-f0-9]{32}.png'}
|
18
29
|
assert body =~ %r{width='16'}
|
19
30
|
assert body =~ %r{height='16'}
|
20
31
|
end
|
data/test/img_test.rb
CHANGED
@@ -9,7 +9,7 @@ class ImgTest < UnitTest
|
|
9
9
|
end
|
10
10
|
|
11
11
|
test "get img with cache buster" do
|
12
|
-
get '/images/email.
|
12
|
+
get '/images/email.7a1b92c3f56ab5cfa73c1aa8222961cf.png'
|
13
13
|
assert_equal last_response.headers['Content-Length'], File.size(r("/app/images/email.png")).to_s
|
14
14
|
end
|
15
15
|
|
data/test/non_existent_test.rb
CHANGED
@@ -42,4 +42,10 @@ class NonExistentTest < UnitTest
|
|
42
42
|
get '/script.min.js'
|
43
43
|
assert body.include?('Spin spin sugar')
|
44
44
|
end
|
45
|
+
|
46
|
+
test "non-existant asset hosts" do
|
47
|
+
file = File.join(app.root, 'app/js/hello.js')
|
48
|
+
|
49
|
+
assert_equal(app.root + '/app/js/hello.js', Sinatra::AssetPack::HtmlHelpers.get_file_uri(file, App.assets))
|
50
|
+
end
|
45
51
|
end
|
data/test/preproc_test.rb
CHANGED
@@ -2,26 +2,35 @@ require File.expand_path('../test_helper', __FILE__)
|
|
2
2
|
|
3
3
|
class PreprocTest < UnitTest
|
4
4
|
test "preproc" do
|
5
|
+
app.stubs(:clear_tilt_cache).returns(true)
|
6
|
+
app.stubs(:development?).returns(false)
|
5
7
|
get '/css/screen.css'
|
6
|
-
assert body =~ %r{email.[
|
8
|
+
assert body =~ %r{email.[a-f0-9]{32}.png}
|
7
9
|
end
|
8
10
|
|
9
11
|
test "preproc static files" do
|
12
|
+
app.stubs(:clear_cache).returns(true)
|
13
|
+
app.stubs(:development?).returns(false)
|
10
14
|
get '/css/style.css'
|
11
|
-
assert body =~ %r{background.[
|
15
|
+
assert body =~ %r{background.[a-f0-9]{32}.jpg}
|
12
16
|
end
|
13
17
|
|
14
18
|
test "no cache-busting number for non-existent images" do
|
19
|
+
app.stubs(:development?).returns(false)
|
15
20
|
get '/css/style.css'
|
16
21
|
assert body.include?('background: url(/images/404.png)')
|
17
22
|
end
|
18
23
|
|
19
24
|
test "preproc on minify" do
|
25
|
+
app.stubs(:clear_cache).returns(true)
|
26
|
+
app.stubs(:development?).returns(false)
|
20
27
|
get '/css/application.css'
|
21
|
-
assert body =~ %r{email.[
|
28
|
+
assert body =~ %r{email.[a-f0-9]{32}.png}
|
22
29
|
end
|
23
30
|
|
24
31
|
test "embed" do
|
32
|
+
app.stubs(:clear_cache).returns(true)
|
33
|
+
app.stubs(:development?).returns(false)
|
25
34
|
get '/css/screen.css'
|
26
35
|
assert body =~ %r{data:image/png;base64,[A-Za-z0-9=/]{100,}}
|
27
36
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class SimplejsTest < UnitTest
|
4
|
+
setup do
|
5
|
+
app.set :reload_templates, true
|
6
|
+
app.assets.js_compression = :simple
|
7
|
+
end
|
8
|
+
|
9
|
+
teardown do
|
10
|
+
app.assets.js_compression = :jsmin
|
11
|
+
end
|
12
|
+
|
13
|
+
test "build" do
|
14
|
+
get '/js/app.js'
|
15
|
+
assert body.include? ");\n\n$(function("
|
16
|
+
end
|
17
|
+
end
|
data/test/unit_test.rb
CHANGED
@@ -17,19 +17,15 @@ class AppTest < UnitTest
|
|
17
17
|
assert last_response.status == 404
|
18
18
|
end
|
19
19
|
|
20
|
-
test '/js/hello.
|
21
|
-
get '/js/hello.
|
20
|
+
test '/js/hello.b1946ac92492d2347c6235b4d2611184.js (with cache buster)' do
|
21
|
+
get '/js/hello.b1946ac92492d2347c6235b4d2611184.js'
|
22
|
+
assert_equal 200, last_response.status
|
22
23
|
assert body == '$(function() { alert("Hello"); });'
|
23
24
|
end
|
24
25
|
|
25
|
-
test '/js/
|
26
|
-
get '/js/
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
test '/js/hi.2834987.js (coffeescript with cache buster)' do
|
31
|
-
get '/js/hi.283947.js'
|
32
|
-
assert last_response.status == 200
|
26
|
+
test '/js/hi.24dcf1d7835ed64640370d52967631f8.js (coffeescript with cache buster)' do
|
27
|
+
get '/js/hi.24dcf1d7835ed64640370d52967631f8.js'
|
28
|
+
assert_equal 200, last_response.status
|
33
29
|
assert body.include? 'yo'
|
34
30
|
assert body.include? 'x = function'
|
35
31
|
end
|
@@ -50,7 +46,7 @@ class AppTest < UnitTest
|
|
50
46
|
end
|
51
47
|
|
52
48
|
test 'returns file of requested type when mixed type assets of varying extension are present' do
|
53
|
-
get '/packages/a_package.
|
49
|
+
get '/packages/a_package.b1946ac92492d2347c6235b4d2611184.js'
|
54
50
|
assert body.include? 'function(){alert("Hello");'
|
55
51
|
end
|
56
52
|
|
@@ -71,24 +67,30 @@ class AppTest < UnitTest
|
|
71
67
|
end
|
72
68
|
|
73
69
|
test "helpers" do
|
70
|
+
app.settings.stubs(:environment).returns(:development)
|
74
71
|
get '/index.html'
|
75
|
-
assert body =~ /<script src='\/js\/hello.
|
76
|
-
assert body =~ /<script src='\/js\/hi.
|
72
|
+
assert body =~ /<script src='\/js\/hello.8ac1b67adf7fa68c1c3b81791b3e116c.js'><\/script>/
|
73
|
+
assert body =~ /<script src='\/js\/hi.24dcf1d7835ed64640370d52967631f8.js'><\/script>/
|
77
74
|
end
|
78
75
|
|
79
76
|
test "helpers in production (compressed html thingie)" do
|
80
|
-
app.
|
77
|
+
app.settings.stubs(:environment).returns(:production)
|
81
78
|
get '/index.html'
|
82
|
-
assert body =~ /<script src='\/js\/app.[
|
79
|
+
assert body =~ /<script src='\/js\/app.[a-f0-9]{32}.js'><\/script>/
|
83
80
|
end
|
84
81
|
|
85
82
|
test "file with multiple dots in name" do
|
86
|
-
get '/js/
|
83
|
+
get '/js/lib-3.2.1.min.js'
|
84
|
+
assert body.include? '$(function() { alert("Hello"); });'
|
85
|
+
end
|
86
|
+
|
87
|
+
test "file in folder glob" do
|
88
|
+
get '/js/vendor/jquery-1.8.0.min.js'
|
87
89
|
assert body.include? '$(function() { alert("Hello"); });'
|
88
90
|
end
|
89
91
|
|
90
92
|
test "compressed js with cache bust" do
|
91
|
-
get '/js/app.
|
93
|
+
get '/js/app.b1946ac92492d2347c6235b4d2611184.js'
|
92
94
|
assert body.include? 'function(){alert("Hello");'
|
93
95
|
assert_includes body, "var x;x=function(){"
|
94
96
|
end
|
@@ -99,13 +101,20 @@ class AppTest < UnitTest
|
|
99
101
|
end
|
100
102
|
|
101
103
|
test "compressed css with cache bust" do
|
102
|
-
get '/css/application.
|
104
|
+
get '/css/application.b1946ac92492d2347c6235b4d2611184.css'
|
103
105
|
assert_includes body, "rgba(0,0,255,0.3)"
|
104
106
|
end
|
105
107
|
|
106
|
-
test "helpers css" do
|
108
|
+
test "helpers css (development)" do
|
109
|
+
app.settings.stubs(:environment).returns(:development)
|
110
|
+
get '/helpers/css'
|
111
|
+
assert body =~ %r{link rel='stylesheet' href='/css/screen.efa279aa02235f0a587791c1ac5d99b9.css' media='screen'}
|
112
|
+
end
|
113
|
+
|
114
|
+
test "helpers css (production)" do
|
115
|
+
app.settings.stubs(:environment).returns(:production)
|
107
116
|
get '/helpers/css'
|
108
|
-
assert body =~ %r{link rel='stylesheet' href='/css/
|
117
|
+
assert body =~ %r{link rel='stylesheet' href='/css/application.[a-f0-9]{32}.css' media='screen'}
|
109
118
|
end
|
110
119
|
|
111
120
|
test 'default expiration of single assets' do
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-assetpack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Rico Sta. Cruz
|
@@ -37,12 +36,11 @@ cert_chain:
|
|
37
36
|
MjN3ZTRFMUx2ZlJuNWdWNzdEaWo2czlWNEhIek1CdUx3bk5iOFQrNmxPblVX
|
38
37
|
YnRpSWRkRAplOGM4aTdQbHJ6aFZKLzhzWFVKc0NreUU4ZDJNeVJ5amx4TT0K
|
39
38
|
LS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo=
|
40
|
-
date: 2013-
|
39
|
+
date: 2013-04-20 00:00:00.000000000 Z
|
41
40
|
dependencies:
|
42
41
|
- !ruby/object:Gem::Dependency
|
43
42
|
name: tilt
|
44
43
|
requirement: !ruby/object:Gem::Requirement
|
45
|
-
none: false
|
46
44
|
requirements:
|
47
45
|
- - ! '>='
|
48
46
|
- !ruby/object:Gem::Version
|
@@ -50,7 +48,6 @@ dependencies:
|
|
50
48
|
type: :runtime
|
51
49
|
prerelease: false
|
52
50
|
version_requirements: !ruby/object:Gem::Requirement
|
53
|
-
none: false
|
54
51
|
requirements:
|
55
52
|
- - ! '>='
|
56
53
|
- !ruby/object:Gem::Version
|
@@ -58,7 +55,6 @@ dependencies:
|
|
58
55
|
- !ruby/object:Gem::Dependency
|
59
56
|
name: sinatra
|
60
57
|
requirement: !ruby/object:Gem::Requirement
|
61
|
-
none: false
|
62
58
|
requirements:
|
63
59
|
- - ! '>='
|
64
60
|
- !ruby/object:Gem::Version
|
@@ -66,7 +62,6 @@ dependencies:
|
|
66
62
|
type: :runtime
|
67
63
|
prerelease: false
|
68
64
|
version_requirements: !ruby/object:Gem::Requirement
|
69
|
-
none: false
|
70
65
|
requirements:
|
71
66
|
- - ! '>='
|
72
67
|
- !ruby/object:Gem::Version
|
@@ -74,7 +69,6 @@ dependencies:
|
|
74
69
|
- !ruby/object:Gem::Dependency
|
75
70
|
name: jsmin
|
76
71
|
requirement: !ruby/object:Gem::Requirement
|
77
|
-
none: false
|
78
72
|
requirements:
|
79
73
|
- - ! '>='
|
80
74
|
- !ruby/object:Gem::Version
|
@@ -82,7 +76,6 @@ dependencies:
|
|
82
76
|
type: :runtime
|
83
77
|
prerelease: false
|
84
78
|
version_requirements: !ruby/object:Gem::Requirement
|
85
|
-
none: false
|
86
79
|
requirements:
|
87
80
|
- - ! '>='
|
88
81
|
- !ruby/object:Gem::Version
|
@@ -90,7 +83,6 @@ dependencies:
|
|
90
83
|
- !ruby/object:Gem::Dependency
|
91
84
|
name: rack-test
|
92
85
|
requirement: !ruby/object:Gem::Requirement
|
93
|
-
none: false
|
94
86
|
requirements:
|
95
87
|
- - ! '>='
|
96
88
|
- !ruby/object:Gem::Version
|
@@ -98,7 +90,20 @@ dependencies:
|
|
98
90
|
type: :runtime
|
99
91
|
prerelease: false
|
100
92
|
version_requirements: !ruby/object:Gem::Requirement
|
101
|
-
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: backports
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
102
107
|
requirements:
|
103
108
|
- - ! '>='
|
104
109
|
- !ruby/object:Gem::Version
|
@@ -106,7 +111,6 @@ dependencies:
|
|
106
111
|
- !ruby/object:Gem::Dependency
|
107
112
|
name: yui-compressor
|
108
113
|
requirement: !ruby/object:Gem::Requirement
|
109
|
-
none: false
|
110
114
|
requirements:
|
111
115
|
- - ! '>='
|
112
116
|
- !ruby/object:Gem::Version
|
@@ -114,7 +118,6 @@ dependencies:
|
|
114
118
|
type: :development
|
115
119
|
prerelease: false
|
116
120
|
version_requirements: !ruby/object:Gem::Requirement
|
117
|
-
none: false
|
118
121
|
requirements:
|
119
122
|
- - ! '>='
|
120
123
|
- !ruby/object:Gem::Version
|
@@ -122,7 +125,6 @@ dependencies:
|
|
122
125
|
- !ruby/object:Gem::Dependency
|
123
126
|
name: sass
|
124
127
|
requirement: !ruby/object:Gem::Requirement
|
125
|
-
none: false
|
126
128
|
requirements:
|
127
129
|
- - ! '>='
|
128
130
|
- !ruby/object:Gem::Version
|
@@ -130,7 +132,6 @@ dependencies:
|
|
130
132
|
type: :development
|
131
133
|
prerelease: false
|
132
134
|
version_requirements: !ruby/object:Gem::Requirement
|
133
|
-
none: false
|
134
135
|
requirements:
|
135
136
|
- - ! '>='
|
136
137
|
- !ruby/object:Gem::Version
|
@@ -138,7 +139,6 @@ dependencies:
|
|
138
139
|
- !ruby/object:Gem::Dependency
|
139
140
|
name: haml
|
140
141
|
requirement: !ruby/object:Gem::Requirement
|
141
|
-
none: false
|
142
142
|
requirements:
|
143
143
|
- - ! '>='
|
144
144
|
- !ruby/object:Gem::Version
|
@@ -146,7 +146,6 @@ dependencies:
|
|
146
146
|
type: :development
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
|
-
none: false
|
150
149
|
requirements:
|
151
150
|
- - ! '>='
|
152
151
|
- !ruby/object:Gem::Version
|
@@ -154,7 +153,6 @@ dependencies:
|
|
154
153
|
- !ruby/object:Gem::Dependency
|
155
154
|
name: coffee-script
|
156
155
|
requirement: !ruby/object:Gem::Requirement
|
157
|
-
none: false
|
158
156
|
requirements:
|
159
157
|
- - ! '>='
|
160
158
|
- !ruby/object:Gem::Version
|
@@ -162,7 +160,6 @@ dependencies:
|
|
162
160
|
type: :development
|
163
161
|
prerelease: false
|
164
162
|
version_requirements: !ruby/object:Gem::Requirement
|
165
|
-
none: false
|
166
163
|
requirements:
|
167
164
|
- - ! '>='
|
168
165
|
- !ruby/object:Gem::Version
|
@@ -170,7 +167,6 @@ dependencies:
|
|
170
167
|
- !ruby/object:Gem::Dependency
|
171
168
|
name: contest
|
172
169
|
requirement: !ruby/object:Gem::Requirement
|
173
|
-
none: false
|
174
170
|
requirements:
|
175
171
|
- - ! '>='
|
176
172
|
- !ruby/object:Gem::Version
|
@@ -178,7 +174,6 @@ dependencies:
|
|
178
174
|
type: :development
|
179
175
|
prerelease: false
|
180
176
|
version_requirements: !ruby/object:Gem::Requirement
|
181
|
-
none: false
|
182
177
|
requirements:
|
183
178
|
- - ! '>='
|
184
179
|
- !ruby/object:Gem::Version
|
@@ -186,7 +181,6 @@ dependencies:
|
|
186
181
|
- !ruby/object:Gem::Dependency
|
187
182
|
name: mocha
|
188
183
|
requirement: !ruby/object:Gem::Requirement
|
189
|
-
none: false
|
190
184
|
requirements:
|
191
185
|
- - ! '>='
|
192
186
|
- !ruby/object:Gem::Version
|
@@ -194,7 +188,6 @@ dependencies:
|
|
194
188
|
type: :development
|
195
189
|
prerelease: false
|
196
190
|
version_requirements: !ruby/object:Gem::Requirement
|
197
|
-
none: false
|
198
191
|
requirements:
|
199
192
|
- - ! '>='
|
200
193
|
- !ruby/object:Gem::Version
|
@@ -202,7 +195,6 @@ dependencies:
|
|
202
195
|
- !ruby/object:Gem::Dependency
|
203
196
|
name: stylus
|
204
197
|
requirement: !ruby/object:Gem::Requirement
|
205
|
-
none: false
|
206
198
|
requirements:
|
207
199
|
- - ! '>='
|
208
200
|
- !ruby/object:Gem::Version
|
@@ -210,7 +202,6 @@ dependencies:
|
|
210
202
|
type: :development
|
211
203
|
prerelease: false
|
212
204
|
version_requirements: !ruby/object:Gem::Requirement
|
213
|
-
none: false
|
214
205
|
requirements:
|
215
206
|
- - ! '>='
|
216
207
|
- !ruby/object:Gem::Version
|
@@ -218,7 +209,6 @@ dependencies:
|
|
218
209
|
- !ruby/object:Gem::Dependency
|
219
210
|
name: uglifier
|
220
211
|
requirement: !ruby/object:Gem::Requirement
|
221
|
-
none: false
|
222
212
|
requirements:
|
223
213
|
- - ! '>='
|
224
214
|
- !ruby/object:Gem::Version
|
@@ -226,7 +216,6 @@ dependencies:
|
|
226
216
|
type: :development
|
227
217
|
prerelease: false
|
228
218
|
version_requirements: !ruby/object:Gem::Requirement
|
229
|
-
none: false
|
230
219
|
requirements:
|
231
220
|
- - ! '>='
|
232
221
|
- !ruby/object:Gem::Version
|
@@ -234,7 +223,6 @@ dependencies:
|
|
234
223
|
- !ruby/object:Gem::Dependency
|
235
224
|
name: rake
|
236
225
|
requirement: !ruby/object:Gem::Requirement
|
237
|
-
none: false
|
238
226
|
requirements:
|
239
227
|
- - ! '>='
|
240
228
|
- !ruby/object:Gem::Version
|
@@ -242,7 +230,6 @@ dependencies:
|
|
242
230
|
type: :development
|
243
231
|
prerelease: false
|
244
232
|
version_requirements: !ruby/object:Gem::Requirement
|
245
|
-
none: false
|
246
233
|
requirements:
|
247
234
|
- - ! '>='
|
248
235
|
- !ruby/object:Gem::Version
|
@@ -250,7 +237,6 @@ dependencies:
|
|
250
237
|
- !ruby/object:Gem::Dependency
|
251
238
|
name: less
|
252
239
|
requirement: !ruby/object:Gem::Requirement
|
253
|
-
none: false
|
254
240
|
requirements:
|
255
241
|
- - ! '>='
|
256
242
|
- !ruby/object:Gem::Version
|
@@ -258,7 +244,6 @@ dependencies:
|
|
258
244
|
type: :development
|
259
245
|
prerelease: false
|
260
246
|
version_requirements: !ruby/object:Gem::Requirement
|
261
|
-
none: false
|
262
247
|
requirements:
|
263
248
|
- - ! '>='
|
264
249
|
- !ruby/object:Gem::Version
|
@@ -351,8 +336,9 @@ files:
|
|
351
336
|
- test/app/app/js/hello.js
|
352
337
|
- test/app/app/js/helloe.js
|
353
338
|
- test/app/app/js/hi.coffee
|
354
|
-
- test/app/app/js/
|
339
|
+
- test/app/app/js/lib-3.2.1.min.js
|
355
340
|
- test/app/app/js/ugly.js
|
341
|
+
- test/app/app/js/vendor/jquery-1.8.0.min.js
|
356
342
|
- test/app/app/js/yoe.coffee
|
357
343
|
- test/app/app/js_glob/a/b/c1/hello.js
|
358
344
|
- test/app/app/js_glob/a/b/c2/hi.js
|
@@ -363,7 +349,9 @@ files:
|
|
363
349
|
- test/app/app/views/index.haml
|
364
350
|
- test/app/config.ru
|
365
351
|
- test/arity_test.rb
|
352
|
+
- test/asset_host_test.rb
|
366
353
|
- test/build_test.rb
|
354
|
+
- test/buster_helpers_test.rb
|
367
355
|
- test/cache_test.rb
|
368
356
|
- test/combined_test.rb
|
369
357
|
- test/compressed_test.rb
|
@@ -379,6 +367,7 @@ files:
|
|
379
367
|
- test/preproc_test.rb
|
380
368
|
- test/redundant_test.rb
|
381
369
|
- test/simplecss_test.rb
|
370
|
+
- test/simplejs_test.rb
|
382
371
|
- test/sqwish_test.rb
|
383
372
|
- test/stylus_test.rb
|
384
373
|
- test/template_cache_test.rb
|
@@ -389,26 +378,25 @@ files:
|
|
389
378
|
- test/yui_test.rb
|
390
379
|
homepage: http://github.com/rstacruz/sinatra-assetpack
|
391
380
|
licenses: []
|
381
|
+
metadata: {}
|
392
382
|
post_install_message:
|
393
383
|
rdoc_options: []
|
394
384
|
require_paths:
|
395
385
|
- lib
|
396
386
|
required_ruby_version: !ruby/object:Gem::Requirement
|
397
|
-
none: false
|
398
387
|
requirements:
|
399
388
|
- - ! '>='
|
400
389
|
- !ruby/object:Gem::Version
|
401
390
|
version: '0'
|
402
391
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
403
|
-
none: false
|
404
392
|
requirements:
|
405
393
|
- - ! '>='
|
406
394
|
- !ruby/object:Gem::Version
|
407
395
|
version: '0'
|
408
396
|
requirements: []
|
409
397
|
rubyforge_project:
|
410
|
-
rubygems_version:
|
398
|
+
rubygems_version: 2.0.3
|
411
399
|
signing_key:
|
412
|
-
specification_version:
|
400
|
+
specification_version: 4
|
413
401
|
summary: Asset packager for Sinatra.
|
414
402
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|