manifesto 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +69 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/lib/manifesto.rb +76 -0
- data/manifesto.gemspec +55 -0
- data/spec/manifesto_spec.rb +25 -0
- data/spec/spec.opts +3 -0
- data/spec/spec_helper.rb +3 -0
- metadata +94 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 John Topley
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
= manifesto
|
2
|
+
|
3
|
+
Manifesto dynamically generates an {HTML5 cache manifest}[http://developer.apple.com/safari/library/documentation/iphone/conceptual/safarijsdatabaseguide/OfflineApplicationCache/OfflineApplicationCache.html] for offline application caching. It returns a list of files within the specified directory and sub-directories.
|
4
|
+
By default it also includes a computed hash of the files' contents, so that if a file is changed a different hash is produced, causing the cache to be automatically invalidated.
|
5
|
+
|
6
|
+
== Requirements
|
7
|
+
|
8
|
+
* Ruby >= 1.8.6 (not tested with previous versions)
|
9
|
+
|
10
|
+
== Installation
|
11
|
+
|
12
|
+
This library is intended to be installed as a Gem.
|
13
|
+
|
14
|
+
$ gem install manifesto
|
15
|
+
|
16
|
+
You might need administrator privileges on your system to install it.
|
17
|
+
|
18
|
+
== Usage
|
19
|
+
|
20
|
+
# Basic usage, list all non-hidden files in ./public and include a computed hash of their contents
|
21
|
+
Manifesto.cache
|
22
|
+
|
23
|
+
# Specify a directory
|
24
|
+
Manifesto.cache :directory => './mobile'
|
25
|
+
|
26
|
+
# Specify a directory and don't compute the hash
|
27
|
+
Manifesto.cache :directory => './mobile', :compute_hash => false
|
28
|
+
|
29
|
+
== Sample Output
|
30
|
+
|
31
|
+
CACHE MANIFEST
|
32
|
+
# Generated by manifesto (http://github.com/johntopley/manifesto)
|
33
|
+
# Hash: 7013a3b8292ceeeb6336849bee1d1365
|
34
|
+
/apple-touch-icon.png
|
35
|
+
/apple-touch-startup.png
|
36
|
+
/index.html
|
37
|
+
/mobile/mobile.css
|
38
|
+
/mobile/mobile.js
|
39
|
+
|
40
|
+
== Sinatra Example
|
41
|
+
|
42
|
+
require 'manifesto.rb'
|
43
|
+
|
44
|
+
get '/manifest' do
|
45
|
+
headers 'Content-Type' => 'text/cache-manifest' # Must be served with this MIME type
|
46
|
+
Manifesto.cache
|
47
|
+
end
|
48
|
+
|
49
|
+
== Ruby on Rails Example
|
50
|
+
|
51
|
+
TODO
|
52
|
+
|
53
|
+
== Issues
|
54
|
+
|
55
|
+
Please use the {GitHub issues tracker}[http://github.com/johntopley/manifesto/issues].
|
56
|
+
|
57
|
+
== Note on Patches/Pull Requests
|
58
|
+
|
59
|
+
* Fork the project
|
60
|
+
* Make your feature addition or bug fix
|
61
|
+
* Add tests for it. This is important so I don't break it in a
|
62
|
+
future version unintentionally
|
63
|
+
* Commit, do not mess with rakefile, version, or history
|
64
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
65
|
+
* Send me a pull request. Bonus points for topic branches
|
66
|
+
|
67
|
+
== Copyright
|
68
|
+
|
69
|
+
Copyright (c) 2010 John Topley. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "manifesto"
|
8
|
+
gem.summary = %Q{Manifesto is a Ruby library that dynamically generates an HTML5 cache manifest}
|
9
|
+
gem.description = %Q{Dynamically generates an HTML5 cache manifest from the contents of a directory}
|
10
|
+
gem.email = "john@johntopley.com"
|
11
|
+
gem.homepage = "http://manifesto.rubyforge.org"
|
12
|
+
gem.authors = ["John Topley"]
|
13
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'spec/rake/spectask'
|
22
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
23
|
+
spec.libs << 'lib' << 'spec'
|
24
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
25
|
+
end
|
26
|
+
|
27
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
28
|
+
spec.libs << 'lib' << 'spec'
|
29
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
30
|
+
spec.rcov_opts = %w{--exclude gems/*,Ruby}
|
31
|
+
spec.rcov = true
|
32
|
+
end
|
33
|
+
|
34
|
+
task :spec => :check_dependencies
|
35
|
+
|
36
|
+
task :default => :spec
|
37
|
+
|
38
|
+
require 'rake/rdoctask'
|
39
|
+
Rake::RDocTask.new do |rdoc|
|
40
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
41
|
+
|
42
|
+
rdoc.rdoc_dir = 'rdoc'
|
43
|
+
rdoc.title = "manifesto #{version}"
|
44
|
+
rdoc.rdoc_files.include('README*')
|
45
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
46
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/manifesto.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'digest/md5'
|
2
|
+
require 'find'
|
3
|
+
|
4
|
+
module Manifesto
|
5
|
+
|
6
|
+
# Returns an Array of non-hidden files within the <tt>./public</tt> directory, unless <tt>:directory</tt> is specified.
|
7
|
+
# The output also includes a computed hash of the files' contents, unless <tt>:compute_hash</tt> is set to <tt>false</tt>.
|
8
|
+
#
|
9
|
+
# === Examples
|
10
|
+
#
|
11
|
+
# Basic usage, list all non-hidden files in <tt>./public</tt> and include a computed hash of their contents:
|
12
|
+
# Manifesto.cache
|
13
|
+
#
|
14
|
+
# Specify a directory:
|
15
|
+
# Manifesto.cache :directory => './mobile'
|
16
|
+
#
|
17
|
+
# Specify a directory and don't compute the hash:
|
18
|
+
# Manifesto.cache :directory => './mobile', :compute_hash => false
|
19
|
+
def self.cache(options = {})
|
20
|
+
directory = options.fetch(:directory, './public')
|
21
|
+
compute_hash = options.fetch(:compute_hash, true)
|
22
|
+
validate_arguments(directory, compute_hash)
|
23
|
+
manifest = []
|
24
|
+
hashes = ''
|
25
|
+
Find.find(directory) do |path|
|
26
|
+
|
27
|
+
# Only include real files (i.e. not directories, symlinks etc.) and non-hidden
|
28
|
+
# files in the manifest.
|
29
|
+
if File.file?(path) && File.basename(path)[0,1] != '.'
|
30
|
+
manifest << "#{normalize_path(directory, path)}\n"
|
31
|
+
hashes += compute_file_contents_hash(path) if compute_hash
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Hash the hashes of each file and output as a comment.
|
36
|
+
manifest << "# Hash: #{Digest::MD5.hexdigest(hashes)}\n" if compute_hash
|
37
|
+
manifest << "# Generated by manifesto (http://github.com/johntopley/manifesto)\n"
|
38
|
+
manifest << "CACHE MANIFEST\n"
|
39
|
+
manifest.reverse
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
# Reads the file contents to calculate the MD5 hash, so that if a file is
|
45
|
+
# changed, the manifest is changed too.
|
46
|
+
def self.compute_file_contents_hash(path)
|
47
|
+
hash = ''
|
48
|
+
digest = Digest::MD5.new
|
49
|
+
File.open(path, 'r') do |file|
|
50
|
+
digest.update(file.read(8192)) until file.eof
|
51
|
+
hash += digest.hexdigest
|
52
|
+
end
|
53
|
+
hash
|
54
|
+
end
|
55
|
+
|
56
|
+
# Strips the directory from the start of path, so that each path is relative
|
57
|
+
# to directory. Add a leading forward slash if not present.
|
58
|
+
def self.normalize_path(directory, path)
|
59
|
+
normalized_path = path[directory.length,path.length]
|
60
|
+
normalized_path = '/' + normalized_path unless normalized_path[0,1] == '/'
|
61
|
+
normalized_path
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.validate_arguments(directory, compute_hash)
|
65
|
+
raise(ArgumentError, ":directory must be a real directory") unless valid_directory?(directory)
|
66
|
+
raise(ArgumentError, ":compute_hash must be a boolean") unless valid_compute_hash?(compute_hash)
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.valid_compute_hash?(compute_hash)
|
70
|
+
compute_hash.is_a?(TrueClass) || compute_hash.is_a?(FalseClass)
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.valid_directory?(directory)
|
74
|
+
File.directory?(directory)
|
75
|
+
end
|
76
|
+
end
|
data/manifesto.gemspec
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{manifesto}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["John Topley"]
|
12
|
+
s.date = %q{2010-06-05}
|
13
|
+
s.description = %q{Dynamically generates an HTML5 cache manifest from the contents of a directory}
|
14
|
+
s.email = %q{john@johntopley.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/manifesto.rb",
|
27
|
+
"manifesto.gemspec",
|
28
|
+
"spec/manifesto_spec.rb",
|
29
|
+
"spec/spec.opts",
|
30
|
+
"spec/spec_helper.rb"
|
31
|
+
]
|
32
|
+
s.homepage = %q{http://manifesto.rubyforge.org}
|
33
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
34
|
+
s.require_paths = ["lib"]
|
35
|
+
s.rubygems_version = %q{1.3.7}
|
36
|
+
s.summary = %q{Manifesto is a Ruby library that dynamically generates an HTML5 cache manifest}
|
37
|
+
s.test_files = [
|
38
|
+
"spec/manifesto_spec.rb",
|
39
|
+
"spec/spec_helper.rb"
|
40
|
+
]
|
41
|
+
|
42
|
+
if s.respond_to? :specification_version then
|
43
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
44
|
+
s.specification_version = 3
|
45
|
+
|
46
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
47
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
48
|
+
else
|
49
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
50
|
+
end
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Manifesto do
|
4
|
+
it "should raise ArgumentError if directory is not a real directory" do
|
5
|
+
expect{ Manifesto.validate_arguments('', false) }.to raise_error(ArgumentError)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should raise ArgumentError if compute_hash is not a boolean" do
|
9
|
+
expect{ Manifesto.validate_arguments('.', nil) }.to raise_error(ArgumentError)
|
10
|
+
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
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: manifesto
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- John Topley
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-06-05 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rspec
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 13
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 2
|
33
|
+
- 9
|
34
|
+
version: 1.2.9
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
description: Dynamically generates an HTML5 cache manifest from the contents of a directory
|
38
|
+
email: john@johntopley.com
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files:
|
44
|
+
- LICENSE
|
45
|
+
- README.rdoc
|
46
|
+
files:
|
47
|
+
- .document
|
48
|
+
- .gitignore
|
49
|
+
- LICENSE
|
50
|
+
- README.rdoc
|
51
|
+
- Rakefile
|
52
|
+
- VERSION
|
53
|
+
- lib/manifesto.rb
|
54
|
+
- manifesto.gemspec
|
55
|
+
- spec/manifesto_spec.rb
|
56
|
+
- spec/spec.opts
|
57
|
+
- spec/spec_helper.rb
|
58
|
+
has_rdoc: true
|
59
|
+
homepage: http://manifesto.rubyforge.org
|
60
|
+
licenses: []
|
61
|
+
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options:
|
64
|
+
- --charset=UTF-8
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
hash: 3
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
version: "0"
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
hash: 3
|
82
|
+
segments:
|
83
|
+
- 0
|
84
|
+
version: "0"
|
85
|
+
requirements: []
|
86
|
+
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 1.3.7
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: Manifesto is a Ruby library that dynamically generates an HTML5 cache manifest
|
92
|
+
test_files:
|
93
|
+
- spec/manifesto_spec.rb
|
94
|
+
- spec/spec_helper.rb
|