public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
use autoload instead of explicit requires for ActionView
josh (author)
Sun Nov 23 11:42:07 -0800 2008
commit  2c01f2b4e9d4a95bb2baca8ae57209eb10aa78b2
tree    7ef23887bc8642b99d9b99736ccccf89eaf5a6d9
parent  e201fc750bf4b7dff1875b7fcdd47f1686ef2052
...
31
32
33
34
35
36
 
 
 
 
37
38
39
40
 
 
 
 
 
 
 
 
 
 
 
 
 
41
42
43
44
 
 
 
45
46
47
48
49
50
51
52
53
 
...
31
32
33
 
 
 
34
35
36
37
38
 
 
 
39
40
41
42
43
44
45
46
47
48
49
50
51
52
 
 
 
53
54
55
56
57
58
 
 
 
 
 
 
59
0
@@ -31,23 +31,29 @@ rescue LoadError
0
   end
0
 end
0
 
0
-require 'action_view/template_handlers'
0
-require 'action_view/renderable'
0
-require 'action_view/renderable_partial'
0
+module ActionView
0
+  def self.load_all!
0
+    [Base, InlineTemplate, TemplateError]
0
+  end
0
 
0
-require 'action_view/template'
0
-require 'action_view/inline_template'
0
-require 'action_view/paths'
0
+  autoload :Base, 'action_view/base'
0
+  autoload :Helpers, 'action_view/helpers'
0
+  autoload :InlineTemplate, 'action_view/inline_template'
0
+  autoload :Partials, 'action_view/partials'
0
+  autoload :PathSet, 'action_view/paths'
0
+  autoload :Renderable, 'action_view/renderable'
0
+  autoload :RenderablePartial, 'action_view/renderable_partial'
0
+  autoload :Template, 'action_view/template'
0
+  autoload :TemplateError, 'action_view/template_error'
0
+  autoload :TemplateHandler, 'action_view/template_handler'
0
+  autoload :TemplateHandlers, 'action_view/template_handlers'
0
+  autoload :Helpers, 'action_view/helpers'
0
+end
0
 
0
-require 'action_view/base'
0
-require 'action_view/partials'
0
-require 'action_view/template_error'
0
+class ERB
0
+  autoload :Util, 'action_view/erb/util'
0
+end
0
 
0
 I18n.load_path << "#{File.dirname(__FILE__)}/action_view/locale/en.yml"
0
 
0
-require 'action_view/helpers'
0
-
0
-ActionView::Base.class_eval do
0
-  include ActionView::Partials
0
-  include ActionView::Helpers
0
-end
0
+ActionView.load_all!
...
157
158
159
160
 
161
162
163
...
157
158
159
 
160
161
162
163
0
@@ -157,7 +157,7 @@ module ActionView #:nodoc:
0
   #
0
   # See the ActionView::Helpers::PrototypeHelper::GeneratorMethods documentation for more details.
0
   class Base
0
-    include ERB::Util
0
+    include Helpers, Partials, ::ERB::Util
0
     extend ActiveSupport::Memoizable
0
 
0
     attr_accessor :base_path, :assigns, :template_extension
...
1
2
3
4
5
6
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
9
10
...
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
0
@@ -1,10 +1,28 @@
0
-Dir.entries(File.expand_path("#{File.dirname(__FILE__)}/helpers")).sort.each do |file|
0
-  next unless file =~ /^([a-z][a-z_]*_helper).rb$/
0
-  require "action_view/helpers/#{$1}"
0
-end
0
-
0
 module ActionView #:nodoc:
0
   module Helpers #:nodoc:
0
+    autoload :ActiveRecordHelper, 'action_view/helpers/active_record_helper'
0
+    autoload :AssetTagHelper, 'action_view/helpers/asset_tag_helper'
0
+    autoload :AtomFeedHelper, 'action_view/helpers/atom_feed_helper'
0
+    autoload :BenchmarkHelper, 'action_view/helpers/benchmark_helper'
0
+    autoload :CacheHelper, 'action_view/helpers/cache_helper'
0
+    autoload :CaptureHelper, 'action_view/helpers/capture_helper'
0
+    autoload :DateHelper, 'action_view/helpers/date_helper'
0
+    autoload :DebugHelper, 'action_view/helpers/debug_helper'
0
+    autoload :FormHelper, 'action_view/helpers/form_helper'
0
+    autoload :FormOptionsHelper, 'action_view/helpers/form_options_helper'
0
+    autoload :FormTagHelper, 'action_view/helpers/form_tag_helper'
0
+    autoload :JavascriptHelper, 'action_view/helpers/javascript_helper'
0
+    autoload :NumberHelper, 'action_view/helpers/number_helper'
0
+    autoload :PrototypeHelper, 'action_view/helpers/prototype_helper'
0
+    autoload :RecordIdentificationHelper, 'action_view/helpers/record_identification_helper'
0
+    autoload :RecordTagHelper, 'action_view/helpers/record_tag_helper'
0
+    autoload :SanitizeHelper, 'action_view/helpers/sanitize_helper'
0
+    autoload :ScriptaculousHelper, 'action_view/helpers/scriptaculous_helper'
0
+    autoload :TagHelper, 'action_view/helpers/tag_helper'
0
+    autoload :TextHelper, 'action_view/helpers/text_helper'
0
+    autoload :TranslationHelper, 'action_view/helpers/translation_helper'
0
+    autoload :UrlHelper, 'action_view/helpers/url_helper'
0
+
0
     def self.included(base)
0
       base.extend(ClassMethods)
0
     end
...
1
2
3
4
5
6
7
8
9
10
11
...
1
2
3
 
 
 
 
 
4
5
6
0
@@ -1,11 +1,6 @@
0
 # Legacy TemplateHandler stub
0
 
0
 module ActionView
0
-  module TemplateHandlers
0
-    module Compilable
0
-    end
0
-  end
0
-
0
   class TemplateHandler
0
     def self.call(template)
0
       new.compile(template)
...
1
2
3
4
5
6
7
 
 
 
 
 
 
 
 
8
9
10
...
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
0
@@ -1,10 +1,13 @@
0
-require 'action_view/template_handler'
0
-require 'action_view/template_handlers/builder'
0
-require 'action_view/template_handlers/erb'
0
-require 'action_view/template_handlers/rjs'
0
-
0
 module ActionView #:nodoc:
0
   module TemplateHandlers #:nodoc:
0
+    autoload :ERB, 'action_view/template_handlers/erb'
0
+    autoload :RJS, 'action_view/template_handlers/rjs'
0
+    autoload :Builder, 'action_view/template_handlers/builder'
0
+
0
+    # Legacy Compilable stub
0
+    module Compilable
0
+    end
0
+
0
     def self.extended(base)
0
       base.register_default_template_handler :erb, TemplateHandlers::ERB
0
       base.register_template_handler :rjs, TemplateHandlers::RJS
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
0
@@ -1,42 +1,3 @@
0
-require 'erb'
0
-
0
-class ERB
0
-  module Util
0
-    HTML_ESCAPE = { '&' => '&amp;',  '>' => '&gt;',   '<' => '&lt;', '"' => '&quot;' }
0
-    JSON_ESCAPE = { '&' => '\u0026', '>' => '\u003E', '<' => '\u003C' }
0
-
0
-    # A utility method for escaping HTML tag characters.
0
-    # This method is also aliased as <tt>h</tt>.
0
-    #
0
-    # In your ERb templates, use this method to escape any unsafe content. For example:
0
-    #   <%=h @person.name %>
0
-    #
0
-    # ==== Example:
0
-    #   puts html_escape("is a > 0 & a < 10?")
0
-    #   # => is a &gt; 0 &amp; a &lt; 10?
0
-    def html_escape(s)
0
-      s.to_s.gsub(/[&"><]/) { |special| HTML_ESCAPE[special] }
0
-    end
0
-
0
-    # A utility method for escaping HTML entities in JSON strings.
0
-    # This method is also aliased as <tt>j</tt>.
0
-    #
0
-    # In your ERb templates, use this method to escape any HTML entities:
0
-    #   <%=j @person.to_json %>
0
-    #
0
-    # ==== Example:
0
-    #   puts json_escape("is a > 0 & a < 10?")
0
-    #   # => is a \u003E 0 \u0026 a \u003C 10?
0
-    def json_escape(s)
0
-      s.to_s.gsub(/[&"><]/) { |special| JSON_ESCAPE[special] }
0
-    end
0
-
0
-    alias j json_escape
0
-    module_function :j
0
-    module_function :json_escape
0
-  end
0
-end
0
-
0
 module ActionView
0
   module TemplateHandlers
0
     class ERB < TemplateHandler

Comments

rogerdpack Wed Dec 03 14:49:08 -0800 2008

isn’t use of autoload deemed non thread safe? http://www.ruby-forum.com/topic/172385 Thanks!

josh Wed Dec 03 15:01:00 -0800 2008

correct, it is not thread safe

threaded mode will eager those these files at boot