Skip to content

Commit

Permalink
Inline with_output_buffer and always return a RawString from Output#t…
Browse files Browse the repository at this point in the history
…o_s.
  • Loading branch information
John Firebaugh committed Jun 10, 2010
1 parent 3d5483c commit e31f662
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/erector/output.rb
Expand Up @@ -41,7 +41,7 @@ def placeholder
end

def to_s
buffer.to_s
RawString.new(buffer.to_s)
end

def to_a
Expand Down
22 changes: 8 additions & 14 deletions lib/erector/widget.rb
Expand Up @@ -104,7 +104,7 @@ def to_pretty
# #content, pass its name in here.
def to_s(options = {}, &blk)
raise "Erector::Widget#to_s now takes an options hash, not a symbol. Try calling \"to_s(:content_method_name=> :#{options})\"" if options.is_a? Symbol
raw(_render(options, &blk).to_s)
_render(options, &blk).to_s
end

# Entry point for rendering a widget (and all its children). Same as #to_s
Expand Down Expand Up @@ -175,8 +175,13 @@ def raw(value)
# output string to a string and returns it as raw text. If at all possible
# you should avoid this method since it hurts performance, and use
# +widget+ or +write_via+ instead.
def capture(&block)
raw(with_output_buffer(&block))
def capture
original_output = @output
@output = Output.new
yield
@output.to_s
ensure
@output = original_output
end

protected
Expand Down Expand Up @@ -242,17 +247,6 @@ def write_via(parent)
end
end

def with_output_buffer(buffer='')
begin
original_output = @output
@output = Output.new {buffer}
yield
buffer
ensure
@output = original_output
end
end

def context(params={})
original_parent = @parent
original_output = @output
Expand Down

0 comments on commit e31f662

Please sign in to comment.