Skip to content

Commit

Permalink
Halt early when searching for a fragment
Browse files Browse the repository at this point in the history
  • Loading branch information
joeldrapper committed Mar 12, 2024
1 parent 44f1503 commit ff33adb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 14 deletions.
6 changes: 5 additions & 1 deletion lib/phlex/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ def begin_target(id)

def end_target
@fragments.delete(@in_target_fragment)
@in_target_fragment = false
if @fragments.any?
@in_target_fragment = false
else
throw(:phlex_fragment_halt)
end
end

def capturing_into(new_buffer)
Expand Down
49 changes: 36 additions & 13 deletions lib/phlex/sgml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,22 +113,45 @@ def __final_call__(buffer = +"", context: Phlex::Context.new, view_context: nil,

return "" unless render?

around_template do
if block
if is_a?(DeferredRender)
__vanish__(self, &block)
view_template
else
view_template do |*args|
if args.length > 0
yield_content_with_args(*args, &block)
if !parent && context.fragments
catch(:phlex_fragment_halt) do
around_template do
if block
if is_a?(DeferredRender)
__vanish__(self, &block)
view_template
else
yield_content(&block)
view_template do |*args|
if args.length > 0
yield_content_with_args(*args, &block)
else
yield_content(&block)
end
end
end
else
view_template
end
end
else
view_template
end
else
around_template do
if block
if is_a?(DeferredRender)
__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
end
end
else
view_template
end
end
end

Expand Down Expand Up @@ -191,7 +214,7 @@ def comment(&block)
end

# This method is very dangerous and should usually be avoided. It will output the given String without any HTML safety. You should never use this method to output unsafe user input.
# @param content [String|nil]
# @param content [String, nil]
# @return [nil]
def unsafe_raw(content = nil)
return nil unless content
Expand Down

0 comments on commit ff33adb

Please sign in to comment.