Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 18 additions & 19 deletions lib/slim/splat/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,7 @@ def build_tag(&block)
tag = @attrs.delete('tag').to_s
tag = @options[:default_tag] if tag.empty?
if block
# This is a bit of a hack to get a universal capturing.
#
# TODO: Add this as a helper somewhere to solve these capturing issues
# once and for all.
#
# If we have Slim capturing disabled and the scope defines the method `capture` (i.e. Rails)
# we use this method to capture the content.
#
# otherwise we just use normal Slim capturing (yield).
#
# See https://github.com/slim-template/slim/issues/591
# https://github.com/slim-template/slim#helpers-capturing-and-includes
#
content =
if @options[:disable_capture] && (scope = block.binding.eval('self')).respond_to?(:capture)
scope.capture(&block)
else
yield
end
content = capture_block_content(&block)
"<#{tag}#{build_attrs}>#{content}</#{tag}>"
else
"<#{tag}#{build_attrs} />"
Expand All @@ -90,6 +72,23 @@ def build_attrs

private

# Captures block content using the appropriate capturing mechanism.
#
# If we have Slim capturing disabled and the scope defines the method `capture` (i.e. Rails)
# we use this method to capture the content.
#
# Otherwise we just use normal Slim capturing (yield).
#
# See https://github.com/slim-template/slim/issues/591
# https://github.com/slim-template/slim#helpers-capturing-and-includes
def capture_block_content(&block)
if @options[:disable_capture] && (scope = block.binding.eval('self')).respond_to?(:capture)
scope.capture(&block)
else
yield
end
end

def hyphen_attr(name, escape, value)
if Hash === value
if @options[:hyphen_underscore_attrs]
Expand Down