public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Prototype helpers should generate Element.insert instead of Insertion.new, which 
has been deprecated in Prototype 1.6.
miloops (author)
Tue Jul 22 07:13:38 -0700 2008
jeremy (committer)
Wed Jul 30 01:42:32 -0700 2008
commit  eaab895f83276674891227c656df9b4cebc50200
tree    04abcb82319b12701ca8690dc829a9fe6b375e98
parent  c8e80f6389b45134c0514dde6736488cf5507765
...
407
408
409
 
410
411
412
...
418
419
420
 
421
422
423
...
434
435
436
437
438
439
 
 
 
 
 
 
 
 
440
441
442
...
445
446
447
448
 
449
450
451
...
585
586
587
 
 
588
589
590
 
591
592
593
594
 
595
596
597
598
 
599
600
601
...
407
408
409
410
411
412
413
...
419
420
421
422
423
424
425
...
436
437
438
 
 
 
439
440
441
442
443
444
445
446
447
448
449
...
452
453
454
 
455
456
457
458
...
592
593
594
595
596
597
598
 
599
600
 
601
 
602
603
 
 
 
604
605
606
607
0
@@ -407,6 +407,7 @@ module ActionController
0
 
0
           if rjs_type == :insert
0
             arg = args.shift
0
+            position  = arg
0
             insertion = "insert_#{arg}".to_sym
0
             raise ArgumentError, "Unknown RJS insertion type #{arg}" unless RJS_STATEMENTS[insertion]
0
             statement = "(#{RJS_STATEMENTS[insertion]})"
0
@@ -418,6 +419,7 @@ module ActionController
0
         else
0
           statement = "#{RJS_STATEMENTS[:any]}"
0
         end
0
+        position ||= Regexp.new(RJS_INSERTIONS.join('|'))
0
 
0
         # Next argument we're looking for is the element identifier. If missing, we pick
0
         # any element.
0
@@ -434,9 +436,14 @@ module ActionController
0
               Regexp.new("\\$\\(\"#{id}\"\\)#{statement}\\(#{RJS_PATTERN_HTML}\\)", Regexp::MULTILINE)
0
             when :remove, :show, :hide, :toggle
0
               Regexp.new("#{statement}\\(\"#{id}\"\\)")
0
-            else
0
-              Regexp.new("#{statement}\\(\"#{id}\", #{RJS_PATTERN_HTML}\\)", Regexp::MULTILINE)
0
-          end
0
+            when :replace, :replace_html
0
+              Regexp.new("#{statement}\\(\"#{id}\", #{RJS_PATTERN_HTML}\\)")
0
+            when :insert, :insert_html
0
+              Regexp.new("Element.insert\\(\\\"#{id}\\\", \\{ #{position}: #{RJS_PATTERN_HTML} \\}\\);")
0
+             else
0
+              Regexp.union(Regexp.new("#{statement}\\(\"#{id}\", #{RJS_PATTERN_HTML}\\)"),
0
+                Regexp.new("Element.insert\\(\\\"#{id}\\\", \\{ #{position}: #{RJS_PATTERN_HTML} \\}\\);"))
0
+           end
0
 
0
         # Duplicate the body since the next step involves destroying it.
0
         matches = nil
0
@@ -445,7 +452,7 @@ module ActionController
0
             matches = @response.body.match(pattern)
0
           else
0
             @response.body.gsub(pattern) do |match|
0
-              html = unescape_rjs($2)
0
+              html = unescape_rjs(match)
0
               matches ||= []
0
               matches.concat HTML::Document.new(html).root.children.select { |n| n.tag? }
0
               ""
0
@@ -585,17 +592,16 @@ module ActionController
0
             :hide                 => /Element\.hide/,
0
             :toggle                 => /Element\.toggle/
0
           }
0
+          RJS_STATEMENTS[:any] = Regexp.new("(#{RJS_STATEMENTS.values.join('|')})")
0
+          RJS_PATTERN_HTML = /"((\\"|[^"])*)"/
0
           RJS_INSERTIONS = [:top, :bottom, :before, :after]
0
           RJS_INSERTIONS.each do |insertion|
0
-            RJS_STATEMENTS["insert_#{insertion}".to_sym] = Regexp.new(Regexp.quote("new Insertion.#{insertion.to_s.camelize}"))
0
+            RJS_STATEMENTS["insert_#{insertion}".to_sym] = /Element.insert\(\"([^\"]*)\", \{ #{insertion.to_s.downcase}: #{RJS_PATTERN_HTML} \}\);/
0
           end
0
-          RJS_STATEMENTS[:any] = Regexp.new("(#{RJS_STATEMENTS.values.join('|')})")
0
           RJS_STATEMENTS[:insert_html] = Regexp.new(RJS_INSERTIONS.collect do |insertion|
0
-            Regexp.quote("new Insertion.#{insertion.to_s.camelize}")
0
+            /Element.insert\(\"([^\"]*)\", \{ #{insertion.to_s.downcase}: #{RJS_PATTERN_HTML} \}\);/
0
           end.join('|'))
0
-          RJS_PATTERN_HTML = /"((\\"|[^"])*)"/
0
-          RJS_PATTERN_EVERYTHING = Regexp.new("#{RJS_STATEMENTS[:any]}\\(\"([^\"]*)\", #{RJS_PATTERN_HTML}\\)",
0
-                                              Regexp::MULTILINE)
0
+          RJS_PATTERN_EVERYTHING = Regexp.new("#{RJS_STATEMENTS[:any]}\\(\"([^\"]*)\", #{RJS_PATTERN_HTML}\\)", Regexp::MULTILINE)
0
           RJS_PATTERN_UNICODE_ESCAPED_CHAR = /\\u([0-9a-zA-Z]{4})/
0
         end
0
 
...
608
609
610
611
 
612
613
614
...
741
742
743
744
 
745
746
747
748
 
749
750
751
752
753
 
 
754
755
756
...
1054
1055
1056
1057
 
1058
1059
1060
...
608
609
610
 
611
612
613
614
...
741
742
743
 
744
745
746
747
 
748
749
750
751
 
 
752
753
754
755
756
...
1054
1055
1056
 
1057
1058
1059
1060
0
@@ -608,7 +608,7 @@ module ActionView
0
         # Example:
0
         #
0
         #   # Generates:
0
-        #   #     new Insertion.Bottom("list", "<li>Some item</li>");
0
+        #   #     new Element.insert("list", { bottom: <li>Some item</li>" });
0
         #   #     new Effect.Highlight("list");
0
         #   #     ["status-indicator", "cancel-link"].each(Element.hide);
0
         #   update_page do |page|
0
@@ -741,16 +741,16 @@ module ActionView
0
           #
0
           #   # Insert the rendered 'navigation' partial just before the DOM
0
           #   # element with ID 'content'.
0
-          #   # Generates: new Insertion.Before("content", "-- Contents of 'navigation' partial --");
0
+          #   # Generates: Element.insert("content", { before: "-- Contents of 'navigation' partial --" });
0
           #   page.insert_html :before, 'content', :partial => 'navigation'
0
           #
0
           #   # Add a list item to the bottom of the <ul> with ID 'list'.
0
-          #   # Generates: new Insertion.Bottom("list", "<li>Last item</li>");
0
+          #   # Generates: Element.insert("list", { bottom: "<li>Last item</li>" });
0
           #   page.insert_html :bottom, 'list', '<li>Last item</li>'
0
           #
0
           def insert_html(position, id, *options_for_render)
0
-            insertion = position.to_s.camelize
0
-            call "new Insertion.#{insertion}", id, render(*options_for_render)
0
+            content = javascript_object_for(render(*options_for_render))
0
+            record "Element.insert(\"#{id}\", { #{position.to_s.downcase}: #{content} });"
0
           end
0
 
0
           # Replaces the inner HTML of the DOM element with the given +id+.
0
@@ -1054,7 +1054,7 @@ module ActionView
0
 
0
         js_options['asynchronous'] = options[:type] != :synchronous
0
         js_options['method']       = method_option_to_s(options[:method]) if options[:method]
0
-        js_options['insertion']    = "Insertion.#{options[:position].to_s.camelize}" if options[:position]
0
+        js_options['insertion']    = options[:position].to_s.downcase if options[:position]
0
         js_options['evalScripts']  = options[:script].nil? || options[:script]
0
 
0
         if options[:form]
...
287
288
289
290
 
291
292
 
293
294
 
295
296
 
297
298
299
...
366
367
368
369
370
 
 
371
372
373
...
287
288
289
 
290
291
 
292
293
 
294
295
 
296
297
298
299
...
366
367
368
 
 
369
370
371
372
373
0
@@ -287,13 +287,13 @@ class JavaScriptGeneratorTest < PrototypeHelperBaseTest
0
   end
0
 
0
   def test_insert_html_with_string
0
-    assert_equal 'new Insertion.Top("element", "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E");',
0
+    assert_equal 'Element.insert("element", { top: "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E" });',
0
       @generator.insert_html(:top, 'element', '<p>This is a test</p>')
0
-    assert_equal 'new Insertion.Bottom("element", "\\u003Cp\u003EThis is a test\\u003C/p\u003E");',
0
+    assert_equal 'Element.insert("element", { bottom: "\\u003Cp\u003EThis is a test\\u003C/p\u003E" });',
0
       @generator.insert_html(:bottom, 'element', '<p>This is a test</p>')
0
-    assert_equal 'new Insertion.Before("element", "\\u003Cp\u003EThis is a test\\u003C/p\u003E");',
0
+    assert_equal 'Element.insert("element", { before: "\\u003Cp\u003EThis is a test\\u003C/p\u003E" });',
0
       @generator.insert_html(:before, 'element', '<p>This is a test</p>')
0
-    assert_equal 'new Insertion.After("element", "\\u003Cp\u003EThis is a test\\u003C/p\u003E");',
0
+    assert_equal 'Element.insert("element", { after: "\\u003Cp\u003EThis is a test\\u003C/p\u003E" });',
0
       @generator.insert_html(:after, 'element', '<p>This is a test</p>')
0
   end
0
 
0
@@ -366,8 +366,8 @@ class JavaScriptGeneratorTest < PrototypeHelperBaseTest
0
     @generator.replace_html('baz', '<p>This is a test</p>')
0
 
0
     assert_equal <<-EOS.chomp, @generator.to_s
0
-new Insertion.Top("element", "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E");
0
-new Insertion.Bottom("element", "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E");
0
+Element.insert("element", { top: "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E" });
0
+Element.insert("element", { bottom: "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E" });
0
 ["foo", "bar"].each(Element.remove);
0
 Element.update("baz", "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E");
0
     EOS

Comments