server_here 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a2f3d06db25ba328e041b309d0cb6a22af5a2738
4
- data.tar.gz: 749277692c101fa3a364d1d8e0be523bcbf2472d
3
+ metadata.gz: 501f9cc54efe0f1b339db851096906c39fa6a6bf
4
+ data.tar.gz: 256f686021ea54265c126b7f5640d2d57574e1f8
5
5
  SHA512:
6
- metadata.gz: b930889fa163f7e21fff8cae858af3d433a197ce59b289a65ea2fb5ebccddb56527e51b5458426ad900359c13e2adc2962c768746b7cf48438b0d49e359845be
7
- data.tar.gz: 97e5c9d63e9f33055e45dcdf551aa4150b7a1b5bf85861913ac1d4320ab4a0eb28b965c4a54b05494afc44edf7fe4765f7ce604e97c7c8ec0eb3539f8234f029
6
+ metadata.gz: 32f7a9d5751790b2b7d3f3c4db9479afa941e63dcae611b242b42f95739a0c869eeb519401b1f9ae15c6296b382b272d3462fc34f59d3b1f294ecdd6b92acd40
7
+ data.tar.gz: 71b0c14a76eb569bf947bde798cce44bb26ebaa9d583ce23b8fec31d6bdf8b69859fa15ae0a89a4877b067660880f7ec8b1ce167e1ce627273fd3e15e5283b7a
data/README.md CHANGED
@@ -20,7 +20,7 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- server_here
23
+ $ server_here
24
24
 
25
25
  ## License
26
26
 
@@ -15,6 +15,7 @@ module ServerHere
15
15
  use Rack::ContentLength
16
16
  use Rack::ConditionalGet
17
17
  use EnvInspector
18
+ use Ls
18
19
  run Core.new
19
20
  }
20
21
  end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module ServerHere
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
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.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-01 00:00:00.000000000 Z
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: