directory_listing 0.3.2 → 0.3.3

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
@@ -1,2 +1,5 @@
1
1
  .DS_Store
2
2
  pkg/*
3
+ .yardoc/*
4
+ doc/*
5
+
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,27 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ directory_listing (0.3.2)
5
+ filesize (>= 0.0.2)
6
+ truncate (>= 0.0.4)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ filesize (0.0.2)
12
+ rack (1.5.2)
13
+ rack-test (0.6.2)
14
+ rack (>= 1.0)
15
+ rake (10.1.0)
16
+ truncate (0.1.0)
17
+ yard (0.8.7)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ bundler (~> 1.3)
24
+ directory_listing!
25
+ rack-test (~> 0.6.2)
26
+ rake
27
+ yard (~> 0.8.7)
data/README.md CHANGED
@@ -1,6 +1,18 @@
1
1
  ### directory_listing: easy, CSS-styled, Apache-like directory listings for Sinatra.
2
2
 
3
- ### Install:
3
+ ### Description
4
+
5
+ ```directory_listing``` is a [Sinatra](http://sinatrarb.com) plugin that generates Apache-like directory listings. It was designed to be:
6
+
7
+ 1. Easy to use and configure
8
+ 2. Style-able with CSS
9
+ 3. Able to replicate all the features of Apache's directory listings including sorting
10
+
11
+ ```directory_listing``` also includes a number of configuration options - see the [Options](#options) section below.
12
+
13
+ A short blog post / announcement exists [here](http://blog.catsanddogshavealltheluck.com/#Directory_Listings_in_Sinatra).
14
+
15
+ ### Install
4
16
 
5
17
  For regular use:
6
18
 
@@ -11,10 +23,11 @@ For regular use:
11
23
  Or from source:
12
24
 
13
25
  ```bash
26
+ bundle install
14
27
  rake install
15
28
  ```
16
29
 
17
- ### Usage:
30
+ ### Usage
18
31
 
19
32
  ```list()``` will return HTML, so the following is a complete Sinatra app that will provide a directory listing of whatever path you navigate to and let you view any file that is served directly:
20
33
 
@@ -39,7 +52,7 @@ not_found do
39
52
  end
40
53
  ```
41
54
 
42
- ### Options:
55
+ ### Options
43
56
 
44
57
  Options are passed in a hash:
45
58
 
@@ -58,7 +71,7 @@ Available options:
58
71
  - ```last_modified_format``` - [format](http://www.ruby-doc.org/core-2.0/Time.html) for last modified date - defaults to ```%Y-%m-%d %H:%M:%S```
59
72
  - ```filename_truncate_length``` - (integer) length to truncate file names to - defaults to 40
60
73
 
61
- ### Styling:
74
+ ### Styling
62
75
 
63
76
  It's pretty easy to figure out how to style ```directory_listing``` by looking at the source, but here are some gotchas:
64
77
 
@@ -87,10 +100,20 @@ table tr > td:first-child + td + td {
87
100
  }
88
101
  ```
89
102
 
90
- ### Contributing:
103
+ ### Getting Help
104
+
105
+ The best way to report a bug or feature request is to [open an issue on GitHub](https://github.com/movesmyers/directory_listing/issues).
106
+
107
+ Additionally, I'd love to hear your feedback about ```directory_listing``` through [Twitter](http://twitter.com/movesmyers) or [email](mailto:rick.myers@me.com).
108
+
109
+ ### Contributing
91
110
 
92
111
  1. Fork it
93
112
  2. Create your feature branch (```git checkout -b my-new-feature```)
94
113
  3. Commit your changes (```git commit -am 'Add some feature'```)
95
114
  4. Push to the branch (```git push origin my-new-feature```)
96
- 5. Create new Pull Request
115
+ 5. Create new Pull Request
116
+
117
+ ### License
118
+
119
+ ```directory_listing``` is licensed under the DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE. See the LICENSE file for details.
data/Rakefile CHANGED
@@ -1 +1,24 @@
1
- require "bundler/gem_tasks"
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+ require 'yard'
4
+
5
+ ##
6
+ # Run the test application
7
+
8
+ task :run do
9
+ `ruby test/test_directory_listing_app.rb -o 0.0.0.0`
10
+ end
11
+
12
+ ##
13
+ # Generate yard docs
14
+
15
+ YARD::Rake::YardocTask.new do |t|
16
+ t.files = ['lib/**/*.rb']
17
+ end
18
+
19
+ ##
20
+ # Run tests
21
+
22
+ Rake::TestTask.new do |t|
23
+ t.libs << 'test'
24
+ end
@@ -11,11 +11,14 @@ Gem::Specification.new do |s|
11
11
  s.email = 'rick.myers@me.com'
12
12
  s.license = 'WTFPL'
13
13
  s.files = `git ls-files`.split($/)
14
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
14
15
  s.homepage = 'https://rubygems.org/gems/directory_listing'
15
16
 
16
17
  s.add_dependency 'filesize', '>=0.0.2'
17
18
  s.add_dependency 'truncate', '>=0.0.4'
18
19
 
19
- s.add_development_dependency "bundler", "~> 1.3"
20
20
  s.add_development_dependency "rake"
21
+ s.add_development_dependency "bundler", "~> 1.3"
22
+ s.add_development_dependency "rack-test", "~> 0.6.2"
23
+ s.add_development_dependency "yard", "~> 0.8.7"
21
24
  end
@@ -15,20 +15,20 @@ class Resource
15
15
  end
16
16
 
17
17
  ##
18
- # Get the mtime for a file.
18
+ # Set the mtime for a file.
19
+ #
20
+ # Returns the mtime as a Time object so it can be sorted.
19
21
 
20
22
  def set_mtime(file)
21
23
  f = File.join(File.join($public_folder, URI.unescape($request_path)), file)
22
24
  html = "\t<td>#{File.mtime(f).strftime($last_modified_format)}</td>"
23
-
24
- ##
25
- # Return the mtime as a Time object so it can be sorted.
26
-
27
25
  return [File.mtime(f), html]
28
26
  end
29
27
 
30
28
  ##
31
- # Get the size for a file.
29
+ # Set the size for a file.
30
+ #
31
+ # Returns the size as number.
32
32
 
33
33
  def set_size(file)
34
34
  html = ""
@@ -42,15 +42,11 @@ class Resource
42
42
  converted = Filesize.from("#{File.stat(f).size} B").pretty
43
43
  html = "\t<td>#{converted}</td>"
44
44
  end
45
-
46
- ##
47
- # Return the mtime as a Time object so it can be sorted.
48
-
49
45
  return [size, html]
50
46
  end
51
47
 
52
48
  ##
53
- # Get the name of the file and its link.
49
+ # Set the name of the file and its link.
54
50
 
55
51
  def set_name(file)
56
52
 
@@ -120,7 +116,7 @@ class Resource
120
116
  #{@name_html}
121
117
  #{@mtime_html}
122
118
  #{@size_html}
123
- \t</tr>"
119
+ </tr>"
124
120
  end
125
121
  end
126
122
  html
@@ -1,3 +1,3 @@
1
1
  module Directory_listing
2
- VERSION = '0.3.2'
2
+ VERSION = '0.3.3'
3
3
  end
@@ -0,0 +1 @@
1
+ 1234
File without changes
File without changes
Binary file
Binary file
Binary file
File without changes
@@ -0,0 +1,110 @@
1
+ ENV['RACK_ENV'] = 'test'
2
+
3
+ require_relative 'test_directory_listing_app'
4
+
5
+ require 'test/unit'
6
+ require 'rack/test'
7
+
8
+ class DirectoryListingTest < Test::Unit::TestCase
9
+ include Rack::Test::Methods
10
+
11
+ def app
12
+ Sinatra::Application
13
+ end
14
+
15
+ ##
16
+ # test that a request to the root directory is ok.
17
+
18
+ def test_index
19
+ get '/'
20
+ assert last_response.ok?
21
+ end
22
+
23
+ ##
24
+ # test trying to list a non-existent file or directory
25
+
26
+ def test_not_found
27
+ get '/does_not_exist'
28
+ assert_equal 'Try again.', last_response.body
29
+ end
30
+
31
+ ##
32
+ # test serving a file (not directory)
33
+
34
+ def test_send_file
35
+ get '/1234.txt'
36
+ assert_equal '1234', last_response.body.chomp
37
+ end
38
+
39
+ ##
40
+ # test defining a stylesheet
41
+
42
+ def test_stylesheets
43
+ get '/stylesheets'
44
+ assert last_response.body.include?('/stylesheets/styles.css')
45
+ end
46
+
47
+ ##
48
+ # test defining a readme
49
+
50
+ def test_readme
51
+ get '/readme'
52
+ assert last_response.body.include?('this is my readme')
53
+ end
54
+
55
+ ##
56
+ # test listing invisibles
57
+
58
+ def test_should_list_invisibles
59
+ get '/should_list_invisibles'
60
+ assert (last_response.body.include?('/should_list_invisibles/.') and
61
+ last_response.body.include?('/should_list_invisibles/..'))
62
+ end
63
+
64
+ ##
65
+ # test sorting
66
+
67
+ def files_array(body)
68
+ files = Array.new
69
+ body.each_line do |line|
70
+ files << $& if /(\d)k.dat/.match(line)
71
+ end
72
+ files
73
+ end
74
+
75
+ def test_sorting_name_ascending
76
+ get '/sorting?sortby=file&direction=ascending'
77
+ files = files_array(last_response.body)
78
+ assert_equal ["1k.dat", "2k.dat", "3k.dat"], files
79
+ end
80
+
81
+ def test_sorting_name_descending
82
+ get '/sorting?sortby=file&direction=descending'
83
+ files = files_array(last_response.body)
84
+ assert_equal ["3k.dat", "2k.dat", "1k.dat"], files
85
+ end
86
+
87
+ def test_sorting_mtime_ascending
88
+ get '/sorting?sortby=mtime&direction=ascending'
89
+ files = files_array(last_response.body)
90
+ assert_equal ["2k.dat", "3k.dat", "1k.dat"], files
91
+ end
92
+
93
+ def test_sorting_mtime_descending
94
+ get '/sorting?sortby=mtime&direction=descending'
95
+ files = files_array(last_response.body)
96
+ assert_equal ["1k.dat", "3k.dat", "2k.dat"], files
97
+ end
98
+
99
+ def test_sorting_size_ascending
100
+ get '/sorting?sortby=size&direction=ascending'
101
+ files = files_array(last_response.body)
102
+ assert_equal ["1k.dat", "2k.dat", "3k.dat"], files
103
+ end
104
+
105
+ def test_sorting_size_descending
106
+ get '/sorting?sortby=size&direction=descending'
107
+ files = files_array(last_response.body)
108
+ assert_equal ["3k.dat", "2k.dat", "1k.dat"], files
109
+ end
110
+ end
@@ -0,0 +1,37 @@
1
+ require 'sinatra'
2
+
3
+ require_relative '../lib/sinatra/directory_listing.rb'
4
+
5
+ get '/stylesheets' do
6
+ list({
7
+ :stylesheet => "/stylesheets/styles.css"
8
+ })
9
+ end
10
+
11
+ get '/readme' do
12
+ list({
13
+ :readme => "this is my readme"
14
+ })
15
+ end
16
+
17
+ get '/should_list_invisibles' do
18
+ list({
19
+ :should_list_invisibles => true
20
+ })
21
+ end
22
+
23
+ get '*' do |path|
24
+ if File.exist?(File.join(settings.public_folder, path))
25
+ if File.directory?(File.join(settings.public_folder, path))
26
+ list()
27
+ else
28
+ send_file File.join(settings.public_folder, path)
29
+ end
30
+ else
31
+ not_found
32
+ end
33
+ end
34
+
35
+ not_found do
36
+ 'Try again.'
37
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: directory_listing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
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: 2013-09-04 00:00:00.000000000 Z
12
+ date: 2013-09-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: filesize
@@ -43,6 +43,22 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: 0.0.4
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
46
62
  - !ruby/object:Gem::Dependency
47
63
  name: bundler
48
64
  requirement: !ruby/object:Gem::Requirement
@@ -60,21 +76,37 @@ dependencies:
60
76
  - !ruby/object:Gem::Version
61
77
  version: '1.3'
62
78
  - !ruby/object:Gem::Dependency
63
- name: rake
79
+ name: rack-test
64
80
  requirement: !ruby/object:Gem::Requirement
65
81
  none: false
66
82
  requirements:
67
- - - ! '>='
83
+ - - ~>
68
84
  - !ruby/object:Gem::Version
69
- version: '0'
85
+ version: 0.6.2
70
86
  type: :development
71
87
  prerelease: false
72
88
  version_requirements: !ruby/object:Gem::Requirement
73
89
  none: false
74
90
  requirements:
75
- - - ! '>='
91
+ - - ~>
76
92
  - !ruby/object:Gem::Version
77
- version: '0'
93
+ version: 0.6.2
94
+ - !ruby/object:Gem::Dependency
95
+ name: yard
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 0.8.7
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 0.8.7
78
110
  description: A Sinatra extension for generating easy, CSS-styled, Apache-like directory
79
111
  listings.
80
112
  email: rick.myers@me.com
@@ -83,6 +115,8 @@ extensions: []
83
115
  extra_rdoc_files: []
84
116
  files:
85
117
  - .gitignore
118
+ - Gemfile
119
+ - Gemfile.lock
86
120
  - LICENSE
87
121
  - README.md
88
122
  - Rakefile
@@ -91,6 +125,15 @@ files:
91
125
  - lib/sinatra/directory_listing/layout.rb
92
126
  - lib/sinatra/directory_listing/resource.rb
93
127
  - lib/sinatra/directory_listing/version.rb
128
+ - test/public/1234.txt
129
+ - test/public/readme/test.txt
130
+ - test/public/should_list_invisibles/test.txt
131
+ - test/public/sorting/1k.dat
132
+ - test/public/sorting/2k.dat
133
+ - test/public/sorting/3k.dat
134
+ - test/public/stylesheets/styles.css
135
+ - test/test_directory_listing.rb
136
+ - test/test_directory_listing_app.rb
94
137
  homepage: https://rubygems.org/gems/directory_listing
95
138
  licenses:
96
139
  - WTFPL
@@ -112,8 +155,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
155
  version: '0'
113
156
  requirements: []
114
157
  rubyforge_project:
115
- rubygems_version: 1.8.24
158
+ rubygems_version: 1.8.23
116
159
  signing_key:
117
160
  specification_version: 3
118
161
  summary: Easy, CSS-styled, Apache-like directory listings for Sinatra.
119
- test_files: []
162
+ test_files:
163
+ - test/public/1234.txt
164
+ - test/public/readme/test.txt
165
+ - test/public/should_list_invisibles/test.txt
166
+ - test/public/sorting/1k.dat
167
+ - test/public/sorting/2k.dat
168
+ - test/public/sorting/3k.dat
169
+ - test/public/stylesheets/styles.css
170
+ - test/test_directory_listing.rb
171
+ - test/test_directory_listing_app.rb
172
+ has_rdoc: