diff --git a/lib/phlex.rb b/lib/phlex.rb index 2bb3a77c..a795a452 100644 --- a/lib/phlex.rb +++ b/lib/phlex.rb @@ -9,7 +9,6 @@ module Phlex autoload :CSV, "phlex/csv" autoload :Callable, "phlex/callable" autoload :Context, "phlex/context" - autoload :DeferredRender, "phlex/deferred_render" autoload :DoubleRenderError, "phlex/errors/double_render_error" autoload :Elements, "phlex/elements" autoload :Error, "phlex/error" diff --git a/lib/phlex/deferred_render.rb b/lib/phlex/deferred_render.rb deleted file mode 100644 index 5873f5fc..00000000 --- a/lib/phlex/deferred_render.rb +++ /dev/null @@ -1,5 +0,0 @@ -# frozen_string_literal: true - -module Phlex::DeferredRender - # This module doesn't do anything. Phlex::HTML#call checks for its inclusion in the ancestry instead. -end diff --git a/lib/phlex/sgml.rb b/lib/phlex/sgml.rb index ec501fcd..fb616455 100644 --- a/lib/phlex/sgml.rb +++ b/lib/phlex/sgml.rb @@ -90,24 +90,23 @@ def call(buffer = +"", context: Phlex::Context.new, view_context: nil, parent: n end @_context.around_render do + before_template(&block) + around_template do if block - if Phlex::DeferredRender === self - vanish(self, &block) - view_template - else - view_template do |*args| - if args.length > 0 - __yield_content_with_args__(*args, &block) - else - __yield_content__(&block) - end + view_template do |*args| + if args.length > 0 + __yield_content_with_args__(*args, &block) + else + __yield_content__(&block) end end else view_template end end + + after_template(&block) end unless parent @@ -235,7 +234,11 @@ def render(renderable = nil, &) def vanish(*args) return unless block_given? - @_context.capturing_into(Phlex::BlackHole) { yield(*args) } + if args.length > 0 + @_context.capturing_into(Phlex::BlackHole) { yield(*args) } + else + @_context.capturing_into(Phlex::BlackHole) { yield(self) } + end nil end @@ -252,10 +255,7 @@ def format_object(object) end def around_template - before_template yield - after_template - nil end diff --git a/quickdraw/sgml/callbacks.test.rb b/quickdraw/sgml/callbacks.test.rb index 60e0b47e..c21b708b 100644 --- a/quickdraw/sgml/callbacks.test.rb +++ b/quickdraw/sgml/callbacks.test.rb @@ -1,8 +1,12 @@ # frozen_string_literal: true class Example < Phlex::HTML - def around_template + def before_template i { "1" } + end + + def around_template + i { "2" } super do i { "3" } @@ -10,15 +14,11 @@ def around_template i { "5" } end - i { "7" } - end - - def before_template - i { "2" } + i { "6" } end def after_template - i { "6" } + i { "7" } end def view_template