Alpha Chen 1 year ago
parent a1141f8f97
commit 61dfdcbcd4
Signed by: alpha
SSH Key Fingerprint: SHA256:3fOT8fiYQG/aK9ntivV3Bqtg8AYQ7q4nV6ZgihOA20g

@ -7,4 +7,5 @@ gem "phlex"
gem "rackup" gem "rackup"
gem "rake" gem "rake"
gem "roda" gem "roda"
gem "ruby-lsp" # TODO: Set up ruby-lsp
gem "tilt" gem "tilt"

@ -5,11 +5,13 @@ GEM
concurrent-ruby (1.2.2) concurrent-ruby (1.2.2)
erb (4.0.2) erb (4.0.2)
cgi (>= 0.3.3) cgi (>= 0.3.3)
language_server-protocol (3.17.0.3)
minitest (5.18.0) minitest (5.18.0)
phlex (1.8.1) phlex (1.8.1)
concurrent-ruby (~> 1.2) concurrent-ruby (~> 1.2)
erb (>= 4) erb (>= 4)
zeitwerk (~> 2.6) zeitwerk (~> 2.6)
prettier_print (1.2.1)
rack (3.0.8) rack (3.0.8)
rackup (2.1.0) rackup (2.1.0)
rack (>= 3) rack (>= 3)
@ -17,6 +19,13 @@ GEM
rake (13.0.6) rake (13.0.6)
roda (3.69.0) roda (3.69.0)
rack rack
ruby-lsp (0.5.1)
language_server-protocol (~> 3.17.0)
sorbet-runtime
syntax_tree (>= 6.1.1, < 7)
sorbet-runtime (0.5.10880)
syntax_tree (6.1.1)
prettier_print (>= 1.2.0)
tilt (2.2.0) tilt (2.2.0)
webrick (1.8.1) webrick (1.8.1)
zeitwerk (2.6.8) zeitwerk (2.6.8)
@ -31,6 +40,7 @@ DEPENDENCIES
rackup rackup
rake rake
roda roda
ruby-lsp
tilt tilt
BUNDLED WITH BUNDLED WITH

@ -5,12 +5,12 @@ class App < Roda
route do |r| route do |r|
r.root do r.root do
render "hello" # render("hello", locals: {name: "Alice"})
view("hello", locals: {name: "Alice"})
end end
end end
end end
require "tilt/template" require "tilt/template"
require "phlex" require "phlex"
@ -19,28 +19,30 @@ module Tilt
def prepare def prepare
end end
# def evaluate(scope, locals) # I have no idea how this works - it's just copied pretty much blindly from here:
# klass = Class.new(Phlex::HTML) #
# klass.class_eval(data, __FILE__, __LINE__) # https://github.com/phlex-ruby/phlex-rails/blob/main/lib/phlex/rails/layout.rb#L18
# klass.new.() def evaluate(scope, locals, &block)
# end klass = Class.new(Phlex::HTML)
klass.class_eval(data, __FILE__, __LINE__)
def precompiled_template(*) component = klass.new(**locals)
data component.call do |yielded|
output = yield
component.unsafe_raw(output)
end
end end
def precompiled_preamble(*) # Not sure if this is better...?
<<~RUBY # def precompiled_preamble(*) = "klass = Class.new(Phlex::HTML) do"
klass = Class.new(Phlex::HTML) do # def precompiled_template(*) = data
RUBY # def precompiled_postamble(locals) = <<~RUBY
end # end
# component = klass.new(**locals)
def precompiled_postamble(*) # component.call do |yielded|
<<~RUBY # output = yield
end # component.unsafe_raw(output)
klass.new.call # end
RUBY # RUBY
end
end end
end end

@ -1,3 +1,7 @@
def initialize(name:)
@name = name
end
def template def template
h1 { "👋 Hello World!" } h1 { "👋 Hello #@name!" }
end end

@ -0,0 +1,5 @@
def template
article do
yield
end
end
Loading…
Cancel
Save