aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2016-03-05 18:59:25 -0500
committerPaul Duncan <pabs@pablotron.org>2016-03-05 18:59:25 -0500
commitceca7411df9b891a1534f0e90540d23e0af74f25 (patch)
treeb9cb63db6af0835add9b1c836934ffa5d42c10b7 /src
parent36bba1cacd2353d97f26ade5aeeca01a3ce9a4cb (diff)
downloadold-guff-ceca7411df9b891a1534f0e90540d23e0af74f25.tar.bz2
old-guff-ceca7411df9b891a1534f0e90540d23e0af74f25.zip
refactor Guff::Handler
Diffstat (limited to 'src')
-rw-r--r--src/guff.cr33
-rw-r--r--src/guff/handler.cr16
2 files changed, 27 insertions, 22 deletions
diff --git a/src/guff.cr b/src/guff.cr
index 7e32bfc..b19db4c 100644
--- a/src/guff.cr
+++ b/src/guff.cr
@@ -17,20 +17,6 @@ module Guff
end
end
- class Handler < ::HTTP::Handler
- getter :model
- getter :config
-
- def initialize(@model : Model, @config : Config)
- end
-
- def call(context : HTTP::Server::Context)
- # do nothing by default
- call_next(context)
- end
- end
-
-
class BlogHandler < Handler
MATCHES = [%r{
^/
@@ -77,13 +63,8 @@ module Guff
$
}x, %r{
- ^/
-
# match index
- blog/?
- |
-
- $
+ ^/$
}x]
def call(context : HTTP::Server::Context)
@@ -103,9 +84,17 @@ module Guff
"baz": "test slug baz",
}
+ RE = Regex.new("^/(?:" + MOCK_SLUGS.keys.join("|") + ").html$")
+
def call(context : HTTP::Server::Context)
- puts "SlugHandler: path = %s" % [context.request.path]
- call_next(context)
+ if md = RE.match(context.request.path || "")
+ context.response.puts "SlugHandler: path = %s, md = %s" % [
+ context.request.path,
+ md.to_s
+ ]
+ else
+ call_next(context)
+ end
end
end
diff --git a/src/guff/handler.cr b/src/guff/handler.cr
new file mode 100644
index 0000000..e665585
--- /dev/null
+++ b/src/guff/handler.cr
@@ -0,0 +1,16 @@
+require "http/server"
+
+module Guff
+ class Handler < ::HTTP::Handler
+ getter :model
+ getter :config
+
+ def initialize(@model : Model, @config : Config)
+ end
+
+ def call(context : HTTP::Server::Context)
+ # do nothing by default
+ call_next(context)
+ end
+ end
+end