server_here 0.1.1 → 0.1.2
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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/server_here.rb +1 -0
- data/lib/server_here/core.rb +0 -8
- data/lib/server_here/ls.rb +62 -0
- data/lib/server_here/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 501f9cc54efe0f1b339db851096906c39fa6a6bf
|
4
|
+
data.tar.gz: 256f686021ea54265c126b7f5640d2d57574e1f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32f7a9d5751790b2b7d3f3c4db9479afa941e63dcae611b242b42f95739a0c869eeb519401b1f9ae15c6296b382b272d3462fc34f59d3b1f294ecdd6b92acd40
|
7
|
+
data.tar.gz: 71b0c14a76eb569bf947bde798cce44bb26ebaa9d583ce23b8fec31d6bdf8b69859fa15ae0a89a4877b067660880f7ec8b1ce167e1ce627273fd3e15e5283b7a
|
data/README.md
CHANGED
data/lib/server_here.rb
CHANGED
data/lib/server_here/core.rb
CHANGED
@@ -5,14 +5,6 @@ module ServerHere
|
|
5
5
|
req = Rack::Request.new env
|
6
6
|
path = File.join('.', req.path_info)
|
7
7
|
|
8
|
-
if not File.exists? path
|
9
|
-
return [404, {'Content-Type' => 'text/plain'}, ["#{path} does not exist"] ]
|
10
|
-
end
|
11
|
-
|
12
|
-
if File.directory? path
|
13
|
-
return [200, {'Content-Type' => 'text/plain'}, [`ls -al #{path}`] ]
|
14
|
-
end
|
15
|
-
|
16
8
|
file = FileWrapper.new path
|
17
9
|
|
18
10
|
header = {
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
module ServerHere
|
5
|
+
class Ls
|
6
|
+
|
7
|
+
def initialize app
|
8
|
+
@app = app
|
9
|
+
end
|
10
|
+
|
11
|
+
def call env
|
12
|
+
req = Rack::Request.new env
|
13
|
+
path = req.path_info
|
14
|
+
|
15
|
+
if not File.exists? in_pwd path
|
16
|
+
return [404, {'Content-Type' => 'text/plain'}, ["#{path} does not exist"] ]
|
17
|
+
end
|
18
|
+
|
19
|
+
if File.directory? in_pwd path
|
20
|
+
return [200, {'Content-Type' => 'text/html'}, [ls_al(path)] ]
|
21
|
+
end
|
22
|
+
|
23
|
+
@app.call env
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def ls_al path
|
29
|
+
rel_path = relative path
|
30
|
+
list = `ls -al #{in_pwd path}`.split("\n")[3..-1]
|
31
|
+
parent_dir = parent rel_path
|
32
|
+
Tmpl.result binding
|
33
|
+
end
|
34
|
+
|
35
|
+
def relative path
|
36
|
+
path == '/' ? '' : path#.sub(/\./, '')
|
37
|
+
end
|
38
|
+
|
39
|
+
def parent path
|
40
|
+
return '/' if no_deeper_than_one? path
|
41
|
+
File.join path.split('/')[0..-2]
|
42
|
+
end
|
43
|
+
|
44
|
+
def no_deeper_than_one? path
|
45
|
+
path.count('/') == 1
|
46
|
+
end
|
47
|
+
|
48
|
+
def in_pwd path
|
49
|
+
'.' + path
|
50
|
+
end
|
51
|
+
|
52
|
+
Tmpl = ERB.new <<-EOS
|
53
|
+
<pre>
|
54
|
+
<a href="<%= parent_dir %>">..</a>
|
55
|
+
<% list.each do |line| %>
|
56
|
+
<a href="<%= rel_path %>/<%= line.split[8] %>"><%= line %></a>
|
57
|
+
<% end%>
|
58
|
+
</pre>
|
59
|
+
EOS
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
data/lib/server_here/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: server_here
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ken
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -76,6 +76,7 @@ files:
|
|
76
76
|
- lib/server_here/env_inspector.rb
|
77
77
|
- lib/server_here/file_wrapper.rb
|
78
78
|
- lib/server_here/ip.rb
|
79
|
+
- lib/server_here/ls.rb
|
79
80
|
- lib/server_here/version.rb
|
80
81
|
- server_here.gemspec
|
81
82
|
homepage:
|