aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2008-11-23 13:42:07 -0600
committerJoshua Peek <josh@joshpeek.com>2008-11-23 13:42:07 -0600
commit2c01f2b4e9d4a95bb2baca8ae57209eb10aa78b2 (patch)
tree7ef23887bc8642b99d9b99736ccccf89eaf5a6d9
parente201fc750bf4b7dff1875b7fcdd47f1686ef2052 (diff)
downloadrails-2c01f2b4e9d4a95bb2baca8ae57209eb10aa78b2.tar.gz
rails-2c01f2b4e9d4a95bb2baca8ae57209eb10aa78b2.tar.bz2
rails-2c01f2b4e9d4a95bb2baca8ae57209eb10aa78b2.zip
use autoload instead of explicit requires for ActionView
-rw-r--r--actionpack/lib/action_view.rb36
-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.rb28
-rw-r--r--actionpack/lib/action_view/template_handler.rb5
-rw-r--r--actionpack/lib/action_view/template_handlers.rb13
-rw-r--r--actionpack/lib/action_view/template_handlers/erb.rb39
7 files changed, 91 insertions, 70 deletions
diff --git a/actionpack/lib/action_view.rb b/actionpack/lib/action_view.rb
index 7b1d3f8e7c..0c76204060 100644
--- a/actionpack/lib/action_view.rb
+++ b/actionpack/lib/action_view.rb
@@ -31,23 +31,29 @@ rescue LoadError
end
end
-require 'action_view/template_handlers'
-require 'action_view/renderable'
-require 'action_view/renderable_partial'
+module ActionView
+ def self.load_all!
+ [Base, InlineTemplate, TemplateError]
+ end
-require 'action_view/template'
-require 'action_view/inline_template'
-require 'action_view/paths'
+ autoload :Base, 'action_view/base'
+ autoload :Helpers, 'action_view/helpers'
+ autoload :InlineTemplate, 'action_view/inline_template'
+ autoload :Partials, 'action_view/partials'
+ autoload :PathSet, 'action_view/paths'
+ autoload :Renderable, 'action_view/renderable'
+ autoload :RenderablePartial, 'action_view/renderable_partial'
+ autoload :Template, 'action_view/template'
+ autoload :TemplateError, 'action_view/template_error'
+ autoload :TemplateHandler, 'action_view/template_handler'
+ autoload :TemplateHandlers, 'action_view/template_handlers'
+ autoload :Helpers, 'action_view/helpers'
+end
-require 'action_view/base'
-require 'action_view/partials'
-require 'action_view/template_error'
+class ERB
+ autoload :Util, 'action_view/erb/util'
+end
I18n.load_path << "#{File.dirname(__FILE__)}/action_view/locale/en.yml"
-require 'action_view/helpers'
-
-ActionView::Base.class_eval do
- include ActionView::Partials
- include ActionView::Helpers
-end
+ActionView.load_all!
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..de8682560f 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
diff --git a/actionpack/lib/action_view/template_handler.rb b/actionpack/lib/action_view/template_handler.rb
index d7e7c9b199..5efe9459b5 100644
--- a/actionpack/lib/action_view/template_handler.rb
+++ b/actionpack/lib/action_view/template_handler.rb
@@ -1,11 +1,6 @@
# Legacy TemplateHandler stub
module ActionView
- module TemplateHandlers
- module Compilable
- end
- end
-
class TemplateHandler
def self.call(template)
new.compile(template)
diff --git a/actionpack/lib/action_view/template_handlers.rb b/actionpack/lib/action_view/template_handlers.rb
index 6c8aa4c2a7..1052c4e75c 100644
--- a/actionpack/lib/action_view/template_handlers.rb
+++ b/actionpack/lib/action_view/template_handlers.rb
@@ -1,10 +1,13 @@
-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'
+
+ # Legacy Compilable stub
+ module Compilable
+ end
+
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