servel 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -0
- data/Gemfile +0 -0
- data/LICENSE.txt +0 -0
- data/README.md +0 -0
- data/Rakefile +0 -0
- data/lib/servel.rb +1 -1
- data/lib/servel/core_ext/pathname.rb +4 -0
- data/lib/servel/haml_context.rb +2 -0
- data/lib/servel/index_view.rb +0 -0
- data/lib/servel/middleware.rb +1 -7
- data/lib/servel/servel.rb +0 -0
- data/lib/servel/templates/_gallery.haml +7 -0
- data/lib/servel/templates/_listing.haml +27 -0
- data/lib/servel/templates/common.css +3 -0
- data/lib/servel/templates/gallery.css +15 -6
- data/lib/servel/templates/gallery.js +55 -6
- data/lib/servel/templates/index.css +36 -3
- data/lib/servel/templates/index.haml +8 -16
- data/lib/servel/templates/listing.css +22 -0
- data/lib/servel/templates/normalize.css +0 -0
- data/lib/servel/version.rb +1 -1
- data/servel.gemspec +1 -0
- metadata +19 -4
- data/lib/servel/gallery_view.rb +0 -24
- data/lib/servel/templates/gallery.haml +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e91e5efe5fb7ebf0a803c7b8651d84188582b93c
|
4
|
+
data.tar.gz: db7b14fbe9096a17722164c6b389fc324268b0c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b56fedb3ecc2caf4f023a58d5bec0d817256d268991d78051c9bdbed8d2f76e8ee40174c4f14c71cc5308a89cddacef9e7fabf4ba273bdabfb6c85ee947275a3
|
7
|
+
data.tar.gz: fbb024ed53a80cb97f9d4d407f69dc9b5840709517b50a9454bc37076893363f3b4084c50a43ba15f70a20da403eed495a1f7c10098dff67c753a5ed7558d071
|
data/.gitignore
CHANGED
File without changes
|
data/Gemfile
CHANGED
File without changes
|
data/LICENSE.txt
CHANGED
File without changes
|
data/README.md
CHANGED
File without changes
|
data/Rakefile
CHANGED
File without changes
|
data/lib/servel.rb
CHANGED
@@ -2,6 +2,7 @@ require 'rack'
|
|
2
2
|
require 'rack/handler/puma'
|
3
3
|
require 'haml'
|
4
4
|
require 'naturalsorter'
|
5
|
+
require 'active_support/all'
|
5
6
|
|
6
7
|
require 'json'
|
7
8
|
require 'pathname'
|
@@ -13,6 +14,5 @@ require "servel/version"
|
|
13
14
|
require "servel/core_ext/pathname"
|
14
15
|
require "servel/haml_context"
|
15
16
|
require "servel/index_view"
|
16
|
-
require "servel/gallery_view"
|
17
17
|
require "servel/middleware"
|
18
18
|
require "servel/servel"
|
data/lib/servel/haml_context.rb
CHANGED
data/lib/servel/index_view.rb
CHANGED
File without changes
|
data/lib/servel/middleware.rb
CHANGED
@@ -20,13 +20,7 @@ class Servel::Middleware
|
|
20
20
|
|
21
21
|
url_path << "/" if url_path != "" && !url_path.end_with?("/")
|
22
22
|
|
23
|
-
|
24
|
-
Servel::GalleryView
|
25
|
-
else
|
26
|
-
Servel::IndexView
|
27
|
-
end
|
28
|
-
|
29
|
-
[200, {}, StringIO.new(klass.new(url_path, fs_path).render(@haml_context))]
|
23
|
+
[200, {}, StringIO.new(Servel::IndexView.new(url_path, fs_path).render(@haml_context))]
|
30
24
|
end
|
31
25
|
|
32
26
|
def url_path_for(url_path)
|
data/lib/servel/servel.rb
CHANGED
File without changes
|
@@ -0,0 +1,27 @@
|
|
1
|
+
%h1 Directory Listing of #{url_path}
|
2
|
+
%table
|
3
|
+
%thead
|
4
|
+
%tr
|
5
|
+
%th Name
|
6
|
+
%th Size
|
7
|
+
%th Modified
|
8
|
+
%tbody
|
9
|
+
- unless url_path == "/"
|
10
|
+
%tr
|
11
|
+
%td
|
12
|
+
(Dir)
|
13
|
+
%a{href: "../"} ../
|
14
|
+
%td
|
15
|
+
%td
|
16
|
+
- (directories + files).each do |file|
|
17
|
+
- relative_path = file.relative_path_from(fs_path)
|
18
|
+
%tr
|
19
|
+
%td
|
20
|
+
- if file.directory?
|
21
|
+
(Dir)
|
22
|
+
%a{href: relative_path, class: "#{"viewable" if file.image? || file.video?} #{"image" if file.image?} #{"video" if file.video?}", target: "_blank"}
|
23
|
+
- extname = relative_path.extname
|
24
|
+
- basename = relative_path.basename(extname)
|
25
|
+
#{basename.to_s.truncate(50)}#{extname}
|
26
|
+
%td= number_to_human_size(file.size)
|
27
|
+
%td= file.mtime.strftime("%e %b %Y %l:%M %p")
|
@@ -1,19 +1,21 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
#gallery {
|
2
|
+
padding: 20px;
|
3
|
+
background: #333;
|
4
|
+
transform: translateZ(0px);
|
3
5
|
}
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
+
.hidden {
|
8
|
+
display: none !important;
|
7
9
|
}
|
8
10
|
|
9
|
-
#image {
|
11
|
+
#image, #video {
|
10
12
|
display: block;
|
11
13
|
max-width: 100%;
|
12
14
|
margin: 0 auto 0 auto;
|
13
15
|
}
|
14
16
|
|
15
17
|
@media (min-width: 992px) {
|
16
|
-
#image {
|
18
|
+
#image, #video {
|
17
19
|
max-height: 100%;
|
18
20
|
}
|
19
21
|
}
|
@@ -83,4 +85,11 @@ body {
|
|
83
85
|
right: 0;
|
84
86
|
height: 100px;
|
85
87
|
z-index: 10001;
|
88
|
+
}
|
89
|
+
|
90
|
+
#page-toggle-size {
|
91
|
+
top: 0;
|
92
|
+
left: 0;
|
93
|
+
height: 100px;
|
94
|
+
z-index: 10001;
|
86
95
|
}
|
@@ -1,9 +1,21 @@
|
|
1
|
+
var pages = null;
|
1
2
|
var currentPage = 1;
|
2
3
|
|
4
|
+
function loadPages() {
|
5
|
+
pages = [];
|
6
|
+
|
7
|
+
var links = document.querySelectorAll("#listing a.viewable");
|
8
|
+
for(var i = 0; i < links.length; i++) {
|
9
|
+
var link = links[i];
|
10
|
+
var type = link.classList.contains("image") ? "image" : "video";
|
11
|
+
pages.push({ url: link.href, type: type });
|
12
|
+
}
|
13
|
+
}
|
14
|
+
|
3
15
|
function page(index) {
|
4
16
|
if(arguments.length == 1) {
|
5
17
|
if(isNaN(index) || index < 1) index = 1;
|
6
|
-
if(index >
|
18
|
+
if(index > pages.length) index = pages.length;
|
7
19
|
|
8
20
|
currentPage = index;
|
9
21
|
showCurrentPage();
|
@@ -36,6 +48,10 @@ function initPaginator() {
|
|
36
48
|
e.stopPropagation();
|
37
49
|
page(page() + 10);
|
38
50
|
});
|
51
|
+
document.querySelector("#page-toggle-size").addEventListener("click", function(e) {
|
52
|
+
e.stopPropagation();
|
53
|
+
document.body.classList.toggle("split-screen");
|
54
|
+
});
|
39
55
|
|
40
56
|
window.addEventListener("keydown", function(event) {
|
41
57
|
if(event.keyCode == 39 || ((event.keyCode == 32 || event.keyCode == 13) && atBottom())) {
|
@@ -51,13 +67,46 @@ function initPaginator() {
|
|
51
67
|
|
52
68
|
function showCurrentPage() {
|
53
69
|
window.scrollTo(0, 0);
|
54
|
-
|
55
|
-
if(
|
70
|
+
var page = pages[currentPage - 1];
|
71
|
+
if(!page) return;
|
72
|
+
|
73
|
+
if(page.type == "image") {
|
74
|
+
document.querySelector("#gallery #video").classList.add("hidden");
|
75
|
+
document.querySelector("#gallery #image").classList.remove("hidden");
|
76
|
+
document.querySelector("#gallery #image").src = page.url;
|
77
|
+
}
|
78
|
+
else {
|
79
|
+
document.querySelector("#gallery #image").classList.add("hidden");
|
80
|
+
document.querySelector("#gallery #video").classList.remove("hidden");
|
81
|
+
document.querySelector("#gallery #video").src = page.url;
|
82
|
+
}
|
83
|
+
|
84
|
+
//if(currentPage < imageUrls.length) (new Image()).src = imageUrls[currentPage];
|
56
85
|
}
|
57
86
|
|
58
|
-
function
|
87
|
+
function openLink(event) {
|
88
|
+
event.preventDefault();
|
89
|
+
|
90
|
+
for(var i = 0; i < pages.length; i++) {
|
91
|
+
if(pages[i].url == this.href) {
|
92
|
+
page(i + 1);
|
93
|
+
return;
|
94
|
+
}
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
98
|
+
function initGallery() {
|
99
|
+
if(!document.querySelector("#gallery")) return;
|
100
|
+
|
59
101
|
initPaginator();
|
60
|
-
|
102
|
+
loadPages();
|
103
|
+
|
104
|
+
document.body.addEventListener("click", function(e) {
|
105
|
+
console.log("clicked, e: ", e);
|
106
|
+
if(e.target && e.target.matches("a.viewable")) openLink.call(e.target, e);
|
107
|
+
});
|
108
|
+
|
109
|
+
page(1);
|
61
110
|
}
|
62
111
|
|
63
|
-
window.addEventListener("DOMContentLoaded",
|
112
|
+
window.addEventListener("DOMContentLoaded", initGallery);
|
@@ -1,3 +1,36 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
}
|
1
|
+
html, body, #gallery {
|
2
|
+
height: 100%;
|
3
|
+
}
|
4
|
+
|
5
|
+
body.split-screen #listing {
|
6
|
+
height: 100%;
|
7
|
+
width: 50%;
|
8
|
+
float: left;
|
9
|
+
overflow: auto;
|
10
|
+
}
|
11
|
+
|
12
|
+
body.split-screen #gallery {
|
13
|
+
width: 50%;
|
14
|
+
float: right;
|
15
|
+
}
|
16
|
+
/*
|
17
|
+
@media screen and (min-width: 1800px) {
|
18
|
+
#listing {
|
19
|
+
float: left;
|
20
|
+
width: 800px;
|
21
|
+
height: 100%;
|
22
|
+
overflow: auto;
|
23
|
+
}
|
24
|
+
|
25
|
+
#gallery {
|
26
|
+
margin-left: 800px;
|
27
|
+
}
|
28
|
+
|
29
|
+
body.gallery-expanded #listing {
|
30
|
+
display: none;
|
31
|
+
}
|
32
|
+
|
33
|
+
body.gallery-expanded #gallery {
|
34
|
+
margin-left: 0;
|
35
|
+
}
|
36
|
+
}*/
|
@@ -7,20 +7,12 @@
|
|
7
7
|
#{include('normalize.css')}
|
8
8
|
#{include('common.css')}
|
9
9
|
#{include('index.css')}
|
10
|
+
#{include('listing.css')}
|
11
|
+
#{include('gallery.css')}
|
12
|
+
|
13
|
+
:javascript
|
14
|
+
#{include('gallery.js')}
|
10
15
|
%body
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
- if show_gallery
|
15
|
-
%li
|
16
|
-
%a{href: "#{url_path}?gallery"} Gallery
|
17
|
-
- unless url_path == "/"
|
18
|
-
%li
|
19
|
-
%a{href: "../"} ../
|
20
|
-
- (directories + files).each do |file|
|
21
|
-
- relative_path = file.relative_path_from(fs_path).to_s
|
22
|
-
%li
|
23
|
-
- if file.directory?
|
24
|
-
(Dir)
|
25
|
-
%a{href: relative_path}
|
26
|
-
= relative_path
|
16
|
+
- if show_gallery
|
17
|
+
#gallery!= partial('gallery')
|
18
|
+
#listing!= partial('listing', { url_path: url_path, fs_path: fs_path, directories: directories, files: files })
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#listing {
|
2
|
+
padding: 20px;
|
3
|
+
}
|
4
|
+
|
5
|
+
#listing h1 {
|
6
|
+
margin-top: 0;
|
7
|
+
}
|
8
|
+
|
9
|
+
table {
|
10
|
+
width: 100%;
|
11
|
+
border-collapse: collapse;
|
12
|
+
border: 1px solid #ddd;
|
13
|
+
}
|
14
|
+
|
15
|
+
th, td {
|
16
|
+
padding: 5px;
|
17
|
+
border: 1px solid #ddd;
|
18
|
+
}
|
19
|
+
|
20
|
+
tbody > tr:nth-of-type(odd) {
|
21
|
+
background-color: #f9f9f9;
|
22
|
+
}
|
File without changes
|
data/lib/servel/version.rb
CHANGED
data/servel.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: servel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brenton "B-Train" Fletcher
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '4'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: activesupport
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
description: Serves files and directories over HTTP.
|
98
112
|
email:
|
99
113
|
- i@bloople.net
|
@@ -112,17 +126,18 @@ files:
|
|
112
126
|
- bin/setup
|
113
127
|
- lib/servel.rb
|
114
128
|
- lib/servel/core_ext/pathname.rb
|
115
|
-
- lib/servel/gallery_view.rb
|
116
129
|
- lib/servel/haml_context.rb
|
117
130
|
- lib/servel/index_view.rb
|
118
131
|
- lib/servel/middleware.rb
|
119
132
|
- lib/servel/servel.rb
|
133
|
+
- lib/servel/templates/_gallery.haml
|
134
|
+
- lib/servel/templates/_listing.haml
|
120
135
|
- lib/servel/templates/common.css
|
121
136
|
- lib/servel/templates/gallery.css
|
122
|
-
- lib/servel/templates/gallery.haml
|
123
137
|
- lib/servel/templates/gallery.js
|
124
138
|
- lib/servel/templates/index.css
|
125
139
|
- lib/servel/templates/index.haml
|
140
|
+
- lib/servel/templates/listing.css
|
126
141
|
- lib/servel/templates/normalize.css
|
127
142
|
- lib/servel/version.rb
|
128
143
|
- servel.gemspec
|
data/lib/servel/gallery_view.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
class Servel::GalleryView
|
2
|
-
def initialize(url_path, fs_path)
|
3
|
-
@url_path = url_path
|
4
|
-
@fs_path = fs_path
|
5
|
-
end
|
6
|
-
|
7
|
-
def render(haml_context)
|
8
|
-
haml_context.render('gallery.haml', locals)
|
9
|
-
end
|
10
|
-
|
11
|
-
def locals
|
12
|
-
image_paths = @fs_path.children.select { |child| child.image? }
|
13
|
-
|
14
|
-
{
|
15
|
-
url_path: @url_path,
|
16
|
-
fs_path: @fs_path,
|
17
|
-
image_paths: sort_paths(image_paths)
|
18
|
-
}
|
19
|
-
end
|
20
|
-
|
21
|
-
def sort_paths(paths)
|
22
|
-
Naturalsorter::Sorter.sort(paths.map(&:to_s), true).map { |path| Pathname.new(path) }
|
23
|
-
end
|
24
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
!!!
|
2
|
-
%html
|
3
|
-
%head
|
4
|
-
%meta{charset: 'utf-8'}
|
5
|
-
%title Gallery for #{url_path}
|
6
|
-
:css
|
7
|
-
#{include('normalize.css')}
|
8
|
-
#{include('common.css')}
|
9
|
-
#{include('gallery.css')}
|
10
|
-
|
11
|
-
:javascript
|
12
|
-
var imagePaths = #{image_paths.map { |file| file.relative_path_from(fs_path).to_s }.to_json};
|
13
|
-
#{include('gallery.js')}
|
14
|
-
|
15
|
-
%body
|
16
|
-
#container
|
17
|
-
%img#image
|
18
|
-
#page-back.paginator ◀
|
19
|
-
#page-next.paginator ▶
|
20
|
-
#page-back-10.paginator ◀◀
|
21
|
-
#page-next-10.paginator ▶▶
|