aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view
diff options
context:
space:
mode:
authorTobias Lütke <tobias.luetke@gmail.com>2007-01-15 15:11:29 +0000
committerTobias Lütke <tobias.luetke@gmail.com>2007-01-15 15:11:29 +0000
commit64a80ef756ae89e85470b598e9c09b66d50a8103 (patch)
treea024129109969f72bd8972d642e5ab904b9f9c10 /actionpack/lib/action_view
parent67194d9c2df972f7483177b8a33356c344e56a88 (diff)
downloadrails-64a80ef756ae89e85470b598e9c09b66d50a8103.tar.gz
rails-64a80ef756ae89e85470b598e9c09b66d50a8103.tar.bz2
rails-64a80ef756ae89e85470b598e9c09b66d50a8103.zip
Allow inGroupsOf and eachSlice to be called through rjs. Closes #7046
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5942 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r--actionpack/lib/action_view/helpers/prototype_helper.rb22
1 files changed, 19 insertions, 3 deletions
diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb
index 71fe29db9a..43d04baf8d 100644
--- a/actionpack/lib/action_view/helpers/prototype_helper.rb
+++ b/actionpack/lib/action_view/helpers/prototype_helper.rb
@@ -784,7 +784,7 @@ module ActionView
end
class JavaScriptCollectionProxy < JavaScriptProxy #:nodoc:
- ENUMERABLE_METHODS_WITH_RETURN = [:all, :any, :collect, :map, :detect, :find, :find_all, :select, :max, :min, :partition, :reject, :sort_by] unless defined? ENUMERABLE_METHODS_WITH_RETURN
+ ENUMERABLE_METHODS_WITH_RETURN = [:all, :any, :collect, :map, :detect, :find, :find_all, :select, :max, :min, :partition, :reject, :sort_by, :in_groups_of, :each_slice] unless defined? ENUMERABLE_METHODS_WITH_RETURN
ENUMERABLE_METHODS = ENUMERABLE_METHODS_WITH_RETURN + [:each] unless defined? ENUMERABLE_METHODS
attr_reader :generator
delegate :arguments_for_call, :to => :generator
@@ -792,11 +792,27 @@ module ActionView
def initialize(generator, pattern)
super(generator, @pattern = pattern)
end
-
+
+ def each_slice(variable, number, &block)
+ if block
+ enumerate :eachSlice, :variable => variable, :method_args => [number], :yield_args => %w(value index), :return => true, &block
+ else
+ add_variable_assignment!(variable)
+ append_enumerable_function!("eachSlice(#{number.to_json});")
+ end
+ end
+
def grep(variable, pattern, &block)
enumerate :grep, :variable => variable, :return => true, :method_args => [pattern], :yield_args => %w(value index), &block
end
-
+
+ def in_groups_of(variable, number, fill_with = nil)
+ arguments = [number]
+ arguments << fill_with unless fill_with.nil?
+ add_variable_assignment!(variable)
+ append_enumerable_function!("inGroupsOf(#{arguments_for_call arguments});")
+ end
+
def inject(variable, memo, &block)
enumerate :inject, :variable => variable, :method_args => [memo], :yield_args => %w(memo value index), :return => true, &block
end