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

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

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

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

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

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