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?
|
def self.action_view?
|
||||||
@@action_view
|
@@action_view
|
||||||
end
|
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
|
# Takes any string, finds all the endlines and converts them to
|
||||||
# HTML entities for endlines so they'll render correctly in
|
# 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".
|
# the local variable <tt>foo</tt> would be assigned to "<p>13</p>\n".
|
||||||
#
|
#
|
||||||
def capture_haml(*args, &block)
|
def capture_haml(*args, &block)
|
||||||
buffer_buffer = buffer.buffer
|
capture_haml_with_buffer(buffer.buffer, *args, &block)
|
||||||
position = buffer_buffer.length
|
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)
|
block.call(*args)
|
||||||
|
|
||||||
captured = buffer_buffer.slice!(position..-1)
|
captured = local_buffer.slice!(position..-1)
|
||||||
|
|
||||||
min_tabs = nil
|
min_tabs = nil
|
||||||
captured.each do |line|
|
captured.each do |line|
|
||||||
|
@ -164,19 +184,6 @@ module Haml
|
||||||
end
|
end
|
||||||
result.to_s
|
result.to_s
|
||||||
end
|
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"
|
include ActionViewMods if self.const_defined? "ActionViewMods"
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,7 +24,10 @@ if action_view_included
|
||||||
#++
|
#++
|
||||||
module ActionViewMods
|
module ActionViewMods
|
||||||
def self.included(othermod) # :nodoc:
|
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
|
end
|
||||||
|
|
||||||
def concat(string, binding = nil) # :nodoc:
|
def concat(string, binding = nil) # :nodoc:
|
||||||
|
|
|
@ -34,6 +34,10 @@
|
||||||
<p>Small</p>
|
<p>Small</p>
|
||||||
<!-- Invisible -->
|
<!-- Invisible -->
|
||||||
</div>
|
</div>
|
||||||
|
<div class='dilly'>
|
||||||
|
<p>foo</p>
|
||||||
|
<h1>bar</h1>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
(<strong>parentheses!</strong>)
|
(<strong>parentheses!</strong>)
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -19,6 +19,10 @@
|
||||||
%h1 Big!
|
%h1 Big!
|
||||||
%p Small
|
%p Small
|
||||||
/ Invisible
|
/ Invisible
|
||||||
|
= capture do
|
||||||
|
.dilly
|
||||||
|
%p foo
|
||||||
|
%h1 bar
|
||||||
= surround '(', ')' do
|
= surround '(', ')' do
|
||||||
%strong parentheses!
|
%strong parentheses!
|
||||||
= precede '*' do
|
= precede '*' do
|
||||||
|
|
Loading…
Add table
Reference in a new issue