servel 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/servel.rb +2 -1
- data/lib/servel/haml_context.rb +0 -4
- data/lib/servel/locals.rb +8 -4
- data/lib/servel/path.rb +49 -0
- data/lib/servel/path_builder.rb +80 -0
- data/lib/servel/templates/_listing.haml +2 -3
- data/lib/servel/templates/index.haml +1 -1
- data/lib/servel/version.rb +1 -1
- metadata +3 -2
- data/lib/servel/pathname_decorator.rb +0 -110
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9415e93e4c4259efd8b7547c1d8a67c8bb71c54
|
4
|
+
data.tar.gz: 87744e0b049184c5b2138fd34ab3e34c292016dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30c5075efb1b5fab6b79ee68b55a18e75fddfe681bd7c03d159a83f2321b97f7442b7cd9430d8c3aadf5117db6a9fd244c48ed1d23200ba8c8f4302f5c915821
|
7
|
+
data.tar.gz: 5e2e42e1b6caf5857a3d16a6d44d8207343401a4188a82af8bbbee4a7cca5bfc599b25755a1c3edba805c247276cadd160444fbc5f1b42509ea4b7dc984d007a
|
data/lib/servel.rb
CHANGED
data/lib/servel/haml_context.rb
CHANGED
@@ -20,10 +20,6 @@ class Servel::HamlContext
|
|
20
20
|
(@build_path + path).read
|
21
21
|
end
|
22
22
|
|
23
|
-
def decorate(path)
|
24
|
-
Servel::PathnameDecorator.new(pathname: path)
|
25
|
-
end
|
26
|
-
|
27
23
|
def haml_engine(path)
|
28
24
|
unless @haml_engine_cache.key?(path)
|
29
25
|
@haml_engine_cache[path] = Haml::Engine.new(include(path), ENGINE_OPTIONS.merge(filename: path))
|
data/lib/servel/locals.rb
CHANGED
@@ -16,19 +16,23 @@ class Servel::Locals
|
|
16
16
|
|
17
17
|
def directories
|
18
18
|
list = @fs_path.children.select { |child| child.directory? }
|
19
|
-
list = sort_paths(list)
|
19
|
+
list = sort_paths(list).map { |path| build(path) }
|
20
20
|
|
21
21
|
unless @url_path == "/"
|
22
|
-
list.unshift(Servel::
|
23
|
-
list.unshift(Servel::
|
22
|
+
list.unshift(Servel::Path.parent("../"))
|
23
|
+
list.unshift(Servel::Path.top(@url_root))
|
24
24
|
end
|
25
25
|
|
26
26
|
list
|
27
27
|
end
|
28
28
|
|
29
|
+
def build(path)
|
30
|
+
Servel::PathBuilder.new(path).build
|
31
|
+
end
|
32
|
+
|
29
33
|
def files
|
30
34
|
list = @fs_path.children.select { |child| child.file? }
|
31
|
-
sort_paths(list)
|
35
|
+
sort_paths(list).map { |path| build(path) }
|
32
36
|
end
|
33
37
|
|
34
38
|
def sort_paths(paths)
|
data/lib/servel/path.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
class Servel::Path
|
2
|
+
attr_reader :type, :media_type, :listing_classes, :icon, :href, :name, :size, :mtime
|
3
|
+
|
4
|
+
def initialize(type:, media_type:, listing_classes:, icon:, href:, name:, size: nil, mtime: nil)
|
5
|
+
@type = type
|
6
|
+
@media_type = media_type
|
7
|
+
@listing_classes = listing_classes
|
8
|
+
@icon = icon
|
9
|
+
@href = href
|
10
|
+
@name = name
|
11
|
+
@size = size
|
12
|
+
@mtime = mtime
|
13
|
+
end
|
14
|
+
|
15
|
+
def listing_attrs
|
16
|
+
{
|
17
|
+
class: @listing_classes,
|
18
|
+
data: {
|
19
|
+
type: @media_type
|
20
|
+
}
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def media?
|
25
|
+
@media_type != "unknown"
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.top(href)
|
29
|
+
Servel::Path.new(
|
30
|
+
type: "Dir",
|
31
|
+
media_type: "unknown",
|
32
|
+
listing_classes: "top directory",
|
33
|
+
icon: "🔝",
|
34
|
+
href: href,
|
35
|
+
name: "Top Directory"
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.parent(href)
|
40
|
+
Servel::Path.new(
|
41
|
+
type: "Dir",
|
42
|
+
media_type: "unknown",
|
43
|
+
listing_classes: "parent directory",
|
44
|
+
icon: "⬆️",
|
45
|
+
href: href,
|
46
|
+
name: "Parent Directory"
|
47
|
+
)
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
class Servel::PathBuilder
|
2
|
+
def initialize(path)
|
3
|
+
@path = Pathname.new(path)
|
4
|
+
end
|
5
|
+
|
6
|
+
def build
|
7
|
+
Servel::Path.new(
|
8
|
+
type: type,
|
9
|
+
media_type: media_type,
|
10
|
+
listing_classes: listing_classes,
|
11
|
+
icon: icon,
|
12
|
+
href: @path.basename,
|
13
|
+
name: @path.basename,
|
14
|
+
size: size,
|
15
|
+
mtime: @path.mtime
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
def image?
|
20
|
+
@path.file? && @path.extname && %w(.jpg .jpeg .png .gif).include?(@path.extname.downcase)
|
21
|
+
end
|
22
|
+
|
23
|
+
def video?
|
24
|
+
@path.file? && @path.extname && %w(.webm .mp4).include?(@path.extname.downcase)
|
25
|
+
end
|
26
|
+
|
27
|
+
def audio?
|
28
|
+
@path.file? && @path.extname && %w(.mp3 .m4a .wav).include?(@path.extname.downcase)
|
29
|
+
end
|
30
|
+
|
31
|
+
def media?
|
32
|
+
image? || video? || audio?
|
33
|
+
end
|
34
|
+
|
35
|
+
def type
|
36
|
+
if @path.directory?
|
37
|
+
"Dir"
|
38
|
+
elsif @path.file?
|
39
|
+
@path.extname.sub(/^\./, "")
|
40
|
+
else
|
41
|
+
""
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def media_type
|
46
|
+
return "video" if video?
|
47
|
+
return "image" if image?
|
48
|
+
return "audio" if audio?
|
49
|
+
"unknown"
|
50
|
+
end
|
51
|
+
|
52
|
+
def listing_classes
|
53
|
+
klasses = []
|
54
|
+
klasses << "media" if media?
|
55
|
+
klasses << "image" if image?
|
56
|
+
klasses << "video" if video?
|
57
|
+
klasses << "audio" if audio?
|
58
|
+
klasses << "file" if @path.file?
|
59
|
+
klasses << "directory" if @path.directory?
|
60
|
+
klasses.join(" ")
|
61
|
+
end
|
62
|
+
|
63
|
+
def icon
|
64
|
+
if @path.directory?
|
65
|
+
"📁"
|
66
|
+
elsif video?
|
67
|
+
"🎞️"
|
68
|
+
elsif image?
|
69
|
+
"🖼️"
|
70
|
+
elsif audio?
|
71
|
+
"🔊"
|
72
|
+
else
|
73
|
+
"📝"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def size
|
78
|
+
@path.directory? ? nil : @path.size
|
79
|
+
end
|
80
|
+
end
|
@@ -10,7 +10,6 @@
|
|
10
10
|
%th.modified Modified
|
11
11
|
%tbody
|
12
12
|
- (directories + files).each do |file|
|
13
|
-
- file = decorate(file)
|
14
13
|
%tr
|
15
14
|
%td
|
16
15
|
%span.icon= file.icon
|
@@ -18,5 +17,5 @@
|
|
18
17
|
%td
|
19
18
|
%a.new-tab{href: file.href, target: "_blank", **file.listing_attrs} (New tab)
|
20
19
|
%td= file.type
|
21
|
-
%td= file.
|
22
|
-
%td= file.
|
20
|
+
%td= file.size.nil? ? "-" : number_to_human_size(file.size)
|
21
|
+
%td= file.mtime.nil? ? "-" : file.mtime.strftime("%e %b %Y %l:%M %p")
|
@@ -14,6 +14,6 @@
|
|
14
14
|
:javascript
|
15
15
|
#{include('gallery.js')}
|
16
16
|
%body
|
17
|
-
- if files.any? { |f|
|
17
|
+
- if files.any? { |f| f.media? }
|
18
18
|
#gallery!= partial('gallery')
|
19
19
|
#listing!= partial('listing', { url_root: url_root, url_path: url_path, directories: directories, files: files })
|
data/lib/servel/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: servel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brenton "B-Train" Fletcher
|
@@ -130,7 +130,8 @@ files:
|
|
130
130
|
- lib/servel/haml_context.rb
|
131
131
|
- lib/servel/home_app.rb
|
132
132
|
- lib/servel/locals.rb
|
133
|
-
- lib/servel/
|
133
|
+
- lib/servel/path.rb
|
134
|
+
- lib/servel/path_builder.rb
|
134
135
|
- lib/servel/templates/_gallery.haml
|
135
136
|
- lib/servel/templates/_listing.haml
|
136
137
|
- lib/servel/templates/common.css
|
@@ -1,110 +0,0 @@
|
|
1
|
-
class Servel::PathnameDecorator < SimpleDelegator
|
2
|
-
def initialize(pathname:, parent: false, top: false)
|
3
|
-
super(pathname)
|
4
|
-
@parent = parent
|
5
|
-
@top = top
|
6
|
-
end
|
7
|
-
|
8
|
-
def image?
|
9
|
-
file? && extname && %w(.jpg .jpeg .png .gif).include?(extname.downcase)
|
10
|
-
end
|
11
|
-
|
12
|
-
def video?
|
13
|
-
file? && extname && %w(.webm .mp4).include?(extname.downcase)
|
14
|
-
end
|
15
|
-
|
16
|
-
def audio?
|
17
|
-
file? && extname && %w(.mp3 .m4a .wav).include?(extname.downcase)
|
18
|
-
end
|
19
|
-
|
20
|
-
def media?
|
21
|
-
image? || video? || audio?
|
22
|
-
end
|
23
|
-
|
24
|
-
def type
|
25
|
-
if directory?
|
26
|
-
"Dir"
|
27
|
-
elsif file?
|
28
|
-
extname.sub(/^\./, "")
|
29
|
-
else
|
30
|
-
""
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def media_type
|
35
|
-
return "video" if video?
|
36
|
-
return "image" if image?
|
37
|
-
return "audio" if audio?
|
38
|
-
"unknown"
|
39
|
-
end
|
40
|
-
|
41
|
-
def listing_classes
|
42
|
-
klasses = []
|
43
|
-
klasses << "media" if media?
|
44
|
-
klasses << "image" if image?
|
45
|
-
klasses << "video" if video?
|
46
|
-
klasses << "audio" if audio?
|
47
|
-
klasses << "top" if top?
|
48
|
-
klasses << "parent" if parent?
|
49
|
-
klasses << "file" if file?
|
50
|
-
klasses << "directory" if directory?
|
51
|
-
klasses.join(" ")
|
52
|
-
end
|
53
|
-
|
54
|
-
def listing_attrs
|
55
|
-
{
|
56
|
-
class: listing_classes,
|
57
|
-
data: {
|
58
|
-
type: media_type
|
59
|
-
}
|
60
|
-
}
|
61
|
-
end
|
62
|
-
|
63
|
-
def top?
|
64
|
-
@top
|
65
|
-
end
|
66
|
-
|
67
|
-
def parent?
|
68
|
-
@parent
|
69
|
-
end
|
70
|
-
|
71
|
-
def virtual?
|
72
|
-
top? || parent?
|
73
|
-
end
|
74
|
-
|
75
|
-
def icon
|
76
|
-
if @top
|
77
|
-
"🔝"
|
78
|
-
elsif @parent
|
79
|
-
"⬆️"
|
80
|
-
elsif directory?
|
81
|
-
"📁"
|
82
|
-
elsif video?
|
83
|
-
"🎞️"
|
84
|
-
elsif image?
|
85
|
-
"🖼️"
|
86
|
-
elsif audio?
|
87
|
-
"🔊"
|
88
|
-
else
|
89
|
-
"📝"
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
def href
|
94
|
-
if @top || @parent
|
95
|
-
to_s
|
96
|
-
else
|
97
|
-
basename
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def name
|
102
|
-
if @top
|
103
|
-
"Top Directory"
|
104
|
-
elsif @parent
|
105
|
-
"Parent Directory"
|
106
|
-
else
|
107
|
-
basename
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|