rack-offline 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,7 +7,7 @@ module Rails
7
7
  @app.call(env)
8
8
  end
9
9
 
10
- def initialize(app = Rails.application, &block)
10
+ def initialize(options = {}, app = Rails.application, &block)
11
11
  config = app.config
12
12
  root = config.paths.public.to_a.first
13
13
 
@@ -17,7 +17,7 @@ module Rails
17
17
  :cache => config.cache_classes,
18
18
  :root => root,
19
19
  :logger => Rails.logger
20
- }
20
+ }.merge(options)
21
21
 
22
22
  super opts, &block
23
23
  end
@@ -30,7 +30,7 @@ module Rails
30
30
  "#{root}/**/*.html",
31
31
  "#{root}/stylesheets/**/*.css",
32
32
  "#{root}/javascripts/**/*.js",
33
- "#{root}/images/**"]
33
+ "#{root}/images/**/*.*"]
34
34
 
35
35
  files.each do |file|
36
36
  cache Pathname.new(file).relative_path_from(root)
@@ -3,12 +3,20 @@ require "rack/offline/version"
3
3
  require "digest/sha2"
4
4
  require "logger"
5
5
  require "pathname"
6
+ require 'uri'
6
7
 
7
8
  module Rack
8
9
  class Offline
9
10
  def self.configure(*args, &block)
10
11
  new(*args, &block)
11
12
  end
13
+
14
+ # interval in seconds used to compute the cache key when in uncached mode
15
+ # which can be set by passing in options[:cache_interval]
16
+ # note: setting it to 0 or a low value will change the cache key every request
17
+ # which means the manifest will never successfully download
18
+ # (since it gets downloaded again at the end)
19
+ UNCACHED_KEY_INTERVAL = 10
12
20
 
13
21
  def initialize(options = {}, &block)
14
22
  @cache = options[:cache]
@@ -28,45 +36,54 @@ module Rack
28
36
  "you need to supply a root so Rack::Offline can " \
29
37
  "calculate a hash of the files." unless @root
30
38
  precache_key!
39
+ else
40
+ @cache_interval = (options[:cache_interval] || UNCACHED_KEY_INTERVAL).to_i
31
41
  end
32
42
  end
33
43
 
34
44
  def call(env)
35
- key = @key || Digest::SHA2.hexdigest(Time.now.to_s + Time.now.usec.to_s)
45
+ key = @key || uncached_key
36
46
 
37
47
  body = ["CACHE MANIFEST"]
38
48
  body << "# #{key}"
39
49
  @config.cache.each do |item|
40
- body << item
50
+ body << URI.escape(item.to_s)
41
51
  end
42
52
 
43
53
  unless @config.network.empty?
44
54
  body << "" << "NETWORK:"
45
55
  @config.network.each do |item|
46
- body << item
56
+ body << URI.escape(item.to_s)
47
57
  end
48
58
  end
49
59
 
50
60
  unless @config.fallback.empty?
51
61
  body << "" << "FALLBACK:"
52
62
  @config.fallback.each do |namespace, url|
53
- body << "#{namespace} #{url}"
63
+ body << "#{namespace} #{URI.escape(url.to_s)}"
54
64
  end
55
65
  end
56
66
 
57
67
  @logger.debug body.join("\n")
58
68
 
59
- [200, {"Content-Type" => "text/cache-manifest"}, body.join("\n")]
69
+ [200, {"Content-Type" => "text/cache-manifest"}, [body.join("\n")]]
60
70
  end
61
71
 
62
72
  private
63
73
 
64
74
  def precache_key!
65
75
  hash = @config.cache.map do |item|
66
- Digest::SHA2.hexdigest(@root.join(item).read)
76
+ path = @root.join(item)
77
+ Digest::SHA2.hexdigest(path.read) if ::File.file?(path)
67
78
  end
68
79
 
69
80
  @key = Digest::SHA2.hexdigest(hash.join)
70
81
  end
82
+
83
+ def uncached_key
84
+ now = Time.now.to_i - Time.now.to_i % @cache_interval
85
+ Digest::SHA2.hexdigest(now.to_s)
86
+ end
87
+
71
88
  end
72
89
  end
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class Offline
3
- VERSION = "0.6.1"
3
+ VERSION = "0.6.2"
4
4
  end
5
- end
5
+ end
metadata CHANGED
@@ -1,66 +1,52 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rack-offline
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 6
8
- - 1
9
- version: 0.6.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.2
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Yehuda Katz
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2010-06-17 00:00:00 -07:00
18
- default_executable:
12
+ date: 2011-08-16 00:00:00.000000000 Z
19
13
  dependencies: []
20
-
21
- description: A Rack endpoint that generates cache manifests and other useful HTML5 offline utilities that are useful on the server-side. Rack::Offline also provides a conventional Rails endpoint (Rails::Offline) that configures Rack::Offline using expected Rails settings
14
+ description: A Rack endpoint that generates cache manifests and other useful HTML5
15
+ offline utilities that are useful on the server-side. Rack::Offline also provides
16
+ a conventional Rails endpoint (Rails::Offline) that configures Rack::Offline using
17
+ expected Rails settings
22
18
  email: wycats@gmail.com
23
19
  executables: []
24
-
25
20
  extensions: []
26
-
27
21
  extra_rdoc_files: []
28
-
29
- files:
22
+ files:
30
23
  - LICENSE
31
24
  - lib/rack/offline/config.rb
32
25
  - lib/rack/offline/version.rb
33
26
  - lib/rack/offline.rb
34
27
  - lib/rack-offline.rb
35
- has_rdoc: true
36
28
  homepage: http://www.yehudakatz.com
37
29
  licenses: []
38
-
39
30
  post_install_message:
40
31
  rdoc_options: []
41
-
42
- require_paths:
32
+ require_paths:
43
33
  - lib
44
- required_ruby_version: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - ">="
47
- - !ruby/object:Gem::Version
48
- segments:
49
- - 0
50
- version: "0"
51
- required_rubygems_version: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- segments:
56
- - 0
57
- version: "0"
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
58
46
  requirements: []
59
-
60
47
  rubyforge_project: rack-offline
61
- rubygems_version: 1.3.6
48
+ rubygems_version: 1.8.8
62
49
  signing_key:
63
50
  specification_version: 3
64
51
  summary: A Rack toolkit for working with offline applications
65
52
  test_files: []
66
-