mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Making ActionView's capture work properly.
git-svn-id: svn://hamptoncatlin.com/haml/branches/edge@167 7063305b-7217-0410-af8c-cdc13e5119b9
This commit is contained in:
parent
566e23b616
commit
1082ac7a65
4 changed files with 40 additions and 22 deletions
|
@ -15,11 +15,6 @@ module Haml
|
|||
def self.action_view?
|
||||
@@action_view
|
||||
end
|
||||
|
||||
# Sets whether or not ActionView is installed on the system.
|
||||
def self.action_view(value) # :nodoc:
|
||||
@@action_view = value
|
||||
end
|
||||
|
||||
# Takes any string, finds all the endlines and converts them to
|
||||
# HTML entities for endlines so they'll render correctly in
|
||||
|
@ -145,12 +140,37 @@ module Haml
|
|||
# the local variable <tt>foo</tt> would be assigned to "<p>13</p>\n".
|
||||
#
|
||||
def capture_haml(*args, &block)
|
||||
buffer_buffer = buffer.buffer
|
||||
position = buffer_buffer.length
|
||||
capture_haml_with_buffer(buffer.buffer, *args, &block)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Sets whether or not ActionView is installed on the system.
|
||||
def self.action_view(value) # :nodoc:
|
||||
@@action_view = value
|
||||
end
|
||||
|
||||
# Gets a reference to the current Haml::Buffer object.
|
||||
def buffer
|
||||
@haml_stack[-1]
|
||||
end
|
||||
|
||||
# Gives a proc the same local "_hamlout" and "_erbout" variables
|
||||
# that the current template has.
|
||||
def bind_proc(&proc)
|
||||
_hamlout = buffer
|
||||
_erbout = _hamlout.buffer
|
||||
proc { |*args| proc.call(*args) }
|
||||
end
|
||||
|
||||
# Performs the function of capture_haml, assuming <tt>local_buffer</tt>
|
||||
# is where the output of block goes.
|
||||
def capture_haml_with_buffer(local_buffer, *args, &block)
|
||||
position = local_buffer.length
|
||||
|
||||
block.call(*args)
|
||||
|
||||
captured = buffer_buffer.slice!(position..-1)
|
||||
captured = local_buffer.slice!(position..-1)
|
||||
|
||||
min_tabs = nil
|
||||
captured.each do |line|
|
||||
|
@ -164,19 +184,6 @@ module Haml
|
|||
end
|
||||
result.to_s
|
||||
end
|
||||
|
||||
# Gets a reference to the current Haml::Buffer object.
|
||||
def buffer # :nodoc:
|
||||
@haml_stack[-1]
|
||||
end
|
||||
|
||||
# Gives a proc the same local "_hamlout" and "_erbout" variables
|
||||
# that the current template has.
|
||||
def bind_proc(&proc) # :nodoc:
|
||||
_hamlout = buffer
|
||||
_erbout = _hamlout.buffer
|
||||
proc { |*args| proc.call(*args) }
|
||||
end
|
||||
|
||||
include ActionViewMods if self.const_defined? "ActionViewMods"
|
||||
end
|
||||
|
|
|
@ -24,7 +24,10 @@ if action_view_included
|
|||
#++
|
||||
module ActionViewMods
|
||||
def self.included(othermod) # :nodoc:
|
||||
othermod.action_view(true)
|
||||
othermod.class_eval do
|
||||
action_view(true)
|
||||
alias_method :capture_erb_with_buffer, :capture_haml_with_buffer
|
||||
end
|
||||
end
|
||||
|
||||
def concat(string, binding = nil) # :nodoc:
|
||||
|
|
|
@ -34,6 +34,10 @@
|
|||
<p>Small</p>
|
||||
<!-- Invisible -->
|
||||
</div>
|
||||
<div class='dilly'>
|
||||
<p>foo</p>
|
||||
<h1>bar</h1>
|
||||
</div>
|
||||
</div>
|
||||
(<strong>parentheses!</strong>)
|
||||
</div>
|
||||
|
|
|
@ -19,6 +19,10 @@
|
|||
%h1 Big!
|
||||
%p Small
|
||||
/ Invisible
|
||||
= capture do
|
||||
.dilly
|
||||
%p foo
|
||||
%h1 bar
|
||||
= surround '(', ')' do
|
||||
%strong parentheses!
|
||||
= precede '*' do
|
||||
|
|
Loading…
Add table
Reference in a new issue