sinatra-assetpack 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile +2 -0
  3. data/HISTORY.md +45 -0
  4. data/README.md +248 -0
  5. data/Rakefile +3 -0
  6. data/example/.gitignore +1 -0
  7. data/example/Rakefile +7 -0
  8. data/example/app.rb +28 -0
  9. data/example/app/css/test.sass +11 -0
  10. data/example/app/images/icon.png +0 -0
  11. data/example/app/js/app.js +3 -0
  12. data/example/app/js/vendor/jquery.js +2 -0
  13. data/example/app/js/vendor/jquery.plugin.js +2 -0
  14. data/example/app/js/vendor/underscore.js +2 -0
  15. data/example/views/index.erb +26 -0
  16. data/lib/sinatra/assetpack.rb +55 -0
  17. data/lib/sinatra/assetpack/buster_helpers.rb +21 -0
  18. data/lib/sinatra/assetpack/class_methods.rb +68 -0
  19. data/lib/sinatra/assetpack/compressor.rb +109 -0
  20. data/lib/sinatra/assetpack/configurator.rb +15 -0
  21. data/lib/sinatra/assetpack/css.rb +35 -0
  22. data/lib/sinatra/assetpack/hasharray.rb +70 -0
  23. data/lib/sinatra/assetpack/helpers.rb +48 -0
  24. data/lib/sinatra/assetpack/html_helpers.rb +17 -0
  25. data/lib/sinatra/assetpack/image.rb +37 -0
  26. data/lib/sinatra/assetpack/options.rb +223 -0
  27. data/lib/sinatra/assetpack/package.rb +111 -0
  28. data/lib/sinatra/assetpack/rake.rb +23 -0
  29. data/lib/sinatra/assetpack/version.rb +7 -0
  30. data/sinatra-assetpack.gemspec +23 -0
  31. data/test/app/.gitignore +1 -0
  32. data/test/app/Rakefile +7 -0
  33. data/test/app/app.rb +51 -0
  34. data/test/app/app/css/js2c.css +494 -0
  35. data/test/app/app/css/screen.sass +9 -0
  36. data/test/app/app/css/sqwishable.css +7 -0
  37. data/test/app/app/css/style.css +2 -0
  38. data/test/app/app/images/background.jpg +1 -0
  39. data/test/app/app/images/email.png +0 -0
  40. data/test/app/app/js/hello.js +1 -0
  41. data/test/app/app/js/hi.coffee +2 -0
  42. data/test/app/app/views/index.haml +1 -0
  43. data/test/build_test.rb +20 -0
  44. data/test/cache_test.rb +10 -0
  45. data/test/helpers_test.rb +23 -0
  46. data/test/img_test.rb +13 -0
  47. data/test/options_test.rb +17 -0
  48. data/test/order_test.rb +21 -0
  49. data/test/preproc_test.rb +23 -0
  50. data/test/simplecss_test.rb +16 -0
  51. data/test/sqwish_test.rb +29 -0
  52. data/test/test_helper.rb +38 -0
  53. data/test/unit_test.rb +96 -0
  54. data/test/yui_test.rb +22 -0
  55. metadata +200 -0
@@ -0,0 +1,9 @@
1
+ #background
2
+ color: rgba(blue, 0.3)
3
+
4
+ #email
5
+ background: url(/images/email.png)
6
+ background-repeat: no-repeat
7
+
8
+ #sidebar
9
+ background: url(/images/email.png?embed)
@@ -0,0 +1,7 @@
1
+ #bg {
2
+ color: red;
3
+ }
4
+
5
+ #bg {
6
+ background: green;
7
+ }
@@ -0,0 +1,2 @@
1
+ div { color: red; }
2
+ body { background: url(/images/background.jpg); }
@@ -0,0 +1 @@
1
+ hello
@@ -0,0 +1 @@
1
+ $(function() { alert("Hello"); });
@@ -0,0 +1,2 @@
1
+ x = ->
2
+ alert 'yo'
@@ -0,0 +1 @@
1
+ != js :app
@@ -0,0 +1,20 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ class BuildTest < UnitTest
4
+ teardown do
5
+ FileUtils.rm_rf app.public
6
+ end
7
+
8
+ test "build" do
9
+ app.assets.css_compression = :simple
10
+ app.assets.build!
11
+
12
+ assert File.file? File.join(app.root, 'public/js/app.js')
13
+ assert Dir[File.join(app.root, 'public/js/app.*.js')].first
14
+
15
+ assert File.read(File.join(app.root, 'public/js/app.js')).include?('function(){alert("Hello");')
16
+
17
+ assert Dir["#{app.root}/public/images/background.*.jpg"].first
18
+ assert Dir["#{app.root}/public/images/email.*.png"].first
19
+ end
20
+ end
@@ -0,0 +1,10 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ class CacheTest < UnitTest
4
+ test "Compressed js caching" do
5
+ app.assets.reset_cache
6
+ # JSMin.expects(:minify).times(1) -- not working?
7
+ get '/js/app.js'
8
+ get '/js/app.js'
9
+ end
10
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ class HelpersTest < UnitTest
4
+ Main.get '/img/foo' do
5
+ img '/images/foo.jpg'
6
+ end
7
+
8
+ Main.get '/img/email' do
9
+ img '/images/email.png'
10
+ end
11
+
12
+ test "img non-existing" do
13
+ get '/img/foo'
14
+ assert body == "<img src='/images/foo.jpg' />"
15
+ end
16
+
17
+ test "img existing" do
18
+ get '/img/email'
19
+ assert body =~ %r{src='/images/email.[0-9]+.png'}
20
+ assert body =~ %r{width='16'}
21
+ assert body =~ %r{height='16'}
22
+ end
23
+ end
@@ -0,0 +1,13 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ class ImgTest < UnitTest
4
+ test "get img" do
5
+ get '/images/email.png'
6
+ assert_equal last_response.headers['Content-Length'], File.size(r("/app/images/email.png")).to_s
7
+ end
8
+
9
+ test "get img with cache buster" do
10
+ get '/images/email.893748.png'
11
+ assert_equal last_response.headers['Content-Length'], File.size(r("/app/images/email.png")).to_s
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+
4
+ class OptionsTest < UnitTest
5
+ class App < Sinatra::Base
6
+ set :root, File.dirname(__FILE__)
7
+ register Sinatra::AssetPack
8
+
9
+ assets {
10
+ js_compression :closure
11
+ }
12
+ end
13
+
14
+ test "options" do
15
+ assert App.assets.js_compression == :closure
16
+ end
17
+ end
@@ -0,0 +1,21 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ class OrderTest < UnitTest
4
+ class App < Sinatra::Base
5
+ set :root, File.expand_path('../app', __FILE__)
6
+ register Sinatra::AssetPack
7
+
8
+ assets {
9
+ css :a, '/css/a.css', [
10
+ '/css/s*.css',
11
+ '/css/j*.css'
12
+ ]
13
+ }
14
+ end
15
+
16
+ test "order" do
17
+ paths = App.assets.packages['a.css'].paths
18
+ assert paths ==
19
+ ["/css/screen.css", "/css/sqwishable.css", "/css/style.css", "/css/js2c.css"]
20
+ end
21
+ end
@@ -0,0 +1,23 @@
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 "preproc on minify" do
15
+ get '/css/application.css'
16
+ assert body =~ %r{email.[0-9]+.png}
17
+ end
18
+
19
+ test "embed" do
20
+ get '/css/screen.css'
21
+ assert body =~ %r{data:image/png;base64,[A-Za-z0-9=/]{100,}}
22
+ end
23
+ 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
@@ -0,0 +1,29 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ class Sqwish < UnitTest
4
+ setup do
5
+ app.assets.css_compression = :sqwish
6
+ app.assets.css_compression_options[:strict] = true
7
+ end
8
+
9
+ teardown do
10
+ app.assets.css_compression = :simple
11
+ app.assets.css_compression_options.delete :strict
12
+ end
13
+
14
+ def self.sqwish?
15
+ `which sqwish` && true rescue false
16
+ end
17
+
18
+ if sqwish?
19
+ test "build" do
20
+ Sinatra::AssetPack::Compressor.expects(:`).with() { |cmd|
21
+ cmd.match /^sqwish .*? --strict$/
22
+ }
23
+
24
+ get '/css/sq.css'
25
+ end
26
+ else
27
+ puts "(No Sqwish found; skipping sqwish tests)"
28
+ end
29
+ end
@@ -0,0 +1,38 @@
1
+ require 'contest'
2
+ require 'jsmin'
3
+ require 'rack/test'
4
+ require 'yaml'
5
+ require 'mocha'
6
+
7
+ require File.expand_path('../app/app.rb', __FILE__)
8
+
9
+ class UnitTest < Test::Unit::TestCase
10
+ include Rack::Test::Methods
11
+
12
+ def app
13
+ Main
14
+ end
15
+
16
+ def d
17
+ puts "-"*80
18
+ puts "#{last_response.status}"
19
+ y last_response.original_headers
20
+ puts "-"*80
21
+ puts ""
22
+ puts last_response.body.gsub(/^/m, ' ')
23
+ puts ""
24
+ end
25
+
26
+ def body
27
+ last_response.body.strip
28
+ end
29
+
30
+ def r(*a)
31
+ File.join app.root, *a
32
+ end
33
+
34
+ def assert_includes(haystack, needle)
35
+ assert haystack.include?(needle), "Expected #{haystack.inspect} to include #{needle.inspect}."
36
+ end
37
+ end
38
+
@@ -0,0 +1,96 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ class AppTest < UnitTest
4
+ test '/js/hello.js (plain js)' do
5
+ get '/js/hello.js'
6
+ assert body == '$(function() { alert("Hello"); });'
7
+ end
8
+
9
+ test '/js/hi.js (coffeescript)' do
10
+ get '/js/hi.js'
11
+ assert body.include? 'yo'
12
+ assert body.include? 'x = function'
13
+ end
14
+
15
+ test '/js/hi.css (404)' do
16
+ get '/js/hi.css'
17
+ assert last_response.status == 404
18
+ end
19
+
20
+ test '/js/hi.2834987.js (with cache buster)' do
21
+ get '/js/hello.283947.js'
22
+ assert body == '$(function() { alert("Hello"); });'
23
+ end
24
+
25
+ test '/js/hi.2834987.js (coffeescript with cache buster)' do
26
+ get '/js/hi.283947.js'
27
+ assert last_response.status == 200
28
+ assert body.include? 'yo'
29
+ assert body.include? 'x = function'
30
+ end
31
+
32
+ test 'wrong extension for static file' do
33
+ get '/js/hello.css'
34
+ assert last_response.status == 404
35
+ end
36
+
37
+ test 'wrong extension for dynamic coffeescript file' do
38
+ get '/js/hi.css'
39
+ assert last_response.status == 404
40
+ end
41
+
42
+ test 'static css' do
43
+ get '/css/style.css'
44
+ assert body.include?('div { color: red; }')
45
+ end
46
+
47
+ test 'sass' do
48
+ get '/css/screen.css'
49
+ assert body =~ /background.*rgba.*255.*0.3/m
50
+ end
51
+
52
+ test "match" do
53
+ files = app.assets.files
54
+ assert files['/css/screen.css'] =~ /app\/css\/screen.sass/
55
+ assert files['/js/hi.js'] =~ /app\/js\/hi.coffee/
56
+ end
57
+
58
+ test "helpers" do
59
+ get '/index.html'
60
+ assert body =~ /<script type='text\/javascript' src='\/js\/hello.[0-9]+.js'><\/script>/
61
+ assert body =~ /<script type='text\/javascript' src='\/js\/hi.[0-9]+.js'><\/script>/
62
+ end
63
+
64
+ test "helpers in production (compressed html thingie)" do
65
+ app.expects(:production?).returns(true)
66
+ get '/index.html'
67
+ assert body =~ /<script type='text\/javascript' src='\/js\/app.[0-9]+.js'><\/script>/
68
+ end
69
+
70
+ test "compressed js" do
71
+ get '/js/app.js'
72
+ assert body.include? 'function(){alert("Hello");'
73
+ assert_includes body, "var x;x=function(){"
74
+ end
75
+
76
+ test "compressed js with cache bust" do
77
+ get '/js/app.38987.js'
78
+ assert body.include? 'function(){alert("Hello");'
79
+ assert_includes body, "var x;x=function(){"
80
+ end
81
+
82
+ test "compressed css" do
83
+ get '/css/application.css'
84
+ assert_includes body, "rgba(0,0,255,0.3)"
85
+ end
86
+
87
+ test "compressed css with cache bust" do
88
+ get '/css/application.388783.css'
89
+ assert_includes body, "rgba(0,0,255,0.3)"
90
+ end
91
+
92
+ test "helpers css" do
93
+ get '/helpers/css'
94
+ assert body =~ %r{link rel='stylesheet' type='text/css' href='/css/screen.[0-9]+.css' media='screen'}
95
+ end
96
+ end
@@ -0,0 +1,22 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ class YuiTest < UnitTest
4
+ setup do
5
+ app.assets.reset_cache
6
+ app.assets.js_compression = :yui
7
+ app.assets.css_compression = :yui
8
+ end
9
+
10
+ teardown do
11
+ app.assets.js_compression = :jsmin
12
+ app.assets.css_compression = :simple
13
+ end
14
+
15
+ test "build" do
16
+ require 'yui/compressor'
17
+ YUI::JavaScriptCompressor.any_instance.expects(:compress).returns "LOL"
18
+
19
+ get '/js/app.js'
20
+ assert body == "LOL"
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,200 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sinatra-assetpack
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Rico Sta. Cruz
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-08-30 00:00:00.000000000 +08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: sinatra
17
+ requirement: &2161442640 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *2161442640
26
+ - !ruby/object:Gem::Dependency
27
+ name: jsmin
28
+ requirement: &2161442220 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *2161442220
37
+ - !ruby/object:Gem::Dependency
38
+ name: rack-test
39
+ requirement: &2161441800 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :runtime
46
+ prerelease: false
47
+ version_requirements: *2161441800
48
+ - !ruby/object:Gem::Dependency
49
+ name: yui-compressor
50
+ requirement: &2161441380 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *2161441380
59
+ - !ruby/object:Gem::Dependency
60
+ name: sass
61
+ requirement: &2161440960 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: *2161440960
70
+ - !ruby/object:Gem::Dependency
71
+ name: haml
72
+ requirement: &2161440540 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: *2161440540
81
+ - !ruby/object:Gem::Dependency
82
+ name: coffee-script
83
+ requirement: &2161440120 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: *2161440120
92
+ - !ruby/object:Gem::Dependency
93
+ name: contest
94
+ requirement: &2161439700 !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ type: :development
101
+ prerelease: false
102
+ version_requirements: *2161439700
103
+ - !ruby/object:Gem::Dependency
104
+ name: mocha
105
+ requirement: &2161439280 !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ type: :development
112
+ prerelease: false
113
+ version_requirements: *2161439280
114
+ description: Package your assets for Sinatra.
115
+ email:
116
+ - rico@sinefunc.com
117
+ executables: []
118
+ extensions: []
119
+ extra_rdoc_files: []
120
+ files:
121
+ - .gitignore
122
+ - Gemfile
123
+ - HISTORY.md
124
+ - README.md
125
+ - Rakefile
126
+ - example/.gitignore
127
+ - example/Rakefile
128
+ - example/app.rb
129
+ - example/app/css/test.sass
130
+ - example/app/images/icon.png
131
+ - example/app/js/app.js
132
+ - example/app/js/vendor/jquery.js
133
+ - example/app/js/vendor/jquery.plugin.js
134
+ - example/app/js/vendor/underscore.js
135
+ - example/views/index.erb
136
+ - lib/sinatra/assetpack.rb
137
+ - lib/sinatra/assetpack/buster_helpers.rb
138
+ - lib/sinatra/assetpack/class_methods.rb
139
+ - lib/sinatra/assetpack/compressor.rb
140
+ - lib/sinatra/assetpack/configurator.rb
141
+ - lib/sinatra/assetpack/css.rb
142
+ - lib/sinatra/assetpack/hasharray.rb
143
+ - lib/sinatra/assetpack/helpers.rb
144
+ - lib/sinatra/assetpack/html_helpers.rb
145
+ - lib/sinatra/assetpack/image.rb
146
+ - lib/sinatra/assetpack/options.rb
147
+ - lib/sinatra/assetpack/package.rb
148
+ - lib/sinatra/assetpack/rake.rb
149
+ - lib/sinatra/assetpack/version.rb
150
+ - sinatra-assetpack.gemspec
151
+ - test/app/.gitignore
152
+ - test/app/Rakefile
153
+ - test/app/app.rb
154
+ - test/app/app/css/js2c.css
155
+ - test/app/app/css/screen.sass
156
+ - test/app/app/css/sqwishable.css
157
+ - test/app/app/css/style.css
158
+ - test/app/app/images/background.jpg
159
+ - test/app/app/images/email.png
160
+ - test/app/app/js/hello.js
161
+ - test/app/app/js/hi.coffee
162
+ - test/app/app/views/index.haml
163
+ - test/build_test.rb
164
+ - test/cache_test.rb
165
+ - test/helpers_test.rb
166
+ - test/img_test.rb
167
+ - test/options_test.rb
168
+ - test/order_test.rb
169
+ - test/preproc_test.rb
170
+ - test/simplecss_test.rb
171
+ - test/sqwish_test.rb
172
+ - test/test_helper.rb
173
+ - test/unit_test.rb
174
+ - test/yui_test.rb
175
+ has_rdoc: true
176
+ homepage: http://github.com/rstacruz/sinatra-assetpack
177
+ licenses: []
178
+ post_install_message:
179
+ rdoc_options: []
180
+ require_paths:
181
+ - lib
182
+ required_ruby_version: !ruby/object:Gem::Requirement
183
+ none: false
184
+ requirements:
185
+ - - ! '>='
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ required_rubygems_version: !ruby/object:Gem::Requirement
189
+ none: false
190
+ requirements:
191
+ - - ! '>='
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ requirements: []
195
+ rubyforge_project:
196
+ rubygems_version: 1.6.2
197
+ signing_key:
198
+ specification_version: 3
199
+ summary: Asset packager for Sinatra.
200
+ test_files: []