directory_listing 0.4 → 0.4.1
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/README.md
CHANGED
|
@@ -100,6 +100,15 @@ table tr > td:first-child + td + td {
|
|
|
100
100
|
}
|
|
101
101
|
```
|
|
102
102
|
|
|
103
|
+
- The navigation bar is in a div called 'nav' and consists of hrefs embedded in h1s:
|
|
104
|
+
|
|
105
|
+
```css
|
|
106
|
+
div.nav h1, div.nav a {
|
|
107
|
+
font-size: 16px;
|
|
108
|
+
font-weight: 600;
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
103
112
|
### Getting Help
|
|
104
113
|
|
|
105
114
|
The best way to report a bug or feature request is to [open an issue on GitHub](https://github.com/movesmyers/directory_listing/issues).
|
|
@@ -11,8 +11,8 @@ class Page
|
|
|
11
11
|
:public_folder,
|
|
12
12
|
:request_path,
|
|
13
13
|
:request_params,
|
|
14
|
+
:request_params_display,
|
|
14
15
|
:current_page,
|
|
15
|
-
:back_to_link,
|
|
16
16
|
:files_html,
|
|
17
17
|
:sort_item,
|
|
18
18
|
:sort_item_display,
|
|
@@ -20,18 +20,69 @@ class Page
|
|
|
20
20
|
:sort_direction_display,
|
|
21
21
|
:file_sort_link,
|
|
22
22
|
:mtime_sort_link,
|
|
23
|
-
:size_sort_link
|
|
23
|
+
:size_sort_link,
|
|
24
|
+
:nav_bar
|
|
24
25
|
|
|
25
26
|
##
|
|
26
|
-
#
|
|
27
|
-
# same sorting parameters as the passed Page object
|
|
27
|
+
# Get URL-appendable (Hash -> String) parameters for a request
|
|
28
28
|
|
|
29
|
-
def
|
|
29
|
+
def request_params_display
|
|
30
30
|
params = ""
|
|
31
|
-
if
|
|
32
|
-
params = "?sortby=" +
|
|
31
|
+
if self.request_params["sortby"] && self.request_params["direction"]
|
|
32
|
+
params = "?sortby=" + self.request_params["sortby"] + "&direction=" + self.request_params["direction"]
|
|
33
33
|
end
|
|
34
34
|
end
|
|
35
|
+
|
|
36
|
+
##
|
|
37
|
+
# Generate the page's navigation bar
|
|
38
|
+
|
|
39
|
+
def nav_bar
|
|
40
|
+
path_array = self.current_page.split("/").drop(1)
|
|
41
|
+
path_count = path_array.count
|
|
42
|
+
params = self.request_params_display
|
|
43
|
+
|
|
44
|
+
if URI.unescape(self.current_page) == "/"
|
|
45
|
+
nav_bar = "Index of /"
|
|
46
|
+
else
|
|
47
|
+
nav_bar = "Index of <a href=\'/#{params}'>/</a>"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
previous_path = ""
|
|
51
|
+
0.upto(path_array.count - 1) do |a|
|
|
52
|
+
|
|
53
|
+
##
|
|
54
|
+
# Get escaped versions of this path and previous path
|
|
55
|
+
|
|
56
|
+
escaped_path = path_array[a].gsub(" ", "%20").gsub("'", "%27")
|
|
57
|
+
escaped_previous = previous_path.gsub(" ", "%20").gsub("'", "%27")
|
|
58
|
+
|
|
59
|
+
##
|
|
60
|
+
# If this is the last directory in the path, it shouldn't have a link
|
|
61
|
+
|
|
62
|
+
if a == path_array.count - 1
|
|
63
|
+
href = ""
|
|
64
|
+
else
|
|
65
|
+
href = "<a href=\'/#{escaped_previous}#{escaped_path}#{params}\'>"
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
##
|
|
69
|
+
# If this is the first directory above the root, don't prepend a slash
|
|
70
|
+
|
|
71
|
+
if a == 0
|
|
72
|
+
nav_bar << " #{href}#{path_array[a]}</a>"
|
|
73
|
+
else
|
|
74
|
+
nav_bar << " / #{href}#{path_array[a]}</a>"
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
previous_path << path_array[a] + "/"
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
@nav_bar = nav_bar
|
|
81
|
+
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
##
|
|
85
|
+
# Return sorting information given an item and the sorting direction
|
|
35
86
|
|
|
36
87
|
def sorting_info(s_item, s_direction)
|
|
37
88
|
|
|
@@ -33,53 +33,21 @@ module Sinatra
|
|
|
33
33
|
# Create a page object and start setting attributes.
|
|
34
34
|
|
|
35
35
|
page = Page.new
|
|
36
|
-
|
|
37
36
|
page.should_list_invisibles = options[:should_list_invisibles]
|
|
38
37
|
page.last_modified_format = options[:last_modified_format]
|
|
39
38
|
page.filename_truncate_length = options[:filename_truncate_length]
|
|
40
39
|
page.public_folder = settings.public_folder
|
|
41
40
|
page.request_path = request.path
|
|
42
41
|
page.request_params = request.params
|
|
42
|
+
page.current_page = URI.unescape(request.path)
|
|
43
43
|
|
|
44
44
|
##
|
|
45
|
-
#
|
|
45
|
+
# Set the readme and stylesheet
|
|
46
46
|
|
|
47
|
-
page.current_page = URI.unescape(request.path)
|
|
48
47
|
page.readme = options[:readme] if options[:readme]
|
|
49
48
|
if options[:stylesheet]
|
|
50
49
|
page.stylesheet = "<link rel='stylesheet' type='text/css' href='/#{options[:stylesheet].sub(/^[\/]*/,"")}'>"
|
|
51
50
|
end
|
|
52
|
-
|
|
53
|
-
##
|
|
54
|
-
# Generate the navigation links
|
|
55
|
-
# Append the sorting information if the current directory is sorted.
|
|
56
|
-
|
|
57
|
-
path_array = page.current_page.split("/").drop(1)
|
|
58
|
-
path_count = path_array.count
|
|
59
|
-
params = page.sorted_url(page)
|
|
60
|
-
|
|
61
|
-
if URI.unescape(request.path) == "/"
|
|
62
|
-
page.back_to_link = "Index of /"
|
|
63
|
-
else
|
|
64
|
-
page.back_to_link = "Index of <a href=\'/#{params}'>/</a>"
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
previous_path = ""
|
|
68
|
-
0.upto(path_array.count - 1) do |a|
|
|
69
|
-
escaped_path = path_array[a].gsub(" ", "%20").gsub("'", "%27")
|
|
70
|
-
escaped_previous = previous_path.gsub(" ", "%20").gsub("'", "%27")
|
|
71
|
-
if a == path_array.count - 1
|
|
72
|
-
href = ""
|
|
73
|
-
else
|
|
74
|
-
href = "<a href=\'/#{escaped_previous}#{escaped_path}#{params}\'>"
|
|
75
|
-
end
|
|
76
|
-
if a == 0
|
|
77
|
-
page.back_to_link << " #{href}#{path_array[a]}</a>"
|
|
78
|
-
else
|
|
79
|
-
page.back_to_link << " / #{href}#{path_array[a]}</a>"
|
|
80
|
-
end
|
|
81
|
-
previous_path << path_array[a] + "/"
|
|
82
|
-
end
|
|
83
51
|
|
|
84
52
|
##
|
|
85
53
|
# Get an array of files to be listed.
|
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:
|
|
4
|
+
version: 0.4.1
|
|
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: 2014-02-
|
|
12
|
+
date: 2014-02-21 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: filesize
|