require "roda" class App < Roda plugin :render, engine: :phlex route do |r| r.root do # render("hello", locals: {name: "Alice"}) view("hello", locals: {name: "Alice"}) end end end require "tilt/template" require "phlex" module Tilt class PhlexTemplate < Template def prepare end # 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 # 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 Tilt.register(Tilt::PhlexTemplate, "phlex")