initial commit

This commit is contained in:
2026-10-25 23:19:29 -06:00
commit 5a3e877217
43 changed files with 2780 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
# frozen_string_literal: true
require 'rack'
require 'json'
require_relative '../renderer'
module FO::HTTP
class Response < Rack::Response
attr_reader :request
def initialize(request)
super('')
@request = request
end
def json(thingy)
body(JSON.generate(thingy))
content_type('application/json; charset=utf-8')
self
end
def template(template_name, locals = {})
path = File.expand_path("#{__dir__}/../views/#{template_name}.erb")
layout_name = locals['layout'].nil? ? 'default' : locals['layout']
layout_path = File.expand_path("#{__dir__}/../views/layouts/#{layout_name}.erb")
body(FO::Renderer.new(layout_path, path, locals).render)
content_type('text/html; charset=utf-8')
self
end
def status(s)
@status = s
self
end
def body(body)
write(body)
self
end
def content_type(type)
set_header('Content-Type', type)
self
end
end
end