sinatra-assetpack 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +12 -5
- data/Gemfile.lock +8 -16
- data/HISTORY.md +11 -1
- data/README.md +9 -3
- data/lib/sinatra/assetpack.rb +1 -1
- data/lib/sinatra/assetpack/options.rb +10 -11
- data/lib/sinatra/assetpack/version.rb +1 -1
- data/sinatra-assetpack.gemspec +3 -1
- data/test/app/app.rb +6 -1
- data/test/app/app/js/jquery-1.8.0.min.js +1 -0
- data/test/app/app/packages/a_package/package.css +1 -0
- data/test/app/app/packages/a_package/package.js +1 -0
- data/test/app/app/packages/a_package/package.png +0 -0
- data/test/arity_test.rb +8 -2
- data/test/cache_test.rb +17 -1
- data/test/ignore_test.rb +2 -2
- data/test/sqwish_test.rb +4 -3
- data/test/test_helper.rb +2 -1
- data/test/unit_test.rb +8 -4
- metadata +6 -19
- data/lib/sinatra/assetpack/hasharray.rb +0 -66
data/.travis.yml
CHANGED
@@ -1,8 +1,15 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- "1.9.3"
|
4
|
-
- "1.9.2"
|
5
3
|
- "1.8.7"
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
- "1.9.2"
|
5
|
+
- "1.9.3"
|
6
|
+
- rbx-18mode
|
7
|
+
- rbx-19mode
|
8
|
+
- jruby-18mode
|
9
|
+
- jruby-19mode
|
10
|
+
- jruby-head
|
11
|
+
- ruby-head
|
12
|
+
matrix:
|
13
|
+
allow_failures:
|
14
|
+
- rvm: jruby-head
|
15
|
+
- rvm: ruby-head
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
sinatra-assetpack (0.1.
|
4
|
+
sinatra-assetpack (0.1.2)
|
5
5
|
jsmin
|
6
6
|
rack-test
|
7
7
|
sinatra
|
@@ -18,16 +18,8 @@ GEM
|
|
18
18
|
coffee-script-source
|
19
19
|
execjs
|
20
20
|
coffee-script-source (1.4.0)
|
21
|
-
columnize (0.3.6)
|
22
21
|
commonjs (0.2.6)
|
23
22
|
contest (0.1.3)
|
24
|
-
debugger (1.2.4)
|
25
|
-
columnize (>= 0.3.1)
|
26
|
-
debugger-linecache (~> 1.1.1)
|
27
|
-
debugger-ruby_core_source (~> 1.1.7)
|
28
|
-
debugger-linecache (1.1.2)
|
29
|
-
debugger-ruby_core_source (>= 1.1.1)
|
30
|
-
debugger-ruby_core_source (1.1.7)
|
31
23
|
execjs (1.4.0)
|
32
24
|
multi_json (~> 1.0)
|
33
25
|
haml (3.1.7)
|
@@ -35,22 +27,22 @@ GEM
|
|
35
27
|
less (2.2.2)
|
36
28
|
commonjs (~> 0.2.6)
|
37
29
|
metaclass (0.0.1)
|
38
|
-
mocha (0.13.
|
30
|
+
mocha (0.13.2)
|
39
31
|
metaclass (~> 0.0.1)
|
40
32
|
multi_json (1.5.0)
|
41
33
|
open4 (1.3.0)
|
42
|
-
rack (1.
|
34
|
+
rack (1.5.0)
|
43
35
|
rack-protection (1.3.2)
|
44
36
|
rack
|
45
37
|
rack-test (0.6.2)
|
46
38
|
rack (>= 1.0)
|
47
39
|
rake (10.0.3)
|
48
40
|
sass (3.2.5)
|
49
|
-
sinatra (1.3.
|
50
|
-
rack (~> 1.
|
51
|
-
rack-protection (~> 1.
|
41
|
+
sinatra (1.3.4)
|
42
|
+
rack (~> 1.4)
|
43
|
+
rack-protection (~> 1.3)
|
52
44
|
tilt (~> 1.3, >= 1.3.3)
|
53
|
-
stylus (0.
|
45
|
+
stylus (0.7.0)
|
54
46
|
execjs
|
55
47
|
stylus-source
|
56
48
|
stylus-source (0.31.0)
|
@@ -62,12 +54,12 @@ GEM
|
|
62
54
|
POpen4 (>= 0.1.4)
|
63
55
|
|
64
56
|
PLATFORMS
|
57
|
+
java
|
65
58
|
ruby
|
66
59
|
|
67
60
|
DEPENDENCIES
|
68
61
|
coffee-script
|
69
62
|
contest
|
70
|
-
debugger
|
71
63
|
haml
|
72
64
|
less
|
73
65
|
mocha
|
data/HISTORY.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
v0.1.3 - Feb 3, 2013
|
2
|
+
----------------------
|
3
|
+
|
4
|
+
### Added
|
5
|
+
* JRuby 1.9 and 1.8 now supported.
|
6
|
+
|
7
|
+
### Fixed:
|
8
|
+
* Deal with assets with exact same name but extensions. (#75)
|
9
|
+
* Ruby 1.8 support (broken in previous v0.1 releases).
|
10
|
+
|
1
11
|
v0.1.2 - Jan 20, 2013
|
2
12
|
----------------------
|
3
13
|
|
@@ -39,7 +49,7 @@ v0.0.11 - Feb 21, 2012
|
|
39
49
|
* Built files from 'rake assetpack:build' now match the mtimes of their sources. (#12)
|
40
50
|
* Update the readme with a note on SASS compression.
|
41
51
|
* Use regular expression route matcher instead of splat pattern for Padrino compatibility. (#19)
|
42
|
-
* Made
|
52
|
+
* Made `link` and `script` tags (generated by helpers) be more HTML5-like.
|
43
53
|
|
44
54
|
### Fixed:
|
45
55
|
* Sinatra >= 1.3.0 compatibility. Use 'public_folder' in Sinatra >=1.3.0. (#25)
|
data/README.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# [Sinatra AssetPack](http://ricostacruz.com/sinatra-assetpack)
|
2
|
-
|
2
|
+
|
3
|
+
> Package your assets transparently in Sinatra.
|
4
|
+
|
5
|
+
[![Build Status](https://travis-ci.org/rstacruz/sinatra-assetpack.png)](https://travis-ci.org/rstacruz/sinatra-assetpack)
|
6
|
+
[![Dependency Status](https://gemnasium.com/rstacruz/sinatra-assetpack.png)](https://gemnasium.com/rstacruz/sinatra-assetpack)
|
7
|
+
[![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/rstacruz/sinatra-assetpack)
|
8
|
+
|
9
|
+
How it works
|
10
|
+
------------
|
3
11
|
|
4
12
|
This is *the* most convenient way to set up your CSS/JS (and images) in a
|
5
13
|
[Sinatra](http://sinatrarb.com) app. Seriously. No need for crappy routes to
|
@@ -14,8 +22,6 @@ render Sass or whatever. No-siree!
|
|
14
22
|
messy *script* and *link* tags.
|
15
23
|
5. BOOM! You're in business baby!
|
16
24
|
|
17
|
-
[![Build Status](https://travis-ci.org/rstacruz/sinatra-assetpack.png)](https://travis-ci.org/rstacruz/sinatra-assetpack)
|
18
|
-
|
19
25
|
Installation
|
20
26
|
------------
|
21
27
|
|
data/lib/sinatra/assetpack.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'rack/test'
|
2
|
+
require 'backports' if RUBY_VERSION < "1.9"
|
2
3
|
|
3
4
|
module Sinatra
|
4
5
|
module AssetPack
|
@@ -47,7 +48,6 @@ module Sinatra
|
|
47
48
|
autoload :Image, "#{PREFIX}/assetpack/image"
|
48
49
|
autoload :Css, "#{PREFIX}/assetpack/css"
|
49
50
|
autoload :Configurator, "#{PREFIX}/assetpack/configurator"
|
50
|
-
autoload :HashArray, "#{PREFIX}/assetpack/hasharray"
|
51
51
|
|
52
52
|
include ClassMethods
|
53
53
|
|
@@ -246,22 +246,21 @@ module Sinatra
|
|
246
246
|
# Returns nil if a file is not found.
|
247
247
|
# TODO: consolidate with local_file_for
|
248
248
|
def dyn_local_file_for(requested_file, from)
|
249
|
-
# Remove extension
|
250
249
|
file = requested_file
|
251
|
-
extension =
|
252
|
-
|
253
|
-
file.
|
254
|
-
|
255
|
-
|
256
|
-
file = $1 if file =~ /^(.*)\.[0-9]+$/
|
257
|
-
|
250
|
+
extension = File.extname(requested_file)
|
251
|
+
# Remove extension
|
252
|
+
file.gsub!(/#{extension}$/, "")
|
253
|
+
# Remove cache-buster (/js/app.28389 => /js/app)
|
254
|
+
file.gsub!(/\.[0-9]+$/, "")
|
258
255
|
matches = Dir[File.join(app.root, from, "#{file}.*")]
|
259
256
|
|
260
257
|
# Fix for filenames with dots (can't do this with glob)
|
261
258
|
matches.select! { |f| f =~ /#{file}\.[^.]+$/ }
|
262
259
|
|
263
|
-
# Sort static file match
|
264
|
-
matches.sort!
|
260
|
+
# Sort static file match, weighting exact file extension matches
|
261
|
+
matches.sort! do |f, _|
|
262
|
+
(File.basename(f) == "#{file}#{extension}" || File.extname(f) == extension) ? -1 : 1
|
263
|
+
end
|
265
264
|
matches.first
|
266
265
|
end
|
267
266
|
|
@@ -320,7 +319,7 @@ module Sinatra
|
|
320
319
|
paths = paths.uniq
|
321
320
|
tuples = paths.map { |key| [key, files[key]] }
|
322
321
|
|
323
|
-
|
322
|
+
Hash[*tuples.flatten]
|
324
323
|
end
|
325
324
|
|
326
325
|
private
|
data/sinatra-assetpack.gemspec
CHANGED
@@ -15,6 +15,9 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.add_dependency "sinatra"
|
16
16
|
s.add_dependency "jsmin"
|
17
17
|
s.add_dependency "rack-test"
|
18
|
+
if RUBY_VERSION < "1.9"
|
19
|
+
s.add_runtime_dependency "backports"
|
20
|
+
end
|
18
21
|
s.add_development_dependency "yui-compressor"
|
19
22
|
s.add_development_dependency "sass"
|
20
23
|
s.add_development_dependency "haml"
|
@@ -25,5 +28,4 @@ Gem::Specification.new do |s|
|
|
25
28
|
s.add_development_dependency "uglifier"
|
26
29
|
s.add_development_dependency "rake"
|
27
30
|
s.add_development_dependency "less"
|
28
|
-
s.add_development_dependency "debugger"
|
29
31
|
end
|
data/test/app/app.rb
CHANGED
@@ -14,10 +14,15 @@ class Main < Sinatra::Base
|
|
14
14
|
disable :show_exceptions
|
15
15
|
|
16
16
|
assets {
|
17
|
-
|
17
|
+
serve '/js', :from => 'app/js'
|
18
18
|
serve '/css', :from => 'app/css'
|
19
19
|
serve '/images', :from => 'app/images'
|
20
20
|
serve '/fonts', :from => 'app/fonts'
|
21
|
+
serve '/packages', :from => 'app/packages'
|
22
|
+
|
23
|
+
js :a_package, '/packages/a_package.js', [
|
24
|
+
'/packages/a_package/package.js',
|
25
|
+
]
|
21
26
|
|
22
27
|
js :skitch, '/skitch.js', [
|
23
28
|
'/js/hi.js',
|
@@ -0,0 +1 @@
|
|
1
|
+
$(function() { alert("Hello"); });
|
@@ -0,0 +1 @@
|
|
1
|
+
.hi { color: red; }
|
@@ -0,0 +1 @@
|
|
1
|
+
$(function() { alert("Hello"); });
|
Binary file
|
data/test/arity_test.rb
CHANGED
@@ -17,8 +17,14 @@ class ArityTest < UnitTest
|
|
17
17
|
|
18
18
|
test "arity in #assets" do
|
19
19
|
paths = App.assets.packages['a.css'].paths
|
20
|
-
|
21
|
-
|
20
|
+
expect = [ "/css/screen.css", "/css/sqwishable.css", "/css/style.css", "/css/stylus.css", "/css/js2c.css" ]
|
21
|
+
if RUBY_VERSION < "1.9"
|
22
|
+
# In 1.8.7 glob returns inconsitent files order so just check array are equivalents
|
23
|
+
assert_equal expect.size, paths.size
|
24
|
+
assert_equal 0, paths.reject{ |p| expect.include?(p) }.size
|
25
|
+
else
|
26
|
+
assert_equal expect, paths
|
27
|
+
end
|
22
28
|
|
23
29
|
assert App.assets.js_compression == :closure
|
24
30
|
assert App.assets.css_compression == :yui
|
data/test/cache_test.rb
CHANGED
@@ -1,8 +1,24 @@
|
|
1
1
|
require File.expand_path('../test_helper', __FILE__)
|
2
2
|
|
3
3
|
class CacheTest < UnitTest
|
4
|
+
class App < UnitTest::App
|
5
|
+
register Sinatra::AssetPack
|
6
|
+
|
7
|
+
set :reload_templates, false
|
8
|
+
assets {
|
9
|
+
js :app, '/js/app.js', [
|
10
|
+
'/js/vendor/**/*.js',
|
11
|
+
'/js/assets/**/*.js',
|
12
|
+
'/js/hi.js',
|
13
|
+
'/js/hell*.js'
|
14
|
+
]
|
15
|
+
js_compression :jsmin
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def app() App; end
|
20
|
+
|
4
21
|
test "Compressed js caching" do
|
5
|
-
app.set :reload_templates, false
|
6
22
|
JSMin.expects(:minify).times(1).returns ""
|
7
23
|
3.times { get '/js/app.js' }
|
8
24
|
end
|
data/test/ignore_test.rb
CHANGED
@@ -20,8 +20,8 @@ class IgnoreTest < UnitTest
|
|
20
20
|
|
21
21
|
test "ignore in package" do
|
22
22
|
get '/main.js'
|
23
|
-
assert body.size > 0
|
24
|
-
assert !body.include?("BUMBLEBEE")
|
23
|
+
assert last_response.body.size > 0
|
24
|
+
assert !last_response.body.include?("BUMBLEBEE")
|
25
25
|
end
|
26
26
|
|
27
27
|
test "package files" do
|
data/test/sqwish_test.rb
CHANGED
@@ -2,6 +2,7 @@ require File.expand_path('../test_helper', __FILE__)
|
|
2
2
|
|
3
3
|
class SqwishTest < UnitTest
|
4
4
|
setup do
|
5
|
+
app.set :reload_templates, true
|
5
6
|
app.assets.css_compression :sqwish, :strict => true
|
6
7
|
end
|
7
8
|
|
@@ -20,10 +21,10 @@ class SqwishTest < UnitTest
|
|
20
21
|
|
21
22
|
if sqwish?
|
22
23
|
test "build" do
|
23
|
-
|
24
|
-
Sinatra::AssetPack::SqwishEngine.any_instance.expects(:css)
|
25
|
-
|
24
|
+
swqished_css = '#bg{background:green;color:red}'
|
25
|
+
Sinatra::AssetPack::SqwishEngine.any_instance.expects(:css).returns swqished_css
|
26
26
|
get '/css/sq.css'
|
27
|
+
assert body == swqished_css
|
27
28
|
end
|
28
29
|
else
|
29
30
|
puts "(No Sqwish found; skipping sqwish tests)"
|
data/test/test_helper.rb
CHANGED
data/test/unit_test.rb
CHANGED
@@ -49,6 +49,11 @@ class AppTest < UnitTest
|
|
49
49
|
assert last_response.status == 404
|
50
50
|
end
|
51
51
|
|
52
|
+
test 'returns file of requested type when mixed type assets of varying extension are present' do
|
53
|
+
get '/packages/a_package.010101.js'
|
54
|
+
assert body.include? 'function(){alert("Hello");'
|
55
|
+
end
|
56
|
+
|
52
57
|
test 'static css' do
|
53
58
|
get '/css/style.css'
|
54
59
|
assert body.include?('div { color: red; }')
|
@@ -77,10 +82,9 @@ class AppTest < UnitTest
|
|
77
82
|
assert body =~ /<script src='\/js\/app.[0-9]+.js'><\/script>/
|
78
83
|
end
|
79
84
|
|
80
|
-
test "
|
81
|
-
get '/js/
|
82
|
-
assert body.include? 'function(){alert("Hello");'
|
83
|
-
assert_includes body, "var x;x=function(){"
|
85
|
+
test "file with multiple dots in name" do
|
86
|
+
get '/js/jquery-1.8.0.min.js'
|
87
|
+
assert body.include? '$(function() { alert("Hello"); });'
|
84
88
|
end
|
85
89
|
|
86
90
|
test "compressed js with cache bust" do
|
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.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-02-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: tilt
|
@@ -235,22 +235,6 @@ dependencies:
|
|
235
235
|
- !ruby/object:Gem::Version
|
236
236
|
version: '0'
|
237
237
|
none: false
|
238
|
-
- !ruby/object:Gem::Dependency
|
239
|
-
name: debugger
|
240
|
-
prerelease: false
|
241
|
-
requirement: !ruby/object:Gem::Requirement
|
242
|
-
requirements:
|
243
|
-
- - ! '>='
|
244
|
-
- !ruby/object:Gem::Version
|
245
|
-
version: '0'
|
246
|
-
none: false
|
247
|
-
type: :development
|
248
|
-
version_requirements: !ruby/object:Gem::Requirement
|
249
|
-
requirements:
|
250
|
-
- - ! '>='
|
251
|
-
- !ruby/object:Gem::Version
|
252
|
-
version: '0'
|
253
|
-
none: false
|
254
238
|
description: Package your assets for Sinatra.
|
255
239
|
email:
|
256
240
|
- rico@sinefunc.com
|
@@ -308,7 +292,6 @@ files:
|
|
308
292
|
- lib/sinatra/assetpack/engines/sqwish.rb
|
309
293
|
- lib/sinatra/assetpack/engines/uglify.rb
|
310
294
|
- lib/sinatra/assetpack/engines/yui.rb
|
311
|
-
- lib/sinatra/assetpack/hasharray.rb
|
312
295
|
- lib/sinatra/assetpack/helpers.rb
|
313
296
|
- lib/sinatra/assetpack/html_helpers.rb
|
314
297
|
- lib/sinatra/assetpack/image.rb
|
@@ -338,11 +321,15 @@ files:
|
|
338
321
|
- test/app/app/js/hello.js
|
339
322
|
- test/app/app/js/helloe.js
|
340
323
|
- test/app/app/js/hi.coffee
|
324
|
+
- test/app/app/js/jquery-1.8.0.min.js
|
341
325
|
- test/app/app/js/ugly.js
|
342
326
|
- test/app/app/js/yoe.coffee
|
343
327
|
- test/app/app/js_glob/a/b/c1/hello.js
|
344
328
|
- test/app/app/js_glob/a/b/c2/hi.js
|
345
329
|
- test/app/app/js_glob/a/b/c2/hola.js
|
330
|
+
- test/app/app/packages/a_package/package.css
|
331
|
+
- test/app/app/packages/a_package/package.js
|
332
|
+
- test/app/app/packages/a_package/package.png
|
346
333
|
- test/app/app/views/index.haml
|
347
334
|
- test/app/config.ru
|
348
335
|
- test/arity_test.rb
|
@@ -1,66 +0,0 @@
|
|
1
|
-
module Sinatra
|
2
|
-
module AssetPack
|
3
|
-
# Class: HashArray
|
4
|
-
# A stopgap solution to Ruby 1.8's lack of ordered hashes.
|
5
|
-
#
|
6
|
-
# A HashArray, for all intents and purposes, acts like an array. However, the
|
7
|
-
# common stuff are overloaded to work with hashes.
|
8
|
-
#
|
9
|
-
# ## Basic usage
|
10
|
-
#
|
11
|
-
# #### Creating
|
12
|
-
# You can create a HashArray by passing it an array.
|
13
|
-
#
|
14
|
-
# dict = HashArray.new([
|
15
|
-
# { :good_morning => "Bonjour" },
|
16
|
-
# { :goodbye => "Au revoir" },
|
17
|
-
# { :good_evening => "Bon nuit" }
|
18
|
-
# ])
|
19
|
-
#
|
20
|
-
# #### Converting
|
21
|
-
# You may also use it like so:
|
22
|
-
#
|
23
|
-
# letters = [ { :a => "Aye"}, { :b => "Bee" } ].to_hash_array
|
24
|
-
#
|
25
|
-
# #### Iterating
|
26
|
-
# Now you can use the typical enumerator functions:
|
27
|
-
#
|
28
|
-
# dict.each do |(key, value)|
|
29
|
-
# puts "#{key} is #{value}"
|
30
|
-
# end
|
31
|
-
#
|
32
|
-
# #=> :good_morning is "Bonjour"
|
33
|
-
# # :goodbye is "Au revoir"
|
34
|
-
# # :good_evening is "Bon nuit"
|
35
|
-
#
|
36
|
-
class HashArray < Array
|
37
|
-
def self.[](*arr)
|
38
|
-
new arr.each_slice(2).map { |(k, v)| Hash[k, v] }
|
39
|
-
end
|
40
|
-
|
41
|
-
# Works like Hash#values.
|
42
|
-
def values
|
43
|
-
inject([]) { |a, (k, v)| a << v; a }
|
44
|
-
end
|
45
|
-
|
46
|
-
# Returns everything as a hash.
|
47
|
-
def to_hash
|
48
|
-
inject({}) { |hash, (k, v)| hash[k] = v; hash }
|
49
|
-
end
|
50
|
-
|
51
|
-
def keys
|
52
|
-
inject([]) { |a, (k, v)| a << k; a }
|
53
|
-
end
|
54
|
-
|
55
|
-
[:each, :map, :map!, :reject, :reject!, :select, :select!].each do |meth|
|
56
|
-
send(:define_method, meth) { |*a, &block|
|
57
|
-
if block.respond_to?(:call)
|
58
|
-
super(*a) { |hash| block.call *hash.to_a }
|
59
|
-
else
|
60
|
-
super(*a)
|
61
|
-
end
|
62
|
-
}
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|