aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2008-11-24 11:11:08 +0100
committerDavid Heinemeier Hansson <david@loudthinking.com>2008-11-24 11:11:08 +0100
commitf3f67ce6212e2ae35470ab2960bb4967ae967ee2 (patch)
tree6a3054b9e4882a3faea6acc8b935db16a0831c4e /actionpack/lib/action_view
parenteea5dc3a34328267407f2cb861e14d9d1f5d7c02 (diff)
parent2dd0ec48a5068a095e362fad2a77d63b86fdfd95 (diff)
downloadrails-f3f67ce6212e2ae35470ab2960bb4967ae967ee2.tar.gz
rails-f3f67ce6212e2ae35470ab2960bb4967ae967ee2.tar.bz2
rails-f3f67ce6212e2ae35470ab2960bb4967ae967ee2.zip
Merge branch 'master' of git@github.com:rails/rails
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r--actionpack/lib/action_view/base.rb2
-rw-r--r--actionpack/lib/action_view/erb/util.rb38
-rw-r--r--actionpack/lib/action_view/helpers.rb29
-rw-r--r--actionpack/lib/action_view/helpers/number_helper.rb7
-rw-r--r--actionpack/lib/action_view/helpers/sanitize_helper.rb11
-rw-r--r--actionpack/lib/action_view/helpers/text_helper.rb10
-rw-r--r--actionpack/lib/action_view/locale/en.yml1
-rw-r--r--actionpack/lib/action_view/template_handler.rb26
-rw-r--r--actionpack/lib/action_view/template_handlers.rb9
-rw-r--r--actionpack/lib/action_view/template_handlers/erb.rb39
-rw-r--r--actionpack/lib/action_view/test_case.rb2
11 files changed, 95 insertions, 79 deletions
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb
index 0d3752d875..7697848713 100644
--- a/actionpack/lib/action_view/base.rb
+++ b/actionpack/lib/action_view/base.rb
@@ -157,7 +157,7 @@ module ActionView #:nodoc:
#
# See the ActionView::Helpers::PrototypeHelper::GeneratorMethods documentation for more details.
class Base
- include ERB::Util
+ include Helpers, Partials, ::ERB::Util
extend ActiveSupport::Memoizable
attr_accessor :base_path, :assigns, :template_extension
diff --git a/actionpack/lib/action_view/erb/util.rb b/actionpack/lib/action_view/erb/util.rb
new file mode 100644
index 0000000000..3c77c5ce76
--- /dev/null
+++ b/actionpack/lib/action_view/erb/util.rb
@@ -0,0 +1,38 @@
+require 'erb'
+
+class ERB
+ module Util
+ HTML_ESCAPE = { '&' => '&amp;', '>' => '&gt;', '<' => '&lt;', '"' => '&quot;' }
+ JSON_ESCAPE = { '&' => '\u0026', '>' => '\u003E', '<' => '\u003C' }
+
+ # A utility method for escaping HTML tag characters.
+ # This method is also aliased as <tt>h</tt>.
+ #
+ # In your ERb templates, use this method to escape any unsafe content. For example:
+ # <%=h @person.name %>
+ #
+ # ==== Example:
+ # puts html_escape("is a > 0 & a < 10?")
+ # # => is a &gt; 0 &amp; a &lt; 10?
+ def html_escape(s)
+ s.to_s.gsub(/[&"><]/) { |special| HTML_ESCAPE[special] }
+ end
+
+ # A utility method for escaping HTML entities in JSON strings.
+ # This method is also aliased as <tt>j</tt>.
+ #
+ # In your ERb templates, use this method to escape any HTML entities:
+ # <%=j @person.to_json %>
+ #
+ # ==== Example:
+ # puts json_escape("is a > 0 & a < 10?")
+ # # => is a \u003E 0 \u0026 a \u003C 10?
+ def json_escape(s)
+ s.to_s.gsub(/[&"><]/) { |special| JSON_ESCAPE[special] }
+ end
+
+ alias j json_escape
+ module_function :j
+ module_function :json_escape
+ end
+end
diff --git a/actionpack/lib/action_view/helpers.rb b/actionpack/lib/action_view/helpers.rb
index ff97df204c..693ab7c2e0 100644
--- a/actionpack/lib/action_view/helpers.rb
+++ b/actionpack/lib/action_view/helpers.rb
@@ -1,10 +1,28 @@
-Dir.entries(File.expand_path("#{File.dirname(__FILE__)}/helpers")).sort.each do |file|
- next unless file =~ /^([a-z][a-z_]*_helper).rb$/
- require "action_view/helpers/#{$1}"
-end
-
module ActionView #:nodoc:
module Helpers #:nodoc:
+ autoload :ActiveRecordHelper, 'action_view/helpers/active_record_helper'
+ autoload :AssetTagHelper, 'action_view/helpers/asset_tag_helper'
+ autoload :AtomFeedHelper, 'action_view/helpers/atom_feed_helper'
+ autoload :BenchmarkHelper, 'action_view/helpers/benchmark_helper'
+ autoload :CacheHelper, 'action_view/helpers/cache_helper'
+ autoload :CaptureHelper, 'action_view/helpers/capture_helper'
+ autoload :DateHelper, 'action_view/helpers/date_helper'
+ autoload :DebugHelper, 'action_view/helpers/debug_helper'
+ autoload :FormHelper, 'action_view/helpers/form_helper'
+ autoload :FormOptionsHelper, 'action_view/helpers/form_options_helper'
+ autoload :FormTagHelper, 'action_view/helpers/form_tag_helper'
+ autoload :JavascriptHelper, 'action_view/helpers/javascript_helper'
+ autoload :NumberHelper, 'action_view/helpers/number_helper'
+ autoload :PrototypeHelper, 'action_view/helpers/prototype_helper'
+ autoload :RecordIdentificationHelper, 'action_view/helpers/record_identification_helper'
+ autoload :RecordTagHelper, 'action_view/helpers/record_tag_helper'
+ autoload :SanitizeHelper, 'action_view/helpers/sanitize_helper'
+ autoload :ScriptaculousHelper, 'action_view/helpers/scriptaculous_helper'
+ autoload :TagHelper, 'action_view/helpers/tag_helper'
+ autoload :TextHelper, 'action_view/helpers/text_helper'
+ autoload :TranslationHelper, 'action_view/helpers/translation_helper'
+ autoload :UrlHelper, 'action_view/helpers/url_helper'
+
def self.included(base)
base.extend(ClassMethods)
end
@@ -24,6 +42,7 @@ module ActionView #:nodoc:
include FormHelper
include FormOptionsHelper
include FormTagHelper
+ include JavaScriptHelper
include NumberHelper
include PrototypeHelper
include RecordIdentificationHelper
diff --git a/actionpack/lib/action_view/helpers/number_helper.rb b/actionpack/lib/action_view/helpers/number_helper.rb
index 77f19b36a6..3e734ccaab 100644
--- a/actionpack/lib/action_view/helpers/number_helper.rb
+++ b/actionpack/lib/action_view/helpers/number_helper.rb
@@ -220,8 +220,6 @@ module ActionView
end
end
- STORAGE_UNITS = %w( Bytes 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
@@ -257,6 +255,7 @@ 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 ' +
@@ -268,12 +267,12 @@ module ActionView
separator ||= (options[:separator] || defaults[:separator])
delimiter ||= (options[:delimiter] || defaults[:delimiter])
- max_exp = STORAGE_UNITS.size - 1
+ 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]
+ unit = storage_units[exponent]
begin
escaped_separator = Regexp.escape(separator)
diff --git a/actionpack/lib/action_view/helpers/sanitize_helper.rb b/actionpack/lib/action_view/helpers/sanitize_helper.rb
index 435ba936e1..200c1d6085 100644
--- a/actionpack/lib/action_view/helpers/sanitize_helper.rb
+++ b/actionpack/lib/action_view/helpers/sanitize_helper.rb
@@ -1,14 +1,5 @@
require 'action_view/helpers/tag_helper'
-
-begin
- require 'html/document'
-rescue LoadError
- html_scanner_path = "#{File.dirname(__FILE__)}/../../action_controller/vendor/html-scanner"
- if File.directory?(html_scanner_path)
- $:.unshift html_scanner_path
- require 'html/document'
- end
-end
+require 'action_controller/vendor/html-scanner'
module ActionView
module Helpers #:nodoc:
diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb
index 510c1a6a76..506138a735 100644
--- a/actionpack/lib/action_view/helpers/text_helper.rb
+++ b/actionpack/lib/action_view/helpers/text_helper.rb
@@ -1,15 +1,5 @@
require 'action_view/helpers/tag_helper'
-begin
- require 'html/document'
-rescue LoadError
- html_scanner_path = "#{File.dirname(__FILE__)}/../../action_controller/vendor/html-scanner"
- if File.directory?(html_scanner_path)
- $:.unshift html_scanner_path
- require 'html/document'
- end
-end
-
module ActionView
module Helpers #:nodoc:
# The TextHelper module provides a set of methods for filtering, formatting
diff --git a/actionpack/lib/action_view/locale/en.yml b/actionpack/lib/action_view/locale/en.yml
index 002226fd9c..9542b035aa 100644
--- a/actionpack/lib/action_view/locale/en.yml
+++ b/actionpack/lib/action_view/locale/en.yml
@@ -44,6 +44,7 @@
# separator:
delimiter: ""
precision: 1
+ storage_units: [Bytes, KB, MB, GB, TB]
# Used in distance_of_time_in_words(), distance_of_time_in_words_to_now(), time_ago_in_words()
datetime:
diff --git a/actionpack/lib/action_view/template_handler.rb b/actionpack/lib/action_view/template_handler.rb
index d7e7c9b199..672da0ed2b 100644
--- a/actionpack/lib/action_view/template_handler.rb
+++ b/actionpack/lib/action_view/template_handler.rb
@@ -1,14 +1,34 @@
# Legacy TemplateHandler stub
-
module ActionView
- module TemplateHandlers
+ module TemplateHandlers #:nodoc:
module Compilable
+ def self.included(base)
+ base.extend(ClassMethods)
+ end
+
+ module ClassMethods
+ def call(template)
+ new.compile(template)
+ end
+ end
+
+ def compile(template)
+ raise "Need to implement #{self.class.name}#compile(template)"
+ end
end
end
class TemplateHandler
def self.call(template)
- new.compile(template)
+ "#{name}.new(self).render(template, local_assigns)"
+ end
+
+ def initialize(view = nil)
+ @view = view
+ end
+
+ def render(template, local_assigns)
+ raise "Need to implement #{self.class.name}#render(template, local_assigns)"
end
end
end
diff --git a/actionpack/lib/action_view/template_handlers.rb b/actionpack/lib/action_view/template_handlers.rb
index 6c8aa4c2a7..d06ddd5fb5 100644
--- a/actionpack/lib/action_view/template_handlers.rb
+++ b/actionpack/lib/action_view/template_handlers.rb
@@ -1,10 +1,9 @@
-require 'action_view/template_handler'
-require 'action_view/template_handlers/builder'
-require 'action_view/template_handlers/erb'
-require 'action_view/template_handlers/rjs'
-
module ActionView #:nodoc:
module TemplateHandlers #:nodoc:
+ autoload :ERB, 'action_view/template_handlers/erb'
+ autoload :RJS, 'action_view/template_handlers/rjs'
+ autoload :Builder, 'action_view/template_handlers/builder'
+
def self.extended(base)
base.register_default_template_handler :erb, TemplateHandlers::ERB
base.register_template_handler :rjs, TemplateHandlers::RJS
diff --git a/actionpack/lib/action_view/template_handlers/erb.rb b/actionpack/lib/action_view/template_handlers/erb.rb
index 3def949f1e..f8d3da15be 100644
--- a/actionpack/lib/action_view/template_handlers/erb.rb
+++ b/actionpack/lib/action_view/template_handlers/erb.rb
@@ -1,42 +1,3 @@
-require 'erb'
-
-class ERB
- module Util
- HTML_ESCAPE = { '&' => '&amp;', '>' => '&gt;', '<' => '&lt;', '"' => '&quot;' }
- JSON_ESCAPE = { '&' => '\u0026', '>' => '\u003E', '<' => '\u003C' }
-
- # A utility method for escaping HTML tag characters.
- # This method is also aliased as <tt>h</tt>.
- #
- # In your ERb templates, use this method to escape any unsafe content. For example:
- # <%=h @person.name %>
- #
- # ==== Example:
- # puts html_escape("is a > 0 & a < 10?")
- # # => is a &gt; 0 &amp; a &lt; 10?
- def html_escape(s)
- s.to_s.gsub(/[&"><]/) { |special| HTML_ESCAPE[special] }
- end
-
- # A utility method for escaping HTML entities in JSON strings.
- # This method is also aliased as <tt>j</tt>.
- #
- # In your ERb templates, use this method to escape any HTML entities:
- # <%=j @person.to_json %>
- #
- # ==== Example:
- # puts json_escape("is a > 0 & a < 10?")
- # # => is a \u003E 0 \u0026 a \u003C 10?
- def json_escape(s)
- s.to_s.gsub(/[&"><]/) { |special| JSON_ESCAPE[special] }
- end
-
- alias j json_escape
- module_function :j
- module_function :json_escape
- end
-end
-
module ActionView
module TemplateHandlers
class ERB < TemplateHandler
diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb
index cdea1def92..4ab4ed233f 100644
--- a/actionpack/lib/action_view/test_case.rb
+++ b/actionpack/lib/action_view/test_case.rb
@@ -1,5 +1,3 @@
-require 'action_controller/test_case'
-
module ActionView
class TestCase < ActiveSupport::TestCase
include ActionController::TestCase::Assertions