diff options
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r-- | actionpack/lib/action_view/base.rb | 10 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/form_tag_helper.rb | 27 | ||||
-rw-r--r-- | actionpack/lib/action_view/renderable.rb | 19 | ||||
-rw-r--r-- | actionpack/lib/action_view/renderable_partial.rb | 18 |
4 files changed, 41 insertions, 33 deletions
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index 6c4da9067d..8c00670087 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -278,9 +278,9 @@ module ActionView #:nodoc: # the same name but differing formats. See +Request#template_format+ # for more details. def template_format - return @template_format if @template_format - - if controller && controller.respond_to?(:request) + if defined? @template_format + @template_format + elsif controller && controller.respond_to?(:request) @template_format = controller.request.template_format else @template_format = :html @@ -366,7 +366,9 @@ module ActionView #:nodoc: end else begin - original_content_for_layout, @content_for_layout = @content_for_layout, render(options) + original_content_for_layout = @content_for_layout if defined?(@content_for_layout) + @content_for_layout = render(options) + if (options[:inline] || options[:file] || options[:text]) @cached_content_for_layout = @content_for_layout render(:file => partial_layout, :locals => local_assigns) diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index e5777b71d7..294c22521e 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -116,7 +116,7 @@ module ActionView # Creates a label field # - # ==== Options + # ==== Options # * Creates standard HTML attributes for the tag. # # ==== Examples @@ -351,19 +351,16 @@ module ActionView disable_with = "this.value='#{disable_with}'" disable_with << ";#{options.delete('onclick')}" if options['onclick'] - options["onclick"] = [ - "this.setAttribute('originalValue', this.value)", - "this.disabled=true", - disable_with, - "result = (this.form.onsubmit ? (this.form.onsubmit() ? this.form.submit() : false) : this.form.submit())", - "if (result == false) { this.value = this.getAttribute('originalValue'); this.disabled = false }", - "return result;", - ].join(";") + options["onclick"] = "if (window.hiddenCommit) { window.hiddenCommit.setAttribute('value', this.value); }" + options["onclick"] << "else { hiddenCommit = this.cloneNode(false);hiddenCommit.setAttribute('type', 'hidden');this.form.appendChild(hiddenCommit); }" + options["onclick"] << "this.setAttribute('originalValue', this.value);this.disabled = true;#{disable_with};" + options["onclick"] << "result = (this.form.onsubmit ? (this.form.onsubmit() ? this.form.submit() : false) : this.form.submit());" + options["onclick"] << "if (result == false) { this.value = this.getAttribute('originalValue');this.disabled = false; }return result;" end if confirm = options.delete("confirm") options["onclick"] ||= '' - options["onclick"] += "return #{confirm_javascript_function(confirm)};" + options["onclick"] << "return #{confirm_javascript_function(confirm)};" end tag :input, { "type" => "submit", "name" => "commit", "value" => value }.update(options.stringify_keys) @@ -374,6 +371,9 @@ module ActionView # <tt>source</tt> is passed to AssetTagHelper#image_path # # ==== Options + # * <tt>:confirm => 'question?'</tt> - This will add a JavaScript confirm + # prompt with the question specified. If the user accepts, the form is + # processed normally, otherwise no action is taken. # * <tt>:disabled</tt> - If set to true, the user will not be able to use this input. # * Any other key creates standard HTML options for the tag. # @@ -390,6 +390,13 @@ module ActionView # image_submit_tag("agree.png", :disabled => true, :class => "agree-disagree-button") # # => <input class="agree-disagree-button" disabled="disabled" src="/images/agree.png" type="image" /> def image_submit_tag(source, options = {}) + options.stringify_keys! + + if confirm = options.delete("confirm") + options["onclick"] ||= '' + options["onclick"] += "return #{confirm_javascript_function(confirm)};" + end + tag :input, { "type" => "image", "src" => path_to_image(source) }.update(options.stringify_keys) end diff --git a/actionpack/lib/action_view/renderable.rb b/actionpack/lib/action_view/renderable.rb index d960335220..0134bc988f 100644 --- a/actionpack/lib/action_view/renderable.rb +++ b/actionpack/lib/action_view/renderable.rb @@ -1,8 +1,7 @@ module ActionView - module Renderable - # NOTE: The template that this mixin is beening include into is frozen - # So you can not set or modify any instance variables - + # NOTE: The template that this mixin is being included into is frozen + # so you cannot set or modify any instance variables + module Renderable #:nodoc: extend ActiveSupport::Memoizable def self.included(base) @@ -33,10 +32,11 @@ module ActionView view.send(:_set_controller_content_type, mime_type) if respond_to?(:mime_type) view.send(method_name(local_assigns), local_assigns) do |*names| - if proc = view.instance_variable_get("@_proc_for_layout") + ivar = :@_proc_for_layout + if view.instance_variable_defined?(ivar) and proc = view.instance_variable_get(ivar) view.capture(*names, &proc) - else - view.instance_variable_get("@content_for_#{names.first || 'layout'}") + elsif view.instance_variable_defined?(ivar = :"@content_for_#{names.first || :layout}") + view.instance_variable_get(ivar) end end end @@ -72,12 +72,9 @@ module ActionView end_src begin - logger = defined?(ActionController) && Base.logger - logger.debug "Compiling template #{render_symbol}" if logger - ActionView::Base::CompiledTemplates.module_eval(source, filename, 0) rescue Exception => e # errors from template code - if logger + if logger = defined?(ActionController) && Base.logger logger.debug "ERROR: compiling #{render_symbol} RAISED #{e}" logger.debug "Function body: #{source}" logger.debug "Backtrace: #{e.backtrace.join("\n")}" diff --git a/actionpack/lib/action_view/renderable_partial.rb b/actionpack/lib/action_view/renderable_partial.rb index 123a9aebbc..d92ff1b8d3 100644 --- a/actionpack/lib/action_view/renderable_partial.rb +++ b/actionpack/lib/action_view/renderable_partial.rb @@ -1,8 +1,7 @@ module ActionView - module RenderablePartial - # NOTE: The template that this mixin is beening include into is frozen - # So you can not set or modify any instance variables - + # NOTE: The template that this mixin is being included into is frozen + # so you cannot set or modify any instance variables + module RenderablePartial #:nodoc: extend ActiveSupport::Memoizable def variable_name @@ -30,10 +29,13 @@ module ActionView local_assigns[variable_name] if view.respond_to?(:controller) - object ||= ActiveSupport::Deprecation::DeprecatedObjectProxy.new( - view.controller.instance_variable_get("@#{variable_name}"), - "@#{variable_name} will no longer be implicitly assigned to #{variable_name}" - ) + ivar = :"@#{variable_name}" + object ||= + if view.controller.instance_variable_defined?(ivar) + ActiveSupport::Deprecation::DeprecatedObjectProxy.new( + view.controller.instance_variable_get(ivar), + "#{ivar} will no longer be implicitly assigned to #{variable_name}") + end end # Ensure correct object is reassigned to other accessors |