public
Description: HTML Abstraction Markup Language - A Markup Haiku
Homepage: http://haml.hamptoncatlin.com
Clone URL: git://github.com/nex3/haml.git
Abstract the no-longer-using-Haml functionality into 
Haml::Helpers#non_haml.
nex3 (author)
Thu Apr 24 10:23:01 -0700 2008
commit  83b6705b94622cc5a932b5cb88ab468035d0433b
tree    48940811d389793772c654fb4ed71e216fa43b29
parent  d4a1a350847a4086309b56fd0932faa4acd5632a
...
42
43
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
46
47
...
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
0
@@ -42,6 +42,24 @@ module Haml
0
     end
0
 
0
     # call-seq:
0
+ # non_haml { ... }
0
+ #
0
+ # Runs a block of code in a non-Haml context
0
+ # (i.e. #is_haml? will return false).
0
+ #
0
+ # This is mainly useful for rendering sub-templates such as partials in a non-Haml language,
0
+ # particularly where helpers may behave differently when run from Haml.
0
+ #
0
+ # Note that this is automatically applied to Rails partials.
0
+ def non_haml
0
+ old_buffer = @haml_buffer
0
+ @haml_buffer = nil
0
+ res = yield
0
+ @haml_buffer = old_buffer
0
+ res
0
+ end
0
+
0
+ # call-seq:
0
     # find_and_preserve(input)
0
     # find_and_preserve {...}
0
     #
...
2
3
4
5
6
7
8
9
 
 
10
11
12
...
2
3
4
 
 
 
 
 
5
6
7
8
9
0
@@ -2,11 +2,8 @@ if defined?(ActionView) and not defined?(Merb::Plugins)
0
   module ActionView
0
     class Base # :nodoc:
0
       def render_with_haml(*args, &block)
0
- old_buffer = @haml_buffer
0
- @haml_buffer = nil
0
- res = render_without_haml(*args, &block)
0
- @haml_buffer = old_buffer
0
- res
0
+ return non_haml { render_without_haml(*args, &block) } if is_haml?
0
+ render_without_haml(*args, &block)
0
       end
0
       alias_method :render_without_haml, :render
0
       alias_method :render, :render_with_haml
...
165
166
167
 
 
 
 
168
169
...
165
166
167
168
169
170
171
172
173
0
@@ -165,5 +165,9 @@ class HelperTest < Test::Unit::TestCase
0
 
0
     assert_equal("<p attr='val'>\n Blah\n</p>\n", result)
0
   end
0
+
0
+ def test_non_haml
0
+ assert_equal("false\n", render("= non_haml { is_haml? }"))
0
+ end
0
 end
0
 

Comments

    No one has commented yet.