fsws 0.0.3 → 1.0.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0bcba62b0f3352750ea47492c3fc24530e4d9cc5
4
- data.tar.gz: 461d4f3023eaab7c1b86ce83523677b267596d5d
3
+ metadata.gz: af44cee1d4d60c45b018fb313847ee4ecabb195d
4
+ data.tar.gz: ecc99c4a4ed8224df584023f0047bed011cbefbe
5
5
  SHA512:
6
- metadata.gz: efce146634e3c9b9ac18eab213d975b9c602c36956207112222b346d9daba36f393ec5e59936256ff206dd4d21487d2cf91dc71c277dc7caf7baabc17a4aff7f
7
- data.tar.gz: d536d27a44d18e1c614794f127c65de3f6bf0e1367e00c9b3f0bf82cfab51fdde37e6ae9c3b7870b89299e2ac903cb6f4f51e7e8771627905d0c2457e4cea4ce
6
+ metadata.gz: 0cc15bea4b54f883a9b24029698248f4864cdaac3c233204afe676bbedcf152edd53af34b38c318cc49ec588f07abde41553ddd032286c01f0662a5181002afa
7
+ data.tar.gz: 327ebdc4b9723eeec94671d3ceaeff89867d662c0ebf3c9736cf87df40f2d60e671f42bc57d0a83c6d84c565dd05522cccd51e5f4e7917eefdb1c4a5e3a2a9d6
data/lib/fsws/cli.rb CHANGED
@@ -1,12 +1,14 @@
1
1
  require 'rack'
2
2
  require 'webrick'
3
3
  require 'thor'
4
+ require 'launchy'
4
5
 
5
6
  module Fsws
6
7
  class CommandLine < Thor
7
- desc '[-h|--host <host>] [-p|--port <port>]', 'Start server.'
8
- option :port, :type => :numeric, :aliases => :p
8
+ desc '[-h|--host <host>] [-p|--port <port>] [-B|--no-browser]', 'Start server.'
9
+ option :port, type: :numeric, aliases: :p
9
10
  option :host, type: :string, aliases: :host
11
+ option :'no-browser', type: :boolean, aliases: :B
10
12
  option :version, type: :boolean, aliases: :v
11
13
  def start
12
14
  if options[:version]
@@ -14,6 +16,7 @@ module Fsws
14
16
  return
15
17
  end
16
18
 
19
+ browser = !options[:'no-browser']
17
20
  port = options[:port] || 8000
18
21
  interface = options[:host] || '127.0.0.1'
19
22
 
@@ -43,7 +46,11 @@ module Fsws
43
46
  AccessLog: []
44
47
  }
45
48
 
46
- Rack::Handler::WEBrick.run(Fsws::server, opts)
49
+ Rack::Handler::WEBrick.run(Fsws::server, opts) do
50
+ if browser
51
+ Launchy.open("http://localhost:#{port}")
52
+ end
53
+ end
47
54
  end
48
55
 
49
56
  desc '-v|--version', 'Print version.'
data/lib/fsws/server.rb CHANGED
@@ -57,10 +57,14 @@ def serve_dir(path)
57
57
 
58
58
  dirs, files = Dir.entries(path).partition { |e| File.directory?(File.join(path, e)) }
59
59
  dirs.delete('.')
60
+ dirs.delete('..') if path == './'
60
61
  dirs.sort!
61
62
  files.sort!
62
63
 
63
- pwd = Pathname.new('/' + Pathname.new(File.absolute_path(path)).relative_path_from(Pathname.new(File.absolute_path(Dir.pwd))).to_s).cleanpath
64
+ target_path = Pathname.new(File.absolute_path(path))
65
+ current_path = Pathname.new(File.absolute_path(Dir.pwd))
66
+ pwd = Pathname.new('/' + target_path.relative_path_from(current_path).to_s).cleanpath.to_s
67
+ pwd += '/' if pwd[-1] != '/'
64
68
 
65
69
  return 200, { 'Content-Type' => 'text/html' }, erb('listing', dirs: dirs, files: files, pwd: pwd)
66
70
  end
data/lib/fsws/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Fsws
2
- VERSION = '0.0.3'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -6,7 +6,15 @@
6
6
  </style>
7
7
  </head>
8
8
  <body>
9
- <h1>Index of <%= pwd %></h1>
9
+ <%
10
+ parts = pwd.split('/').map { |p| p + '/' }
11
+ parts = ['/'] if parts.empty?
12
+ paths = parts.inject([]) { |acc, part| acc << ((acc.last || '') + part) }
13
+ paths = paths.zip(parts)
14
+ %>
15
+ <h1>
16
+ Index of <% paths.each { |path| %><a href="<%= path.first %>"><%= path.last %></a><% } %>
17
+ </h1>
10
18
  <% if !dirs.empty? %>
11
19
  <ul>
12
20
  <% for dir in dirs %>
@@ -13,6 +13,17 @@ a:hover {
13
13
  h1 {
14
14
  margin-bottom: 10px;
15
15
  }
16
+ h1 a {
17
+ color: #000;
18
+ display: inline;
19
+ background: inherit;
20
+ padding: 0;
21
+ margin: 0;
22
+ }
23
+ h1 a:hover {
24
+ background: inherit;
25
+ color: #47b;
26
+ }
16
27
  body {
17
28
  margin: 10px;
18
29
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fsws
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Schmich
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0.19'
41
+ - !ruby/object:Gem::Dependency
42
+ name: launchy
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '2.4'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.4'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement