1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

Merge branch 'stable'

Conflicts:
	lib/sass/engine.rb
This commit is contained in:
Nathan Weizenbaum 2008-09-24 18:51:15 -07:00
commit 158226dcd5
8 changed files with 80 additions and 30 deletions

View file

@ -254,7 +254,26 @@ module Haml
# the local variable <tt>foo</tt> would be assigned to "<p>13</p>\n".
#
def capture_haml(*args, &block)
capture_haml_with_buffer(haml_buffer.buffer, *args, &block)
buffer = eval('_hamlout', block) rescue haml_buffer
with_haml_buffer(buffer) do
position = haml_buffer.buffer.length
block.call(*args)
captured = haml_buffer.buffer.slice!(position..-1)
min_tabs = nil
captured.each do |line|
tabs = line.index(/[^ ]/)
min_tabs ||= tabs
min_tabs = min_tabs > tabs ? tabs : min_tabs
end
result = captured.map do |line|
line[min_tabs..-1]
end
result.to_s
end
end
# Outputs text directly to the Haml buffer, with the proper tabulation
@ -379,6 +398,21 @@ module Haml
private
# call-seq:
# with_haml_buffer(buffer) {...}
#
# Runs the block with the given buffer as the currently active buffer.
def with_haml_buffer(buffer)
@haml_buffer, old_buffer = buffer, @haml_buffer
old_buffer.active, was_active = false, old_buffer.active? if old_buffer
@haml_buffer.active = true
yield
ensure
@haml_buffer.active = false
old_buffer.active = was_active if old_buffer
@haml_buffer = old_buffer
end
# Gets a reference to the current Haml::Buffer object.
def haml_buffer
@haml_buffer
@ -392,28 +426,6 @@ module Haml
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 = local_buffer.slice!(position..-1)
min_tabs = nil
captured.each do |line|
tabs = line.index(/[^ ]/)
min_tabs ||= tabs
min_tabs = min_tabs > tabs ? tabs : min_tabs
end
result = captured.map do |line|
line[min_tabs..-1]
end
result.to_s
end
include ActionViewExtensions if self.const_defined? "ActionViewExtensions"
end
end

View file

@ -2,7 +2,15 @@ if defined?(ActionView) and not defined?(Merb::Plugins)
module ActionView
class Base # :nodoc:
def render_with_haml(*args, &block)
return non_haml { render_without_haml(*args, &block) } if is_haml?
options = args.first
# If render :layout is used with a block,
# it concats rather than returning a string
# so we need it to keep thinking it's Haml
# until it hits the sub-render
if is_haml? && !(options.is_a?(Hash) && options[:layout] && block_given?)
return non_haml { render_without_haml(*args, &block) }
end
render_without_haml(*args, &block)
end
alias_method :render_without_haml, :render

View file

@ -0,0 +1,5 @@
<h1>Partial layout used with for block:</h1>
<div class='partial-layout'>
<h2>This is inside a partial layout</h2>
<p>Some content within a layout</p>
</div>

View file

@ -1,6 +1,7 @@
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../test_helper'
require 'haml/template'
require 'sass/plugin'
require File.dirname(__FILE__) + '/mocks/article'
module Haml::Filters::Test
@ -17,11 +18,17 @@ module Haml::Helpers
end
end
class DummyController
def self.controller_path
''
end
end
class TemplateTest < Test::Unit::TestCase
TEMPLATE_PATH = File.join(File.dirname(__FILE__), "templates")
TEMPLATES = %w{ very_basic standard helpers
whitespace_handling original_engine list helpful
silent_script tag_parsing just_stuff partials
silent_script tag_parsing just_stuff partials partial_layout
filters nuke_outer_whitespace nuke_inner_whitespace }
def setup
@ -35,11 +42,21 @@ class TemplateTest < Test::Unit::TestCase
@base.finder.append_view_path(TEMPLATE_PATH)
end
@base.send(:evaluate_assigns)
if @base.private_methods.include?('evaluate_assigns')
@base.send(:evaluate_assigns)
else
# Rails 2.2
@base.send(:_evaluate_assigns_and_ivars)
end
# This is used by form_for.
# It's usually provided by ActionController::Base.
def @base.protect_against_forgery?; false; end
# filters template uses :sass
Sass::Plugin.options.update(:line_comments => true, :style => :compact)
@base.controller = DummyController.new
end
def render(text)

View file

@ -0,0 +1,3 @@
.partial-layout
%h2 This is inside a partial layout
= yield

View file

@ -0,0 +1,3 @@
%h1 Partial layout used with for block:
- render :layout => 'layout_for_partial.haml' do
%p Some content within a layout

View file

@ -1,8 +1,4 @@
#!/usr/bin/env ruby
MERB_ENV = RAILS_ENV = 'testing'
RAILS_ROOT = '.'
require File.dirname(__FILE__) + '/../test_helper'
require 'sass/plugin'
require 'fileutils'

View file

@ -16,3 +16,9 @@ require 'test/unit'
$:.unshift lib_dir unless $:.include?(lib_dir)
require 'haml'
require 'sass'
# required because of Sass::Plugin
unless defined? RAILS_ROOT
RAILS_ROOT = '.'
MERB_ENV = RAILS_ENV = 'testing'
end