Compare commits
No commits in common. "9c9ceaf4f8e479bc24eff9cf42c281276a4ad9dc" and "9ba3bddc9645d245f440c6406da4fb58f6f2fc35" have entirely different histories.
9c9ceaf4f8
...
9ba3bddc96
|
@ -13,9 +13,9 @@ app = Hyde::Server.new do
|
||||||
postprocess do |request, response|
|
postprocess do |request, response|
|
||||||
puts "Request: #{request}, response: #{response}"
|
puts "Request: #{request}, response: #{response}"
|
||||||
end
|
end
|
||||||
index ["index.html"]
|
index ["index"]
|
||||||
root "#{ENV['PWD']}/assets"
|
root "#{ENV['PWD']}/assets"
|
||||||
serve "/**/*.(html|css|js)"
|
serve "*.(html|css|js)"
|
||||||
get "/wormhole/:test/*" do |suffix, test: nil|
|
get "/wormhole/:test/*" do |suffix, test: nil|
|
||||||
<<~RESPONSE
|
<<~RESPONSE
|
||||||
You tried accessing #{suffix} at named param #{test}
|
You tried accessing #{suffix} at named param #{test}
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title> Cleverly done, mr. freeman </title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h1>Cleverly done, mr. freeman</h1>
|
|
||||||
<hr/>
|
|
||||||
<p>But you are not supposed to be here</p>
|
|
||||||
<p><b>Get back where you belong.</b></p>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
|
@ -21,13 +21,16 @@ module Hyde
|
||||||
# Set root path (appends matched part of the path).
|
# Set root path (appends matched part of the path).
|
||||||
# @param path [String
|
# @param path [String
|
||||||
def root(path)
|
def root(path)
|
||||||
|
raise StandardError, "path should be a String" unless path.is_a? String
|
||||||
|
|
||||||
@origin.root = path
|
@origin.root = path
|
||||||
end
|
end
|
||||||
|
|
||||||
# Set root path (without appending matched part).
|
# Set root path (without appending matched part).
|
||||||
# @param path [String
|
# @param path [String
|
||||||
def remap(path)
|
def remap(path)
|
||||||
@origin.remap = path
|
root(path)
|
||||||
|
@origin.remap = true
|
||||||
end
|
end
|
||||||
|
|
||||||
# Add a preprocessor to the path.
|
# Add a preprocessor to the path.
|
||||||
|
|
|
@ -9,29 +9,12 @@ module Hyde
|
||||||
# @abstract
|
# @abstract
|
||||||
class Node
|
class Node
|
||||||
# @param path [Object]
|
# @param path [Object]
|
||||||
def initialize(path, parent:)
|
def initialize(path)
|
||||||
@pattern = Pattern.new(path).freeze
|
@pattern = Pattern.new(path).freeze
|
||||||
@properties = Hyde::Util::Lookup.new(parent&.properties)
|
|
||||||
@root = nil
|
@root = nil
|
||||||
@remap = false
|
@remap = false
|
||||||
end
|
end
|
||||||
|
|
||||||
# Set Node file root (like root in Nginx)
|
|
||||||
# @param path [String]
|
|
||||||
def root=(path)
|
|
||||||
raise StandardError, "path should be a String" unless path.is_a? String
|
|
||||||
|
|
||||||
@properties["path"] = File.expand_path(path)
|
|
||||||
@root = File.expand_path(path)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Set Node absolute file path (like alias in Nginx)
|
|
||||||
# @param path [String]
|
|
||||||
def remap=(path)
|
|
||||||
self.root = path
|
|
||||||
@remap = true
|
|
||||||
end
|
|
||||||
|
|
||||||
# Try to navigate the path. Run method callback in response.
|
# Try to navigate the path. Run method callback in response.
|
||||||
# @param [Hyde::Request]
|
# @param [Hyde::Request]
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
|
@ -66,7 +49,7 @@ module Hyde
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :remap, :root
|
attr_accessor :remap, :root
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
|
|
@ -25,9 +25,11 @@ module Hyde
|
||||||
# @param parent [Hyde::Node] Parent object to inherit properties to
|
# @param parent [Hyde::Node] Parent object to inherit properties to
|
||||||
# @param setup [#call] Setup block
|
# @param setup [#call] Setup block
|
||||||
def initialize(path, parent:, &setup)
|
def initialize(path, parent:, &setup)
|
||||||
super(path, parent: parent)
|
super(path)
|
||||||
# Child nodes array
|
# Child nodes array
|
||||||
@children = []
|
@children = []
|
||||||
|
# Inherited properties array
|
||||||
|
@properties = Hyde::Util::Lookup.new(parent&.properties)
|
||||||
# Arrays of preprocessors, postprocessors and filters
|
# Arrays of preprocessors, postprocessors and filters
|
||||||
@preprocessors = []
|
@preprocessors = []
|
||||||
@postprocessors = []
|
@postprocessors = []
|
||||||
|
|
|
@ -100,12 +100,11 @@ module Hyde
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# i shall name thee Norxondor Glorbulon
|
|
||||||
|
|
||||||
# Regexp pattern to match glob tokens
|
# Regexp pattern to match glob tokens
|
||||||
TOKENS = /
|
TOKENS = /
|
||||||
( # Glob-specific tokens
|
( # Glob-specific tokens
|
||||||
(?<=(?:\/|^))\*\*(?:\/|$) | # Freestanding globstar
|
\/\*\*\/ | # Freestanding globstar
|
||||||
|
\*\* | # Attached globstar
|
||||||
\* | # Regular glob
|
\* | # Regular glob
|
||||||
\[!?\w-\w\]\+ | # Character group
|
\[!?\w-\w\]\+ | # Character group
|
||||||
(?<=\/):[\w_]+(?=(?:\/|$)) | # Named glob
|
(?<=\/):[\w_]+(?=(?:\/|$)) | # Named glob
|
||||||
|
@ -154,7 +153,8 @@ module Hyde
|
||||||
def build_regexp(tokens)
|
def build_regexp(tokens)
|
||||||
Regexp.new(tokens.map do |filter|
|
Regexp.new(tokens.map do |filter|
|
||||||
case filter
|
case filter
|
||||||
when /(\/|^)\*\*(\/|$)/ then "(?:(.*)/|)" # FIXME: this may return nil
|
when "/**/" then "/(?:(.*)\/|)" # FIXME: this may return nil
|
||||||
|
when "**" then "(.*)"
|
||||||
when "*" then "([^/]*)"
|
when "*" then "([^/]*)"
|
||||||
when /^\([\w\/|_-]+\)$/ then filter.sub('-', '\\-')
|
when /^\([\w\/|_-]+\)$/ then filter.sub('-', '\\-')
|
||||||
when /^\[!?\w-\w\]\+$/ then filter.sub('!', '^')
|
when /^\[!?\w-\w\]\+$/ then filter.sub('!', '^')
|
||||||
|
|
|
@ -21,7 +21,8 @@ module Hyde
|
||||||
# @param path [Object]
|
# @param path [Object]
|
||||||
# @param parent [Hyde::Node]
|
# @param parent [Hyde::Node]
|
||||||
def initialize(path, parent:)
|
def initialize(path, parent:)
|
||||||
super(path, parent: parent)
|
super(path)
|
||||||
|
@properties = Hyde::Util::Lookup.new(parent&.properties)
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :properties
|
attr_reader :properties
|
||||||
|
|
|
@ -20,10 +20,7 @@ module Hyde
|
||||||
# @param request [Hyde::Request]
|
# @param request [Hyde::Request]
|
||||||
# @return [Boolean] true if file was found
|
# @return [Boolean] true if file was found
|
||||||
def process(request)
|
def process(request)
|
||||||
path = File.expand_path(request.filepath)
|
File.open(request.filepath.delete_suffix("/"))
|
||||||
return unless path.start_with? @properties["path"]
|
|
||||||
|
|
||||||
File.open(path.delete_suffix("/"))
|
|
||||||
rescue StandardError
|
rescue StandardError
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,7 +15,7 @@ module Hyde
|
||||||
@param = {}
|
@param = {}
|
||||||
@splat = []
|
@splat = []
|
||||||
# Traversal route. Public and writable.
|
# Traversal route. Public and writable.
|
||||||
@path = URI.decode_www_form_component(env["PATH_INFO"].dup)
|
@path = env["PATH_INFO"].dup
|
||||||
# File serving path. Public and writable.
|
# File serving path. Public and writable.
|
||||||
@filepath = "/"
|
@filepath = "/"
|
||||||
# Encapsulates all rack variables. Should not be public.
|
# Encapsulates all rack variables. Should not be public.
|
||||||
|
|
|
@ -28,9 +28,10 @@ module Hyde
|
||||||
"content-type": "text/html"
|
"content-type": "text/html"
|
||||||
}
|
}
|
||||||
[headers, page]
|
[headers, page]
|
||||||
end,
|
end
|
||||||
"path" => "/"
|
}.each do |k, v|
|
||||||
}.each { |k, v| @properties[k] = v unless @properties[k] }
|
@properties[k] = v unless @properties[k]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Rack ingress point.
|
# Rack ingress point.
|
||||||
|
|
|
@ -69,27 +69,6 @@ class TestGlob < Test::Unit::TestCase
|
||||||
puts("Testing: #{test}")
|
puts("Testing: #{test}")
|
||||||
assert_equal(result, unit.match?(test))
|
assert_equal(result, unit.match?(test))
|
||||||
end
|
end
|
||||||
unit = Glob.new("**/*.php")
|
|
||||||
[
|
|
||||||
"archive.php", true,
|
|
||||||
"assets/thing.js", false,
|
|
||||||
"assetsthing.js", false,
|
|
||||||
"parts/thing.php", true,
|
|
||||||
"partsthing.php", true,
|
|
||||||
".php", true,
|
|
||||||
"parts/extra/test.php", true,
|
|
||||||
"archive.php", true,
|
|
||||||
"assets/thing.js", false,
|
|
||||||
"assetsthing.js", false,
|
|
||||||
"parts/thing.php", true,
|
|
||||||
"partsthing.php", true,
|
|
||||||
".php", true,
|
|
||||||
"parts/extra/test.php", true,
|
|
||||||
"parts/extra/test.php/literally/anything/here", true
|
|
||||||
].each_slice(2) do |test, result|
|
|
||||||
puts("Testing: #{test}")
|
|
||||||
assert_equal(result, unit.match?(test))
|
|
||||||
end
|
|
||||||
puts "Test group: char ranges"
|
puts "Test group: char ranges"
|
||||||
unit = Glob.new("/test/[9-z]+")
|
unit = Glob.new("/test/[9-z]+")
|
||||||
[
|
[
|
||||||
|
|
Loading…
Reference in New Issue