Browse Source

fixed dsl stuff, made a better example

master
Yessiest 8 months ago
parent
commit
9ba3bddc96
  1. 18
      examples/config.ru
  2. 1
      examples/lib
  3. 0
      examples/norxondor_gorgonax/assets/index.html
  4. 0
      examples/norxondor_gorgonax/assets/pee.css
  5. 36
      examples/norxondor_gorgonax/config.ru
  6. 1
      examples/norxondor_gorgonax/lib
  7. 1
      examples/norxondor_gorgonax/readme.txt
  8. 8
      lib/hyde/dsl/probe_methods.rb
  9. 2
      lib/hyde/probe.rb
  10. 1
      lib/hyde/probe/handler.rb

18
examples/config.ru

@ -1,18 +0,0 @@
# frozen_string_literal: true
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/lib")
require_relative 'lib/hyde'
app = Hyde::Server.new do
preprocess do |request|
puts "New request: #{request}"
end
filter do
rand < 0.5
end
index ["index"]
root "#{ENV['PWD']}/assets"
serve "*.(html|css|js)"
end
run app

1
examples/lib

@ -1 +0,0 @@
../lib

0
examples/assets/index.html → examples/norxondor_gorgonax/assets/index.html

0
examples/assets/pee.css → examples/norxondor_gorgonax/assets/pee.css

36
examples/norxondor_gorgonax/config.ru

@ -0,0 +1,36 @@
# frozen_string_literal: true
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/lib")
require_relative 'lib/hyde'
app = Hyde::Server.new do
preprocess do |request|
puts "New request: #{request}"
end
filter do
rand < 0.9
end
postprocess do |request, response|
puts "Request: #{request}, response: #{response}"
end
index ["index"]
root "#{ENV['PWD']}/assets"
serve "*.(html|css|js)"
get "/wormhole/:test/*" do |suffix, test: nil|
<<~RESPONSE
You tried accessing #{suffix} at named param #{test}
Your request is a #{request} object
#{Hyde::VLINE}
RESPONSE
end
get "/bounce-random" do
bounce if rand < 0.5
"you win!"
end
get "/404" do
die(404, backtrace: ["backtrace field", "you can write a lot of crap here"])
end
end
run app

1
examples/norxondor_gorgonax/lib

@ -0,0 +1 @@
../../lib

1
examples/norxondor_gorgonax/readme.txt

@ -0,0 +1 @@
This example just shows a lot of stuff for no particular reason. Should work out of the box without any dependencies or anything.

8
lib/hyde/dsl/probe_methods.rb

@ -9,7 +9,7 @@ module Hyde
# Get the current request
# @return [Hyde::Request]
def request
@request
@origin.request
end
# Stop execution and generate a boilerplate response with the given code
@ -18,8 +18,8 @@ module Hyde
# @raise [UncaughtThrowError] throws :finish to return back to Server
def die(errorcode, backtrace: nil)
throw :finish, [errorcode].append(
*(@properties["handle.#{errorcode}"] or
@properties["handle.default"]).call(
*(@origin.properties["handle.#{errorcode}"] or
@origin.properties["handle.default"]).call(
errorcode,
backtrace: backtrace
)
@ -29,7 +29,7 @@ module Hyde
# Bounce request to the next handler
# @raise [UncaughtThrowError] throws :break to get out of the callback
def bounce
raise :break
throw :break
end
# Set response status (generate response if one doesn't exist yet)

2
lib/hyde/probe.rb

@ -25,6 +25,8 @@ module Hyde
@properties = Hyde::Util::Lookup.new(parent&.properties)
end
attr_reader :properties
# Method callback on successful request navigation.
# Throws an error upon reaching the path.
# This behaviour should only be used internally.

1
lib/hyde/probe/handler.rb

@ -17,6 +17,7 @@ module Hyde
end
attr_accessor :response
attr_reader :request
# Method callback on successful request navigation.
# Runs block supplied with object initialization.

Loading…
Cancel
Save