snap 0.1.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/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +37 -0
- data/Rakefile +56 -0
- data/TODO +23 -0
- data/VERSION +1 -0
- data/bin/snap +21 -0
- data/lib/snap.rb +2 -0
- data/lib/snap/assets/icons/back.png +0 -0
- data/lib/snap/assets/icons/dir.png +0 -0
- data/lib/snap/assets/icons/forward.png +0 -0
- data/lib/snap/assets/icons/text.png +0 -0
- data/lib/snap/assets/snap.jpg +0 -0
- data/lib/snap/assets/styles.css +17 -0
- data/lib/snap/server.rb +95 -0
- data/lib/snap/snap_file.rb +57 -0
- data/lib/snap/views/code.erb +17 -0
- data/lib/snap/views/index.erb +37 -0
- data/lib/snap/views/not_found.erb +18 -0
- data/snap.gemspec +80 -0
- data/test/helper.rb +10 -0
- data/test/test_snap.rb +31 -0
- data/test/test_snap_file.rb +57 -0
- metadata +120 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Nick Stielau
|
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,37 @@
|
|
1
|
+
= snap
|
2
|
+
|
3
|
+
Directory listings faster than you can say 'onomatopoeia'.
|
4
|
+
|
5
|
+
Snap helps you quickly browse through directories and examine files in your browser.
|
6
|
+
|
7
|
+
Install the gem with:
|
8
|
+
|
9
|
+
$: sudo gem install snap
|
10
|
+
|
11
|
+
Run Snap, chrooted to the current directory
|
12
|
+
View at: http://localhost:4567
|
13
|
+
|
14
|
+
$: snap
|
15
|
+
|
16
|
+
Run Snap, chrooted to your home directory
|
17
|
+
View at: http://localhost:4567
|
18
|
+
|
19
|
+
$: snap -r ~
|
20
|
+
|
21
|
+
Run Snap with a different port
|
22
|
+
View at: http://localhost:3000
|
23
|
+
|
24
|
+
$: snap -p 3000
|
25
|
+
|
26
|
+
View other Snap options:
|
27
|
+
|
28
|
+
$: snap -h
|
29
|
+
Usage: snap [options]
|
30
|
+
-e env
|
31
|
+
-s server
|
32
|
+
-p port
|
33
|
+
-r root
|
34
|
+
|
35
|
+
== Copyright
|
36
|
+
|
37
|
+
Copyright (c) 2009 Nick Stielau. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "snap"
|
8
|
+
gem.summary = %Q{Directory listings faster than you can say 'onomatopoeia'.}
|
9
|
+
gem.description = %Q{A Sinatra app to make directory listings a snap!}
|
10
|
+
gem.email = "nick.stielau@gmail.com"
|
11
|
+
gem.homepage = "http://nstielau.github.com/snap"
|
12
|
+
gem.authors = ["Nick Stielau"]
|
13
|
+
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
14
|
+
gem.add_development_dependency "mocha", ">= 0.9.8"
|
15
|
+
gem.add_development_dependency "rack-test", ">= 0.5.1"
|
16
|
+
gem.add_runtime_dependency 'sinatra', '>= 0.9.4'
|
17
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
18
|
+
end
|
19
|
+
Jeweler::GemcutterTasks.new
|
20
|
+
rescue LoadError
|
21
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
22
|
+
end
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
Rake::TestTask.new(:test) do |test|
|
26
|
+
test.libs << 'lib' << 'test'
|
27
|
+
test.pattern = 'test/**/test_*.rb'
|
28
|
+
test.verbose = true
|
29
|
+
end
|
30
|
+
|
31
|
+
begin
|
32
|
+
require 'rcov/rcovtask'
|
33
|
+
Rcov::RcovTask.new do |test|
|
34
|
+
test.libs << 'test'
|
35
|
+
test.pattern = 'test/**/test_*.rb'
|
36
|
+
test.verbose = true
|
37
|
+
end
|
38
|
+
rescue LoadError
|
39
|
+
task :rcov do
|
40
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
task :test => :check_dependencies
|
45
|
+
|
46
|
+
task :default => :test
|
47
|
+
|
48
|
+
require 'rake/rdoctask'
|
49
|
+
Rake::RDocTask.new do |rdoc|
|
50
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
51
|
+
|
52
|
+
rdoc.rdoc_dir = 'rdoc'
|
53
|
+
rdoc.title = "snap #{version}"
|
54
|
+
rdoc.rdoc_files.include('README*')
|
55
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
56
|
+
end
|
data/TODO
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
##########
|
2
|
+
## TODO ##
|
3
|
+
##########
|
4
|
+
|
5
|
+
# Add '..' directory to go back
|
6
|
+
# Pretty print size
|
7
|
+
# Pretty up template, w CSS
|
8
|
+
# Line up columns/headers
|
9
|
+
# Serve images, html, and text different (Mime Types!)
|
10
|
+
# Add type field
|
11
|
+
# Move icon code from snap_file into helper
|
12
|
+
# Syntax highlight code?
|
13
|
+
# Truncate long file names
|
14
|
+
# Add gh-pages branch
|
15
|
+
# Make submodule or whatever
|
16
|
+
# Canonicalize trailing '/' with redirect
|
17
|
+
# BDD: Define tests
|
18
|
+
# Test + Mock + Shoulda
|
19
|
+
# Breadcumberize path
|
20
|
+
# Deal with symlinks
|
21
|
+
# Deal with files with spaces for 'type'
|
22
|
+
# Favicon
|
23
|
+
# SnapFileType class
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/snap
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'sinatra'
|
5
|
+
require 'snap'
|
6
|
+
|
7
|
+
require 'optparse'
|
8
|
+
|
9
|
+
options = {}
|
10
|
+
if ARGV.any?
|
11
|
+
OptionParser.new { |op|
|
12
|
+
op.banner = "Usage: snap [options]"
|
13
|
+
op.on('-e env') { |val| options[:environment] = val.to_sym }
|
14
|
+
op.on('-s server') { |val| options[:server] = val }
|
15
|
+
op.on('-p port') { |val| options[:port] = val.to_i }
|
16
|
+
op.on('-r root') { |val| options[:root] = val }
|
17
|
+
}.parse!(ARGV.dup)
|
18
|
+
end
|
19
|
+
|
20
|
+
# run!
|
21
|
+
Snap::Server.run!(options)
|
data/lib/snap.rb
ADDED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,17 @@
|
|
1
|
+
body {
|
2
|
+
background-color: #eee;
|
3
|
+
}
|
4
|
+
|
5
|
+
div#wrapper {
|
6
|
+
width: 800px;
|
7
|
+
padding: 20px;
|
8
|
+
}
|
9
|
+
|
10
|
+
div#content {
|
11
|
+
width: 600px;
|
12
|
+
background-color: #ccc;
|
13
|
+
-moz-border-radius: 5px;
|
14
|
+
-webkit-border-radius: 5px;
|
15
|
+
border: 2px solid #777;
|
16
|
+
padding: 10px;
|
17
|
+
}
|
data/lib/snap/server.rb
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'sinatra'
|
3
|
+
require 'erb'
|
4
|
+
require 'digest/md5'
|
5
|
+
|
6
|
+
module Snap
|
7
|
+
class Server < Sinatra::Base
|
8
|
+
set :views, File.dirname(__FILE__) + '/views'
|
9
|
+
|
10
|
+
#require 'logger'
|
11
|
+
#use Rack::CommonLogger, Logger.new(STDOUT)
|
12
|
+
# Add Rack::Cache
|
13
|
+
|
14
|
+
def self.run!(options={})
|
15
|
+
@@root_dir = options[:root]
|
16
|
+
super.run! if super.respond_to?("run!")
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_root_dir
|
20
|
+
@@root_dir ||= Dir.pwd
|
21
|
+
end
|
22
|
+
|
23
|
+
# TODO: Cattr?
|
24
|
+
def get_current_dir
|
25
|
+
@dir
|
26
|
+
end
|
27
|
+
|
28
|
+
def set_current_dir(newdir)
|
29
|
+
@dir = newdir
|
30
|
+
end
|
31
|
+
|
32
|
+
#############
|
33
|
+
# Snap Assets
|
34
|
+
get '/__snap__*/:file.:format' do
|
35
|
+
filename = File.dirname(__FILE__) + "/assets#{params[:splat]}/#{params[:file]}.#{params[:format]}"
|
36
|
+
headers({"Cache-Control" => "max-age=3600, public"})
|
37
|
+
content_type params[:format]
|
38
|
+
send_file filename
|
39
|
+
end
|
40
|
+
|
41
|
+
######
|
42
|
+
# 404
|
43
|
+
not_found do
|
44
|
+
status 404
|
45
|
+
erb :not_found
|
46
|
+
end
|
47
|
+
|
48
|
+
####################
|
49
|
+
# Main splat handler
|
50
|
+
get '/*' do
|
51
|
+
relative_location = params[:splat]
|
52
|
+
full_location = File.join(get_root_dir, relative_location)
|
53
|
+
if File.exist?(full_location)
|
54
|
+
if File.directory?(full_location)
|
55
|
+
set_current_dir(full_location)
|
56
|
+
erb :index
|
57
|
+
elsif File.file?(full_location)
|
58
|
+
if params[:format] && params[:format].to_sym == :code
|
59
|
+
@full_location = full_location
|
60
|
+
erb :code
|
61
|
+
else
|
62
|
+
send_file full_location, :type => params[:format] || File.extname(full_location)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
else
|
66
|
+
raise Sinatra::NotFound
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
def get_snap_files
|
72
|
+
files = Dir.glob("#{get_current_dir}/**").map{|f| SnapFile.new(f)}
|
73
|
+
files.insert(0,SnapFile.new(File.join(get_current_dir, '..'))) unless at_root?
|
74
|
+
files
|
75
|
+
end
|
76
|
+
|
77
|
+
def at_root?
|
78
|
+
File.expand_path(get_current_dir) == File.expand_path(get_root_dir)
|
79
|
+
end
|
80
|
+
|
81
|
+
# def breadcrumberize_path
|
82
|
+
# relative_path = get_current_dir.sub(get_root_dir, "")
|
83
|
+
# puts "Relative path is #{relative_path}"
|
84
|
+
# relative_parts = relative_path.split("/")
|
85
|
+
# relative_parts.pop
|
86
|
+
# puts "relative_parts are #{relative_parts.inspect}"
|
87
|
+
# b_root = get_current_dir
|
88
|
+
# relative_parts.each do |p|
|
89
|
+
# b_root = b_root.sub(p, "<a href=\"/#{p}\">#{p}</a>")
|
90
|
+
# puts "Bboot is now #{b_root}"
|
91
|
+
# end
|
92
|
+
# b_root
|
93
|
+
# end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Snap
|
2
|
+
class SnapFile
|
3
|
+
def initialize(file_name)
|
4
|
+
@path = file_name.sub("//", "/")
|
5
|
+
end
|
6
|
+
|
7
|
+
def name
|
8
|
+
if @path && @path.match("/")
|
9
|
+
@path.split("/").last
|
10
|
+
else
|
11
|
+
@path
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def path
|
16
|
+
@path
|
17
|
+
end
|
18
|
+
|
19
|
+
def relative_to(dir)
|
20
|
+
rel = @path.sub(dir, "")
|
21
|
+
end
|
22
|
+
|
23
|
+
def size
|
24
|
+
File.size(@path)
|
25
|
+
end
|
26
|
+
|
27
|
+
def mtime
|
28
|
+
return if File.symlink?(@path)
|
29
|
+
mtime = File.mtime(@path)
|
30
|
+
if (mtime.to_i > Time.now.to_i - 24*60*60)
|
31
|
+
mtime.strftime("%I:%M:%S %p")
|
32
|
+
else
|
33
|
+
mtime.strftime("%Y-%m-%d")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def type
|
38
|
+
escaped_path = @path.gsub(" ", "\\ ")
|
39
|
+
type = `file #{escaped_path}`.strip.sub(/.*:\s*/, "")
|
40
|
+
type = "text" if type.match("text")
|
41
|
+
type = "jpeg" if type.match("JPEG image data")
|
42
|
+
type = "png" if type.match("PNG image")
|
43
|
+
type = "executable" if type.match("executable")
|
44
|
+
type[0..11]
|
45
|
+
end
|
46
|
+
|
47
|
+
# TODO: Get this HTML outta here
|
48
|
+
def icon
|
49
|
+
return "<img src=\"/__snap__/icons/dir.png\"/>" if directory?
|
50
|
+
return "<img src=\"/__snap__/icons/text.png\"/>"
|
51
|
+
end
|
52
|
+
|
53
|
+
def directory?
|
54
|
+
type.match("directory")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/html4/loose.dtd">
|
3
|
+
<html lang="en">
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
6
|
+
<title>Snap! <%=get_current_dir %></title>
|
7
|
+
<link rel="stylesheet" type="text/css" href="/__snap__/styles.css" media="screen, print" />
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
<div>
|
11
|
+
<h3>Looking at <%= @full_location %></h3>
|
12
|
+
<pre>
|
13
|
+
<%= File.read(@full_location) %>
|
14
|
+
</pre>
|
15
|
+
</div>
|
16
|
+
</body>
|
17
|
+
</html>
|
@@ -0,0 +1,37 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/html4/loose.dtd">
|
3
|
+
<html lang="en">
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
6
|
+
<title>Snap! <%= get_current_dir %></title>
|
7
|
+
<link rel="stylesheet" type="text/css" href="/__snap__/styles.css" media="screen, print" />
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
<img src='/__snap__/snap.jpg' style="position:absolute;">
|
11
|
+
<div align="center">
|
12
|
+
<div id="wrapper">
|
13
|
+
<div id="content">
|
14
|
+
<h3>Listing <%= get_current_dir %> </h3>
|
15
|
+
<table>
|
16
|
+
<tr>
|
17
|
+
<th></th>
|
18
|
+
<th>File</th>
|
19
|
+
<th>Last Modified</th>
|
20
|
+
<th>Size</th>
|
21
|
+
<th>Type</th>
|
22
|
+
</tr>
|
23
|
+
<% get_snap_files.each do |f| %>
|
24
|
+
<tr>
|
25
|
+
<td><%= f.icon %></td>
|
26
|
+
<td><a href="<%= f.relative_to(get_root_dir) %>"><%= f.name %></a></td>
|
27
|
+
<td><%= f.mtime %></td>
|
28
|
+
<td><%= f.size %> bytes</a></td>
|
29
|
+
<td><%= f.type %></td>
|
30
|
+
</tr>
|
31
|
+
<% end %>
|
32
|
+
</table>
|
33
|
+
</div>
|
34
|
+
</div>
|
35
|
+
</div>
|
36
|
+
</body>
|
37
|
+
</html>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/html4/loose.dtd">
|
3
|
+
<html lang="en">
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
6
|
+
<title>Snap! <%= get_current_dir %></title>
|
7
|
+
<link rel="stylesheet" type="text/css" href="/__snap__/styles.css" media="screen, print" />
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
<img src='/__snap__/snap.jpg'/ style="position:absolute;">
|
11
|
+
<div align="center">
|
12
|
+
<div id="content">
|
13
|
+
<h3>404izzle</h3>
|
14
|
+
Go back to <a href="/"><%= get_root_dir %></a>.
|
15
|
+
</div>
|
16
|
+
</div>
|
17
|
+
</body>
|
18
|
+
</html>
|
data/snap.gemspec
ADDED
@@ -0,0 +1,80 @@
|
|
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{snap}
|
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 = ["Nick Stielau"]
|
12
|
+
s.date = %q{2009-11-29}
|
13
|
+
s.default_executable = %q{snap}
|
14
|
+
s.description = %q{A Sinatra app to make directory listings a snap!}
|
15
|
+
s.email = %q{nick.stielau@gmail.com}
|
16
|
+
s.executables = ["snap"]
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE",
|
19
|
+
"README.rdoc"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
".gitignore",
|
24
|
+
"LICENSE",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"TODO",
|
28
|
+
"VERSION",
|
29
|
+
"bin/snap",
|
30
|
+
"lib/snap.rb",
|
31
|
+
"lib/snap/assets/icons/back.png",
|
32
|
+
"lib/snap/assets/icons/dir.png",
|
33
|
+
"lib/snap/assets/icons/forward.png",
|
34
|
+
"lib/snap/assets/icons/text.png",
|
35
|
+
"lib/snap/assets/snap.jpg",
|
36
|
+
"lib/snap/assets/styles.css",
|
37
|
+
"lib/snap/server.rb",
|
38
|
+
"lib/snap/snap_file.rb",
|
39
|
+
"lib/snap/views/code.erb",
|
40
|
+
"lib/snap/views/index.erb",
|
41
|
+
"lib/snap/views/not_found.erb",
|
42
|
+
"snap.gemspec",
|
43
|
+
"test/helper.rb",
|
44
|
+
"test/test_snap.rb",
|
45
|
+
"test/test_snap_file.rb"
|
46
|
+
]
|
47
|
+
s.homepage = %q{http://nstielau.github.com/snap}
|
48
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
49
|
+
s.require_paths = ["lib"]
|
50
|
+
s.rubygems_version = %q{1.3.5}
|
51
|
+
s.summary = %q{Directory listings faster than you can say 'onomatopoeia'.}
|
52
|
+
s.test_files = [
|
53
|
+
"test/helper.rb",
|
54
|
+
"test/test_snap.rb",
|
55
|
+
"test/test_snap_file.rb"
|
56
|
+
]
|
57
|
+
|
58
|
+
if s.respond_to? :specification_version then
|
59
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
60
|
+
s.specification_version = 3
|
61
|
+
|
62
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
63
|
+
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
64
|
+
s.add_development_dependency(%q<mocha>, [">= 0.9.8"])
|
65
|
+
s.add_development_dependency(%q<rack-test>, [">= 0.5.1"])
|
66
|
+
s.add_runtime_dependency(%q<sinatra>, [">= 0.9.4"])
|
67
|
+
else
|
68
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
69
|
+
s.add_dependency(%q<mocha>, [">= 0.9.8"])
|
70
|
+
s.add_dependency(%q<rack-test>, [">= 0.5.1"])
|
71
|
+
s.add_dependency(%q<sinatra>, [">= 0.9.4"])
|
72
|
+
end
|
73
|
+
else
|
74
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
75
|
+
s.add_dependency(%q<mocha>, [">= 0.9.8"])
|
76
|
+
s.add_dependency(%q<rack-test>, [">= 0.5.1"])
|
77
|
+
s.add_dependency(%q<sinatra>, [">= 0.9.4"])
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
data/test/helper.rb
ADDED
data/test/test_snap.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
#require 'helper'
|
2
|
+
require 'snap'
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rack/test'
|
5
|
+
require 'test/unit'
|
6
|
+
|
7
|
+
class SnapAppTest < Test::Unit::TestCase
|
8
|
+
include Rack::Test::Methods
|
9
|
+
|
10
|
+
def app
|
11
|
+
Snap::Server
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_title
|
15
|
+
get '/'
|
16
|
+
assert last_response.body.match(/.<title>Snap! \/.*<\/title>/)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_title_with_path
|
20
|
+
get '/'
|
21
|
+
string = "<title>Snap! #{Dir.pwd}/<\/title>"
|
22
|
+
assert last_response.body.match(string), "Body doesn't contain #{string}:\n#{last_response.body}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_404
|
26
|
+
get '/couldnt/possibly/exist'
|
27
|
+
assert_equal(last_response.status, 404)
|
28
|
+
assert(last_response.body.match("404"))
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'snap/snap_file'
|
3
|
+
|
4
|
+
class SnapFileTest < Test::Unit::TestCase
|
5
|
+
def test_file_name
|
6
|
+
a = Snap::SnapFile.new('/path/to/some_file')
|
7
|
+
assert_equal(a.name, "some_file")
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_file_name_with_space
|
11
|
+
a = Snap::SnapFile.new('/path/to/some file')
|
12
|
+
assert_equal(a.name, "some file")
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_file_type
|
16
|
+
a = Snap::SnapFile.new(__FILE__)
|
17
|
+
assert_equal(a.type, "text")
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_file_type_with_space
|
21
|
+
Tempfile.open("snap test temp") do |f|
|
22
|
+
a = Snap::SnapFile.new(f.path)
|
23
|
+
assert_equal(a.type, "empty")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_file_size
|
28
|
+
a = Snap::SnapFile.new(__FILE__)
|
29
|
+
assert(a.size > 0)
|
30
|
+
assert_equal(a.size.class, Fixnum)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_empty_file_size
|
34
|
+
Tempfile.open("snap_test_temp") do |f|
|
35
|
+
a = Snap::SnapFile.new(f.path)
|
36
|
+
assert_equal(a.size, 0, "Tempfile should be of size 0")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_mtime
|
41
|
+
Tempfile.open("snap_test_temp") do |f|
|
42
|
+
a = Snap::SnapFile.new(f.path)
|
43
|
+
assert(a.mtime.match(/\d\d:\d\d:\d\d??/), "Mtime is #{a.mtime}")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_relative_path
|
48
|
+
a = Snap::SnapFile.new(__FILE__)
|
49
|
+
assert_equal(a.relative_to(File.dirname(__FILE__)), "/#{File.basename(__FILE__)}")
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_path
|
53
|
+
a = Snap::SnapFile.new(__FILE__)
|
54
|
+
assert_equal(a.path, __FILE__)
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: snap
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nick Stielau
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-29 00:00:00 -08:00
|
13
|
+
default_executable: snap
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: thoughtbot-shoulda
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: mocha
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.9.8
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rack-test
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.5.1
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: sinatra
|
47
|
+
type: :runtime
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.9.4
|
54
|
+
version:
|
55
|
+
description: A Sinatra app to make directory listings a snap!
|
56
|
+
email: nick.stielau@gmail.com
|
57
|
+
executables:
|
58
|
+
- snap
|
59
|
+
extensions: []
|
60
|
+
|
61
|
+
extra_rdoc_files:
|
62
|
+
- LICENSE
|
63
|
+
- README.rdoc
|
64
|
+
files:
|
65
|
+
- .document
|
66
|
+
- .gitignore
|
67
|
+
- LICENSE
|
68
|
+
- README.rdoc
|
69
|
+
- Rakefile
|
70
|
+
- TODO
|
71
|
+
- VERSION
|
72
|
+
- bin/snap
|
73
|
+
- lib/snap.rb
|
74
|
+
- lib/snap/assets/icons/back.png
|
75
|
+
- lib/snap/assets/icons/dir.png
|
76
|
+
- lib/snap/assets/icons/forward.png
|
77
|
+
- lib/snap/assets/icons/text.png
|
78
|
+
- lib/snap/assets/snap.jpg
|
79
|
+
- lib/snap/assets/styles.css
|
80
|
+
- lib/snap/server.rb
|
81
|
+
- lib/snap/snap_file.rb
|
82
|
+
- lib/snap/views/code.erb
|
83
|
+
- lib/snap/views/index.erb
|
84
|
+
- lib/snap/views/not_found.erb
|
85
|
+
- snap.gemspec
|
86
|
+
- test/helper.rb
|
87
|
+
- test/test_snap.rb
|
88
|
+
- test/test_snap_file.rb
|
89
|
+
has_rdoc: true
|
90
|
+
homepage: http://nstielau.github.com/snap
|
91
|
+
licenses: []
|
92
|
+
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options:
|
95
|
+
- --charset=UTF-8
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: "0"
|
103
|
+
version:
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: "0"
|
109
|
+
version:
|
110
|
+
requirements: []
|
111
|
+
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 1.3.5
|
114
|
+
signing_key:
|
115
|
+
specification_version: 3
|
116
|
+
summary: Directory listings faster than you can say 'onomatopoeia'.
|
117
|
+
test_files:
|
118
|
+
- test/helper.rb
|
119
|
+
- test/test_snap.rb
|
120
|
+
- test/test_snap_file.rb
|