blob: 28948cf48f29395fc7a134e6de469966013b0bfd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
require "kemal"
module Indrajith::Dev::Crystal
VERSION = "0.1.0"
macro page_renderer(filename)
render "src/views/#{{{filename}}}.ecr", "src/views/layout.ecr"
end
def self.htmx_request?(context)
context.request.headers.has_key?("HX-Request") ||
context.request.headers.has_key?("Hx-Request") ||
context.request.headers.has_key?("hx-request")
end
get "/" do |context|
if htmx_request?(context)
partial_content = render("src/views/home.ecr")
context.response.content_type = "text/html"
context.response.print partial_content
else
context.response.content_type = "text/html"
page_renderer "home"
end
end
Kemal.run
end
|