actionpack 2.1.2 → 2.2.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of actionpack might be problematic. Click here for more details.
- data/CHANGELOG +223 -7
- data/README +6 -12
- data/Rakefile +11 -11
- data/lib/action_controller.rb +9 -9
- data/lib/action_controller/assertions/response_assertions.rb +29 -78
- data/lib/action_controller/assertions/routing_assertions.rb +33 -33
- data/lib/action_controller/assertions/selector_assertions.rb +9 -5
- data/lib/action_controller/base.rb +227 -161
- data/lib/action_controller/benchmarking.rb +37 -24
- data/lib/action_controller/caching/actions.rb +53 -21
- data/lib/action_controller/caching/fragments.rb +10 -36
- data/lib/action_controller/caching/sweeping.rb +3 -3
- data/lib/action_controller/cgi_ext/session.rb +2 -22
- data/lib/action_controller/cgi_process.rb +8 -46
- data/lib/action_controller/components.rb +4 -1
- data/lib/action_controller/cookies.rb +10 -0
- data/lib/action_controller/dispatcher.rb +49 -15
- data/lib/action_controller/filters.rb +48 -10
- data/lib/action_controller/headers.rb +16 -14
- data/lib/action_controller/helpers.rb +2 -2
- data/lib/action_controller/http_authentication.rb +1 -1
- data/lib/action_controller/integration.rb +57 -60
- data/lib/action_controller/layout.rb +27 -53
- data/lib/action_controller/mime_responds.rb +5 -1
- data/lib/action_controller/mime_type.rb +64 -42
- data/lib/action_controller/mime_types.rb +2 -1
- data/lib/action_controller/performance_test.rb +16 -0
- data/lib/action_controller/polymorphic_routes.rb +16 -9
- data/lib/action_controller/rack_process.rb +303 -0
- data/lib/action_controller/request.rb +205 -97
- data/lib/action_controller/request_forgery_protection.rb +2 -2
- data/lib/action_controller/request_profiler.rb +0 -0
- data/lib/action_controller/rescue.rb +20 -115
- data/lib/action_controller/resources.rb +186 -83
- data/lib/action_controller/response.rb +140 -26
- data/lib/action_controller/routing.rb +28 -30
- data/lib/action_controller/routing/builder.rb +45 -54
- data/lib/action_controller/routing/optimisations.rb +31 -21
- data/lib/action_controller/routing/recognition_optimisation.rb +33 -27
- data/lib/action_controller/routing/route.rb +162 -147
- data/lib/action_controller/routing/route_set.rb +8 -7
- data/lib/action_controller/routing/routing_ext.rb +4 -1
- data/lib/action_controller/routing/segments.rb +50 -21
- data/lib/action_controller/session/cookie_store.rb +3 -2
- data/lib/action_controller/session/drb_server.rb +7 -7
- data/lib/action_controller/session_management.rb +6 -2
- data/lib/action_controller/streaming.rb +15 -8
- data/lib/action_controller/templates/rescues/diagnostics.erb +2 -2
- data/lib/action_controller/templates/rescues/template_error.erb +2 -2
- data/lib/action_controller/test_case.rb +66 -2
- data/lib/action_controller/test_process.rb +71 -66
- data/lib/action_controller/translation.rb +13 -0
- data/lib/action_controller/url_rewriter.rb +90 -13
- data/lib/action_controller/vendor/html-scanner/html/node.rb +9 -2
- data/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +1 -1
- data/lib/action_controller/vendor/html-scanner/html/selector.rb +2 -2
- data/lib/action_controller/verification.rb +2 -2
- data/lib/action_pack/version.rb +1 -1
- data/lib/action_view.rb +19 -11
- data/lib/action_view/base.rb +184 -150
- data/lib/action_view/helpers.rb +38 -0
- data/lib/action_view/helpers/active_record_helper.rb +56 -27
- data/lib/action_view/helpers/asset_tag_helper.rb +356 -153
- data/lib/action_view/helpers/atom_feed_helper.rb +74 -19
- data/lib/action_view/helpers/benchmark_helper.rb +3 -3
- data/lib/action_view/helpers/cache_helper.rb +1 -2
- data/lib/action_view/helpers/capture_helper.rb +19 -44
- data/lib/action_view/helpers/date_helper.rb +486 -296
- data/lib/action_view/helpers/debug_helper.rb +20 -13
- data/lib/action_view/helpers/form_helper.rb +71 -30
- data/lib/action_view/helpers/form_options_helper.rb +15 -85
- data/lib/action_view/helpers/form_tag_helper.rb +61 -38
- data/lib/action_view/helpers/javascript_helper.rb +80 -89
- data/lib/action_view/helpers/number_helper.rb +179 -74
- data/lib/action_view/helpers/prototype_helper.rb +216 -201
- data/lib/action_view/helpers/record_tag_helper.rb +4 -5
- data/lib/action_view/helpers/sanitize_helper.rb +65 -33
- data/lib/action_view/helpers/scriptaculous_helper.rb +2 -2
- data/lib/action_view/helpers/tag_helper.rb +39 -22
- data/lib/action_view/helpers/text_helper.rb +212 -118
- data/lib/action_view/helpers/translation_helper.rb +21 -0
- data/lib/action_view/helpers/url_helper.rb +100 -58
- data/lib/action_view/inline_template.rb +13 -14
- data/lib/action_view/locale/en.yml +91 -0
- data/lib/action_view/partials.rb +100 -55
- data/lib/action_view/paths.rb +125 -0
- data/lib/action_view/renderable.rb +102 -0
- data/lib/action_view/renderable_partial.rb +48 -0
- data/lib/action_view/template.rb +90 -101
- data/lib/action_view/template_error.rb +11 -21
- data/lib/action_view/template_handler.rb +8 -28
- data/lib/action_view/template_handlers.rb +45 -0
- data/lib/action_view/template_handlers/builder.rb +5 -15
- data/lib/action_view/template_handlers/erb.rb +9 -6
- data/lib/action_view/template_handlers/rjs.rb +2 -17
- data/lib/action_view/test_case.rb +7 -4
- data/test/abstract_unit.rb +4 -1
- data/test/active_record_unit.rb +28 -30
- data/test/activerecord/render_partial_with_record_identification_test.rb +25 -12
- data/test/controller/action_pack_assertions_test.rb +8 -37
- data/test/controller/addresses_render_test.rb +0 -3
- data/test/controller/assert_select_test.rb +51 -24
- data/test/controller/base_test.rb +4 -4
- data/test/controller/caching_test.rb +136 -66
- data/test/controller/capture_test.rb +1 -21
- data/test/controller/cgi_test.rb +157 -10
- data/test/controller/components_test.rb +41 -25
- data/test/controller/content_type_test.rb +49 -17
- data/test/controller/cookie_test.rb +1 -1
- data/test/controller/deprecation/deprecated_base_methods_test.rb +0 -3
- data/test/controller/dispatcher_test.rb +9 -1
- data/test/controller/filter_params_test.rb +2 -2
- data/test/controller/filters_test.rb +13 -13
- data/test/controller/html-scanner/cdata_node_test.rb +15 -0
- data/test/controller/html-scanner/node_test.rb +21 -0
- data/test/controller/html-scanner/sanitizer_test.rb +14 -0
- data/test/controller/integration_test.rb +167 -6
- data/test/controller/layout_test.rb +11 -68
- data/test/controller/logging_test.rb +46 -0
- data/test/controller/mime_responds_test.rb +61 -59
- data/test/controller/mime_type_test.rb +6 -6
- data/test/controller/polymorphic_routes_test.rb +37 -2
- data/test/controller/rack_test.rb +323 -0
- data/test/controller/redirect_test.rb +72 -71
- data/test/controller/render_test.rb +1120 -108
- data/test/controller/request_forgery_protection_test.rb +66 -52
- data/test/controller/request_test.rb +103 -146
- data/test/controller/rescue_test.rb +20 -24
- data/test/controller/resources_test.rb +408 -25
- data/test/controller/routing_test.rb +1774 -1774
- data/test/controller/send_file_test.rb +0 -4
- data/test/controller/session/cookie_store_test.rb +53 -1
- data/test/controller/test_test.rb +15 -37
- data/test/controller/translation_test.rb +26 -0
- data/test/controller/url_rewriter_test.rb +27 -28
- data/test/controller/view_paths_test.rb +48 -47
- data/test/fixtures/_top_level_partial.html.erb +1 -0
- data/test/fixtures/_top_level_partial_only.erb +1 -0
- data/test/fixtures/developers/_developer.erb +1 -0
- data/test/fixtures/fun/games/_game.erb +1 -0
- data/test/fixtures/fun/serious/games/_game.erb +1 -0
- data/test/fixtures/functional_caching/formatted_fragment_cached.html.erb +3 -0
- data/test/fixtures/functional_caching/formatted_fragment_cached.js.rjs +6 -0
- data/test/fixtures/functional_caching/formatted_fragment_cached.xml.builder +5 -0
- data/test/fixtures/functional_caching/inline_fragment_cached.html.erb +2 -0
- data/test/fixtures/layouts/_column.html.erb +2 -0
- data/test/fixtures/projects/_project.erb +1 -0
- data/test/fixtures/public/javascripts/subdir/subdir.js +1 -0
- data/test/fixtures/public/stylesheets/subdir/subdir.css +1 -0
- data/test/fixtures/replies/_reply.erb +1 -0
- data/test/fixtures/test/_counter.html.erb +1 -0
- data/test/fixtures/test/_customer.erb +1 -1
- data/test/fixtures/test/_customer_with_var.erb +1 -0
- data/test/fixtures/test/_layout_for_block_with_args.html.erb +3 -0
- data/test/fixtures/test/_local_inspector.html.erb +1 -0
- data/test/fixtures/test/_partial_with_only_html_version.html.erb +1 -0
- data/test/fixtures/test/hello.builder +1 -1
- data/test/fixtures/test/hyphen-ated.erb +1 -0
- data/test/fixtures/test/implicit_content_type.atom.builder +2 -0
- data/test/fixtures/test/nested_layout.erb +3 -0
- data/test/fixtures/test/non_erb_block_content_for.builder +1 -1
- data/test/fixtures/test/sub_template_raise.html.erb +1 -0
- data/test/fixtures/test/template.erb +1 -0
- data/test/fixtures/test/using_layout_around_block_with_args.html.erb +1 -0
- data/test/template/active_record_helper_i18n_test.rb +46 -0
- data/test/template/active_record_helper_test.rb +24 -24
- data/test/template/asset_tag_helper_test.rb +161 -29
- data/test/template/atom_feed_helper_test.rb +114 -5
- data/test/template/compiled_templates_test.rb +59 -0
- data/test/template/date_helper_i18n_test.rb +113 -0
- data/test/template/date_helper_test.rb +403 -109
- data/test/template/form_helper_test.rb +213 -154
- data/test/template/form_options_helper_test.rb +249 -897
- data/test/template/form_tag_helper_test.rb +80 -32
- data/test/template/javascript_helper_test.rb +17 -18
- data/test/template/number_helper_i18n_test.rb +54 -0
- data/test/template/number_helper_test.rb +43 -13
- data/test/template/prototype_helper_test.rb +101 -84
- data/test/template/record_tag_helper_test.rb +24 -20
- data/test/template/render_test.rb +193 -0
- data/test/template/sanitize_helper_test.rb +3 -3
- data/test/template/tag_helper_test.rb +34 -14
- data/test/template/text_helper_test.rb +83 -9
- data/test/template/translation_helper_test.rb +28 -0
- data/test/template/url_helper_test.rb +55 -18
- metadata +57 -18
- data/lib/action_view/helpers/javascripts/controls.js +0 -963
- data/lib/action_view/helpers/javascripts/dragdrop.js +0 -972
- data/lib/action_view/helpers/javascripts/effects.js +0 -1120
- data/lib/action_view/helpers/javascripts/prototype.js +0 -4225
- data/lib/action_view/partial_template.rb +0 -70
- data/lib/action_view/template_finder.rb +0 -177
- data/lib/action_view/template_handlers/compilable.rb +0 -128
- data/test/controller/custom_handler_test.rb +0 -45
- data/test/controller/new_render_test.rb +0 -945
- data/test/fixtures/test/block_content_for.erb +0 -2
- data/test/fixtures/test/erb_content_for.erb +0 -2
- data/test/template/deprecated_erb_variable_test.rb +0 -9
- data/test/template/template_finder_test.rb +0 -73
- data/test/template/template_object_test.rb +0 -95
data/lib/action_view/template.rb
CHANGED
@@ -1,127 +1,116 @@
|
|
1
|
+
require 'action_controller/mime_type'
|
2
|
+
|
1
3
|
module ActionView #:nodoc:
|
2
|
-
class Template
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
@
|
13
|
-
@
|
14
|
-
@
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
@handler = self.class.handler_class_for_extension(@extension).new(@view)
|
4
|
+
class Template
|
5
|
+
extend TemplateHandlers
|
6
|
+
extend ActiveSupport::Memoizable
|
7
|
+
include Renderable
|
8
|
+
|
9
|
+
attr_accessor :filename, :load_path, :base_path, :name, :format, :extension
|
10
|
+
delegate :to_s, :to => :path
|
11
|
+
|
12
|
+
def initialize(template_path, load_paths = [])
|
13
|
+
template_path = template_path.dup
|
14
|
+
@base_path, @name, @format, @extension = split(template_path)
|
15
|
+
@base_path.to_s.gsub!(/\/$/, '') # Push to split method
|
16
|
+
@load_path, @filename = find_full_path(template_path, load_paths)
|
17
|
+
|
18
|
+
# Extend with partial super powers
|
19
|
+
extend RenderablePartial if @name =~ /^_/
|
19
20
|
end
|
20
21
|
|
21
|
-
def
|
22
|
-
|
23
|
-
rescue Exception => e
|
24
|
-
raise e unless filename
|
25
|
-
if TemplateError === e
|
26
|
-
e.sub_template_of(filename)
|
27
|
-
raise e
|
28
|
-
else
|
29
|
-
raise TemplateError.new(self, @view.assigns, e)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def render
|
34
|
-
prepare!
|
35
|
-
@handler.render(self)
|
22
|
+
def format_and_extension
|
23
|
+
(extensions = [format, extension].compact.join(".")).blank? ? nil : extensions
|
36
24
|
end
|
25
|
+
memoize :format_and_extension
|
37
26
|
|
38
|
-
def
|
39
|
-
|
27
|
+
def multipart?
|
28
|
+
format && format.include?('.')
|
40
29
|
end
|
41
30
|
|
42
|
-
def
|
43
|
-
|
31
|
+
def content_type
|
32
|
+
format.gsub('.', '/')
|
44
33
|
end
|
45
34
|
|
46
|
-
def
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
def prepare!
|
51
|
-
@view.send :evaluate_assigns
|
52
|
-
@view.current_render_extension = @extension
|
53
|
-
|
54
|
-
if @handler.compilable?
|
55
|
-
@handler.compile_template(self) # compile the given template, if necessary
|
56
|
-
@method = @view.method_names[method_key] # Set the method name for this template and run it
|
57
|
-
end
|
35
|
+
def mime_type
|
36
|
+
Mime::Type.lookup_by_extension(format) if format
|
58
37
|
end
|
38
|
+
memoize :mime_type
|
59
39
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
if use_full_path
|
65
|
-
if @extension
|
66
|
-
@filename = @finder.pick_template(@path_without_extension, @extension)
|
67
|
-
else
|
68
|
-
@extension = @finder.pick_template_extension(@path).to_s
|
69
|
-
raise_missing_template_exception unless @extension
|
70
|
-
|
71
|
-
@filename = @finder.pick_template(@path, @extension)
|
72
|
-
@extension = @extension.gsub(/^.+\./, '') # strip off any formats
|
73
|
-
end
|
74
|
-
else
|
75
|
-
@filename = @path
|
76
|
-
end
|
40
|
+
def path
|
41
|
+
[base_path, [name, format, extension].compact.join('.')].compact.join('/')
|
42
|
+
end
|
43
|
+
memoize :path
|
77
44
|
|
78
|
-
|
45
|
+
def path_without_extension
|
46
|
+
[base_path, [name, format].compact.join('.')].compact.join('/')
|
79
47
|
end
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
template_type = (@path =~ /layouts/i) ? 'layout' : 'template'
|
85
|
-
raise(MissingTemplate, "Missing #{template_type} #{full_template_path} in view path #{display_paths}")
|
48
|
+
memoize :path_without_extension
|
49
|
+
|
50
|
+
def path_without_format_and_extension
|
51
|
+
[base_path, name].compact.join('/')
|
86
52
|
end
|
53
|
+
memoize :path_without_format_and_extension
|
87
54
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
# Register a class that knows how to handle template files with the given
|
94
|
-
# extension. This can be used to implement new template types.
|
95
|
-
# The constructor for the class must take the ActiveView::Base instance
|
96
|
-
# as a parameter, and the class must implement a +render+ method that
|
97
|
-
# takes the contents of the template to render as well as the Hash of
|
98
|
-
# local assigns available to the template. The +render+ method ought to
|
99
|
-
# return the rendered template as a string.
|
100
|
-
def self.register_template_handler(extension, klass)
|
101
|
-
@@template_handlers[extension.to_sym] = klass
|
102
|
-
TemplateFinder.update_extension_cache_for(extension.to_s)
|
55
|
+
def relative_path
|
56
|
+
path = File.expand_path(filename)
|
57
|
+
path.sub!(/^#{Regexp.escape(File.expand_path(RAILS_ROOT))}\//, '') if defined?(RAILS_ROOT)
|
58
|
+
path
|
103
59
|
end
|
60
|
+
memoize :relative_path
|
104
61
|
|
105
|
-
def
|
106
|
-
|
62
|
+
def source
|
63
|
+
File.read(filename)
|
107
64
|
end
|
65
|
+
memoize :source
|
108
66
|
|
109
|
-
def
|
110
|
-
|
111
|
-
@@default_template_handlers = klass
|
67
|
+
def method_segment
|
68
|
+
relative_path.to_s.gsub(/([^a-zA-Z0-9_])/) { $1.ord }
|
112
69
|
end
|
70
|
+
memoize :method_segment
|
113
71
|
|
114
|
-
def
|
115
|
-
(
|
72
|
+
def render_template(view, local_assigns = {})
|
73
|
+
render(view, local_assigns)
|
74
|
+
rescue Exception => e
|
75
|
+
raise e unless filename
|
76
|
+
if TemplateError === e
|
77
|
+
e.sub_template_of(self)
|
78
|
+
raise e
|
79
|
+
else
|
80
|
+
raise TemplateError.new(self, view.assigns, e)
|
81
|
+
end
|
116
82
|
end
|
117
83
|
|
118
|
-
|
119
|
-
|
120
|
-
|
84
|
+
private
|
85
|
+
def valid_extension?(extension)
|
86
|
+
Template.template_handler_extensions.include?(extension)
|
87
|
+
end
|
88
|
+
|
89
|
+
def find_full_path(path, load_paths)
|
90
|
+
load_paths = Array(load_paths) + [nil]
|
91
|
+
load_paths.each do |load_path|
|
92
|
+
file = [load_path, path].compact.join('/')
|
93
|
+
return load_path, file if File.file?(file)
|
94
|
+
end
|
95
|
+
raise MissingTemplate.new(load_paths, path)
|
96
|
+
end
|
121
97
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
98
|
+
# Returns file split into an array
|
99
|
+
# [base_path, name, format, extension]
|
100
|
+
def split(file)
|
101
|
+
if m = file.match(/^(.*\/)?([^\.]+)\.?(\w+)?\.?(\w+)?\.?(\w+)?$/)
|
102
|
+
if m[5] # Multipart formats
|
103
|
+
[m[1], m[2], "#{m[3]}.#{m[4]}", m[5]]
|
104
|
+
elsif m[4] # Single format
|
105
|
+
[m[1], m[2], m[3], m[4]]
|
106
|
+
else
|
107
|
+
if valid_extension?(m[3]) # No format
|
108
|
+
[m[1], m[2], nil, m[3]]
|
109
|
+
else # No extension
|
110
|
+
[m[1], m[2], m[3], nil]
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
126
115
|
end
|
127
116
|
end
|
@@ -7,12 +7,14 @@ module ActionView
|
|
7
7
|
attr_reader :original_exception
|
8
8
|
|
9
9
|
def initialize(template, assigns, original_exception)
|
10
|
-
@
|
11
|
-
@assigns, @source, @original_exception = assigns.dup, template.source, original_exception
|
12
|
-
@file_path = template.filename
|
10
|
+
@template, @assigns, @original_exception = template, assigns.dup, original_exception
|
13
11
|
@backtrace = compute_backtrace
|
14
12
|
end
|
15
13
|
|
14
|
+
def file_name
|
15
|
+
@template.relative_path
|
16
|
+
end
|
17
|
+
|
16
18
|
def message
|
17
19
|
ActiveSupport::Deprecation.silence { original_exception.message }
|
18
20
|
end
|
@@ -24,7 +26,7 @@ module ActionView
|
|
24
26
|
def sub_template_message
|
25
27
|
if @sub_templates
|
26
28
|
"Trace of template inclusion: " +
|
27
|
-
@sub_templates.collect { |template|
|
29
|
+
@sub_templates.collect { |template| template.relative_path }.join(", ")
|
28
30
|
else
|
29
31
|
""
|
30
32
|
end
|
@@ -34,18 +36,18 @@ module ActionView
|
|
34
36
|
return unless num = line_number
|
35
37
|
num = num.to_i
|
36
38
|
|
37
|
-
source_code =
|
39
|
+
source_code = @template.source.split("\n")
|
38
40
|
|
39
41
|
start_on_line = [ num - SOURCE_CODE_RADIUS - 1, 0 ].max
|
40
42
|
end_on_line = [ num + SOURCE_CODE_RADIUS - 1, source_code.length].min
|
41
43
|
|
42
44
|
indent = ' ' * indentation
|
43
45
|
line_counter = start_on_line
|
44
|
-
return unless source_code = source_code[start_on_line..end_on_line]
|
45
|
-
|
46
|
+
return unless source_code = source_code[start_on_line..end_on_line]
|
47
|
+
|
46
48
|
source_code.sum do |line|
|
47
49
|
line_counter += 1
|
48
|
-
"#{indent}#{line_counter}: #{line}"
|
50
|
+
"#{indent}#{line_counter}: #{line}\n"
|
49
51
|
end
|
50
52
|
end
|
51
53
|
|
@@ -63,12 +65,6 @@ module ActionView
|
|
63
65
|
end
|
64
66
|
end
|
65
67
|
|
66
|
-
def file_name
|
67
|
-
stripped = strip_base_path(@file_path)
|
68
|
-
stripped.slice!(0,1) if stripped[0] == ?/
|
69
|
-
stripped
|
70
|
-
end
|
71
|
-
|
72
68
|
def to_s
|
73
69
|
"\n\n#{self.class} (#{message}) #{source_location}:\n" +
|
74
70
|
"#{source_extract}\n #{clean_backtrace.join("\n ")}\n\n"
|
@@ -88,12 +84,6 @@ module ActionView
|
|
88
84
|
]
|
89
85
|
end
|
90
86
|
|
91
|
-
def strip_base_path(path)
|
92
|
-
stripped_path = File.expand_path(path).gsub(@base_path, "")
|
93
|
-
stripped_path.gsub!(/^#{Regexp.escape File.expand_path(RAILS_ROOT)}/, '') if defined?(RAILS_ROOT)
|
94
|
-
stripped_path
|
95
|
-
end
|
96
|
-
|
97
87
|
def source_location
|
98
88
|
if line_number
|
99
89
|
"on line ##{line_number} of "
|
@@ -105,6 +95,6 @@ module ActionView
|
|
105
95
|
end
|
106
96
|
|
107
97
|
if defined?(Exception::TraceSubstitutions)
|
108
|
-
Exception::TraceSubstitutions << [/:in\s+`_run_
|
98
|
+
Exception::TraceSubstitutions << [/:in\s+`_run_.*'\s*$/, '']
|
109
99
|
Exception::TraceSubstitutions << [%r{^\s*#{Regexp.escape RAILS_ROOT}/}, ''] if defined?(RAILS_ROOT)
|
110
100
|
end
|
@@ -1,34 +1,14 @@
|
|
1
|
-
|
2
|
-
class TemplateHandler
|
1
|
+
# Legacy TemplateHandler stub
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
def self.compilable?
|
9
|
-
false
|
10
|
-
end
|
11
|
-
|
12
|
-
def initialize(view)
|
13
|
-
@view = view
|
14
|
-
end
|
15
|
-
|
16
|
-
def render(template)
|
17
|
-
end
|
18
|
-
|
19
|
-
def compile(template)
|
20
|
-
end
|
21
|
-
|
22
|
-
def compilable?
|
23
|
-
self.class.compilable?
|
24
|
-
end
|
25
|
-
|
26
|
-
def line_offset
|
27
|
-
self.class.line_offset
|
3
|
+
module ActionView
|
4
|
+
module TemplateHandlers
|
5
|
+
module Compilable
|
28
6
|
end
|
7
|
+
end
|
29
8
|
|
30
|
-
|
31
|
-
def
|
9
|
+
class TemplateHandler
|
10
|
+
def self.call(template)
|
11
|
+
new.compile(template)
|
32
12
|
end
|
33
13
|
end
|
34
14
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'action_view/template_handler'
|
2
|
+
require 'action_view/template_handlers/builder'
|
3
|
+
require 'action_view/template_handlers/erb'
|
4
|
+
require 'action_view/template_handlers/rjs'
|
5
|
+
|
6
|
+
module ActionView #:nodoc:
|
7
|
+
module TemplateHandlers #:nodoc:
|
8
|
+
def self.extended(base)
|
9
|
+
base.register_default_template_handler :erb, TemplateHandlers::ERB
|
10
|
+
base.register_template_handler :rjs, TemplateHandlers::RJS
|
11
|
+
base.register_template_handler :builder, TemplateHandlers::Builder
|
12
|
+
|
13
|
+
# TODO: Depreciate old template extensions
|
14
|
+
base.register_template_handler :rhtml, TemplateHandlers::ERB
|
15
|
+
base.register_template_handler :rxml, TemplateHandlers::Builder
|
16
|
+
end
|
17
|
+
|
18
|
+
@@template_handlers = {}
|
19
|
+
@@default_template_handlers = nil
|
20
|
+
|
21
|
+
# Register a class that knows how to handle template files with the given
|
22
|
+
# extension. This can be used to implement new template types.
|
23
|
+
# The constructor for the class must take the ActiveView::Base instance
|
24
|
+
# as a parameter, and the class must implement a +render+ method that
|
25
|
+
# takes the contents of the template to render as well as the Hash of
|
26
|
+
# local assigns available to the template. The +render+ method ought to
|
27
|
+
# return the rendered template as a string.
|
28
|
+
def register_template_handler(extension, klass)
|
29
|
+
@@template_handlers[extension.to_sym] = klass
|
30
|
+
end
|
31
|
+
|
32
|
+
def template_handler_extensions
|
33
|
+
@@template_handlers.keys.map(&:to_s).sort
|
34
|
+
end
|
35
|
+
|
36
|
+
def register_default_template_handler(extension, klass)
|
37
|
+
register_template_handler(extension, klass)
|
38
|
+
@@default_template_handlers = klass
|
39
|
+
end
|
40
|
+
|
41
|
+
def handler_class_for_extension(extension)
|
42
|
+
(extension && @@template_handlers[extension.to_sym]) || @@default_template_handlers
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -5,22 +5,12 @@ module ActionView
|
|
5
5
|
class Builder < TemplateHandler
|
6
6
|
include Compilable
|
7
7
|
|
8
|
-
def self.line_offset
|
9
|
-
2
|
10
|
-
end
|
11
|
-
|
12
8
|
def compile(template)
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
def cache_fragment(block, name = {}, options = nil)
|
21
|
-
@view.fragment_for(block, name, options) do
|
22
|
-
eval('xml.target!', block.binding)
|
23
|
-
end
|
9
|
+
"_set_controller_content_type(Mime::XML);" +
|
10
|
+
"xml = ::Builder::XmlMarkup.new(:indent => 2);" +
|
11
|
+
"self.output_buffer = xml.target!;" +
|
12
|
+
template.source +
|
13
|
+
";xml.target!;"
|
24
14
|
end
|
25
15
|
end
|
26
16
|
end
|
@@ -42,14 +42,17 @@ module ActionView
|
|
42
42
|
class ERB < TemplateHandler
|
43
43
|
include Compilable
|
44
44
|
|
45
|
+
# Specify trim mode for the ERB compiler. Defaults to '-'.
|
46
|
+
# See ERb documentation for suitable values.
|
47
|
+
cattr_accessor :erb_trim_mode
|
48
|
+
self.erb_trim_mode = '-'
|
49
|
+
|
45
50
|
def compile(template)
|
46
|
-
::ERB.new(template.source, nil, @
|
47
|
-
end
|
51
|
+
src = ::ERB.new("<% __in_erb_template=true %>#{template.source}", nil, erb_trim_mode, '@output_buffer').src
|
48
52
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
53
|
+
# Ruby 1.9 prepends an encoding to the source. However this is
|
54
|
+
# useless because you can only set an encoding on the first line
|
55
|
+
RUBY_VERSION >= '1.9' ? src.sub(/\A#coding:.*\n/, '') : src
|
53
56
|
end
|
54
57
|
end
|
55
58
|
end
|
@@ -3,24 +3,9 @@ module ActionView
|
|
3
3
|
class RJS < TemplateHandler
|
4
4
|
include Compilable
|
5
5
|
|
6
|
-
def self.line_offset
|
7
|
-
2
|
8
|
-
end
|
9
|
-
|
10
6
|
def compile(template)
|
11
|
-
"controller.response.content_type ||= Mime::JS
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
def cache_fragment(block, name = {}, options = nil) #:nodoc:
|
16
|
-
@view.fragment_for(block, name, options) do
|
17
|
-
begin
|
18
|
-
debug_mode, ActionView::Base.debug_rjs = ActionView::Base.debug_rjs, false
|
19
|
-
eval('page.to_s', block.binding)
|
20
|
-
ensure
|
21
|
-
ActionView::Base.debug_rjs = debug_mode
|
22
|
-
end
|
23
|
-
end
|
7
|
+
"controller.response.content_type ||= Mime::JS;" +
|
8
|
+
"update_page do |page|;#{template.source}\nend"
|
24
9
|
end
|
25
10
|
end
|
26
11
|
end
|