manifesto 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -32,17 +32,27 @@ You might need administrator privileges on your system to install it.
32
32
  # Specify a directory and don't compute the hash
33
33
  Manifesto.cache :directory => './mobile', :compute_hash => false
34
34
 
35
+ # Add network includes
36
+ Manifesto.cache :directory => '.mobile', :network_includes => ['http://google.com', 'http://github.com']
37
+
38
+ # Add file exclusions
39
+ Manifesto.cache :directory => '.mobile', :excludes => ['dynamic-dir/', 'dynamic.js')]
40
+
35
41
  == Sample Output
36
42
 
37
43
  CACHE MANIFEST
38
44
  # Generated by manifesto (http://github.com/johntopley/manifesto)
39
45
  # Hash: 7013a3b8292ceeeb6336849bee1d1365
46
+ CACHE:
40
47
  /apple-touch-icon.png
41
48
  /apple-touch-startup.png
42
49
  /index.html
43
50
  /mobile/mobile.css
44
51
  /mobile/mobile.js
45
52
 
53
+ NETWORK:
54
+ http://github.com
55
+
46
56
  == Sinatra Example
47
57
 
48
58
  require 'manifesto.rb'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.0
1
+ 0.7.0
@@ -19,25 +19,40 @@ class Manifesto
19
19
  def self.cache(options = {})
20
20
  directory = options.fetch(:directory, './public')
21
21
  compute_hash = options.fetch(:compute_hash, true)
22
- validate_options(directory, compute_hash)
22
+ timestamp = options.fetch(:timestamp, true)
23
+ timestamp_exclusions = options.fetch(:timestamp_exclusions, [])
24
+ network_includes = options.fetch(:network_includes, [])
25
+ excludes = options.fetch(:excludes, [])
26
+ validate_options(directory, compute_hash, timestamp, network_includes, excludes)
23
27
  manifest = []
24
28
  hashes = ''
25
29
 
30
+ if !network_includes.empty? then
31
+ network_includes.each { |inc| manifest << "#{inc}\n" }
32
+ manifest << "\nNETWORK:\n"
33
+ end
34
+
26
35
  get_file_paths(directory).each do |path|
27
-
28
36
  # Only include real files (i.e. not directories, symlinks etc.) and non-hidden
29
37
  # files in the manifest.
30
38
  if File.file?(path) && File.basename(path)[0,1] != '.'
31
- manifest << "#{normalize_path(directory, path)}\n"
39
+ if not in_path(path, excludes) then
40
+ if timestamp and not in_path(path, timestamp_exclusions)
41
+ manifest << "#{normalize_path(directory, path)}?#{get_timestamp(path)}\n"
42
+ else
43
+ manifest << "#{normalize_path(directory, path)}\n"
44
+ end
45
+ end
32
46
  hashes += compute_file_contents_hash(path) if compute_hash
33
47
  end
34
48
  end
35
49
 
36
50
  # Hash the hashes of each file and output as a comment.
51
+ manifest << "CACHE:\n"
37
52
  manifest << "# Hash: #{Digest::MD5.hexdigest(hashes)}\n" if compute_hash
38
53
  manifest << "# Generated by manifesto (http://github.com/johntopley/manifesto)\n"
39
54
  manifest << "CACHE MANIFEST\n"
40
- manifest.reverse
55
+ manifest.reverse.join
41
56
  end
42
57
 
43
58
  # Reads the file contents to calculate the MD5 hash, so that if a file is
@@ -66,11 +81,29 @@ class Manifesto
66
81
  normalized_path = '/' + normalized_path unless normalized_path[0,1] == '/'
67
82
  normalized_path
68
83
  end
84
+
85
+ # Calculates the timestamp for a given file using same methodology as Rails' asset timestamps.
86
+ def self.get_timestamp(path)
87
+ File.mtime(path).to_i.to_s
88
+ end
89
+
90
+ # Determines whether or not the path contains any of the targets; used for exclusions/inclusions.
91
+ def self.in_path(path, targets)
92
+ targets.each do |target|
93
+ if path.include? target
94
+ return true
95
+ end
96
+ end
97
+ false
98
+ end
69
99
 
70
100
  # Checks that the options passed to the <tt>cache</tt> method are valid.
71
- def self.validate_options(directory, compute_hash)
101
+ def self.validate_options(directory, compute_hash, timestamp, network_includes, excludes)
72
102
  raise(ArgumentError, ":directory must be a real directory") unless valid_directory?(directory)
73
103
  raise(ArgumentError, ":compute_hash must be a boolean") unless valid_compute_hash?(compute_hash)
104
+ raise(ArgumentError, ":timestamp must be a boolean") unless valid_timestamp?(timestamp)
105
+ raise(ArgumentError, ":network_includes must be an array") unless valid_network_includes?(network_includes)
106
+ raise(ArgumentError, ":excludes must be an array") unless valid_excludes?(excludes)
74
107
  end
75
108
 
76
109
  # Checks that the <tt>compute_hash</tt> option is a boolean.
@@ -82,4 +115,19 @@ class Manifesto
82
115
  def self.valid_directory?(directory)
83
116
  File.directory?(directory)
84
117
  end
118
+
119
+ # Checks that the <tt>timestamp</tt> option is a boolean.
120
+ def self.valid_timestamp?(timestamp)
121
+ timestamp.is_a?(TrueClass) || timestamp.is_a?(FalseClass)
122
+ end
123
+
124
+ # Checks that the <tt>network_includes</tt> option is a boolean.
125
+ def self.valid_network_includes?(network_includes)
126
+ network_includes.is_a?(Array)
127
+ end
128
+
129
+ # Checks that the <tt>excludes</tt> option is a boolean.
130
+ def self.valid_excludes?(excludes)
131
+ excludes.is_a?(Array)
132
+ end
85
133
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{manifesto}
8
- s.version = "0.6.0"
8
+ s.version = "0.7.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["John Topley", "Nasir Jamal"]
12
- s.date = %q{2010-06-30}
12
+ s.date = %q{2012-02-04}
13
13
  s.description = %q{Dynamically generates an HTML5 cache manifest from the contents of a directory}
14
14
  s.email = %q{john@johntopley.com}
15
15
  s.extra_rdoc_files = [
@@ -33,7 +33,7 @@ Gem::Specification.new do |s|
33
33
  s.rdoc_options = ["--charset=UTF-8"]
34
34
  s.require_paths = ["lib"]
35
35
  s.rubyforge_project = %q{manifesto}
36
- s.rubygems_version = %q{1.3.7}
36
+ s.rubygems_version = %q{1.7.2}
37
37
  s.summary = %q{Manifesto is a Ruby library that dynamically generates an HTML5 cache manifest}
38
38
  s.test_files = [
39
39
  "spec/manifesto_spec.rb",
@@ -41,7 +41,6 @@ Gem::Specification.new do |s|
41
41
  ]
42
42
 
43
43
  if s.respond_to? :specification_version then
44
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
45
44
  s.specification_version = 3
46
45
 
47
46
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
@@ -3,11 +3,23 @@ require File.dirname(__FILE__) + '/spec_helper'
3
3
  describe Manifesto do
4
4
  describe ".validate_options" do
5
5
  it "should raise ArgumentError if directory is not a real directory" do
6
- expect{ Manifesto.validate_options('', false) }.to raise_error(ArgumentError)
6
+ expect{ Manifesto.validate_options('', false, false, [], []) }.to raise_error(ArgumentError)
7
7
  end
8
8
 
9
9
  it "should raise ArgumentError if compute_hash is not a boolean" do
10
- expect{ Manifesto.validate_options('.', nil) }.to raise_error(ArgumentError)
10
+ expect{ Manifesto.validate_options('.', nil, false, [], []) }.to raise_error(ArgumentError)
11
+ end
12
+
13
+ it "should raise ArgumentError if timestamp is not a boolean" do
14
+ expect{ Manifesto.validate_options('.', false, nil, [], []) }.to raise_error(ArgumentError)
15
+ end
16
+
17
+ it "should raise ArgumentError if network_includes is not an array" do
18
+ expect{ Manifesto.validate_options('.', false, false, nil, []) }.to raise_error(ArgumentError)
19
+ end
20
+
21
+ it "should raise ArgumentError if excludes is not an array" do
22
+ expect{ Manifesto.validate_options('.', false, false, [], nil) }.to raise_error(ArgumentError)
11
23
  end
12
24
  end
13
25
 
@@ -40,6 +52,11 @@ describe Manifesto do
40
52
  Manifesto.stub!(:get_file_paths).and_return([])
41
53
  end
42
54
 
55
+ it "should not get the timestamp" do
56
+ Manifesto.should_receive(:get_timestamp).never
57
+ Manifesto.cache
58
+ end
59
+
43
60
  it "should not compute hash" do
44
61
  Manifesto.should_receive(:compute_file_contents_hash).never
45
62
  Manifesto.cache
@@ -58,6 +75,11 @@ describe Manifesto do
58
75
  File.stub!(:file?).and_return(false)
59
76
  end
60
77
 
78
+ it "should not get the timestamp" do
79
+ Manifesto.should_receive(:get_timestamp).never
80
+ Manifesto.cache
81
+ end
82
+
61
83
  it "should not compute hash" do
62
84
  Manifesto.should_receive(:compute_file_contents_hash).never
63
85
  Manifesto.cache
@@ -75,6 +97,11 @@ describe Manifesto do
75
97
  File.stub!(:file?).and_return(true)
76
98
  end
77
99
 
100
+ it "should not get the timestamp" do
101
+ Manifesto.should_receive(:get_timestamp).never
102
+ Manifesto.cache
103
+ end
104
+
78
105
  it "should not compute hash" do
79
106
  Manifesto.should_receive(:compute_file_contents_hash).never
80
107
  Manifesto.cache
@@ -93,6 +120,11 @@ describe Manifesto do
93
120
  Manifesto.stub!(:compute_file_contents_hash).and_return('asdfsafasdfsdfszxsd')
94
121
  end
95
122
 
123
+ it "should get the timestamp" do
124
+ Manifesto.should_receive(:get_timestamp).and_return('anything')
125
+ Manifesto.cache
126
+ end
127
+
96
128
  it "should compute the hash" do
97
129
  Manifesto.should_receive(:compute_file_contents_hash).and_return('anything')
98
130
  Manifesto.cache
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: manifesto
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
5
- prerelease: false
4
+ hash: 3
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
- - 6
8
+ - 7
9
9
  - 0
10
- version: 0.6.0
10
+ version: 0.7.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - John Topley
@@ -16,8 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-06-30 00:00:00 +01:00
20
- default_executable:
19
+ date: 2012-02-04 00:00:00 Z
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
23
22
  name: rspec
@@ -56,7 +55,6 @@ files:
56
55
  - spec/manifesto_spec.rb
57
56
  - spec/spec.opts
58
57
  - spec/spec_helper.rb
59
- has_rdoc: true
60
58
  homepage: http://github.com/johntopley/manifesto
61
59
  licenses: []
62
60
 
@@ -86,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
84
  requirements: []
87
85
 
88
86
  rubyforge_project: manifesto
89
- rubygems_version: 1.3.7
87
+ rubygems_version: 1.7.2
90
88
  signing_key:
91
89
  specification_version: 3
92
90
  summary: Manifesto is a Ruby library that dynamically generates an HTML5 cache manifest