1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Reorg options_for_javascript and array_or_string_for_javascript

This commit is contained in:
Joshua Peek 2010-01-30 16:13:49 -06:00
parent 570e02c96a
commit 657d85580e
3 changed files with 17 additions and 17 deletions

View file

@ -95,23 +95,6 @@ module ActionView
def javascript_cdata_section(content) #:nodoc:
"\n//#{cdata_section("\n#{content}\n//")}\n"
end
protected
def options_for_javascript(options)
if options.empty?
'{}'
else
"{#{options.keys.map { |k| "#{k}:#{options[k]}" }.sort.join(', ')}}"
end
end
def array_or_string_for_javascript(option)
if option.kind_of?(Array)
"['#{option.join('\',\'')}']"
elsif !option.nil?
"'#{option}'"
end
end
end
end
end

View file

@ -624,6 +624,14 @@ module ActionView
end
protected
def options_for_javascript(options)
if options.empty?
'{}'
else
"{#{options.keys.map { |k| "#{k}:#{options[k]}" }.sort.join(', ')}}"
end
end
def options_for_ajax(options)
js_options = build_callbacks(options)

View file

@ -216,6 +216,15 @@ module ActionView
%(Droppables.add(#{ActiveSupport::JSON.encode(element_id)}, #{options_for_javascript(options)});)
end
protected
def array_or_string_for_javascript(option)
if option.kind_of?(Array)
"['#{option.join('\',\'')}']"
elsif !option.nil?
"'#{option}'"
end
end
end
module PrototypeHelper