aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers
diff options
context:
space:
mode:
authorSam Stephenson <sam@37signals.com>2006-01-23 07:27:24 +0000
committerSam Stephenson <sam@37signals.com>2006-01-23 07:27:24 +0000
commit5f44411d948f0cefb6a968a357d305c4c97c2174 (patch)
tree166ed212aeafff5269f1e77badb88c6b958e36ff /actionpack/lib/action_view/helpers
parent84361478256f620cc3c4d31235eeec28bba058f0 (diff)
downloadrails-5f44411d948f0cefb6a968a357d305c4c97c2174.tar.gz
rails-5f44411d948f0cefb6a968a357d305c4c97c2174.tar.bz2
rails-5f44411d948f0cefb6a968a357d305c4c97c2174.zip
Backing out of [3470] until visual_effect, et al can work
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3471 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view/helpers')
-rw-r--r--actionpack/lib/action_view/helpers/prototype_helper.rb58
1 files changed, 14 insertions, 44 deletions
diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb
index edf6f50a06..d35334a98c 100644
--- a/actionpack/lib/action_view/helpers/prototype_helper.rb
+++ b/actionpack/lib/action_view/helpers/prototype_helper.rb
@@ -370,52 +370,34 @@ module ActionView
# this in your Ajax response bodies, either in a <script> tag or as plain
# JavaScript sent with a Content-type of "text/javascript".
#
- # Create new instances with PrototypeHelper#update_page or with
- # ActionController::Base#render, then call #insert_html, #replace_html,
- # #remove, #show, #hide, #visual_effect, or any other of the built-in
- # methods on the yielded generator in any order you like to modify the
- # content and appearance of the current page.
+ # Create new instances with PrototypeHelper#update_page, then call
+ # #insert_html, #replace_html, #remove, #show, or #hide on the yielded
+ # generator in any order you like to modify the content and appearance of
+ # the current page. (You can also call other helper methods which
+ # return JavaScript, such as
+ # ActionView::Helpers::ScriptaculousHelper#visual_effect.)
#
# Example:
#
# update_page do |page|
- # page.insert_html :bottom, 'list', "<li>#{@item.name}</li>"
+ # page.insert_html :bottom, 'list', '<li>Last item</li>'
# page.visual_effect :highlight, 'list'
# page.hide 'status-indicator', 'cancel-link'
# end
#
# generates the following JavaScript:
#
- # new Insertion.Bottom("list", "<li>Some item</li>");
+ # new Insertion.Bottom("list", "<li>Last item</li>");
# new Effect.Highlight("list");
# ["status-indicator", "cancel-link"].each(Element.hide);
#
- # Helper methods can be used in conjunction with JavaScriptGenerator.
- # When a helper method is called inside an update block on the +page+
- # object, that method will also have access to a +page+ object.
- #
- # Example:
- #
- # module ApplicationHelper
- # def update_time
- # page.replace_html 'time', Time.now.to_s(:db)
- # page.visual_effect :highlight, 'time'
- # end
- # end
- #
- # # Controller action
- # def poll
- # render :update { |page| page.update_time }
- # end
- #
# You can also use PrototypeHelper#update_page_tag instead of
# PrototypeHelper#update_page to wrap the generated JavaScript in a
# <script> tag.
class JavaScriptGenerator
- def initialize(context, &block) #:nodoc:
+ def initialize(context) #:nodoc:
@context, @lines = context, []
- include_helpers_from_context
- @context.instance_exec(self, &block)
+ yield self
end
def to_s #:nodoc:
@@ -519,24 +501,12 @@ module ActionView
yield
record "}, #{(seconds * 1000).to_i})"
end
-
- # Starts a Scriptaculous visual effect. See
- # ActionView::Helpers::ScriptaculousHelper for more information.
- def visual_effect(name, id, options = {})
- record ScriptaculousHelper::visual_effect(name, id, options)
- end
-
+
private
- def include_helpers_from_context
- @context.extended_by.each do |mod|
- extend mod unless mod.name =~ /^ActionView::Helpers/
- end
+ def method_missing(method, *arguments, &block)
+ record(@context.send(method, *arguments, &block))
end
-
- def page
- self
- end
-
+
def record(line)
returning line = "#{line.to_s.chomp.gsub /\;$/, ''};" do
self << line