diff --git a/lib/app.rb b/lib/app.rb index a652f8e..3c9efa2 100644 --- a/lib/app.rb +++ b/lib/app.rb @@ -122,11 +122,20 @@ module Tilt # # https://github.com/phlex-ruby/phlex-rails/blob/main/lib/phlex/rails/layout.rb#L18 def evaluate(scope, locals, &block) - p scope - p locals klass = Class.new(Phlex::HTML) klass.class_eval(data, __FILE__, __LINE__) - component = klass.new(**locals) + + component = klass.new + + scope.instance_variables + .reject { _2.start_with?("@_") } + .each do |k| + component.instance_variable_set(k, scope.instance_variable_get(k)) + end + locals.each do |k,v| + component.instance_variable_set("@#{k}", v) + end + component.call do |yielded| output = yield component.unsafe_raw(output) diff --git a/views/hello.phlex b/views/hello.phlex index bb3b3d2..5c7a363 100644 --- a/views/hello.phlex +++ b/views/hello.phlex @@ -1,7 +1,3 @@ -def initialize(name:) - @name = name -end - def template h1 { "👋 Hello #@name!" } end