directory_listing 0.6.2 → 0.6.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9692a7377e281b36851d6caf01896f1980307217
4
- data.tar.gz: abd645f08b3adf7bbd2d22c24cebec1650166388
3
+ metadata.gz: 241d7e83370def28838e157f7a2f2649b7b8148d
4
+ data.tar.gz: f856b6f389aff56ec50e61544116f1fb2913765a
5
5
  SHA512:
6
- metadata.gz: 6154b4696475e4a01c0e6c12e9901b3e2d46b784c9aa167f9b7c82358c14788909d05f473de298862ad6a6ff96d3f0816228d2eb2c20332129d5d2c5c21cfdf8
7
- data.tar.gz: 61e7353073d51b3a2ddfe36a195f190324344f1e5e8e4eaa27df44648fde8051064a20933613946f174a28f1c40b47e399fd86f8c1c6c2510c37fe1ccdc3ef12
6
+ metadata.gz: 18d7c48f75f5d69d93d977ae1825c03546a2a9a0b6a47877021609f17bdac30b4e8dbb95a1f1b22ddd967692c7ddc427269e3e590681ecd4b3c924b21b5304f0
7
+ data.tar.gz: 174a66908985f434a410344315a5cb57bb225c9d428227456608f7b56e0dc48a9ab1be660875fe5cb3dee90075476de4eae8e1fe5d53a837cefd568f21c5d1b7
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- directory_listing (0.6.0)
4
+ directory_listing (0.6.2)
5
5
  filesize (>= 0.0.2)
6
- sinatra
6
+ sinatra (>= 1.4.5)
7
7
  truncate (>= 0.0.4)
8
8
 
9
9
  GEM
@@ -16,13 +16,14 @@ GEM
16
16
  rack-test (0.6.2)
17
17
  rack (>= 1.0)
18
18
  rake (10.1.0)
19
+ shotgun (0.9)
20
+ rack (>= 1.0)
19
21
  sinatra (1.4.5)
20
22
  rack (~> 1.4)
21
23
  rack-protection (~> 1.4)
22
24
  tilt (~> 1.3, >= 1.3.4)
23
25
  tilt (1.4.1)
24
26
  truncate (0.1.0)
25
- yard (0.8.7)
26
27
 
27
28
  PLATFORMS
28
29
  ruby
@@ -31,5 +32,5 @@ DEPENDENCIES
31
32
  bundler (~> 1.3)
32
33
  directory_listing!
33
34
  rack-test (~> 0.6.2)
34
- rake
35
- yard (~> 0.8.7)
35
+ rake (~> 10.1.0)
36
+ shotgun (~> 0.9)
data/README.md CHANGED
@@ -6,7 +6,8 @@
6
6
 
7
7
  1. Easy to use and configure
8
8
  2. Style-able with CSS
9
- 3. Able to replicate all the features of Apache's directory listings including sorting
9
+ 3. Embeddable
10
+ 4. Able to replicate all the features of Apache's directory listings including sorting
10
11
 
11
12
  ```directory_listing``` also includes a number of configuration options - see the [Options](#options) section below.
12
13
 
@@ -64,6 +65,7 @@ list({
64
65
  Available options:
65
66
 
66
67
  - ```stylesheet``` - a stylesheet to style the generated directory listing with, relative to your ```public_folder```
68
+ - ```embed_in``` - an ```erb``` template in which to embed the directory listing, relative to your ```public_folder``` [(see below)](#embedding).
67
69
  - ```readme``` - an HTML string that will be appended at the footer of the generated directory listing
68
70
  - ```favicon``` - URL to a favicon
69
71
  - ```should_list_invisibles``` - whether the directory listing should include invisibles (dotfiles) - true or false, defaults to false
@@ -72,6 +74,39 @@ Available options:
72
74
  - ```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```
73
75
  - ```filename_truncate_length``` - length to truncate file names to - integer, defaults to 40
74
76
 
77
+ ### Embedding
78
+
79
+ By default, ```directory_listing``` will generate a complete HTML page. However, you can use the ```embed_in``` option to pass in your own ```erb``` template.
80
+ You should look at the [default template](lib/sinatra/directory_listing/layout.rb) to get an idea of the layout, but you should include the following:
81
+
82
+ - ```<%= page.current_page %>``` - the name of the current page
83
+ - ```<%= page.sort_item_display %>``` - how the page is currently sorted
84
+ - ```<%= page.sort_direction_display %>``` - the direction the items are sorted in
85
+ - ```<%= page.favicon %>``` - the favicon
86
+ - ```<%= page.stylesheet %>``` - the stylesheet
87
+ - ```<%= page.nav_bar %>``` - the page's navigation bar
88
+ - ```<%= page.file_sort_link %>``` - link to sort by filename
89
+ - ```<%= page.mtime_sort_link %>``` - link to sort by mtime
90
+ - ```<%= page.size_sort_link %>``` - link to sort by size
91
+ - ```<%= page.files_html %>``` - the file listing
92
+ - ```<%= page.readme %>``` - the readme
93
+
94
+ If you want to embed the default file listing (but are passing a custom template to modify other attributes), you can use the following table:
95
+
96
+ ```html
97
+ <table>
98
+ <tr>
99
+ <th><a href='<%= page.file_sort_link %>'>File</a></th>
100
+ <th><a href='<%= page.mtime_sort_link %>'>Last modified</a></th>
101
+ <th><a href='<%= page.size_sort_link %>'>Size</a></th>
102
+ </tr>
103
+ <%= page.files_html %>
104
+ </table>
105
+ <hr><hr>
106
+ ```
107
+
108
+ NOTE: You should not put your ```erb``` template in a method as the gem does - you should be passing an actual ```.erb``` file to the ```embed_in``` option.
109
+
75
110
  ### Styling
76
111
 
77
112
  It's pretty easy to figure out how to style ```directory_listing``` by looking at the source, but here are some gotchas:
data/Rakefile CHANGED
@@ -1,25 +1,12 @@
1
1
  require "bundler/gem_tasks"
2
2
  require 'rake/testtask'
3
- require 'yard'
4
-
5
- ##
6
- # Run the test application
7
3
 
8
4
  desc "Run the test application on port 4567"
9
5
  task :run do
10
- `ruby test/test_directory_listing_app.rb -o 0.0.0.0`
11
- end
12
-
13
- ##
14
- # Generate yard docs
15
-
16
- YARD::Rake::YardocTask.new do |t|
17
- t.files = ['lib/**/*.rb']
6
+ `shotgun test/test_directory_listing_app.rb -o 0.0.0.0`
18
7
  end
19
8
 
20
- ##
21
- # Run tests
22
-
9
+ desc "Run tests"
23
10
  Rake::TestTask.new do |t|
24
11
  t.libs << 'test'
25
12
  end
@@ -27,4 +14,4 @@ end
27
14
  ##
28
15
  # Default -> run tests
29
16
 
30
- task :default => 'test'
17
+ task :default => [:test]
@@ -14,12 +14,12 @@ Gem::Specification.new do |s|
14
14
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
15
15
  s.homepage = 'https://rubygems.org/gems/directory_listing'
16
16
 
17
- s.add_dependency 'sinatra'
17
+ s.add_dependency 'sinatra', '>=1.4.5'
18
18
  s.add_dependency 'filesize', '>=0.0.2'
19
19
  s.add_dependency 'truncate', '>=0.0.4'
20
20
 
21
- s.add_development_dependency "rake"
21
+ s.add_development_dependency "rake", "~> 10.1.0"
22
22
  s.add_development_dependency "bundler", "~> 1.3"
23
+ s.add_development_dependency "shotgun", "~> 0.9"
23
24
  s.add_development_dependency "rack-test", "~> 0.6.2"
24
- s.add_development_dependency "yard", "~> 0.8.7"
25
25
  end
@@ -28,6 +28,7 @@ module Sinatra
28
28
  :last_modified_format => "%Y-%m-%d %H:%M:%S",
29
29
  :filename_truncate_length => 40,
30
30
  :stylesheet => "",
31
+ :embed_in => "",
31
32
  :favicon => "",
32
33
  :readme => ""
33
34
  }.merge(o)
@@ -40,17 +41,20 @@ module Sinatra
40
41
  page.should_show_file_exts = options[:should_show_file_exts]
41
42
  page.smart_sort = options[:smart_sort]
42
43
  page.last_modified_format = options[:last_modified_format]
43
- page.filename_truncate_length = options[:filename_truncate_length]
44
+ page.filename_truncate_length = options[:filename_truncate_length]
44
45
  page.public_folder = settings.public_folder
45
46
  page.request_path = request.path
46
47
  page.request_params = request.params
47
48
  page.current_page = URI.unescape(request.path)
48
49
 
49
50
  ##
50
- # Set the readme, stylesheet, and favicon
51
-
51
+ # Set the erb template to embed in, the readme, stylesheet, and favicon
52
+
52
53
  page.readme = options[:readme] if options[:readme]
53
54
  page.favicon = options[:favicon] if options[:favicon]
55
+ if options[:embed_in]
56
+ page.embed_in = options[:embed_in]
57
+ end
54
58
  if options[:stylesheet]
55
59
  page.stylesheet = "<link rel='stylesheet' type='text/css' href='/#{options[:stylesheet].sub(/^[\/]*/,"")}'>"
56
60
  end
@@ -123,7 +127,16 @@ module Sinatra
123
127
  ##
124
128
  # Generate and return the complete page from the erb template.
125
129
 
126
- erb = ERB.new(LAYOUT)
130
+ if !page.embed_in.empty?
131
+ path = File.join(settings.public_folder, page.embed_in)
132
+ if File.exists?(path)
133
+ erb = ERB.new(IO.read(path))
134
+ else
135
+ erb = ERB.new(LAYOUT)
136
+ end
137
+ else
138
+ erb = ERB.new(LAYOUT)
139
+ end
127
140
  erb.result(binding)
128
141
  end
129
142
 
@@ -11,6 +11,7 @@ class Page
11
11
  :stylesheet,
12
12
  :favicon,
13
13
  :readme,
14
+ :embed_in,
14
15
  :public_folder,
15
16
  :request_path,
16
17
  :request_params,
@@ -1,3 +1,3 @@
1
1
  module Directory_listing
2
- VERSION = '0.6.2'
2
+ VERSION = '0.6.3'
3
3
  end
@@ -0,0 +1,29 @@
1
+ <html>
2
+ <head>
3
+ <title>using custom erb template</title>
4
+ <%= page.stylesheet %>
5
+ </head>
6
+ <body>
7
+
8
+ <b><a><%= page.nav_bar %></a></b>
9
+ <br><br>
10
+
11
+ <a>page.sort_item_display: <%= page.sort_item_display %></a><br>
12
+ <a>page.sort_direction_display: <%= page.sort_direction_display %></a><br>
13
+ <br><br>
14
+
15
+ <hr>
16
+ <table>
17
+ <tr>
18
+ <th><a href='<%= page.file_sort_link %>'>File</a></th>
19
+ <th><a href='<%= page.mtime_sort_link %>'>Last modified</a></th>
20
+ <th><a href='<%= page.size_sort_link %>'>Size</a></th>
21
+ </tr>
22
+ <%= page.files_html %>
23
+ </table>
24
+ <hr>
25
+ <br><br>
26
+
27
+ <a>here's a readme: <%= page.readme %></a>
28
+ </body>
29
+ </html>
@@ -1,11 +1,10 @@
1
1
  ENV['RACK_ENV'] = 'test'
2
-
3
- require_relative 'test_directory_listing_app'
4
-
5
- require 'test/unit'
2
+ require 'minitest/autorun'
6
3
  require 'rack/test'
7
4
 
8
- class DirectoryListingTest < Test::Unit::TestCase
5
+ require File.expand_path '../test_directory_listing_app.rb', __FILE__
6
+
7
+ class DirectoryListingTest < MiniTest::Unit::TestCase
9
8
  include Rack::Test::Methods
10
9
 
11
10
  def app
@@ -43,6 +42,14 @@ class DirectoryListingTest < Test::Unit::TestCase
43
42
  get '/stylesheets'
44
43
  assert last_response.body.include?('/stylesheets/styles.css')
45
44
  end
45
+
46
+ ##
47
+ # test embedding a custom erb template
48
+
49
+ def embed_in
50
+ get '/embed_in'
51
+ assert last_response.body.include?('using custom erb template')
52
+ end
46
53
 
47
54
  ##
48
55
  # test defining a readme
@@ -14,6 +14,13 @@ get '/readme' do
14
14
  })
15
15
  end
16
16
 
17
+ get '/embed_in' do
18
+ list({
19
+ :embed_in => "/embed_in/layout.erb",
20
+ :readme => "this is my readme"
21
+ })
22
+ end
23
+
17
24
  get '/favicon' do
18
25
  list({
19
26
  :favicon => "/favicon/favicon.ico"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: directory_listing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Myers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-03 00:00:00.000000000 Z
11
+ date: 2015-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '>='
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 1.4.5
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '>='
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 1.4.5
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: filesize
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -56,16 +56,16 @@ dependencies:
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 10.1.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ~>
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: 10.1.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: bundler
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -81,33 +81,33 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '1.3'
83
83
  - !ruby/object:Gem::Dependency
84
- name: rack-test
84
+ name: shotgun
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ~>
88
88
  - !ruby/object:Gem::Version
89
- version: 0.6.2
89
+ version: '0.9'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - ~>
95
95
  - !ruby/object:Gem::Version
96
- version: 0.6.2
96
+ version: '0.9'
97
97
  - !ruby/object:Gem::Dependency
98
- name: yard
98
+ name: rack-test
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - ~>
102
102
  - !ruby/object:Gem::Version
103
- version: 0.8.7
103
+ version: 0.6.2
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - ~>
109
109
  - !ruby/object:Gem::Version
110
- version: 0.8.7
110
+ version: 0.6.2
111
111
  description: A Sinatra extension for generating easy, CSS-styled, Apache-like directory
112
112
  listings.
113
113
  email: rick.myers@me.com
@@ -128,6 +128,7 @@ files:
128
128
  - lib/sinatra/directory_listing/resource.rb
129
129
  - lib/sinatra/directory_listing/version.rb
130
130
  - test/public/1234.txt
131
+ - test/public/embed_in/layout.erb
131
132
  - test/public/favicon/favicon.ico
132
133
  - test/public/level1/level2/level3/level 4/test
133
134
  - test/public/level1/level2/level3/test
@@ -168,6 +169,7 @@ specification_version: 4
168
169
  summary: Easy, CSS-styled, Apache-like directory listings for Sinatra.
169
170
  test_files:
170
171
  - test/public/1234.txt
172
+ - test/public/embed_in/layout.erb
171
173
  - test/public/favicon/favicon.ico
172
174
  - test/public/level1/level2/level3/level 4/test
173
175
  - test/public/level1/level2/level3/test