diff options
author | Xavier Noria <fxn@hashref.com> | 2010-05-04 19:36:26 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2010-05-04 19:36:26 +0200 |
commit | 583b60d109522907020700225f1c739737297a2d (patch) | |
tree | a36d986cbbb73c94d217cbe86c9af7ef97a89567 /actionpack/lib/action_view | |
parent | 44a98967676492995d19fd4d541dbc9d52bf6b53 (diff) | |
parent | 0dd3b4630fea4bd4d4010b7096c9ee79d34c4501 (diff) | |
download | rails-583b60d109522907020700225f1c739737297a2d.tar.gz rails-583b60d109522907020700225f1c739737297a2d.tar.bz2 rails-583b60d109522907020700225f1c739737297a2d.zip |
Merge remote branch 'rails/master'
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r-- | actionpack/lib/action_view/helpers/form_helper.rb | 8 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/translation_helper.rb | 10 | ||||
-rw-r--r-- | actionpack/lib/action_view/locale/en.yml | 28 | ||||
-rw-r--r-- | actionpack/lib/action_view/render/partials.rb | 4 | ||||
-rw-r--r-- | actionpack/lib/action_view/render/rendering.rb | 2 | ||||
-rw-r--r-- | actionpack/lib/action_view/template.rb | 2 | ||||
-rw-r--r-- | actionpack/lib/action_view/template/error.rb | 32 | ||||
-rw-r--r-- | actionpack/lib/action_view/testing/resolvers.rb | 43 |
8 files changed, 74 insertions, 55 deletions
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index d3604925e8..6e26ae6c29 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -1165,13 +1165,13 @@ module ActionView # submit button label, otherwise, it uses "Update Post". # # Those labels can be customized using I18n, under the helpers.submit key and accept - # the {{model}} as translation interpolation: + # the %{model} as translation interpolation: # # en: # helpers: # submit: - # create: "Create a {{model}}" - # update: "Confirm changes to {{model}}" + # create: "Create a %{model}" + # update: "Confirm changes to %{model}" # # It also searches for a key specific for the given object: # @@ -1179,7 +1179,7 @@ module ActionView # helpers: # submit: # post: - # create: "Add {{model}}" + # create: "Add %{model}" # def submit(value=nil, options={}) value, options = nil, value if value.is_a?(Hash) diff --git a/actionpack/lib/action_view/helpers/translation_helper.rb b/actionpack/lib/action_view/helpers/translation_helper.rb index 89c1b4a275..086ad261c8 100644 --- a/actionpack/lib/action_view/helpers/translation_helper.rb +++ b/actionpack/lib/action_view/helpers/translation_helper.rb @@ -20,7 +20,7 @@ module ActionView options[:raise] = true translation = I18n.translate(scope_key_by_partial(key), options) translation = (translation.respond_to?(:join) ? translation.join : translation) - if html_safe_translation_key? key + if html_safe_translation_key?(key) translation.html_safe else translation @@ -53,12 +53,8 @@ module ActionView end def html_safe_translation_key?(key) - last_key = if key.is_a? Array - key.last - else - key.to_s.split('.').last - end - (last_key == "html") || (last_key.ends_with? "_html") + key = key.is_a?(Array) ? key.last : key.to_s + key =~ /(\b|_|\.)html$/ end end end diff --git a/actionpack/lib/action_view/locale/en.yml b/actionpack/lib/action_view/locale/en.yml index 187e010e30..9004e52c5b 100644 --- a/actionpack/lib/action_view/locale/en.yml +++ b/actionpack/lib/action_view/locale/en.yml @@ -102,37 +102,37 @@ half_a_minute: "half a minute" less_than_x_seconds: one: "less than 1 second" - other: "less than {{count}} seconds" + other: "less than %{count} seconds" x_seconds: one: "1 second" - other: "{{count}} seconds" + other: "%{count} seconds" less_than_x_minutes: one: "less than a minute" - other: "less than {{count}} minutes" + other: "less than %{count} minutes" x_minutes: one: "1 minute" - other: "{{count}} minutes" + other: "%{count} minutes" about_x_hours: one: "about 1 hour" - other: "about {{count}} hours" + other: "about %{count} hours" x_days: one: "1 day" - other: "{{count}} days" + other: "%{count} days" about_x_months: one: "about 1 month" - other: "about {{count}} months" + other: "about %{count} months" x_months: one: "1 month" - other: "{{count}} months" + other: "%{count} months" about_x_years: one: "about 1 year" - other: "about {{count}} years" + other: "about %{count} years" over_x_years: one: "over 1 year" - other: "over {{count}} years" + other: "over %{count} years" almost_x_years: one: "almost 1 year" - other: "almost {{count}} years" + other: "almost %{count} years" prompts: year: "Year" month: "Month" @@ -148,7 +148,7 @@ # Default translation keys for submit FormHelper submit: - create: 'Create {{model}}' - update: 'Update {{model}}' - submit: 'Save {{model}}' + create: 'Create %{model}' + update: 'Update %{model}' + submit: 'Save %{model}' diff --git a/actionpack/lib/action_view/render/partials.rb b/actionpack/lib/action_view/render/partials.rb index 4d23d55687..974345633c 100644 --- a/actionpack/lib/action_view/render/partials.rb +++ b/actionpack/lib/action_view/render/partials.rb @@ -211,12 +211,12 @@ module ActionView identifier = ((@template = find_template) ? @template.identifier : @path) if @collection - ActiveSupport::Notifications.instrument("action_view.render_collection", + ActiveSupport::Notifications.instrument("render_collection.action_view", :identifier => identifier || "collection", :count => @collection.size) do render_collection end else - content = ActiveSupport::Notifications.instrument("action_view.render_partial", + content = ActiveSupport::Notifications.instrument("render_partial.action_view", :identifier => identifier) do render_partial end diff --git a/actionpack/lib/action_view/render/rendering.rb b/actionpack/lib/action_view/render/rendering.rb index 492326964a..4198013f57 100644 --- a/actionpack/lib/action_view/render/rendering.rb +++ b/actionpack/lib/action_view/render/rendering.rb @@ -52,7 +52,7 @@ module ActionView locals = options[:locals] || {} layout = find_layout(layout) if layout - ActiveSupport::Notifications.instrument("action_view.render_template", + ActiveSupport::Notifications.instrument("render_template.action_view", :identifier => template.identifier, :layout => layout.try(:virtual_path)) do content = template.render(self, locals) { |*name| _layout_for(*name) } diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb index 3c0cd35359..a1a970e2d2 100644 --- a/actionpack/lib/action_view/template.rb +++ b/actionpack/lib/action_view/template.rb @@ -41,7 +41,7 @@ module ActionView def render(view, locals, &block) # Notice that we use a bang in this instrumentation because you don't want to # consume this in production. This is only slow if it's being listened to. - ActiveSupport::Notifications.instrument("action_view.render_template!", :virtual_path => @virtual_path) do + ActiveSupport::Notifications.instrument("!render_template.action_view", :virtual_path => @virtual_path) do method_name = compile(locals, view) view.send(method_name, locals, &block) end diff --git a/actionpack/lib/action_view/template/error.rb b/actionpack/lib/action_view/template/error.rb index 5222ffa89c..a947d746e3 100644 --- a/actionpack/lib/action_view/template/error.rb +++ b/actionpack/lib/action_view/template/error.rb @@ -21,17 +21,18 @@ module ActionView super("Missing #{template_type} #{path} with #{details.inspect} in view paths #{display_paths}") end end + class Template # The Template::Error exception is raised when the compilation of the template fails. This exception then gathers a # bunch of intimate details and uses it to report a very precise exception message. class Error < ActionViewError #:nodoc: SOURCE_CODE_RADIUS = 3 - attr_reader :original_exception + attr_reader :original_exception, :backtrace def initialize(template, assigns, original_exception) @template, @assigns, @original_exception = template, assigns.dup, original_exception - @backtrace = compute_backtrace + @backtrace = original_exception.backtrace end def file_name @@ -42,14 +43,6 @@ module ActionView ActiveSupport::Deprecation.silence { original_exception.message } end - def clean_backtrace - if defined?(Rails) && Rails.respond_to?(:backtrace_cleaner) - Rails.backtrace_cleaner.clean(original_exception.backtrace) - else - original_exception.backtrace - end - end - def sub_template_message if @sub_templates "Trace of template inclusion: " + @@ -87,29 +80,16 @@ module ActionView @line_number ||= if file_name regexp = /#{Regexp.escape File.basename(file_name)}:(\d+)/ - - $1 if message =~ regexp or clean_backtrace.find { |line| line =~ regexp } + $1 if message =~ regexp || backtrace.find { |line| line =~ regexp } end end def to_s - "\n#{self.class} (#{message}) #{source_location}:\n" + - "#{source_extract}\n #{clean_backtrace.join("\n ")}\n\n" - end - - # don't do anything nontrivial here. Any raised exception from here becomes fatal - # (and can't be rescued). - def backtrace - @backtrace + "\n#{self.class} (#{message}) #{source_location}:\n\n" + + "#{source_extract(4)}\n #{backtrace.join("\n ")}\n\n" end private - def compute_backtrace - [ - "#{source_location.capitalize}\n\n#{source_extract(4)}\n " + - clean_backtrace.join("\n ") - ] - end def source_location if line_number diff --git a/actionpack/lib/action_view/testing/resolvers.rb b/actionpack/lib/action_view/testing/resolvers.rb new file mode 100644 index 0000000000..578c56c6c4 --- /dev/null +++ b/actionpack/lib/action_view/testing/resolvers.rb @@ -0,0 +1,43 @@ +require 'action_view/template/resolver' + +module ActionView #:nodoc: + # Use FixtureResolver in your tests to simulate the presence of files on the + # file system. This is used internally by Rails' own test suite, and is + # useful for testing extensions that have no way of knowing what the file + # system will look like at runtime. + class FixtureResolver < PathResolver + attr_reader :hash + + def initialize(hash = {}) + super() + @hash = hash + end + + private + + def query(path, exts, formats) + query = Regexp.escape(path) + exts.each do |ext| + query << '(' << ext.map {|e| e && Regexp.escape(".#{e}") }.join('|') << '|)' + end + + templates = [] + @hash.select { |k,v| k =~ /^#{query}$/ }.each do |path, source| + handler, format = extract_handler_and_format(path, formats) + templates << Template.new(source, path, handler, + :virtual_path => path, :format => format) + end + + templates.sort_by {|t| -t.identifier.match(/^#{query}$/).captures.reject(&:blank?).size } + end + end + + class NullResolver < ActionView::PathResolver + def query(path, exts, formats) + handler, format = extract_handler_and_format(path, formats) + [ActionView::Template.new("Template generated by Null Resolver", path, handler, :virtual_path => path, :format => format)] + end + end + +end + |