From 72608521871f73d6b07afa5f6f36e0dedcf1d079 Mon Sep 17 00:00:00 2001 From: Josh Date: Sun, 4 Jan 2009 14:54:35 +0000 Subject: Fix date_select within fields_for with an index [#1666 state:resolved] [Josh, Frederick Cheung] Signed-off-by: Frederick Cheung --- actionpack/lib/action_view/helpers/date_helper.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'actionpack/lib/action_view') diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb index 4305617ac8..b4c1adbe76 100644 --- a/actionpack/lib/action_view/helpers/date_helper.rb +++ b/actionpack/lib/action_view/helpers/date_helper.rb @@ -860,7 +860,7 @@ module ActionView # => post[written_on(1i)] def input_name_from_type(type) prefix = @options[:prefix] || ActionView::Helpers::DateTimeSelector::DEFAULT_PREFIX - prefix += "[#{@options[:index]}]" if @options[:index] + prefix += "[#{@options[:index]}]" if @options.has_key?(:index) field_name = @options[:field_name] || type if @options[:include_position] @@ -923,7 +923,7 @@ module ActionView options[:field_name] = @method_name options[:include_position] = true options[:prefix] ||= @object_name - options[:index] ||= @auto_index + options[:index] = @auto_index if @auto_index && !options.has_key?(:index) options[:datetime_separator] ||= ' — ' options[:time_separator] ||= ' : ' @@ -961,15 +961,15 @@ module ActionView class FormBuilder def date_select(method, options = {}, html_options = {}) - @template.date_select(@object_name, method, options.merge(:object => @object), html_options) + @template.date_select(@object_name, method, objectify_options(options), html_options) end def time_select(method, options = {}, html_options = {}) - @template.time_select(@object_name, method, options.merge(:object => @object), html_options) + @template.time_select(@object_name, method, objectify_options(options), html_options) end def datetime_select(method, options = {}, html_options = {}) - @template.datetime_select(@object_name, method, options.merge(:object => @object), html_options) + @template.datetime_select(@object_name, method, objectify_options(options), html_options) end end end -- cgit v1.2.3 From fe013ce93415a88b6c23fd750bd8cbab60d6395d Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 16 Jan 2009 20:36:50 -0800 Subject: Fix performance regression --- actionpack/lib/action_view/template.rb | 2 +- actionpack/lib/action_view/template_handlers.rb | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'actionpack/lib/action_view') diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb index 88ee07d95b..9d1e0d3ac5 100644 --- a/actionpack/lib/action_view/template.rb +++ b/actionpack/lib/action_view/template.rb @@ -204,7 +204,7 @@ module ActionView #:nodoc: private def valid_extension?(extension) - Template.template_handler_extensions.include?(extension) + !Template.registered_template_handler(extension).nil? end def find_full_path(path, load_paths) diff --git a/actionpack/lib/action_view/template_handlers.rb b/actionpack/lib/action_view/template_handlers.rb index d06ddd5fb5..205f8628f0 100644 --- a/actionpack/lib/action_view/template_handlers.rb +++ b/actionpack/lib/action_view/template_handlers.rb @@ -32,13 +32,17 @@ module ActionView #:nodoc: @@template_handlers.keys.map(&:to_s).sort end + def registered_template_handler(extension) + extension && @@template_handlers[extension.to_sym] + end + def register_default_template_handler(extension, klass) register_template_handler(extension, klass) @@default_template_handlers = klass end def handler_class_for_extension(extension) - (extension && @@template_handlers[extension.to_sym]) || @@default_template_handlers + registered_template_handler(extension) || @@default_template_handlers end end end -- cgit v1.2.3 From 39e1ac658efc80e4c54abef4f1c7679e4b3dc2ac Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Sun, 18 Jan 2009 18:10:58 +0000 Subject: Merge docrails --- .../lib/action_view/helpers/asset_tag_helper.rb | 124 ++++++++++++--------- 1 file changed, 74 insertions(+), 50 deletions(-) (limited to 'actionpack/lib/action_view') diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index 58f8cca6be..f6abea38ed 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -6,54 +6,70 @@ module ActionView module Helpers #:nodoc: # This module provides methods for generating HTML that links views to assets such # as images, javascripts, stylesheets, and feeds. These methods do not verify - # the assets exist before linking to them. + # the assets exist before linking to them: + # + # image_tag("rails.png") + # # => Rails src= + # stylesheet_link_tag("application") + # # => # # === Using asset hosts + # # By default, Rails links to these assets on the current host in the public - # folder, but you can direct Rails to link to assets from a dedicated assets server by - # setting ActionController::Base.asset_host in your config/environment.rb. For example, - # let's say your asset host is assets.example.com. + # folder, but you can direct Rails to link to assets from a dedicated asset + # server by setting ActionController::Base.asset_host in the application + # configuration, typically in config/environments/production.rb. + # For example, you'd define assets.example.com to be your asset + # host this way: # # ActionController::Base.asset_host = "assets.example.com" + # + # Helpers take that into account: + # # image_tag("rails.png") - # => Rails + # # => Rails # stylesheet_link_tag("application") - # => + # # => # - # This is useful since browsers typically open at most two connections to a single host, - # which means your assets often wait in single file for their turn to load. You can - # alleviate this by using a %d wildcard in asset_host (for example, "assets%d.example.com") - # to automatically distribute asset requests among four hosts (e.g., "assets0.example.com" through "assets3.example.com") - # so browsers will open eight connections rather than two. + # Browsers typically open at most two simultaneous connections to a single + # host, which means your assets often have to wait for other assets to finish + # downloading. You can alleviate this by using a %d wildcard in the + # +asset_host+. For example, "assets%d.example.com". If that wildcard is + # present Rails distributes asset requests among the corresponding four hosts + # "assets0.example.com", ..., "assets3.example.com". With this trick browsers + # will open eight simultaneous connections rather than two. # # image_tag("rails.png") - # => Rails + # # => Rails # stylesheet_link_tag("application") - # => + # # => # - # To do this, you can either setup 4 actual hosts, or you can use wildcard DNS to CNAME - # the wildcard to a single asset host. You can read more about setting up your DNS CNAME records from - # your ISP. + # To do this, you can either setup four actual hosts, or you can use wildcard + # DNS to CNAME the wildcard to a single asset host. You can read more about + # setting up your DNS CNAME records from your ISP. # # Note: This is purely a browser performance optimization and is not meant # for server load balancing. See http://www.die.net/musings/page_load_time/ # for background. # - # Alternatively, you can exert more control over the asset host by setting asset_host to a proc - # that takes a single source argument. This is useful if you are unable to setup 4 actual hosts or have - # fewer/more than 4 hosts. The example proc below generates http://assets1.example.com and - # http://assets2.example.com randomly. + # Alternatively, you can exert more control over the asset host by setting + # +asset_host+ to a proc like this: # - # ActionController::Base.asset_host = Proc.new { |source| "http://assets#{rand(2) + 1}.example.com" } + # ActionController::Base.asset_host = Proc.new { |source| + # "http://assets#{rand(2) + 1}.example.com" + # } # image_tag("rails.png") - # => Rails + # # => Rails # stylesheet_link_tag("application") - # => + # # => # - # The proc takes a source parameter (which is the path of the source asset) and an optional - # request parameter (which is an entire instance of an ActionController::AbstractRequest - # subclass). This can be used to generate a particular asset host depending on the asset path and the particular - # request. + # The example above generates "http://assets1.example.com" and + # "http://assets2.example.com" randomly. This option is useful for example if + # you need fewer/more than four hosts, custom host names, etc. + # + # As you see the proc takes a +source+ parameter. That's a string with the + # absolute path of the asset with any extensions and timestamps in place, + # for example "/images/rails.png?1230601161". # # ActionController::Base.asset_host = Proc.new { |source| # if source.starts_with?('/images') @@ -63,14 +79,16 @@ module ActionView # end # } # image_tag("rails.png") - # => Rails + # # => Rails # stylesheet_link_tag("application") - # => + # # => # - # The optional request parameter to the proc is useful in particular for serving assets from an - # SSL-protected page. The example proc below disables asset hosting for HTTPS connections, while still sending - # assets for plain HTTP requests from asset hosts. This is useful for avoiding mixed media warnings when serving - # non-HTTP assets from HTTPS web pages when you don't have an SSL certificate for each of the asset hosts. + # Alternatively you may ask for a second parameter +request+. That one is + # particularly useful for serving assets from an SSL-protected page. The + # example proc below disables asset hosting for HTTPS connections, while + # still sending assets for plain HTTP requests from asset hosts. If you don't + # have SSL certificates for each of the asset hosts this technique allows you + # to avoid warnings in the client about mixed media. # # ActionController::Base.asset_host = Proc.new { |source, request| # if request.ssl? @@ -80,7 +98,8 @@ module ActionView # end # } # - # You can also implement a custom asset host object that responds to the call method and tasks one or two parameters just like the proc. + # You can also implement a custom asset host object that responds to +call+ + # and takes either one or two parameters just like the proc. # # config.action_controller.asset_host = AssetHostingWithMinimumSsl.new( # "http://asset%d.example.com", "https://asset1.example.com" @@ -88,24 +107,29 @@ module ActionView # # === Using asset timestamps # - # By default, Rails will append all asset paths with that asset's timestamp. This allows you to set a cache-expiration date for the - # asset far into the future, but still be able to instantly invalidate it by simply updating the file (and hence updating the timestamp, - # which then updates the URL as the timestamp is part of that, which in turn busts the cache). + # By default, Rails appends asset's timestamps to all asset paths. This allows + # you to set a cache-expiration date for the asset far into the future, but + # still be able to instantly invalidate it by simply updating the file (and + # hence updating the timestamp, which then updates the URL as the timestamp + # is part of that, which in turn busts the cache). # - # It's the responsibility of the web server you use to set the far-future expiration date on cache assets that you need to take - # advantage of this feature. Here's an example for Apache: + # It's the responsibility of the web server you use to set the far-future + # expiration date on cache assets that you need to take advantage of this + # feature. Here's an example for Apache: # - # # Asset Expiration - # ExpiresActive On - # - # ExpiresDefault "access plus 1 year" - # + # # Asset Expiration + # ExpiresActive On + # + # ExpiresDefault "access plus 1 year" + # # - # Also note that in order for this to work, all your application servers must return the same timestamps. This means that they must - # have their clocks synchronized. If one of them drift out of sync, you'll see different timestamps at random and the cache won't - # work. Which means that the browser will request the same assets over and over again even thought they didn't change. You can use - # something like Live HTTP Headers for Firefox to verify that the cache is indeed working (and that the assets are not being - # requested over and over). + # Also note that in order for this to work, all your application servers must + # return the same timestamps. This means that they must have their clocks + # synchronized. If one of them drifts out of sync, you'll see different + # timestamps at random and the cache won't work. In that case the browser + # will request the same assets over and over again even thought they didn't + # change. You can use something like Live HTTP Headers for Firefox to verify + # that the cache is indeed working. module AssetTagHelper ASSETS_DIR = defined?(Rails.public_path) ? Rails.public_path : "public" JAVASCRIPTS_DIR = "#{ASSETS_DIR}/javascripts" @@ -117,7 +141,7 @@ module ActionView # :atom. Control the link options in url_for format using the # +url_options+. You can modify the LINK tag itself in +tag_options+. # - # ==== Options: + # ==== Options # * :rel - Specify the relation of this link, defaults to "alternate" # * :type - Override the auto-generated mime type # * :title - Specify the title of the link, defaults to the +type+ -- cgit v1.2.3 From a98cd7ca9b2f24a4500963e58ba5c37d6bdf9259 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 25 Jan 2009 22:50:02 -0600 Subject: Add localized templates # Default locale app/views/messages/index.html.erb # I18n.locale is set to :da (Danish) app/views/messages/index.da.html.erb --- actionpack/lib/action_view/paths.rb | 6 +++- actionpack/lib/action_view/template.rb | 56 +++++++++++++++++++++++++--------- 2 files changed, 47 insertions(+), 15 deletions(-) (limited to 'actionpack/lib/action_view') diff --git a/actionpack/lib/action_view/paths.rb b/actionpack/lib/action_view/paths.rb index 19207e7262..cb351620d2 100644 --- a/actionpack/lib/action_view/paths.rb +++ b/actionpack/lib/action_view/paths.rb @@ -37,7 +37,11 @@ module ActionView #:nodoc: template_path = original_template_path.sub(/^\//, '') each do |load_path| - if format && (template = load_path["#{template_path}.#{format}"]) + if format && (template = load_path["#{template_path}.#{I18n.locale}.#{format}"]) + return template + elsif format && (template = load_path["#{template_path}.#{format}"]) + return template + elsif template = load_path["#{template_path}.#{I18n.locale}"] return template elsif template = load_path[template_path] return template diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb index 9d1e0d3ac5..6f3bf576eb 100644 --- a/actionpack/lib/action_view/template.rb +++ b/actionpack/lib/action_view/template.rb @@ -93,13 +93,14 @@ module ActionView #:nodoc: @@exempt_from_layout.merge(regexps) end - attr_accessor :filename, :load_path, :base_path, :name, :format, :extension + attr_accessor :filename, :load_path, :base_path + attr_accessor :locale, :name, :format, :extension delegate :to_s, :to => :path def initialize(template_path, load_paths = []) template_path = template_path.dup @load_path, @filename = find_full_path(template_path, load_paths) - @base_path, @name, @format, @extension = split(template_path) + @base_path, @name, @locale, @format, @extension = split(template_path) @base_path.to_s.gsub!(/\/$/, '') # Push to split method # Extend with partial super powers @@ -137,17 +138,17 @@ module ActionView #:nodoc: memoize :mime_type def path - [base_path, [name, format, extension].compact.join('.')].compact.join('/') + [base_path, [name, locale, format, extension].compact.join('.')].compact.join('/') end memoize :path def path_without_extension - [base_path, [name, format].compact.join('.')].compact.join('/') + [base_path, [name, locale, format].compact.join('.')].compact.join('/') end memoize :path_without_extension def path_without_format_and_extension - [base_path, name].compact.join('/') + [base_path, [name, locale].compact.join('.')].compact.join('/') end memoize :path_without_format_and_extension @@ -207,6 +208,10 @@ module ActionView #:nodoc: !Template.registered_template_handler(extension).nil? end + def valid_locale?(locale) + I18n.available_locales.include?(locale.to_sym) + end + def find_full_path(path, load_paths) load_paths = Array(load_paths) + [nil] load_paths.each do |load_path| @@ -217,19 +222,42 @@ module ActionView #:nodoc: end # Returns file split into an array - # [base_path, name, format, extension] + # [base_path, name, locale, format, extension] def split(file) - if m = file.match(/^(.*\/)?([^\.]+)\.?(\w+)?\.?(\w+)?\.?(\w+)?$/) - if valid_extension?(m[5]) # Multipart formats - [m[1], m[2], "#{m[3]}.#{m[4]}", m[5]] - elsif valid_extension?(m[4]) # Single format - [m[1], m[2], m[3], m[4]] - elsif valid_extension?(m[3]) # No format - [m[1], m[2], nil, m[3]] + if m = file.match(/^(.*\/)?([^\.]+)\.(.*)$/) + base_path = m[1] + name = m[2] + extensions = m[3] + else + return + end + + locale = nil + format = nil + extension = nil + + if m = extensions.match(/^(\w+)?\.?(\w+)?\.?(\w+)?\.?/) + if valid_locale?(m[1]) && m[2] && valid_extension?(m[3]) # All three + locale = m[1] + format = m[2] + extension = m[3] + elsif m[1] && m[2] && valid_extension?(m[3]) # Multipart formats + format = "#{m[1]}.#{m[2]}" + extension = m[3] + elsif valid_extension?(m[1]) # Just extension + extension = m[1] + elsif valid_locale?(m[1]) && valid_extension?(m[2]) # locale and extension + locale = m[1] + extension = m[2] + elsif valid_extension?(m[2]) # format and extension + format = m[1] + extension = m[2] else # No extension - [m[1], m[2], m[3], nil] + format = m[1] end end + + [base_path, name, locale, format, extension] end end end -- cgit v1.2.3 From 57f0b859004698a38d6aa7d5cebc00de3fcb346d Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 26 Jan 2009 13:15:29 -0600 Subject: Fix for failing ActionMailer multipart tests --- actionpack/lib/action_view/template.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/lib/action_view') diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb index 6f3bf576eb..1361a969a9 100644 --- a/actionpack/lib/action_view/template.rb +++ b/actionpack/lib/action_view/template.rb @@ -244,14 +244,14 @@ module ActionView #:nodoc: elsif m[1] && m[2] && valid_extension?(m[3]) # Multipart formats format = "#{m[1]}.#{m[2]}" extension = m[3] - elsif valid_extension?(m[1]) # Just extension - extension = m[1] elsif valid_locale?(m[1]) && valid_extension?(m[2]) # locale and extension locale = m[1] extension = m[2] elsif valid_extension?(m[2]) # format and extension format = m[1] extension = m[2] + elsif valid_extension?(m[1]) # Just extension + extension = m[1] else # No extension format = m[1] end -- cgit v1.2.3 From 17db28f1ca0597fa1e9abdcacd934ca27d589fb9 Mon Sep 17 00:00:00 2001 From: Yaroslav Markin Date: Thu, 1 Jan 2009 21:29:11 +0300 Subject: Improve i18n support for number_to_human_size helper: * now using pluralization properly * storage unit translations moved to number.human.storage_units.units * introduced number.human.storage_units.format for languages that do not follow "{{number}} {{unit}}" format (Japanese) NOTE: I18n table changed, you will need to update your translations. [#1634 state:committed] Signed-off-by: Jeremy Kemper --- .../lib/action_view/helpers/number_helper.rb | 45 ++++++++++++++-------- actionpack/lib/action_view/locale/en.yml | 13 ++++++- 2 files changed, 40 insertions(+), 18 deletions(-) (limited to 'actionpack/lib/action_view') diff --git a/actionpack/lib/action_view/helpers/number_helper.rb b/actionpack/lib/action_view/helpers/number_helper.rb index 3e734ccaab..e622f97b9e 100644 --- a/actionpack/lib/action_view/helpers/number_helper.rb +++ b/actionpack/lib/action_view/helpers/number_helper.rb @@ -220,6 +220,8 @@ module ActionView end end + STORAGE_UNITS = [:byte, :kb, :mb, :gb, :tb].freeze + # Formats the bytes in +size+ into a more understandable representation # (e.g., giving it 1500 yields 1.5 KB). This method is useful for # reporting file sizes to users. This method returns nil if @@ -247,7 +249,7 @@ module ActionView # number_to_human_size(1234567, 2) # => 1.18 MB # number_to_human_size(483989, 0) # => 473 KB def number_to_human_size(number, *args) - return number.nil? ? nil : pluralize(number.to_i, "Byte") if number.to_i < 1024 + return nil if number.nil? options = args.extract_options! options.symbolize_keys! @@ -255,7 +257,6 @@ module ActionView defaults = I18n.translate(:'number.format', :locale => options[:locale], :raise => true) rescue {} human = I18n.translate(:'number.human.format', :locale => options[:locale], :raise => true) rescue {} defaults = defaults.merge(human) - storage_units = I18n.translate(:'number.human.storage_units', :locale => options[:locale], :raise => true) unless args.empty? ActiveSupport::Deprecation.warn('number_to_human_size takes an option hash ' + @@ -267,22 +268,32 @@ module ActionView separator ||= (options[:separator] || defaults[:separator]) delimiter ||= (options[:delimiter] || defaults[:delimiter]) - max_exp = storage_units.size - 1 - number = Float(number) - exponent = (Math.log(number) / Math.log(1024)).to_i # Convert to base 1024 - exponent = max_exp if exponent > max_exp # we need this to avoid overflow for the highest unit - number /= 1024 ** exponent - unit = storage_units[exponent] + storage_units_format = I18n.translate(:'number.human.storage_units.format', :locale => options[:locale], :raise => true) - begin - escaped_separator = Regexp.escape(separator) - number_with_precision(number, - :precision => precision, - :separator => separator, - :delimiter => delimiter - ).sub(/(\d)(#{escaped_separator}[1-9]*)?0+\z/, '\1\2').sub(/#{escaped_separator}\z/, '') + " #{unit}" - rescue - number + if number.to_i < 1024 + unit = I18n.translate(:'number.human.storage_units.units.byte', :locale => options[:locale], :count => number.to_i, :raise => true) + storage_units_format.gsub(/%n/, number.to_i.to_s).gsub(/%u/, unit) + else + max_exp = STORAGE_UNITS.size - 1 + number = Float(number) + exponent = (Math.log(number) / Math.log(1024)).to_i # Convert to base 1024 + exponent = max_exp if exponent > max_exp # we need this to avoid overflow for the highest unit + number /= 1024 ** exponent + + unit_key = STORAGE_UNITS[exponent] + unit = I18n.translate(:"number.human.storage_units.units.#{unit_key}", :locale => options[:locale], :count => number, :raise => true) + + begin + escaped_separator = Regexp.escape(separator) + formatted_number = number_with_precision(number, + :precision => precision, + :separator => separator, + :delimiter => delimiter + ).sub(/(\d)(#{escaped_separator}[1-9]*)?0+\z/, '\1\2').sub(/#{escaped_separator}\z/, '') + storage_units_format.gsub(/%n/, formatted_number).gsub(/%u/, unit) + rescue + number + end end end end diff --git a/actionpack/lib/action_view/locale/en.yml b/actionpack/lib/action_view/locale/en.yml index a880fd83ef..afe35691bc 100644 --- a/actionpack/lib/action_view/locale/en.yml +++ b/actionpack/lib/action_view/locale/en.yml @@ -44,7 +44,18 @@ # separator: delimiter: "" precision: 1 - storage_units: [Bytes, KB, MB, GB, TB] + storage_units: + # Storage units output formatting. + # %u is the storage unit, %n is the number (default: 2 MB) + format: "%n %u" + units: + byte: + one: "Byte" + other: "Bytes" + kb: "KB" + mb: "MB" + gb: "GB" + tb: "TB" # Used in distance_of_time_in_words(), distance_of_time_in_words_to_now(), time_ago_in_words() datetime: -- cgit v1.2.3 From 093f758bd05d5b6144fd06aa0606c2f987c4ee09 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 27 Jan 2009 14:09:11 -0600 Subject: Restore implicit rendering for XHR requests that want a HTML template [#1590 state:resolved] --- actionpack/lib/action_view/paths.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'actionpack/lib/action_view') diff --git a/actionpack/lib/action_view/paths.rb b/actionpack/lib/action_view/paths.rb index cb351620d2..ee26542a07 100644 --- a/actionpack/lib/action_view/paths.rb +++ b/actionpack/lib/action_view/paths.rb @@ -45,6 +45,9 @@ module ActionView #:nodoc: return template elsif template = load_path[template_path] return template + # Try to find html version if the format is javascript + elsif format == :js && template = load_path["#{template_path}.html"] + return template end end -- cgit v1.2.3 From 9a8e2a059c823498e0fb318f25b926a6d015ef87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Rodr=C3=ADguez=20Troiti=C3=B1o?= Date: Fri, 12 Sep 2008 23:56:56 +0200 Subject: Ensure selected option is not ignored for collection_select. [#1037 state:resolved] Signed-off-by: Pratik Naik --- actionpack/lib/action_view/helpers/form_options_helper.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'actionpack/lib/action_view') diff --git a/actionpack/lib/action_view/helpers/form_options_helper.rb b/actionpack/lib/action_view/helpers/form_options_helper.rb index 9ed50a9653..3991c5c0cc 100644 --- a/actionpack/lib/action_view/helpers/form_options_helper.rb +++ b/actionpack/lib/action_view/helpers/form_options_helper.rb @@ -349,8 +349,9 @@ module ActionView html_options = html_options.stringify_keys add_default_name_and_id(html_options) value = value(object) + selected_value = options.has_key?(:selected) ? options[:selected] : value content_tag( - "select", add_options(options_from_collection_for_select(collection, value_method, text_method, value), options, value), html_options + "select", add_options(options_from_collection_for_select(collection, value_method, text_method, selected_value), options, value), html_options ) end -- cgit v1.2.3 From 91eeb0ff119d34d0fcdb44d3d7fcbb7924208e05 Mon Sep 17 00:00:00 2001 From: Dan Weinand Date: Thu, 30 Oct 2008 12:52:12 -0500 Subject: Using the highlight helper on text with html shouldn't highlight text inside html attributes. [#1302 state:resolved] Signed-off-by: Pratik Naik --- actionpack/lib/action_view/helpers/text_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/action_view') diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index 1d9e4fe9b8..b1eb6891fa 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -107,7 +107,7 @@ module ActionView text else match = Array(phrases).map { |p| Regexp.escape(p) }.join('|') - text.gsub(/(#{match})/i, options[:highlighter]) + text.gsub(/(#{match})(?!(?:[^<]*?)?(?:["'])[^<>]*>)/i, options[:highlighter]) end end -- cgit v1.2.3 From 8761663a68bd7ddd918f78fb3def4697784024f2 Mon Sep 17 00:00:00 2001 From: Jon Crawford Date: Thu, 29 Jan 2009 17:59:44 +0000 Subject: Added grouped_options_for_select helper method for wrapping option tags in optgroups. [#977 state:resolved] Signed-off-by: Pratik Naik --- .../lib/action_view/helpers/form_options_helper.rb | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'actionpack/lib/action_view') diff --git a/actionpack/lib/action_view/helpers/form_options_helper.rb b/actionpack/lib/action_view/helpers/form_options_helper.rb index 3991c5c0cc..54c82cbd1d 100644 --- a/actionpack/lib/action_view/helpers/form_options_helper.rb +++ b/actionpack/lib/action_view/helpers/form_options_helper.rb @@ -277,6 +277,62 @@ module ActionView end end + # Returns a string of tags, like options_for_select, but + # wraps them with tags. + # + # Parameters: + # * +grouped_options+ - Accepts a nested array or hash of strings. The first value serves as the + # label while the second value must be an array of options. The second value can be a + # nested array of text-value pairs. See options_for_select for more info. + # Ex. ["North America",[["United States","US"],["Canada","CA"]]] + # * +selected_key+ - A value equal to the +value+ attribute for one of the tags, + # which will have the +selected+ attribute set. Note: It is possible for this value to match multiple options + # as you might have the same option in multiple groups. Each will then get selected="selected". + # * +prompt+ - set to true or a prompt string. When the select element doesn’t have a value yet, this + # prepends an option with a generic prompt — "Please select" — or the given prompt string. + # + # Sample usage (Array): + # grouped_options = [ + # ['North America', + # [['United States','US'],'Canada']], + # ['Europe', + # ['Denmark','Germany','France']] + # ] + # grouped_options_for_select(grouped_options) + # + # Sample usage (Hash): + # grouped_options = { + # 'North America' => [['United States','US], 'Canada'], + # 'Europe' => ['Denmark','Germany','France'] + # } + # grouped_options_for_select(grouped_options) + # + # Possible output: + # + # + # + # + # + # + # + # + # + # + # Note: Only the and tags are returned, so you still have to + # wrap the output in an appropriate