From 65b8385c86fc79bc9a1af72fa66e8b5a97b55144 Mon Sep 17 00:00:00 2001 From: Nathan de Vries Date: Fri, 12 Dec 2008 17:26:55 +1100 Subject: [PATCH] Provide a configuration setting (TagHelper#generate_non_self_closing_tags) to allow a global override of self-closing tags generation. Useful when you want to use stylesheet_link_tag etc. in HTML 4.01 Transitional layouts. Also allows stylesheet_link_tag(:screen, :open => true). --- actionpack/lib/action_view/helpers/tag_helper.rb | 14 +++++++++++++- 1 files changed, 13 insertions(+), 1 deletions(-) diff --git a/actionpack/lib/action_view/helpers/tag_helper.rb b/actionpack/lib/action_view/helpers/tag_helper.rb index af8c4d5..9efa430 100644 --- a/actionpack/lib/action_view/helpers/tag_helper.rb +++ b/actionpack/lib/action_view/helpers/tag_helper.rb @@ -8,6 +8,15 @@ module ActionView module TagHelper include ERB::Util + mattr_accessor :generate_non_self_closing_tags + self.generate_non_self_closing_tags = false + alias :generate_non_self_closing_tags? :generate_non_self_closing_tags + + def self.included(base) #:nodoc: + base.mattr_accessor :generate_non_self_closing_tags + base.generate_non_self_closing_tags ||= generate_non_self_closing_tags + end + BOOLEAN_ATTRIBUTES = %w(disabled readonly multiple checked).to_set BOOLEAN_ATTRIBUTES.merge(BOOLEAN_ATTRIBUTES.map(&:to_sym)) @@ -37,7 +46,10 @@ module ActionView # # tag("img", { :src => "open & shut.png" }, false, false) # # => - def tag(name, options = nil, open = false, escape = true) + def tag(name, options = nil, open = generate_non_self_closing_tags?, escape = true) + open = options.delete('open') || open + escape = options.delete('escape') || escape + "<#{name}#{tag_options(options, escape) if options}#{open ? ">" : " />"}" end -- 1.6.0.4