manifesto 0.1.0 → 0.5.0
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/Rakefile +6 -1
- data/VERSION +1 -1
- data/lib/manifesto.rb +12 -6
- data/manifesto.gemspec +4 -3
- data/spec/manifesto_spec.rb +124 -19
- metadata +6 -6
data/Rakefile
CHANGED
@@ -8,12 +8,17 @@ begin
|
|
8
8
|
gem.summary = %Q{Manifesto is a Ruby library that dynamically generates an HTML5 cache manifest}
|
9
9
|
gem.description = %Q{Dynamically generates an HTML5 cache manifest from the contents of a directory}
|
10
10
|
gem.email = "john@johntopley.com"
|
11
|
-
gem.homepage = "http://manifesto
|
11
|
+
gem.homepage = "http://github.com/johntopley/manifesto"
|
12
12
|
gem.authors = ["John Topley"]
|
13
13
|
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
+
gem.rubyforge_project = "manifesto"
|
14
15
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
16
|
end
|
16
17
|
Jeweler::GemcutterTasks.new
|
18
|
+
|
19
|
+
Jeweler::RubyforgeTasks.new do |rubyforge|
|
20
|
+
rubyforge.doc_task = "rdoc"
|
21
|
+
end
|
17
22
|
rescue LoadError
|
18
23
|
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
24
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
data/lib/manifesto.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'digest/md5'
|
2
2
|
require 'find'
|
3
3
|
|
4
|
-
|
4
|
+
class Manifesto
|
5
5
|
|
6
6
|
# Returns an Array of non-hidden files within the <tt>./public</tt> directory, unless <tt>:directory</tt> is specified.
|
7
7
|
# The output also includes a computed hash of the files' contents, unless <tt>:compute_hash</tt> is set to <tt>false</tt>.
|
@@ -19,10 +19,11 @@ module Manifesto
|
|
19
19
|
def self.cache(options = {})
|
20
20
|
directory = options.fetch(:directory, './public')
|
21
21
|
compute_hash = options.fetch(:compute_hash, true)
|
22
|
-
|
22
|
+
validate_options(directory, compute_hash)
|
23
23
|
manifest = []
|
24
24
|
hashes = ''
|
25
|
-
|
25
|
+
|
26
|
+
get_file_paths(directory).each do |path|
|
26
27
|
|
27
28
|
# Only include real files (i.e. not directories, symlinks etc.) and non-hidden
|
28
29
|
# files in the manifest.
|
@@ -39,8 +40,6 @@ module Manifesto
|
|
39
40
|
manifest.reverse
|
40
41
|
end
|
41
42
|
|
42
|
-
private
|
43
|
-
|
44
43
|
# Reads the file contents to calculate the MD5 hash, so that if a file is
|
45
44
|
# changed, the manifest is changed too.
|
46
45
|
def self.compute_file_contents_hash(path)
|
@@ -53,6 +52,13 @@ module Manifesto
|
|
53
52
|
hash
|
54
53
|
end
|
55
54
|
|
55
|
+
# Recursively find all file entries from within a directory.
|
56
|
+
def self.get_file_paths(directory)
|
57
|
+
entries = []
|
58
|
+
Find.find(directory) { |entry| entries << entry }
|
59
|
+
entries
|
60
|
+
end
|
61
|
+
|
56
62
|
# Strips the directory from the start of path, so that each path is relative
|
57
63
|
# to directory. Add a leading forward slash if not present.
|
58
64
|
def self.normalize_path(directory, path)
|
@@ -61,7 +67,7 @@ module Manifesto
|
|
61
67
|
normalized_path
|
62
68
|
end
|
63
69
|
|
64
|
-
def self.
|
70
|
+
def self.validate_options(directory, compute_hash)
|
65
71
|
raise(ArgumentError, ":directory must be a real directory") unless valid_directory?(directory)
|
66
72
|
raise(ArgumentError, ":compute_hash must be a boolean") unless valid_compute_hash?(compute_hash)
|
67
73
|
end
|
data/manifesto.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{manifesto}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.5.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"]
|
12
|
-
s.date = %q{2010-06-
|
12
|
+
s.date = %q{2010-06-09}
|
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 = [
|
@@ -29,9 +29,10 @@ Gem::Specification.new do |s|
|
|
29
29
|
"spec/spec.opts",
|
30
30
|
"spec/spec_helper.rb"
|
31
31
|
]
|
32
|
-
s.homepage = %q{http://manifesto
|
32
|
+
s.homepage = %q{http://github.com/johntopley/manifesto}
|
33
33
|
s.rdoc_options = ["--charset=UTF-8"]
|
34
34
|
s.require_paths = ["lib"]
|
35
|
+
s.rubyforge_project = %q{manifesto}
|
35
36
|
s.rubygems_version = %q{1.3.7}
|
36
37
|
s.summary = %q{Manifesto is a Ruby library that dynamically generates an HTML5 cache manifest}
|
37
38
|
s.test_files = [
|
data/spec/manifesto_spec.rb
CHANGED
@@ -1,25 +1,130 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
|
3
3
|
describe Manifesto do
|
4
|
-
|
5
|
-
|
4
|
+
describe ".validate_options" do
|
5
|
+
it "should raise ArgumentError if directory is not a real directory" do
|
6
|
+
expect{ Manifesto.validate_options('', false) }.to raise_error(ArgumentError)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should raise ArgumentError if compute_hash is not a boolean" do
|
10
|
+
expect{ Manifesto.validate_options('.', nil) }.to raise_error(ArgumentError)
|
11
|
+
end
|
6
12
|
end
|
7
|
-
|
8
|
-
|
9
|
-
|
13
|
+
|
14
|
+
describe ".cache" do
|
15
|
+
before(:each) do
|
16
|
+
Manifesto.stub!(:validate_options).and_return(true)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should validate the options" do
|
20
|
+
Manifesto.should_receive(:validate_options).and_return(true)
|
21
|
+
Manifesto.cache
|
22
|
+
end
|
23
|
+
|
24
|
+
context "when default directory" do
|
25
|
+
it "should get file paths from the default directory" do
|
26
|
+
Manifesto.should_receive(:get_file_paths).with('./public').and_return([])
|
27
|
+
Manifesto.cache
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "when directory is specified" do
|
32
|
+
it "should get file path from within the specified directory" do
|
33
|
+
Manifesto.should_receive(:get_file_paths).with('./mobile').and_return([])
|
34
|
+
Manifesto.cache(:directory => './mobile')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "when there are no files in the directory" do
|
39
|
+
before(:each) do
|
40
|
+
Manifesto.stub!(:get_file_paths).and_return([])
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should not compute hash" do
|
44
|
+
Manifesto.should_receive(:compute_file_contents_hash).never
|
45
|
+
Manifesto.cache
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "when there are files in the directories" do
|
50
|
+
it "should check the file" do
|
51
|
+
File.should_receive(:file?)
|
52
|
+
Manifesto.cache
|
53
|
+
end
|
54
|
+
|
55
|
+
context "and path is for the directory or symlink" do
|
56
|
+
before(:each) do
|
57
|
+
Manifesto.stub!(:get_file_paths).and_return(['public/dir1', 'public/symlink'])
|
58
|
+
File.stub!(:file?).and_return(false)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should not compute hash" do
|
62
|
+
Manifesto.should_receive(:compute_file_contents_hash).never
|
63
|
+
Manifesto.cache
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should not normalize the path" do
|
67
|
+
Manifesto.should_receive(:normalize_path).never
|
68
|
+
Manifesto.cache
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context "and path is for the hidden file" do
|
73
|
+
before(:each) do
|
74
|
+
Manifesto.stub!(:get_file_paths).and_return(['public/.hiddenfile'])
|
75
|
+
File.stub!(:file?).and_return(true)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should not compute hash" do
|
79
|
+
Manifesto.should_receive(:compute_file_contents_hash).never
|
80
|
+
Manifesto.cache
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should not normalize the path" do
|
84
|
+
Manifesto.should_receive(:normalize_path).never
|
85
|
+
Manifesto.cache
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context "and path is for a valid file" do
|
90
|
+
before(:each) do
|
91
|
+
Manifesto.stub!(:get_file_paths).and_return(['/public/file1'])
|
92
|
+
File.stub!(:file?).and_return(true)
|
93
|
+
Manifesto.stub!(:compute_file_contents_hash).and_return('asdfsafasdfsdfszxsd')
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should compute the hash" do
|
97
|
+
Manifesto.should_receive(:compute_file_contents_hash).and_return('anything')
|
98
|
+
Manifesto.cache
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should normalize path" do
|
102
|
+
Manifesto.should_receive(:normalize_path).with('./public', '/public/file1')
|
103
|
+
Manifesto.cache
|
104
|
+
end
|
105
|
+
|
106
|
+
context "and return an array of values" do
|
107
|
+
it "should return an array of 4 elements" do
|
108
|
+
Manifesto.cache.size.should eql(4)
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should have 'CACHE MANIFEST text in the first element of the return array'" do
|
112
|
+
Manifesto.cache.first.should eql("CACHE MANIFEST\n")
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should have 'generated by manifesto text'" do
|
116
|
+
Manifesto.cache.should be_include("# Generated by manifesto (http://github.com/johntopley/manifesto)\n")
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should have the file name in the last element of the array" do
|
120
|
+
Manifesto.cache.last.should eql("/file1\n")
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should return the hash" do
|
124
|
+
Manifesto.cache.should be_include("# Hash: f2d6ac219e22a0eed707a24d65777a0e\n")
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
10
129
|
end
|
11
|
-
|
12
|
-
it "should return a list of files within the default directory"
|
13
|
-
|
14
|
-
it "should return a list of files within the specified directory"
|
15
|
-
|
16
|
-
it "should compute a hash of the files within the default directory"
|
17
|
-
|
18
|
-
it "should compute a hash of the files within the specified directory"
|
19
|
-
|
20
|
-
it "should compute a different hash if the content of a file changes"
|
21
|
-
|
22
|
-
it "shouldn't include hidden files or directories within the default directory"
|
23
|
-
|
24
|
-
it "shouldn't include hidden files or directories within the specified directory"
|
25
130
|
end
|
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:
|
4
|
+
hash: 11
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 5
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.5.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- John Topley
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-06-
|
18
|
+
date: 2010-06-09 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -56,7 +56,7 @@ files:
|
|
56
56
|
- spec/spec.opts
|
57
57
|
- spec/spec_helper.rb
|
58
58
|
has_rdoc: true
|
59
|
-
homepage: http://manifesto
|
59
|
+
homepage: http://github.com/johntopley/manifesto
|
60
60
|
licenses: []
|
61
61
|
|
62
62
|
post_install_message:
|
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
84
|
version: "0"
|
85
85
|
requirements: []
|
86
86
|
|
87
|
-
rubyforge_project:
|
87
|
+
rubyforge_project: manifesto
|
88
88
|
rubygems_version: 1.3.7
|
89
89
|
signing_key:
|
90
90
|
specification_version: 3
|