servel 0.12.0 → 0.13.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/entry_factory.rb +2 -0
- data/lib/servel/index.rb +18 -26
- data/lib/servel/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04bbc42b03ba43d1ec342e7f397178a97eeff3a9
|
4
|
+
data.tar.gz: 1a9a865af005bd23156c2a76053f4bbd6adbdbf1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4bdb0287d5b8c289e99b1e9c0ab940f4369fd63b7f3b55e350aebc6acbe3c838f18b81cd96262f9f23c2d7347f438743e12c8dc4227bd24adb185897e3eccade
|
7
|
+
data.tar.gz: ad5e295d7c21189dbe42934a97e424c03ef76a6280ab948ccf473864829038a9e9ef5c2da4cf1592682ad63ae003197bf42dbc3940aba4962416eb34cdac3a59
|
data/lib/servel/entry_factory.rb
CHANGED
data/lib/servel/index.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
class Servel::Index
|
2
2
|
extend Servel::Instrumentation
|
3
|
-
|
3
|
+
RENDER_CACHE = LruRedux::ThreadSafeCache.new(100)
|
4
4
|
SORT_METHODS = ["name", "mtime", "size", "type"]
|
5
5
|
SORT_DIRECTIONS = ["asc", "desc"]
|
6
6
|
|
@@ -12,31 +12,15 @@ class Servel::Index
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def render
|
15
|
-
Servel::HamlContext.render('index.haml', locals)
|
15
|
+
RENDER_CACHE.getset(render_cache_key) { Servel::HamlContext.render('index.haml', locals) }
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
19
|
-
|
20
|
-
param = "name" unless SORT_METHODS.include?(param)
|
21
|
-
param
|
22
|
-
end
|
23
|
-
|
24
|
-
def sort_direction
|
25
|
-
param = @params["_servel_sort_direction"]
|
26
|
-
param = "asc" unless SORT_DIRECTIONS.include?(param)
|
27
|
-
param
|
28
|
-
end
|
29
|
-
|
30
|
-
def locals_cache_key
|
31
|
-
@locals_cache_key ||= [@fs_path.to_s, @fs_path.mtime.to_i, sort_method, sort_direction].join("-")
|
18
|
+
def render_cache_key
|
19
|
+
@render_cache_key ||= [@fs_path.to_s, @fs_path.mtime.to_i, sort_method, sort_direction].join("-")
|
32
20
|
end
|
33
21
|
|
34
22
|
def locals
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
def build_locals
|
39
|
-
entries = @fs_path.children.map { |path| Servel::EntryFactory.for(path) }
|
23
|
+
entries = @fs_path.children.map { |path| Servel::EntryFactory.for(path) }.compact
|
40
24
|
|
41
25
|
{
|
42
26
|
url_root: @url_root,
|
@@ -50,6 +34,18 @@ class Servel::Index
|
|
50
34
|
}
|
51
35
|
end
|
52
36
|
|
37
|
+
def sort_method
|
38
|
+
param = @params["_servel_sort_method"]
|
39
|
+
param = "name" unless SORT_METHODS.include?(param)
|
40
|
+
param
|
41
|
+
end
|
42
|
+
|
43
|
+
def sort_direction
|
44
|
+
param = @params["_servel_sort_direction"]
|
45
|
+
param = "asc" unless SORT_DIRECTIONS.include?(param)
|
46
|
+
param
|
47
|
+
end
|
48
|
+
|
53
49
|
def directories(entries)
|
54
50
|
list = apply_sort(entries.select { |entry| entry.directory? })
|
55
51
|
|
@@ -83,9 +79,5 @@ class Servel::Index
|
|
83
79
|
entries
|
84
80
|
end
|
85
81
|
|
86
|
-
|
87
|
-
Naturalsorter::Sorter.sort_by_method(entries, :name, true)
|
88
|
-
end
|
89
|
-
|
90
|
-
instrument :locals, :directories, :files, :sort_entries
|
82
|
+
instrument :render, :locals, :directories, :files, :apply_sort
|
91
83
|
end
|
data/lib/servel/version.rb
CHANGED