public
Description: HTML Abstraction Markup Language - A Markup Haiku
Homepage: http://haml.hamptoncatlin.com
Clone URL: git://github.com/nex3/haml.git
Tagging 1.5.2.


git-svn-id: svn://hamptoncatlin.com/haml/tags/rel_1-5-2@493 
7063305b-7217-0410-af8c-cdc13e5119b9
nex3 (author)
Mon Apr 09 22:04:57 -0700 2007
commit  83fcf48c1e554470aa0db7c05208c8710d78f950
tree    b0b60fb8de2c9d6cb01cc91df66694dc4e0576bb
parent  fa00635843a84a06e040f2b4cc53c3ee6292fad8
...
202
203
204
 
205
206
207
...
265
266
267
 
268
269
270
...
311
312
313
314
 
315
316
317
...
423
424
425
426
427
428
429
430
431
 
 
 
 
 
 
 
 
432
433
434
...
517
518
519
520
 
521
522
523
...
541
542
543
544
 
545
546
547
...
592
593
594
595
 
596
597
598
...
202
203
204
205
206
207
208
...
266
267
268
269
270
271
272
...
313
314
315
 
316
317
318
319
...
425
426
427
 
 
 
 
 
 
428
429
430
431
432
433
434
435
436
437
438
...
521
522
523
 
524
525
526
527
...
545
546
547
 
548
549
550
551
...
596
597
598
 
599
600
601
602
0
@@ -202,6 +202,7 @@ END
0
     def do_precompile
0
       push_silent <<-END
0
         def _haml_render
0
+ @haml_is_haml = true
0
         _hamlout = @haml_stack[-1]
0
         _erbout = _hamlout.buffer
0
       END
0
@@ -265,6 +266,7 @@ END
0
       # Close all the open tags
0
       @template_tabs.times { close }
0
 
0
+ push_silent "@haml_is_haml = false"
0
       push_silent "end"
0
     end
0
     
0
@@ -311,7 +313,7 @@ END
0
         sub_line = line[1..-1]
0
         unless sub_line[0] == SILENT_COMMENT
0
           mbk = mid_block_keyword?(line)
0
- push_silent(sub_line, !mbk)
0
+ push_silent(sub_line, !mbk, true)
0
           if (@block_opened && !mbk) || line[1..-1].split(' ', 2)[0] == "case"
0
             push_and_tabulate([:script])
0
           end
0
@@ -423,12 +425,14 @@ END
0
 
0
     # Evaluates <tt>text</tt> in the context of <tt>@scope_object</tt>, but
0
     # does not output the result.
0
- def push_silent(text, add_index = false)
0
- if add_index
0
- @precompiled << "@haml_lineno = #{@index}\n#{text}\n"
0
- else
0
- # Not really DRY, but probably faster
0
- @precompiled << "#{text}\n"
0
+ def push_silent(text, add_index = false, can_suppress = false)
0
+ unless can_suppress && @options[:suppress_eval]
0
+ if add_index
0
+ @precompiled << "@haml_lineno = #{@index}\n#{text}\n"
0
+ else
0
+ # Not really DRY, but probably faster
0
+ @precompiled << "#{text}\n"
0
+ end
0
       end
0
     end
0
 
0
@@ -517,7 +521,7 @@ END
0
 
0
     # Closes a Ruby block.
0
     def close_block
0
- push_silent "end"
0
+ push_silent "end", false, true
0
       @template_tabs -= 1
0
     end
0
 
0
@@ -541,7 +545,7 @@ END
0
     
0
     # Closes a loud Ruby block.
0
     def close_loud(command)
0
- push_silent 'end'
0
+ push_silent 'end', false, true
0
       @precompiled << command
0
       @template_tabs -= 1
0
     end
0
@@ -592,7 +596,7 @@ END
0
 
0
         value_exists = !value.empty?
0
         attributes_hash = "nil" if attributes_hash.nil? || @options[:suppress_eval]
0
- object_ref = "nil" unless object_ref
0
+ object_ref = "nil" if object_ref.nil? || @options[:suppress_eval]
0
 
0
         if @block_opened
0
           if atomic
...
229
230
231
232
 
233
234
235
...
229
230
231
 
232
233
234
235
0
@@ -229,7 +229,7 @@ module Haml
0
     # also works in other ActionView templates,
0
     # where it will always return false.
0
     def is_haml?
0
- @haml_stack ? @haml_stack.size > 0 : false
0
+ @haml_is_haml
0
     end
0
   end
0
 end
...
10
11
12
 
 
 
 
 
 
 
 
 
 
 
 
13
14
15
...
22
23
24
25
 
 
26
27
28
...
40
41
42
43
 
 
44
45
46
...
56
57
58
59
 
 
60
61
62
...
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
...
34
35
36
 
37
38
39
40
41
...
53
54
55
 
56
57
58
59
60
...
70
71
72
 
73
74
75
76
77
0
@@ -10,6 +10,18 @@ end
0
 
0
 if action_view_included
0
   module ActionView
0
+ class Base # :nodoc:
0
+ def render_with_haml(*args)
0
+ was_haml = is_haml?
0
+ @haml_is_haml = false
0
+ res = render_without_haml(*args)
0
+ @haml_is_haml = was_haml
0
+ res
0
+ end
0
+ alias_method :render_without_haml, :render
0
+ alias_method :render, :render_with_haml
0
+ end
0
+
0
     # This overrides various helpers in ActionView
0
     # to make them work more effectively with Haml.
0
     module Helpers
0
@@ -22,7 +34,8 @@ if action_view_included
0
             concat_without_haml(string, binding)
0
           end
0
         end
0
- alias_method_chain :concat, :haml
0
+ alias_method :concat_without_haml, :concat
0
+ alias_method :concat, :concat_with_haml
0
       end
0
       
0
       module FormTagHelper
0
@@ -40,7 +53,8 @@ if action_view_included
0
           concat "\n" if block_given? && is_haml?
0
           res
0
         end
0
- alias_method_chain :form_tag, :haml
0
+ alias_method :form_tag_without_haml, :form_tag
0
+ alias_method :form_tag, :form_tag_with_haml
0
       end
0
       
0
       module FormHelper
0
@@ -56,7 +70,8 @@ if action_view_included
0
           form_for_without_haml(object_name, *args, &proc)
0
           concat "\n" if block_given? && is_haml?
0
         end
0
- alias_method_chain :form_for, :haml
0
+ alias_method :form_for_without_haml, :form_for
0
+ alias_method :form_for, :form_for_with_haml
0
       end
0
       
0
       def generate_content_class_names
...
57
58
59
 
60
 
61
62
63
...
57
58
59
60
61
62
63
64
65
0
@@ -57,7 +57,9 @@ class EngineTest < Test::Unit::TestCase
0
 
0
   def test_stop_eval
0
     assert_equal("", render("= 'Hello'", :suppress_eval => true))
0
+ assert_equal("", render("- _hamlout << 'foo'", :suppress_eval => true))
0
     assert_equal("<div id='foo' />\n", render("#foo{:yes => 'no'}/", :suppress_eval => true))
0
+ assert_equal("<div />\n", render("%div[1]/", :suppress_eval => true))
0
 
0
     begin
0
       assert_equal("", render(":ruby\n puts 'hello'", :suppress_eval => true))
...
101
102
103
 
 
 
 
104
105
106
...
101
102
103
104
105
106
107
108
109
110
0
@@ -101,6 +101,10 @@ class HelperTest < Test::Unit::TestCase
0
 
0
   def test_is_haml
0
     assert(!ActionView::Base.new.is_haml?)
0
+ assert_equal("true\n", render("= is_haml?"))
0
+ assert_equal("true\n", render("= is_haml?", :action_view))
0
+ assert_equal("false", @base.render(:inline => '<%= is_haml? %>'))
0
+ assert_equal("false\n", render("= render :inline => '<%= is_haml? %>'", :action_view))
0
   end
0
 end
0
 

Comments

    No one has commented yet.