mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Merge branch 'master' into scss
This commit is contained in:
commit
7ba6975518
7 changed files with 84 additions and 6 deletions
|
@ -257,6 +257,10 @@ that surrounds the filtered text with `<style>` and CDATA tags.
|
|||
* Add a railtie so Haml and Sass will be automatically loaded in Rails 3.
|
||||
Thanks to [Daniel Neighman](http://pancakestacks.wordpress.com/).
|
||||
|
||||
* Add a deprecation message for using `-` with methods like `form_for`
|
||||
that return strings in Rails 3.
|
||||
This is [the same deprecation that exists in Rails 3](http://github.com/rails/rails/commit/9de83050d3a4b260d4aeb5d09ec4eb64f913ba64).
|
||||
|
||||
## 2.2.21
|
||||
|
||||
[Tagged on GitHub](http://github.com/nex3/haml/commit/2.2.21).
|
||||
|
|
|
@ -33,6 +33,38 @@ module Haml
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Rails 3.0 prints a deprecation warning when block helpers
|
||||
# return strings that go unused.
|
||||
# We want to print the same deprecation warning,
|
||||
# so we have to compile in a method call to check for it.
|
||||
#
|
||||
# I don't like having this in the precompiler pipeline,
|
||||
# and I'd like to get rid of it once Rails 3.1 is well-established.
|
||||
if defined?(ActionView::OutputBuffer) &&
|
||||
Haml::Util.has?(:instance_method, ActionView::OutputBuffer, :append_if_string=)
|
||||
module Precompiler
|
||||
def push_silent_with_haml_block_deprecation(text, can_suppress = false)
|
||||
unless can_suppress && block_opened? && !mid_block_keyword?("- #{text}") &&
|
||||
text =~ ActionView::Template::Handlers::Erubis::BLOCK_EXPR
|
||||
return push_silent_without_haml_block_deprecation(text, can_suppress)
|
||||
end
|
||||
|
||||
push_silent_without_haml_block_deprecation("_hamlout.append_if_string= #{text}", can_suppress)
|
||||
end
|
||||
alias_method :push_silent_without_haml_block_deprecation, :push_silent
|
||||
alias_method :push_silent, :push_silent_with_haml_block_deprecation
|
||||
end
|
||||
|
||||
class Buffer
|
||||
def append_if_string=(value)
|
||||
if value.is_a?(String) && !value.is_a?(ActionView::NonConcattingString)
|
||||
ActiveSupport::Deprecation.warn("- style block helpers are deprecated. Please use =", caller)
|
||||
buffer << value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if defined? ActionView::Template and ActionView::Template.respond_to? :register_template_handler
|
||||
|
|
|
@ -641,8 +641,9 @@ HAML
|
|||
<p>foo-end</p>
|
||||
<p>bar-end</p>
|
||||
HTML
|
||||
- "foo-end-bar-end".gsub(/\\w+-end/) do |s|
|
||||
- ("foo-end-bar-end".gsub(/\\w+-end/) do |s|
|
||||
%p= s
|
||||
- end; nil)
|
||||
HAML
|
||||
end
|
||||
|
||||
|
|
|
@ -131,7 +131,14 @@ HAML
|
|||
end
|
||||
|
||||
def test_capture_haml
|
||||
assert_equal("\"<p>13</p>\\n\"\n", render("- foo = capture_haml(13) do |a|\n %p= a\n= foo.dump"))
|
||||
assert_equal(<<HTML, render(<<HAML))
|
||||
"<p>13</p>\\n"
|
||||
HTML
|
||||
- (foo = capture_haml(13) do |a|
|
||||
%p= a
|
||||
- end; nil)
|
||||
= foo.dump
|
||||
HAML
|
||||
end
|
||||
|
||||
def test_content_tag_block
|
||||
|
|
|
@ -231,10 +231,13 @@ baz
|
|||
HTML
|
||||
%p
|
||||
foo
|
||||
- with_output_buffer do
|
||||
-# Parenthesis required due to Rails 3.0 deprecation of block helpers
|
||||
-# that return strings.
|
||||
- (with_output_buffer do
|
||||
bar
|
||||
= "foo".gsub(/./) do |s|
|
||||
- "flup"
|
||||
- end; nil)
|
||||
baz
|
||||
HAML
|
||||
end
|
||||
|
@ -270,6 +273,28 @@ END
|
|||
end
|
||||
end
|
||||
|
||||
if defined?(ActionView::OutputBuffer) &&
|
||||
Haml::Util.has?(:instance_method, ActionView::OutputBuffer, :append_if_string=)
|
||||
def test_av_block_deprecation_warning
|
||||
assert_warning(/^DEPRECATION WARNING: - style block helpers are deprecated\. Please use =\./) do
|
||||
assert_equal <<HTML, render(<<HAML, :action_view)
|
||||
<form action="" method="post">
|
||||
Title:
|
||||
<input id="article_title" name="article[title]" size="30" type="text" value="Hello" />
|
||||
Body:
|
||||
<input id="article_body" name="article[body]" size="30" type="text" value="World" />
|
||||
</form>
|
||||
HTML
|
||||
- form_for :article, @article, :url => '' do |f|
|
||||
Title:
|
||||
= f.text_field :title
|
||||
Body:
|
||||
= f.text_field :body
|
||||
HAML
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
## XSS Protection Tests
|
||||
|
||||
# In order to enable these, either test against Rails 3.0
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
%h1 Partial layout used with for block:
|
||||
- render :layout => 'layout_for_partial.haml' do
|
||||
%p Some content within a layout
|
||||
- if Haml::Util.ap_geq_3?
|
||||
= render :layout => 'layout_for_partial.haml' do
|
||||
%p Some content within a layout
|
||||
- else
|
||||
- render :layout => 'layout_for_partial.haml' do
|
||||
%p Some content within a layout
|
||||
|
|
|
@ -41,7 +41,12 @@ class Test::Unit::TestCase
|
|||
def assert_warning(message)
|
||||
the_real_stderr, $stderr = $stderr, StringIO.new
|
||||
yield
|
||||
assert_equal message.strip, $stderr.string.strip
|
||||
|
||||
if message.is_a?(Regexp)
|
||||
assert_match message, $stderr.string.strip
|
||||
else
|
||||
assert_equal message.strip, $stderr.string.strip
|
||||
end
|
||||
ensure
|
||||
$stderr = the_real_stderr
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue