servel 0.14.0 → 0.15.0

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: cdd4343b043f0e31a6f28099e1f2b30853361e57
4
- data.tar.gz: a530e4b6f5430f339b0599c8186d9da21d9d918b
3
+ metadata.gz: 117d9e0db92881231808a7525938dff72a12e3a3
4
+ data.tar.gz: 75a69275c182a29ec34edcb53f75b95dea805fa6
5
5
  SHA512:
6
- metadata.gz: 20bf86b2fd1a0189296a42797514f31720e386742c8123edd7006f82fd86c86406cd948f72bdb4946a3ac6a98cde365846a6d16561526124d301a4793cd0f6b0
7
- data.tar.gz: 94b29d8b4d557bc28a0b5ab1762678474196ba72c6a4b9979b1fa2198bd235e5362a0159b2b93a22d2c29712f82488ed55abb3253284037e3d4852efa28c3a90
6
+ metadata.gz: 224b28d1b3254a7adcfdaa517daf5c1c18511b06fafe1d43b7c6987fb4672d8d330d7dd3cbfd907cc1d1377bb7e0247b6f068db946791d80f76670f53c784cbb
7
+ data.tar.gz: 3250aee872e9305c7fe415b3bbaa34954da1e062ff7fc2401294846b2e082c957fb0e7b3cad8248c3dc8370b49cfb9d66f808c56186a1b51a378f8888882e441
data/.gitignore CHANGED
@@ -1,9 +1,9 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
9
  /Gemfile.lock
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
- source "https://rubygems.org"
2
-
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
-
5
- # Specify your gem's dependencies in servel.gemspec
6
- gemspec
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in servel.gemspec
6
+ gemspec
data/LICENSE.txt CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2017 Brenton "B-Train" Fletcher
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Brenton "B-Train" Fletcher
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,39 +1,39 @@
1
- # Servel
2
-
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/servel`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'servel'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install servel
22
-
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
-
33
- ## Contributing
34
-
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/servel.
36
-
37
- ## License
38
-
39
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
1
+ # Servel
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/servel`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'servel'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install servel
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/servel.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -1,2 +1,2 @@
1
- require "bundler/gem_tasks"
2
- task :default => :spec
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console CHANGED
@@ -1,14 +1,14 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "servel"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "servel"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup CHANGED
@@ -1,8 +1,8 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/servel.rb CHANGED
File without changes
data/lib/servel/app.rb CHANGED
@@ -1,20 +1,27 @@
1
1
  class Servel::App
2
+ UTF_8 = Encoding::UTF_8
3
+ SCRIPT_NAME = Rack::SCRIPT_NAME
4
+ PATH_INFO = Rack::PATH_INFO
5
+
2
6
  def initialize(root)
3
7
  @root = Pathname.new(root)
4
8
  @file_server = Rack::File.new(root.to_s)
5
9
  end
6
10
 
7
11
  def call(env)
8
- url_root = env["SCRIPT_NAME"]
9
- url_path = clean_url_path(env["PATH_INFO"])
12
+ env[SCRIPT_NAME] = try_encode(env[SCRIPT_NAME])
13
+ env[PATH_INFO] = try_encode(env[PATH_INFO])
14
+
15
+ url_root = env[SCRIPT_NAME]
16
+ url_path = clean_url_path(env[PATH_INFO])
10
17
 
11
- return redirect("#{url_root}/") if env["PATH_INFO"] == ""
18
+ return redirect("#{url_root}/") if env[PATH_INFO] == ""
12
19
 
13
20
  fs_path = @root + url_path[1..-1]
14
21
 
15
22
  return @file_server.call(env) if fs_path.file?
16
23
 
17
- return redirect("#{url_root}#{url_path}/") unless env["PATH_INFO"].end_with?("/")
24
+ return redirect("#{url_root}#{url_path}/") unless env[PATH_INFO].end_with?("/")
18
25
 
19
26
  return [404, {}, []] unless fs_path.exist?
20
27
 
@@ -23,7 +30,7 @@ class Servel::App
23
30
  end
24
31
 
25
32
  def redirect(location)
26
- [302, { "Location" => location }, []]
33
+ [302, { "Location" => Rack::Utils.escape_path(location) }, []]
27
34
  end
28
35
 
29
36
  def clean_url_path(path)
@@ -31,4 +38,11 @@ class Servel::App
31
38
  raise unless Rack::Utils.valid_path?(url_path)
32
39
  Rack::Utils.clean_path_info(url_path)
33
40
  end
41
+
42
+ def try_encode(string)
43
+ return string if string.encoding == UTF_8
44
+ string.encode(UTF_8)
45
+ rescue Encoding::UndefinedConversionError, Encoding::InvalidByteSequenceError
46
+ string
47
+ end
34
48
  end
data/lib/servel/cli.rb CHANGED
@@ -1,18 +1,18 @@
1
- class Servel::CLI
2
- def initialize(argv)
3
- @argv = argv
4
- end
5
-
6
- def start
7
- Rack::Handler::Puma.run(Servel.build_app(path_map))
8
- end
9
-
10
- def path_map
11
- @argv.map do |arg|
12
- root, url_root = arg.split(":" , 2)
13
- root = Pathname.new(root).realpath
14
-
15
- [root, url_root || "/"]
16
- end.to_h
17
- end
1
+ class Servel::CLI
2
+ def initialize(argv)
3
+ @argv = argv
4
+ end
5
+
6
+ def start
7
+ Rack::Handler::Puma.run(Servel.build_app(path_map))
8
+ end
9
+
10
+ def path_map
11
+ @argv.map do |arg|
12
+ root, url_root = arg.split(":" , 2)
13
+ root = Pathname.new(root).realpath
14
+
15
+ [root, url_root || "/"]
16
+ end.to_h
17
+ end
18
18
  end
data/lib/servel/entry.rb CHANGED
@@ -1,27 +1,27 @@
1
- class Servel::Entry
2
- attr_reader :ftype, :type, :media_type, :listing_classes, :icon, :href, :name, :size, :mtime
3
-
4
- def initialize(ftype:, type:, media_type: nil, listing_classes:, icon:, href:, name:, size: nil, mtime: nil)
5
- @ftype = ftype
6
- @type = type
7
- @media_type = media_type
8
- @listing_classes = listing_classes
9
- @icon = icon
10
- @href = href
11
- @name = name
12
- @size = size
13
- @mtime = mtime
14
- end
15
-
16
- def directory?
17
- @ftype == :directory
18
- end
19
-
20
- def file?
21
- @ftype == :file
22
- end
23
-
24
- def media?
25
- !@media_type.nil?
26
- end
1
+ class Servel::Entry
2
+ attr_reader :ftype, :type, :media_type, :listing_classes, :icon, :href, :name, :size, :mtime
3
+
4
+ def initialize(ftype:, type:, media_type: nil, listing_classes:, icon:, href:, name:, size: nil, mtime: nil)
5
+ @ftype = ftype
6
+ @type = type
7
+ @media_type = media_type
8
+ @listing_classes = listing_classes
9
+ @icon = icon
10
+ @href = href
11
+ @name = name
12
+ @size = size
13
+ @mtime = mtime
14
+ end
15
+
16
+ def directory?
17
+ @ftype == :directory
18
+ end
19
+
20
+ def file?
21
+ @ftype == :file
22
+ end
23
+
24
+ def media?
25
+ !@media_type.nil?
26
+ end
27
27
  end
File without changes
@@ -1,54 +1,54 @@
1
- class Servel::HamlContext
2
- extend Servel::Instrumentation
3
- include ActiveSupport::NumberHelper
4
-
5
- LOCK = Mutex.new
6
-
7
- def self.render(template, locals)
8
- [200, {}, [new.render(template, locals)]]
9
- end
10
-
11
- def initialize
12
- @build_path = Pathname.new(__FILE__).dirname.realpath + 'templates'
13
- end
14
-
15
- def render(template, locals = {})
16
- haml_engine(template).render(self, locals)
17
- end
18
-
19
- def partial(name, locals = {})
20
- render("_#{name}.haml", locals)
21
- end
22
-
23
- def include(path)
24
- (@build_path + path).read
25
- end
26
-
27
- def sort_attrs(sort, current_method)
28
- data = { sort_method: current_method, sort_direction: "asc" }
29
- classes = ["sortable"]
30
- if sort[:method] == current_method
31
- data[:sort_active] = true
32
- data[:sort_direction] = sort[:direction]
33
- classes << "sort-active"
34
- classes << "sort-#{sort[:direction]}"
35
- end
36
-
37
- {
38
- data: data,
39
- class: classes
40
- }
41
- end
42
-
43
- def haml_engine(path)
44
- LOCK.synchronize do
45
- @@haml_engine_cache ||= {}
46
- unless @@haml_engine_cache.key?(path)
47
- @@haml_engine_cache[path] = Hamlit::Template.new(filename: path) { include(path) }
48
- end
49
- @@haml_engine_cache[path]
50
- end
51
- end
52
-
53
- instrument :render, :partial, :include
1
+ class Servel::HamlContext
2
+ extend Servel::Instrumentation
3
+ include ActiveSupport::NumberHelper
4
+
5
+ LOCK = Mutex.new
6
+
7
+ def self.render(template, locals)
8
+ [200, {}, [new.render(template, locals)]]
9
+ end
10
+
11
+ def initialize
12
+ @build_path = Pathname.new(__FILE__).dirname.realpath + 'templates'
13
+ end
14
+
15
+ def render(template, locals = {})
16
+ haml_engine(template).render(self, locals)
17
+ end
18
+
19
+ def partial(name, locals = {})
20
+ render("_#{name}.haml", locals)
21
+ end
22
+
23
+ def include(path)
24
+ (@build_path + path).read
25
+ end
26
+
27
+ def sort_attrs(sort, current_method)
28
+ data = { sort_method: current_method, sort_direction: "asc" }
29
+ classes = ["sortable"]
30
+ if sort[:method] == current_method
31
+ data[:sort_active] = true
32
+ data[:sort_direction] = sort[:direction]
33
+ classes << "sort-active"
34
+ classes << "sort-#{sort[:direction]}"
35
+ end
36
+
37
+ {
38
+ data: data,
39
+ class: classes
40
+ }
41
+ end
42
+
43
+ def haml_engine(path)
44
+ LOCK.synchronize do
45
+ @@haml_engine_cache ||= {}
46
+ unless @@haml_engine_cache.key?(path)
47
+ @@haml_engine_cache[path] = Hamlit::Template.new(filename: path) { include(path) }
48
+ end
49
+ @@haml_engine_cache[path]
50
+ end
51
+ end
52
+
53
+ instrument :render, :partial, :include
54
54
  end
File without changes
data/lib/servel/index.rb CHANGED
File without changes
@@ -1,26 +1,26 @@
1
- module Servel::Instrumentation
2
- def instrument(*method_names)
3
- return unless ENV["DEBUG"] == "1"
4
-
5
- Array(method_names).each do |method_name|
6
- original_method_name = "#{method_name}_without_instrumentation"
7
-
8
- alias_method original_method_name, method_name
9
-
10
- cumulative_time_spent = 0
11
-
12
- define_method(method_name) do |*args|
13
- start = Time.now
14
-
15
- return_value = __send__(original_method_name, *args)
16
-
17
- finish = Time.now
18
- time_spent = ((finish - start) * 1000.0)
19
- cumulative_time_spent += time_spent
20
- puts "Running #{self.class.name}<#{object_id}>##{method_name}: #{time_spent.round(3)}ms (cumulative: #{cumulative_time_spent.round(3)}ms)"
21
-
22
- return_value
23
- end
24
- end
25
- end
26
- end
1
+ module Servel::Instrumentation
2
+ def instrument(*method_names)
3
+ return unless ENV["DEBUG"] == "1"
4
+
5
+ Array(method_names).each do |method_name|
6
+ original_method_name = "#{method_name}_without_instrumentation"
7
+
8
+ alias_method original_method_name, method_name
9
+
10
+ cumulative_time_spent = 0
11
+
12
+ define_method(method_name) do |*args|
13
+ start = Time.now
14
+
15
+ return_value = __send__(original_method_name, *args)
16
+
17
+ finish = Time.now
18
+ time_spent = ((finish - start) * 1000.0)
19
+ cumulative_time_spent += time_spent
20
+ puts "Running #{self.class.name}<#{object_id}>##{method_name}: #{time_spent.round(3)}ms (cumulative: #{cumulative_time_spent.round(3)}ms)"
21
+
22
+ return_value
23
+ end
24
+ end
25
+ end
26
+ end
File without changes
@@ -17,9 +17,9 @@
17
17
  %tr
18
18
  %td
19
19
  %span.icon= file.icon
20
- %a.default{href: file.href, class: file.listing_classes, data: { type: file.media_type }}= file.name
20
+ %a.default{href: Rack::Utils.escape_path(file.href), class: file.listing_classes, data: { type: file.media_type }}= file.name
21
21
  %td
22
- %a.new-tab{href: file.href, class: file.listing_classes, target: "_blank"} (New tab)
22
+ %a.new-tab{href: Rack::Utils.escape_path(file.href), class: file.listing_classes, target: "_blank"} (New tab)
23
23
  %td= file.type
24
24
  %td= file.size.nil? ? "-" : number_to_human_size(file.size)
25
25
  %td= file.mtime.nil? ? "-" : file.mtime.strftime("%e %b %Y %l:%M %p")
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,26 +1,26 @@
1
- function initListing() {
2
- $ = document.querySelector.bind(document);
3
-
4
- function applySort(sortable) {
5
- var params = new URLSearchParams(location.search.slice(1));
6
- params.set("_servel_sort_method", sortable.dataset.sortMethod);
7
- params.set("_servel_sort_direction", sortable.dataset.sortDirection);
8
-
9
- if('sortActive' in sortable.dataset) {
10
- params.set("_servel_sort_direction", sortable.dataset.sortDirection == "asc" ? "desc" : "asc");
11
- }
12
-
13
- location.href = location.pathname + "?" + params.toString();
14
- }
15
-
16
- document.body.addEventListener("click", function(e) {
17
- if(!e.target) return;
18
-
19
- if(e.target.closest("th.sortable")) {
20
- e.preventDefault();
21
- applySort(e.target.closest("th.sortable"));
22
- }
23
- });
24
- }
25
-
1
+ function initListing() {
2
+ $ = document.querySelector.bind(document);
3
+
4
+ function applySort(sortable) {
5
+ var params = new URLSearchParams(location.search.slice(1));
6
+ params.set("_servel_sort_method", sortable.dataset.sortMethod);
7
+ params.set("_servel_sort_direction", sortable.dataset.sortDirection);
8
+
9
+ if('sortActive' in sortable.dataset) {
10
+ params.set("_servel_sort_direction", sortable.dataset.sortDirection == "asc" ? "desc" : "asc");
11
+ }
12
+
13
+ location.href = location.pathname + "?" + params.toString();
14
+ }
15
+
16
+ document.body.addEventListener("click", function(e) {
17
+ if(!e.target) return;
18
+
19
+ if(e.target.closest("th.sortable")) {
20
+ e.preventDefault();
21
+ applySort(e.target.closest("th.sortable"));
22
+ }
23
+ });
24
+ }
25
+
26
26
  window.addEventListener("DOMContentLoaded", initListing);
File without changes
File without changes
@@ -1,3 +1,3 @@
1
1
  module Servel
2
- VERSION = "0.14.0"
2
+ VERSION = "0.15.0"
3
3
  end
data/servel.gemspec CHANGED
File without changes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: servel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brenton "B-Train" Fletcher
@@ -184,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
184
  version: '0'
185
185
  requirements: []
186
186
  rubyforge_project:
187
- rubygems_version: 2.6.13
187
+ rubygems_version: 2.6.14
188
188
  signing_key:
189
189
  specification_version: 4
190
190
  summary: Serves files and directories over HTTP.