Add Phlex base layout and wire root route through it
Assisted-by: GLM-5.1 via pi
diff --git a/lib/app.rb b/lib/app.rb
index c130264..09938f0 100644
--- a/lib/app.rb
+++ b/lib/app.rb
@@ -1,11 +1,18 @@
# frozen_string_literal: true
require "roda"
+require_relative "views/layout"
class App < Roda
route do |r|
r.root do
- "ok"
+ render_with_layout { "ok" }
end
end
+
+ private
+
+ def render_with_layout(&block)
+ Views::Layout.new(&block).call
+ end
end
diff --git a/lib/views/layout.rb b/lib/views/layout.rb
new file mode 100644
index 0000000..5b0782a
--- /dev/null
+++ b/lib/views/layout.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+require "phlex"
+
+module Views
+end
+
+class Views::Layout < Phlex::HTML
+ def initialize(title: "Domus", &content)
+ @title = title
+ @content = content
+ end
+
+ def view_template
+ doctype
+
+ html(lang: "en") do
+ head do
+ title { @title }
+ end
+
+ body do
+ yield
+ end
+ end
+ end
+end
diff --git a/test/test_app.rb b/test/test_app.rb
index 81dd232..c6c7065 100644
--- a/test/test_app.rb
+++ b/test/test_app.rb
@@ -14,6 +14,7 @@ class TestApp < Minitest::Test
def test_root
get "/"
assert_equal 200, last_response.status
- assert_equal "ok", last_response.body
+ assert_includes last_response.body, "<title>Domus</title>"
+ assert_includes last_response.body, "ok"
end
end