directory_listing 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3cf8138fc74458cee692795f92ea3e8436cb795e
4
- data.tar.gz: 10a82b76d2bbdbbb7b98fb379c90c40470ee92d4
3
+ metadata.gz: 513baf59cf0a27dc639d52bbff9ab369e8a2bd33
4
+ data.tar.gz: 4d7bde85c5440ef7fb3b83d38ac3eaefadbc779b
5
5
  SHA512:
6
- metadata.gz: 050ce306863a84e889bd0caeb1e77736d355b652302c09cd8370d8fce04051cfdc9d48e4878ded09df5079cb72c27c1c27dc903f4229a1f5cb5b4e91a9e06cc8
7
- data.tar.gz: 23bfe4fc941b14c4952e2663493d493a3ea65fbcc1985704e41f566fb51dd889a9d548b007cf327ad58a32177d2a5740349897c9a0c0e2f1f4b0b5749b4e0e30
6
+ metadata.gz: 69be2fc4333486ce6278e1c3fe5c29703e83793f2a9b30f268ecd0bdf496ce09da65771594295ccef5f33bf2700c21734941a2520ce5cfa8ad458ae9d6e724b1
7
+ data.tar.gz: dad9fab1bd163a162b484120d92385df7127d6f70f01c0ab46526f233ddaee3f79aadd1d97cd9b98e17d6284e91175a50f87a5a93d04ba922ae4e7e5faa02f38
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- directory_listing (0.4.3)
4
+ directory_listing (0.6.0)
5
5
  filesize (>= 0.0.2)
6
6
  sinatra
7
7
  truncate (>= 0.0.4)
@@ -11,12 +11,12 @@ GEM
11
11
  specs:
12
12
  filesize (0.0.3)
13
13
  rack (1.5.2)
14
- rack-protection (1.5.2)
14
+ rack-protection (1.5.3)
15
15
  rack
16
16
  rack-test (0.6.2)
17
17
  rack (>= 1.0)
18
18
  rake (10.1.0)
19
- sinatra (1.4.4)
19
+ sinatra (1.4.5)
20
20
  rack (~> 1.4)
21
21
  rack-protection (~> 1.4)
22
22
  tilt (~> 1.3, >= 1.3.4)
data/README.md CHANGED
@@ -10,8 +10,6 @@
10
10
 
11
11
  ```directory_listing``` also includes a number of configuration options - see the [Options](#options) section below.
12
12
 
13
- A short blog post / announcement exists [here](http://blog.catsanddogshavealltheluck.com/#Directory_Listings_in_Sinatra).
14
-
15
13
  ### Install
16
14
 
17
15
  For regular use:
@@ -69,6 +67,7 @@ Available options:
69
67
  - ```readme``` - an HTML string that will be appended at the footer of the generated directory listing
70
68
  - ```should_list_invisibles``` - whether the directory listing should include invisibles (dotfiles) - true or false, defaults to false
71
69
  - ```should_show_file_exts``` - whether the directory listing should show file extensions - true or false, defaults to true
70
+ - ```smart_sort``` - whether sorting should ignore "[Tt]he " at the beginning of filenames - true or false, defaults to true
72
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```
73
72
  - ```filename_truncate_length``` - length to truncate file names to - integer, defaults to 40
74
73
 
@@ -24,6 +24,7 @@ module Sinatra
24
24
  options = {
25
25
  :should_list_invisibles => false,
26
26
  :should_show_file_exts => true,
27
+ :smart_sort => true,
27
28
  :last_modified_format => "%Y-%m-%d %H:%M:%S",
28
29
  :filename_truncate_length => 40,
29
30
  :stylesheet => "",
@@ -36,6 +37,7 @@ module Sinatra
36
37
  page = Page.new
37
38
  page.should_list_invisibles = options[:should_list_invisibles]
38
39
  page.should_show_file_exts = options[:should_show_file_exts]
40
+ page.smart_sort = options[:smart_sort]
39
41
  page.last_modified_format = options[:last_modified_format]
40
42
  page.filename_truncate_length = options[:filename_truncate_length]
41
43
  page.public_folder = settings.public_folder
@@ -5,6 +5,7 @@ class Page
5
5
 
6
6
  attr_accessor :should_list_invisibles,
7
7
  :should_show_file_exts,
8
+ :smart_sort,
8
9
  :last_modified_format,
9
10
  :filename_truncate_length,
10
11
  :stylesheet,
@@ -5,13 +5,15 @@ class Resource
5
5
  ##
6
6
  # Class definition for a single resource to be listed.
7
7
  # Each resource object has accessors for its file name, regular name,
8
- # size and mtime, as well as those components wrapped in html.
8
+ # sortable name (removing "[Tt]he") size and mtime, as well as those
9
+ # components wrapped in html.
9
10
 
10
- attr_accessor :file, :page, :name_html, :mtime, :mtime_html, :size, :size_html
11
+ attr_accessor :file, :page, :sort_name, :name_html, :mtime, :mtime_html, :size, :size_html
11
12
 
12
13
  def initialize(file, page)
13
14
  @page = page
14
15
  @file = file
16
+ @sort_name = file.gsub(/^[Tt]he /,"")
15
17
  @name_html = set_name(file)
16
18
  @mtime, @mtime_html = set_mtime(file)
17
19
  @size, @size_html = set_size(file)
@@ -136,6 +138,7 @@ class Resource
136
138
  # Direction should be "ascending" or "descending"
137
139
 
138
140
  def self.sort(resource_array, sortby, direction)
141
+ sortby = "sort_name" if resource_array[0].page.smart_sort == true #and sortby = "file"
139
142
  new_array = resource_array.sort_by {|a| a.send(sortby)}
140
143
  new_array.reverse! if direction == "descending"
141
144
  new_array
@@ -1,3 +1,3 @@
1
1
  module Directory_listing
2
- VERSION = '0.5.1'
2
+ VERSION = '0.6.0'
3
3
  end
@@ -72,7 +72,7 @@ class DirectoryListingTest < Test::Unit::TestCase
72
72
  ##
73
73
  # test sorting
74
74
 
75
- def files_array(body)
75
+ def sorting_array(body)
76
76
  files = Array.new
77
77
  body.each_line do |line|
78
78
  files << $& if /(\d)k.dat/.match(line)
@@ -82,41 +82,41 @@ class DirectoryListingTest < Test::Unit::TestCase
82
82
 
83
83
  def test_sorting_name_ascending
84
84
  get '/sorting?sortby=file&direction=ascending'
85
- files = files_array(last_response.body)
85
+ files = sorting_array(last_response.body)
86
86
  assert_equal ["1k.dat", "2k.dat", "3k.dat"], files
87
87
  end
88
88
 
89
89
  def test_sorting_name_descending
90
90
  get '/sorting?sortby=file&direction=descending'
91
- files = files_array(last_response.body)
91
+ files = sorting_array(last_response.body)
92
92
  assert_equal ["3k.dat", "2k.dat", "1k.dat"], files
93
93
  end
94
94
 
95
95
  def test_sorting_mtime_ascending
96
96
  get '/sorting?sortby=mtime&direction=ascending'
97
- files = files_array(last_response.body)
97
+ files = sorting_array(last_response.body)
98
98
  assert_equal ["2k.dat", "3k.dat", "1k.dat"], files
99
99
  end
100
100
 
101
101
  def test_sorting_mtime_descending
102
102
  get '/sorting?sortby=mtime&direction=descending'
103
- files = files_array(last_response.body)
103
+ files = sorting_array(last_response.body)
104
104
  assert_equal ["1k.dat", "3k.dat", "2k.dat"], files
105
105
  end
106
106
 
107
107
  def test_sorting_size_ascending
108
108
  get '/sorting?sortby=size&direction=ascending'
109
- files = files_array(last_response.body)
109
+ files = sorting_array(last_response.body)
110
110
  assert_equal ["1k.dat", "2k.dat", "3k.dat"], files
111
111
  end
112
112
 
113
113
  def test_sorting_size_descending
114
114
  get '/sorting?sortby=size&direction=descending'
115
- files = files_array(last_response.body)
115
+ files = sorting_array(last_response.body)
116
116
  assert_equal ["3k.dat", "2k.dat", "1k.dat"], files
117
117
  end
118
118
 
119
- ##
119
+ ##
120
120
  # test navigation bar
121
121
 
122
122
  def test_navigation_bar
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.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Myers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-24 00:00:00.000000000 Z
11
+ date: 2014-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -161,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
161
  version: '0'
162
162
  requirements: []
163
163
  rubyforge_project:
164
- rubygems_version: 2.0.3
164
+ rubygems_version: 2.0.14
165
165
  signing_key:
166
166
  specification_version: 4
167
167
  summary: Easy, CSS-styled, Apache-like directory listings for Sinatra.