assets_offline 0.0.4 → 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.
data/.gitignore CHANGED
@@ -3,3 +3,4 @@
3
3
  Gemfile.lock
4
4
  pkg/*
5
5
  *.*~
6
+ .svn
@@ -1,7 +1,7 @@
1
1
  assets_offline
2
2
  ============
3
3
 
4
- **Stable Version**: 0.0.3
4
+ **Stable Version**: 0.0.5
5
5
 
6
6
  This gem is specifically for Rails 3.1 projects that wish to use HTML5 and its offline cache feature with the Asset Pipeline.
7
7
 
@@ -61,7 +61,7 @@ Roadmap
61
61
  Changelog
62
62
  ---------
63
63
 
64
- **v0.0.3**
64
+ **v0.0.5**
65
65
 
66
66
  * Beta release
67
67
 
@@ -70,7 +70,7 @@ Credits
70
70
  -------
71
71
 
72
72
  * [broomyocymru](mailto: broomyocymru@hotmail.com)
73
-
73
+ * [jmacdonald]
74
74
 
75
75
  License
76
76
  -------
@@ -1,63 +1,19 @@
1
1
  require 'yaml'
2
2
 
3
3
  class AssetsOfflineController < ActionController::Base
4
+ Mime::Type.register 'text/cache-manifest', :manifest
4
5
 
5
6
  def show
7
+ # Load the configuration file and make it accessible to the template.
6
8
  config = YAML.load_file("#{Rails.root}/config/assets_offline.yml")
7
- root = config[params[:id]]
9
+ @root = config[params[:id]]
8
10
 
9
- body = "CACHE MANIFEST \n"
10
- body << "# GENERATED USING ASSET_OFFLINE\n"
11
- body << "# Mode: #{Rails.env} \n"
12
- body << "# #{generate_key()} \n\n"
13
- # CACHE SECTION
14
- body << "CACHE:\n"
15
- if !root["asset-cache"].blank? and root["asset-cache"].count() > 0
16
- root["asset-cache"].each do |asset_name|
17
- body << "#{view_context.asset_path(asset_name)}\n"
18
- end
19
- end
20
- if !root["cache"].blank? and root["cache"].count() > 0
21
- root["cache"].each do |asset_name|
22
- body << "#{asset_name}\n"
23
- end
24
- end
25
- body << "\n"
11
+ # Generate the checksum for the file.
12
+ @key = generate_key()
26
13
 
27
- # NETWORK SECTION
28
- body << "NETWORK:\n"
29
- body << "# Resources where a connection is required \n"
30
- if !root["asset-network"].blank? and root["asset-network"].count() > 0
31
- root["asset-network"].each do |asset_name|
32
- body << "#{view_context.asset_path(asset_name)}\n"
33
- end
14
+ respond_to do |format|
15
+ format.manifest
34
16
  end
35
- if !root["network"].blank? and root["network"].count() > 0
36
- root["network"].each do |asset_name|
37
- body << "#{asset_name}\n"
38
- end
39
- end
40
- body << "\n"
41
-
42
- #FALLBACK SECTION
43
- body << "FALLBACK:\n"
44
- body << "# Resources where a connection is used if available \n"
45
- if !root["asset-fallback"].blank? and root["asset-fallback"].count() > 0
46
- root["asset-fallback"].each do |asset_name|
47
- asset_name_part = asset_name.split("#")
48
- body << "#{view_context.asset_path(asset_name_part[0].strip())} #{view_context.asset_path(asset_name_part[1].strip())}\n"
49
- end
50
- end
51
- if !root["fallback"].blank? and root["fallback"].count() > 0
52
- root["fallback"].each do |asset_name|
53
- asset_name_part = asset_name.split("#")
54
- body << "#{asset_name_part[0].strip()} #{asset_name_part[1].strip()}\n"
55
- end
56
- end
57
- body << "\n"
58
-
59
- headers['Content-Type'] = 'text/cache-manifest'
60
- render :text => body, :layout => false
61
17
  end
62
18
 
63
19
  private
@@ -0,0 +1,82 @@
1
+ module AssetsOfflineHelper
2
+ def cached_resources
3
+ resources = Array.new
4
+
5
+ if !@root["asset-cache"].blank? and @root["asset-cache"].count() > 0
6
+ @root["asset-cache"].each do |asset_name|
7
+ # Build the resource as a path.
8
+ resource = asset_path(asset_name)
9
+
10
+ # Add the query string appended to assets in development mode.
11
+ resource << '?body=1' if Rails.env == 'development'
12
+
13
+ # Add the resource to the list of resources.
14
+ resources << resource
15
+ end
16
+ end
17
+ if !@root["cache"].blank? and @root["cache"].count() > 0
18
+ @root["cache"].each do |asset_name|
19
+ # Initially, use the asset name as-is.
20
+ resource = asset_name
21
+
22
+ # Add the query string appended to assets in development mode.
23
+ resource << '?body=1' if Rails.env == 'development'
24
+
25
+ # Add the resource to the list of resources.
26
+ resources << resource
27
+ end
28
+ end
29
+
30
+ return resources.join("\n")
31
+ end
32
+
33
+ def network_resources
34
+ resources = Array.new
35
+
36
+ if !@root["asset-network"].blank? and @root["asset-network"].count() > 0
37
+ @root["asset-network"].each do |asset_name|
38
+ # Build the resource as a path.
39
+ resource = asset_path(asset_name)
40
+
41
+ # Add the query string appended to assets in development mode.
42
+ resource << '?body=1' if Rails.env == 'development'
43
+
44
+ # Add the resource to the list of resources.
45
+ resources << resource
46
+ end
47
+ end
48
+ if !@root["network"].blank? and @root["network"].count() > 0
49
+ @root["network"].each do |asset_name|
50
+ # Initially, use the asset name as-is.
51
+ resource = asset_name
52
+
53
+ # Add the query string appended to assets in development mode.
54
+ resource << '?body=1' if Rails.env == 'development'
55
+
56
+ # Add the resource to the list of resources.
57
+ resources << resource
58
+ end
59
+ end
60
+
61
+ return resources.join("\n")
62
+ end
63
+
64
+ def fallback_resources
65
+ resources = Array.new
66
+
67
+ if !@root["asset-fallback"].blank? and @root["asset-fallback"].count() > 0
68
+ @root["asset-fallback"].each do |asset_name|
69
+ asset_name_part = asset_name.split("#")
70
+ resources << asset_path(asset_name_part[0].strip()) + asset_path(asset_name_part[1].strip())
71
+ end
72
+ end
73
+ if !@root["fallback"].blank? and @root["fallback"].count() > 0
74
+ @root["fallback"].each do |asset_name|
75
+ asset_name_part = asset_name.split("#")
76
+ resources << asset_name_part[0].strip() + asset_name_part[1].strip()
77
+ end
78
+ end
79
+
80
+ return resources.join("\n")
81
+ end
82
+ end
@@ -0,0 +1,14 @@
1
+ CACHE MANIFEST
2
+ <%= cached_resources %>
3
+
4
+ NETWORK:
5
+ # Resources where a connection is required
6
+ <%= network_resources %>
7
+
8
+ FALLBACK:
9
+ # Resources where a connection is used if available
10
+ <%= fallback_resources %>
11
+
12
+ # GENERATED USING ASSET_OFFLINE
13
+ # Mode: <%= Rails.env %>
14
+ # <%= @key %>
@@ -1,3 +1,3 @@
1
1
  Rails.application.routes.draw do
2
- resources :assets_offline
2
+ resources :assets_offline, :defaults => {:format => 'manifest'}
3
3
  end
@@ -1,3 +1,3 @@
1
1
  module AssetsOffline
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: assets_offline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
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: 2011-12-05 00:00:00.000000000Z
12
+ date: 2012-01-17 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: Rails 3.1 offline cache manifest view
15
15
  email:
@@ -22,25 +22,13 @@ files:
22
22
  - Gemfile
23
23
  - README.textile
24
24
  - Rakefile
25
- - app/.svn/all-wcprops
26
- - app/.svn/entries
27
- - app/controllers/.svn/all-wcprops
28
- - app/controllers/.svn/entries
29
- - app/controllers/.svn/text-base/assets_offline_controller.rb.svn-base
30
25
  - app/controllers/assets_offline_controller.rb
26
+ - app/helpers/assets_offline_helper.rb
27
+ - app/views/assets_offline/show.manifest.erb
31
28
  - assets_offline.gemspec
32
- - config/.svn/all-wcprops
33
- - config/.svn/entries
34
- - config/.svn/text-base/routes.rb.svn-base
35
29
  - config/routes.rb
36
30
  - init.rb
37
- - lib/.svn/all-wcprops
38
- - lib/.svn/entries
39
- - lib/.svn/text-base/assets_offline.rb.svn-base
40
31
  - lib/assets_offline.rb
41
- - lib/assets_offline/.svn/all-wcprops
42
- - lib/assets_offline/.svn/entries
43
- - lib/assets_offline/.svn/text-base/version.rb.svn-base
44
32
  - lib/assets_offline/version.rb
45
33
  homepage: ''
46
34
  licenses: []
@@ -1,5 +0,0 @@
1
- K 25
2
- svn:wc:ra_dav:version-url
3
- V 56
4
- /svn/TorexNG/!svn/ver/3734/trunk/gems/assets_offline/app
5
- END
@@ -1,31 +0,0 @@
1
- 10
2
-
3
- dir
4
- 3734
5
- https://svn.torex.com/svn/TorexNG/trunk/gems/assets_offline/app
6
- https://svn.torex.com/svn/TorexNG
7
-
8
-
9
-
10
- 2011-12-02T15:46:33.442319Z
11
- 3734
12
- Anthony.Broome
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
- 45178cb0-7fed-444c-b58d-06e1424a9ccb
28
-
29
- controllers
30
- dir
31
-
@@ -1,11 +0,0 @@
1
- K 25
2
- svn:wc:ra_dav:version-url
3
- V 68
4
- /svn/TorexNG/!svn/ver/3734/trunk/gems/assets_offline/app/controllers
5
- END
6
- assets_offline_controller.rb
7
- K 25
8
- svn:wc:ra_dav:version-url
9
- V 97
10
- /svn/TorexNG/!svn/ver/3734/trunk/gems/assets_offline/app/controllers/assets_offline_controller.rb
11
- END
@@ -1,62 +0,0 @@
1
- 10
2
-
3
- dir
4
- 3734
5
- https://svn.torex.com/svn/TorexNG/trunk/gems/assets_offline/app/controllers
6
- https://svn.torex.com/svn/TorexNG
7
-
8
-
9
-
10
- 2011-12-02T15:46:33.442319Z
11
- 3734
12
- Anthony.Broome
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
- 45178cb0-7fed-444c-b58d-06e1424a9ccb
28
-
29
- assets_offline_controller.rb
30
- file
31
-
32
-
33
-
34
-
35
- 2011-12-02T14:38:49.402396Z
36
- fa45977fe7a847e4fa4be00ea5d80b3d
37
- 2011-12-02T15:46:33.442319Z
38
- 3734
39
- Anthony.Broome
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
-
61
- 2490
62
-
@@ -1,85 +0,0 @@
1
- require 'yaml'
2
-
3
- class AssetsOfflineController < ActionController::Base
4
-
5
- def show
6
- config = YAML.load_file("#{Rails.root}/config/assets_offline.yml")
7
- root = config[params[:id]]
8
-
9
- body = "# GENERATED USING ASSET_OFFLINE\n"
10
- body << "# Mode: #{Rails.env} \n"
11
- body << "# #{generate_key()} \n\n"
12
-
13
- body << "CACHE MANIFEST \n"
14
- # CACHE SECTION
15
- if !root["asset-cache"].blank? and root["asset-cache"].count() > 0
16
- root["asset-cache"].each do |asset_name|
17
- body << "#{view_context.asset_path(asset_name)}\n"
18
- end
19
- end
20
- if !root["cache"].blank? and root["cache"].count() > 0
21
- root["cache"].each do |asset_name|
22
- body << "#{asset_name}\n"
23
- end
24
- end
25
- body << "\n"
26
-
27
- # NETWORK SECTION
28
- body << "NETWORK:\n"
29
- body << "# Resources where a connection is required \n"
30
- if !root["asset-network"].blank? and root["asset-network"].count() > 0
31
- root["asset-network"].each do |asset_name|
32
- body << "#{view_context.asset_path(asset_name)}\n"
33
- end
34
- end
35
- if !root["network"].blank? and root["network"].count() > 0
36
- root["network"].each do |asset_name|
37
- body << "#{asset_name}\n"
38
- end
39
- end
40
- body << "\n"
41
-
42
- #FALLBACK SECTION
43
- body << "FALLBACK:\n"
44
- body << "# Resources where a connection is used if available \n"
45
- if !root["asset-fallback"].blank? and root["asset-fallback"].count() > 0
46
- root["asset-fallback"].each do |asset_name|
47
- asset_name_part = asset_name.split("#")
48
- body << "#{view_context.asset_path(asset_name_part[0].strip())} #{view_context.asset_path(asset_name_part[1].strip())}\n"
49
- end
50
- end
51
- if !root["fallback"].blank? and root["fallback"].count() > 0
52
- root["fallback"].each do |asset_name|
53
- asset_name_part = asset_name.split("#")
54
- body << "#{asset_name_part[0].strip()} #{asset_name_part[1].strip()}\n"
55
- end
56
- end
57
- body << "\n"
58
-
59
- headers['Content-Type'] = 'text/cache-manifest'
60
- render :text => body, :layout => false
61
- end
62
-
63
- private
64
-
65
- def generate_key
66
- if Rails.env.production?
67
- production_key
68
- else
69
- development_key
70
- end
71
-
72
- end
73
-
74
- def production_key
75
- #Invalidate production by updating the datetime stamp in the comment
76
- path = "#{Rails.root}/config/assets_offline.yml"
77
- Digest::SHA2.hexdigest(File.read(path)) if ::File.file?(path)
78
- end
79
-
80
- def development_key
81
- now = Time.now.to_i - Time.now.to_i % 5
82
- Digest::SHA2.hexdigest(now.to_s)
83
- end
84
-
85
- end
@@ -1,11 +0,0 @@
1
- K 25
2
- svn:wc:ra_dav:version-url
3
- V 59
4
- /svn/TorexNG/!svn/ver/3734/trunk/gems/assets_offline/config
5
- END
6
- routes.rb
7
- K 25
8
- svn:wc:ra_dav:version-url
9
- V 69
10
- /svn/TorexNG/!svn/ver/3734/trunk/gems/assets_offline/config/routes.rb
11
- END
@@ -1,62 +0,0 @@
1
- 10
2
-
3
- dir
4
- 3734
5
- https://svn.torex.com/svn/TorexNG/trunk/gems/assets_offline/config
6
- https://svn.torex.com/svn/TorexNG
7
-
8
-
9
-
10
- 2011-12-02T15:46:33.442319Z
11
- 3734
12
- Anthony.Broome
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
- 45178cb0-7fed-444c-b58d-06e1424a9ccb
28
-
29
- routes.rb
30
- file
31
-
32
-
33
-
34
-
35
- 2011-12-02T14:39:29.970397Z
36
- 1b9a1db281aa1d112beb8340d29ead47
37
- 2011-12-02T15:46:33.442319Z
38
- 3734
39
- Anthony.Broome
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
-
61
- 66
62
-
@@ -1,3 +0,0 @@
1
- Rails.application.routes.draw do
2
- resources :assets_offline
3
- end
@@ -1,11 +0,0 @@
1
- K 25
2
- svn:wc:ra_dav:version-url
3
- V 56
4
- /svn/TorexNG/!svn/ver/3734/trunk/gems/assets_offline/lib
5
- END
6
- assets_offline.rb
7
- K 25
8
- svn:wc:ra_dav:version-url
9
- V 74
10
- /svn/TorexNG/!svn/ver/3734/trunk/gems/assets_offline/lib/assets_offline.rb
11
- END
@@ -1,65 +0,0 @@
1
- 10
2
-
3
- dir
4
- 3734
5
- https://svn.torex.com/svn/TorexNG/trunk/gems/assets_offline/lib
6
- https://svn.torex.com/svn/TorexNG
7
-
8
-
9
-
10
- 2011-12-02T15:46:33.442319Z
11
- 3734
12
- Anthony.Broome
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
- 45178cb0-7fed-444c-b58d-06e1424a9ccb
28
-
29
- assets_offline
30
- dir
31
-
32
- assets_offline.rb
33
- file
34
-
35
-
36
-
37
-
38
- 2011-12-02T15:12:09.590444Z
39
- 7f49316f1e14bcd77b955b39158c6a6d
40
- 2011-12-02T15:46:33.442319Z
41
- 3734
42
- Anthony.Broome
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
-
64
- 145
65
-
@@ -1,6 +0,0 @@
1
- require "assets_offline/version"
2
-
3
- module AssetsOffline
4
- class Engine < Rails::Engine
5
- end if defined?(Rails) && Rails::VERSION::MAJOR == 3
6
- end
@@ -1,11 +0,0 @@
1
- K 25
2
- svn:wc:ra_dav:version-url
3
- V 71
4
- /svn/TorexNG/!svn/ver/3734/trunk/gems/assets_offline/lib/assets_offline
5
- END
6
- version.rb
7
- K 25
8
- svn:wc:ra_dav:version-url
9
- V 82
10
- /svn/TorexNG/!svn/ver/3734/trunk/gems/assets_offline/lib/assets_offline/version.rb
11
- END
@@ -1,62 +0,0 @@
1
- 10
2
-
3
- dir
4
- 3734
5
- https://svn.torex.com/svn/TorexNG/trunk/gems/assets_offline/lib/assets_offline
6
- https://svn.torex.com/svn/TorexNG
7
-
8
-
9
-
10
- 2011-12-02T15:46:33.442319Z
11
- 3734
12
- Anthony.Broome
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
- 45178cb0-7fed-444c-b58d-06e1424a9ccb
28
-
29
- version.rb
30
- file
31
-
32
-
33
-
34
-
35
- 2011-12-02T15:16:44.894451Z
36
- c47858446fefbb4d8ef552e650df25ea
37
- 2011-12-02T15:46:33.442319Z
38
- 3734
39
- Anthony.Broome
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
-
61
- 45
62
-
@@ -1,3 +0,0 @@
1
- module AssetsOffline
2
- VERSION = "0.0.3"
3
- end