sinatra-assetpack 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,4 +1,3 @@
1
- /Gemfile.lock
2
1
  /.rvmrc
3
2
  /.sass-cache
4
3
  /doc/
@@ -0,0 +1,79 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sinatra-assetpack (0.1.1)
5
+ jsmin
6
+ rack-test
7
+ sinatra
8
+ tilt (>= 1.3.0)
9
+
10
+ GEM
11
+ remote: http://rubygems.org/
12
+ specs:
13
+ POpen4 (0.1.4)
14
+ Platform (>= 0.4.0)
15
+ open4
16
+ Platform (0.4.0)
17
+ coffee-script (2.2.0)
18
+ coffee-script-source
19
+ execjs
20
+ coffee-script-source (1.4.0)
21
+ columnize (0.3.6)
22
+ commonjs (0.2.6)
23
+ 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
+ execjs (1.4.0)
32
+ multi_json (~> 1.0)
33
+ haml (3.1.7)
34
+ jsmin (1.0.1)
35
+ less (2.2.2)
36
+ commonjs (~> 0.2.6)
37
+ metaclass (0.0.1)
38
+ mocha (0.13.1)
39
+ metaclass (~> 0.0.1)
40
+ multi_json (1.5.0)
41
+ open4 (1.3.0)
42
+ rack (1.4.4)
43
+ rack-protection (1.3.2)
44
+ rack
45
+ rack-test (0.6.2)
46
+ rack (>= 1.0)
47
+ rake (10.0.3)
48
+ sass (3.2.5)
49
+ sinatra (1.3.3)
50
+ rack (~> 1.3, >= 1.3.6)
51
+ rack-protection (~> 1.2)
52
+ tilt (~> 1.3, >= 1.3.3)
53
+ stylus (0.6.2)
54
+ execjs
55
+ stylus-source
56
+ stylus-source (0.31.0)
57
+ tilt (1.3.3)
58
+ uglifier (1.3.0)
59
+ execjs (>= 0.3.0)
60
+ multi_json (~> 1.0, >= 1.0.2)
61
+ yui-compressor (0.9.6)
62
+ POpen4 (>= 0.1.4)
63
+
64
+ PLATFORMS
65
+ ruby
66
+
67
+ DEPENDENCIES
68
+ coffee-script
69
+ contest
70
+ debugger
71
+ haml
72
+ less
73
+ mocha
74
+ rake
75
+ sass
76
+ sinatra-assetpack!
77
+ stylus
78
+ uglifier
79
+ yui-compressor
data/HISTORY.md CHANGED
@@ -1,3 +1,9 @@
1
+ v0.1.2 - Jan 20, 2013
2
+ ----------------------
3
+
4
+ ### Added:
5
+ * Support for custom cache control headers for packed assets. (#43)
6
+
1
7
  v0.1.1 - Jan 15, 2013
2
8
  ----------------------
3
9
 
data/README.md CHANGED
@@ -529,6 +529,32 @@ end
529
529
  # >> Listening on 0.0.0.0:4567, CTRL+C to stop
530
530
  ```
531
531
 
532
+ ### assets.expires
533
+ Sets cache control headers for all assets handled by AssetPack. Defaults to `expires 86400*30, :public`. Passes the arguments to [Sinatras #expires](http://rubydoc.info/gems/sinatra/Sinatra/Helpers#expires-instance_method).
534
+
535
+ ``` ruby
536
+ # Usage:
537
+ expires amount, *values
538
+ ```
539
+
540
+ #### Example
541
+ In this example all assets get cached for a year.
542
+
543
+ ``` ruby
544
+ class App < Sinatra::Base
545
+ assets {
546
+ js_compression :closure
547
+
548
+ js :application, [
549
+ '/js/vendor/jquery.*.js',
550
+ '/js/vendor/jquery.js'
551
+ ]
552
+ expires 86400*365, :public
553
+ }
554
+ end
555
+ ```
556
+
557
+
532
558
  API reference: helpers
533
559
  ----------------------
534
560
 
@@ -30,6 +30,7 @@ module Sinatra
30
30
 
31
31
  content_type package.type
32
32
  last_modified mtime
33
+ assets_expires
33
34
  contents
34
35
  end
35
36
  end
@@ -50,7 +51,7 @@ module Sinatra
50
51
  # Send headers
51
52
  content_type fmt.to_sym
52
53
  last_modified File.mtime(fn).to_i
53
- expires 86400*30, :public
54
+ assets_expires
54
55
 
55
56
  format = File.extname(fn)[1..-1]
56
57
 
@@ -56,6 +56,15 @@ module Sinatra
56
56
  def asset_path_for(file, from)
57
57
  settings.assets.dyn_local_file_for file, from
58
58
  end
59
+
60
+ def assets_expires
61
+ if settings.assets.expires.nil?
62
+ expires 86400*30, :public
63
+ else
64
+ expires *settings.assets.expires
65
+ end
66
+ end
67
+
59
68
  end
60
69
  end
61
70
  end
@@ -159,6 +159,14 @@ module Sinatra
159
159
 
160
160
  attrib :prebuild # Bool
161
161
 
162
+ def expires(*args)
163
+ if args.empty?
164
+ @expires
165
+ else
166
+ @expires = args
167
+ end
168
+ end
169
+
162
170
  def js_compression(name=nil, options=nil)
163
171
  @js_compression = name unless name.nil?
164
172
  @js_compression_options = options if options.is_a?(Hash)
@@ -1,7 +1,7 @@
1
1
  module Sinatra
2
2
  module AssetPack
3
3
  def self.version
4
- "0.1.1"
4
+ "0.1.2"
5
5
  end
6
6
  end
7
7
  end
@@ -25,4 +25,5 @@ Gem::Specification.new do |s|
25
25
  s.add_development_dependency "uglifier"
26
26
  s.add_development_dependency "rake"
27
27
  s.add_development_dependency "less"
28
+ s.add_development_dependency "debugger"
28
29
  end
@@ -53,6 +53,7 @@ class Main < Sinatra::Base
53
53
  '/css/scre*.css',
54
54
  '/css/screen.css'
55
55
  ]
56
+
56
57
  }
57
58
 
58
59
  get '/index.html' do
@@ -4,7 +4,8 @@ require 'tilt'
4
4
  require 'stylus'
5
5
  require 'rack/test'
6
6
  require 'yaml'
7
- require 'mocha'
7
+ require 'mocha/setup'
8
+ require 'debugger'
8
9
 
9
10
  require File.expand_path('../app/app.rb', __FILE__)
10
11
 
@@ -103,4 +103,37 @@ class AppTest < UnitTest
103
103
  get '/helpers/css'
104
104
  assert body =~ %r{link rel='stylesheet' href='/css/screen.[0-9]+.css' media='screen'}
105
105
  end
106
+
107
+ test 'default expiration of single assets' do
108
+ get '/js/hi.js'
109
+ assert_equal "public, max-age=#{86400*30}", last_response.headers['Cache-Control']
110
+ assert_equal (Time.now + (86400*30)).httpdate, last_response.headers['Expires']
111
+ end
112
+
113
+ test 'custom expiration of single assets' do
114
+ app.settings.assets.expires 86400*365, :public
115
+
116
+ get '/js/hi.js'
117
+ assert_equal "public, max-age=#{86400*365}", last_response.headers['Cache-Control']
118
+ assert_equal (Time.now + (86400*365)).httpdate, last_response.headers['Expires']
119
+
120
+ app.settings.assets.instance_variable_set('@expires', nil)
121
+ end
122
+
123
+ test 'default expiration of packed assets' do
124
+ get '/js/app.js'
125
+ assert_equal "public, max-age=#{86400*30}", last_response.headers['Cache-Control']
126
+ assert_equal (Time.now + (86400*30)).httpdate, last_response.headers['Expires']
127
+ end
128
+
129
+ test 'custom expiration of single assets' do
130
+ app.settings.assets.expires 86400*365, :public
131
+
132
+ get '/js/app.js'
133
+ assert_equal "public, max-age=#{86400*365}", last_response.headers['Cache-Control']
134
+ assert_equal (Time.now + (86400*365)).httpdate, last_response.headers['Expires']
135
+
136
+ app.settings.assets.instance_variable_set('@expires', nil)
137
+ end
138
+
106
139
  end
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.1
4
+ version: 0.1.2
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-01-15 00:00:00.000000000 Z
12
+ date: 2013-01-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: tilt
@@ -235,6 +235,22 @@ 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
238
254
  description: Package your assets for Sinatra.
239
255
  email:
240
256
  - rico@sinefunc.com
@@ -245,6 +261,7 @@ files:
245
261
  - .gitignore
246
262
  - .travis.yml
247
263
  - Gemfile
264
+ - Gemfile.lock
248
265
  - HISTORY.md
249
266
  - README.md
250
267
  - Rakefile