actionpack 3.0.0.beta4 → 3.0.0.rc

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.

Files changed (102) hide show
  1. data/CHANGELOG +36 -0
  2. data/{README → README.rdoc} +79 -137
  3. data/lib/abstract_controller.rb +1 -0
  4. data/lib/abstract_controller/asset_paths.rb +1 -1
  5. data/lib/abstract_controller/base.rb +3 -12
  6. data/lib/abstract_controller/rendering.rb +2 -2
  7. data/lib/abstract_controller/view_paths.rb +2 -1
  8. data/lib/action_controller.rb +1 -2
  9. data/lib/action_controller/base.rb +3 -9
  10. data/lib/action_controller/log_subscriber.rb +56 -0
  11. data/lib/action_controller/metal.rb +10 -3
  12. data/lib/action_controller/metal/helpers.rb +5 -4
  13. data/lib/action_controller/metal/hide_actions.rb +3 -3
  14. data/lib/action_controller/metal/instrumentation.rb +2 -1
  15. data/lib/action_controller/metal/mime_responds.rb +13 -10
  16. data/lib/action_controller/metal/rack_delegation.rb +0 -4
  17. data/lib/action_controller/metal/request_forgery_protection.rb +1 -1
  18. data/lib/action_controller/metal/rescue.rb +9 -0
  19. data/lib/action_controller/metal/responder.rb +13 -5
  20. data/lib/action_controller/metal/streaming.rb +2 -0
  21. data/lib/action_controller/metal/url_for.rb +5 -5
  22. data/lib/action_controller/railtie.rb +14 -23
  23. data/lib/action_controller/record_identifier.rb +6 -25
  24. data/lib/action_controller/test_case.rb +18 -6
  25. data/lib/action_controller/vendor/html-scanner/html/node.rb +1 -0
  26. data/lib/action_controller/vendor/html-scanner/html/tokenizer.rb +1 -0
  27. data/lib/action_dispatch.rb +6 -0
  28. data/lib/action_dispatch/http/cache.rb +2 -2
  29. data/lib/action_dispatch/http/filter_parameters.rb +10 -66
  30. data/lib/action_dispatch/http/mime_type.rb +1 -1
  31. data/lib/action_dispatch/http/parameter_filter.rb +72 -0
  32. data/lib/action_dispatch/http/parameters.rb +31 -2
  33. data/lib/action_dispatch/http/request.rb +4 -1
  34. data/lib/action_dispatch/http/upload.rb +2 -2
  35. data/lib/action_dispatch/middleware/callbacks.rb +4 -4
  36. data/lib/action_dispatch/middleware/cookies.rb +39 -6
  37. data/lib/action_dispatch/middleware/flash.rb +9 -2
  38. data/lib/action_dispatch/middleware/session/abstract_store.rb +121 -36
  39. data/lib/action_dispatch/middleware/session/cookie_store.rb +26 -19
  40. data/lib/action_dispatch/middleware/session/mem_cache_store.rb +9 -1
  41. data/lib/action_dispatch/middleware/show_exceptions.rb +2 -2
  42. data/lib/action_dispatch/middleware/stack.rb +12 -5
  43. data/lib/action_dispatch/railtie.rb +1 -1
  44. data/lib/action_dispatch/routing.rb +11 -13
  45. data/lib/action_dispatch/routing/deprecated_mapper.rb +6 -388
  46. data/lib/action_dispatch/routing/mapper.rb +364 -234
  47. data/lib/action_dispatch/routing/polymorphic_routes.rb +186 -0
  48. data/lib/action_dispatch/routing/route.rb +11 -2
  49. data/lib/action_dispatch/routing/route_set.rb +62 -28
  50. data/lib/action_dispatch/routing/url_for.rb +2 -1
  51. data/lib/action_dispatch/testing/assertions.rb +0 -2
  52. data/lib/action_dispatch/testing/assertions/routing.rb +0 -1
  53. data/lib/action_dispatch/testing/assertions/selector.rb +20 -24
  54. data/lib/action_dispatch/testing/integration.rb +2 -2
  55. data/lib/action_dispatch/testing/test_response.rb +2 -2
  56. data/lib/action_pack/version.rb +1 -1
  57. data/lib/action_view.rb +1 -0
  58. data/lib/action_view/base.rb +20 -21
  59. data/lib/action_view/context.rb +9 -12
  60. data/lib/action_view/helpers.rb +0 -2
  61. data/lib/action_view/helpers/active_model_helper.rb +17 -2
  62. data/lib/action_view/helpers/asset_tag_helper.rb +15 -33
  63. data/lib/action_view/helpers/atom_feed_helper.rb +5 -3
  64. data/lib/action_view/helpers/cache_helper.rb +4 -2
  65. data/lib/action_view/helpers/capture_helper.rb +4 -4
  66. data/lib/action_view/helpers/csrf_helper.rb +3 -1
  67. data/lib/action_view/helpers/date_helper.rb +10 -5
  68. data/lib/action_view/helpers/debug_helper.rb +3 -1
  69. data/lib/action_view/helpers/form_helper.rb +36 -30
  70. data/lib/action_view/helpers/form_options_helper.rb +7 -6
  71. data/lib/action_view/helpers/form_tag_helper.rb +17 -6
  72. data/lib/action_view/helpers/javascript_helper.rb +1 -0
  73. data/lib/action_view/helpers/number_helper.rb +16 -45
  74. data/lib/action_view/helpers/prototype_helper.rb +14 -16
  75. data/lib/action_view/helpers/raw_output_helper.rb +9 -0
  76. data/lib/action_view/helpers/record_tag_helper.rb +5 -0
  77. data/lib/action_view/helpers/sanitize_helper.rb +26 -20
  78. data/lib/action_view/helpers/scriptaculous_helper.rb +6 -5
  79. data/lib/action_view/helpers/tag_helper.rb +2 -1
  80. data/lib/action_view/helpers/text_helper.rb +24 -111
  81. data/lib/action_view/helpers/translation_helper.rb +17 -10
  82. data/lib/action_view/helpers/url_helper.rb +26 -33
  83. data/lib/action_view/log_subscriber.rb +28 -0
  84. data/lib/action_view/lookup_context.rb +2 -0
  85. data/lib/action_view/paths.rb +1 -0
  86. data/lib/action_view/railtie.rb +15 -3
  87. data/lib/action_view/render/layouts.rb +2 -1
  88. data/lib/action_view/render/partials.rb +3 -1
  89. data/lib/action_view/render/rendering.rb +2 -1
  90. data/lib/action_view/template.rb +12 -8
  91. data/lib/action_view/template/error.rb +1 -0
  92. data/lib/action_view/template/handlers.rb +1 -0
  93. data/lib/action_view/template/resolver.rb +2 -1
  94. data/lib/action_view/template/text.rb +1 -0
  95. data/lib/action_view/test_case.rb +42 -20
  96. metadata +44 -23
  97. data/lib/action_controller/polymorphic_routes.rb +0 -182
  98. data/lib/action_controller/railties/log_subscriber.rb +0 -56
  99. data/lib/action_controller/railties/url_helpers.rb +0 -14
  100. data/lib/action_dispatch/testing/assertions/model.rb +0 -19
  101. data/lib/action_view/helpers/record_identification_helper.rb +0 -20
  102. data/lib/action_view/railties/log_subscriber.rb +0 -24
@@ -1,9 +1,9 @@
1
1
  require 'set'
2
2
  require 'active_support/json'
3
- require 'active_support/core_ext/object/returning'
4
3
  require 'active_support/core_ext/object/blank'
5
4
 
6
5
  module ActionView
6
+ # = Action View Prototype Helpers
7
7
  module Helpers
8
8
  # Prototype[http://www.prototypejs.org/] is a JavaScript library that provides
9
9
  # DOM[http://en.wikipedia.org/wiki/Document_Object_Model] manipulation,
@@ -94,17 +94,15 @@ module ActionView
94
94
  # See JavaScriptGenerator for information on updating multiple elements
95
95
  # on the page in an Ajax response.
96
96
  module PrototypeHelper
97
- unless const_defined? :CALLBACKS
98
- CALLBACKS = Set.new([ :create, :uninitialized, :loading, :loaded,
99
- :interactive, :complete, :failure, :success ] +
100
- (100..599).to_a)
101
- AJAX_OPTIONS = Set.new([ :before, :after, :condition, :url,
102
- :asynchronous, :method, :insertion, :position,
103
- :form, :with, :update, :script, :type ]).merge(CALLBACKS)
104
- end
97
+ CALLBACKS = Set.new([ :create, :uninitialized, :loading, :loaded,
98
+ :interactive, :complete, :failure, :success ] +
99
+ (100..599).to_a)
100
+ AJAX_OPTIONS = Set.new([ :before, :after, :condition, :url,
101
+ :asynchronous, :method, :insertion, :position,
102
+ :form, :with, :update, :script, :type ]).merge(CALLBACKS)
105
103
 
106
104
  # Returns the JavaScript needed for a remote function.
107
- # Takes the same arguments as link_to_remote.
105
+ # See the link_to_remote documentation at http://github.com/rails/prototype_legacy_helper as it takes the same arguments.
108
106
  #
109
107
  # Example:
110
108
  # # Generates: <select id="options" onchange="new Ajax.Updater('options',
@@ -133,7 +131,7 @@ module ActionView
133
131
 
134
132
  url_options = options[:url]
135
133
  url_options = url_options.merge(:escape => false) if url_options.is_a?(Hash)
136
- function << "'#{escape_javascript(url_for(url_options))}'"
134
+ function << "'#{html_escape(escape_javascript(url_for(url_options)))}'"
137
135
  function << ", #{javascript_options})"
138
136
 
139
137
  function = "#{options[:before]}; #{function}" if options[:before]
@@ -141,7 +139,7 @@ module ActionView
141
139
  function = "if (#{options[:condition]}) { #{function}; }" if options[:condition]
142
140
  function = "if (confirm('#{escape_javascript(options[:confirm])}')) { #{function}; }" if options[:confirm]
143
141
 
144
- return function
142
+ return function.html_safe
145
143
  end
146
144
 
147
145
  # All the methods were moved to GeneratorMethods so that
@@ -229,7 +227,7 @@ module ActionView
229
227
  # <script> tag.
230
228
  module GeneratorMethods
231
229
  def to_s #:nodoc:
232
- returning javascript = @lines * $/ do
230
+ (@lines * $/).tap do |javascript|
233
231
  if ActionView::Base.debug_rjs
234
232
  source = javascript.dup
235
233
  javascript.replace "try {\n#{source}\n} catch (e) "
@@ -531,9 +529,9 @@ module ActionView
531
529
  end
532
530
 
533
531
  def record(line)
534
- returning line = "#{line.to_s.chomp.gsub(/\;\z/, '')};" do
535
- self << line
536
- end
532
+ line = "#{line.to_s.chomp.gsub(/\;\z/, '')};"
533
+ self << line
534
+ line
537
535
  end
538
536
 
539
537
  def render(*options)
@@ -1,6 +1,15 @@
1
1
  module ActionView #:nodoc:
2
+ # = Action View Raw Output Helper
2
3
  module Helpers #:nodoc:
3
4
  module RawOutputHelper
5
+ # This method outputs without escaping a string. Since escaping tags is
6
+ # now default, this can be used when you don't want Rails to automatically
7
+ # escape tags. This is not recommended if the data is coming from the user's
8
+ # input.
9
+ #
10
+ # For example:
11
+ #
12
+ # <%=raw @user.name %>
4
13
  def raw(stringish)
5
14
  stringish.to_s.html_safe
6
15
  end
@@ -1,6 +1,11 @@
1
+ require 'action_controller/record_identifier'
2
+
1
3
  module ActionView
4
+ # = Action View Record Tag Helpers
2
5
  module Helpers
3
6
  module RecordTagHelper
7
+ include ActionController::RecordIdentifier
8
+
4
9
  # Produces a wrapper DIV element with id and class parameters that
5
10
  # relate to the specified Active Record object. Usage example:
6
11
  #
@@ -2,19 +2,25 @@ require 'action_controller/vendor/html-scanner'
2
2
  require 'action_view/helpers/tag_helper'
3
3
 
4
4
  module ActionView
5
+ # = Action View Sanitize Helpers
5
6
  module Helpers #:nodoc:
6
7
  # The SanitizeHelper module provides a set of methods for scrubbing text of undesired HTML elements.
7
- # These helper methods extend ActionView making them callable within your template files.
8
+ # These helper methods extend Action View making them callable within your template files.
8
9
  module SanitizeHelper
9
- # This +sanitize+ helper will html encode all tags and strip all attributes that aren't specifically allowed.
10
- # It also strips href/src tags with invalid protocols, like javascript: especially. It does its best to counter any
11
- # tricks that hackers may use, like throwing in unicode/ascii/hex values to get past the javascript: filters. Check out
10
+ # This +sanitize+ helper will html encode all tags and strip all attributes that
11
+ # aren't specifically allowed.
12
+ #
13
+ # It also strips href/src tags with invalid protocols, like javascript: especially.
14
+ # It does its best to counter any tricks that hackers may use, like throwing in
15
+ # unicode/ascii/hex values to get past the javascript: filters. Check out
12
16
  # the extensive test suite.
13
17
  #
14
18
  # <%= sanitize @article.body %>
15
19
  #
16
- # You can add or remove tags/attributes if you want to customize it a bit. See ActionView::Base for full docs on the
17
- # available options. You can add tags/attributes for single uses of +sanitize+ by passing either the <tt>:attributes</tt> or <tt>:tags</tt> options:
20
+ # You can add or remove tags/attributes if you want to customize it a bit.
21
+ # See ActionView::Base for full docs on the available options. You can add
22
+ # tags/attributes for single uses of +sanitize+ by passing either the
23
+ # <tt>:attributes</tt> or <tt>:tags</tt> options:
18
24
  #
19
25
  # Normal Use
20
26
  #
@@ -26,13 +32,13 @@ module ActionView
26
32
  #
27
33
  # Add table tags to the default allowed tags
28
34
  #
29
- # Rails::Initializer.run do |config|
35
+ # class Application < Rails::Application
30
36
  # config.action_view.sanitized_allowed_tags = 'table', 'tr', 'td'
31
37
  # end
32
38
  #
33
39
  # Remove tags to the default allowed tags
34
40
  #
35
- # Rails::Initializer.run do |config|
41
+ # class Application < Rails::Application
36
42
  # config.after_initialize do
37
43
  # ActionView::Base.sanitized_allowed_tags.delete 'div'
38
44
  # end
@@ -40,7 +46,7 @@ module ActionView
40
46
  #
41
47
  # Change allowed default attributes
42
48
  #
43
- # Rails::Initializer.run do |config|
49
+ # class Application < Rails::Application
44
50
  # config.action_view.sanitized_allowed_attributes = 'id', 'class', 'style'
45
51
  # end
46
52
  #
@@ -137,7 +143,7 @@ module ActionView
137
143
  # Gets the HTML::FullSanitizer instance used by +strip_tags+. Replace with
138
144
  # any object that responds to +sanitize+.
139
145
  #
140
- # Rails::Initializer.run do |config|
146
+ # class Application < Rails::Application
141
147
  # config.action_view.full_sanitizer = MySpecialSanitizer.new
142
148
  # end
143
149
  #
@@ -148,7 +154,7 @@ module ActionView
148
154
  # Gets the HTML::LinkSanitizer instance used by +strip_links+. Replace with
149
155
  # any object that responds to +sanitize+.
150
156
  #
151
- # Rails::Initializer.run do |config|
157
+ # class Application < Rails::Application
152
158
  # config.action_view.link_sanitizer = MySpecialSanitizer.new
153
159
  # end
154
160
  #
@@ -159,7 +165,7 @@ module ActionView
159
165
  # Gets the HTML::WhiteListSanitizer instance used by sanitize and +sanitize_css+.
160
166
  # Replace with any object that responds to +sanitize+.
161
167
  #
162
- # Rails::Initializer.run do |config|
168
+ # class Application < Rails::Application
163
169
  # config.action_view.white_list_sanitizer = MySpecialSanitizer.new
164
170
  # end
165
171
  #
@@ -169,7 +175,7 @@ module ActionView
169
175
 
170
176
  # Adds valid HTML attributes that the +sanitize+ helper checks for URIs.
171
177
  #
172
- # Rails::Initializer.run do |config|
178
+ # class Application < Rails::Application
173
179
  # config.action_view.sanitized_uri_attributes = 'lowsrc', 'target'
174
180
  # end
175
181
  #
@@ -179,7 +185,7 @@ module ActionView
179
185
 
180
186
  # Adds to the Set of 'bad' tags for the +sanitize+ helper.
181
187
  #
182
- # Rails::Initializer.run do |config|
188
+ # class Application < Rails::Application
183
189
  # config.action_view.sanitized_bad_tags = 'embed', 'object'
184
190
  # end
185
191
  #
@@ -189,7 +195,7 @@ module ActionView
189
195
 
190
196
  # Adds to the Set of allowed tags for the +sanitize+ helper.
191
197
  #
192
- # Rails::Initializer.run do |config|
198
+ # class Application < Rails::Application
193
199
  # config.action_view.sanitized_allowed_tags = 'table', 'tr', 'td'
194
200
  # end
195
201
  #
@@ -199,7 +205,7 @@ module ActionView
199
205
 
200
206
  # Adds to the Set of allowed HTML attributes for the +sanitize+ helper.
201
207
  #
202
- # Rails::Initializer.run do |config|
208
+ # class Application < Rails::Application
203
209
  # config.action_view.sanitized_allowed_attributes = 'onclick', 'longdesc'
204
210
  # end
205
211
  #
@@ -209,7 +215,7 @@ module ActionView
209
215
 
210
216
  # Adds to the Set of allowed CSS properties for the #sanitize and +sanitize_css+ helpers.
211
217
  #
212
- # Rails::Initializer.run do |config|
218
+ # class Application < Rails::Application
213
219
  # config.action_view.sanitized_allowed_css_properties = 'expression'
214
220
  # end
215
221
  #
@@ -219,7 +225,7 @@ module ActionView
219
225
 
220
226
  # Adds to the Set of allowed CSS keywords for the +sanitize+ and +sanitize_css+ helpers.
221
227
  #
222
- # Rails::Initializer.run do |config|
228
+ # class Application < Rails::Application
223
229
  # config.action_view.sanitized_allowed_css_keywords = 'expression'
224
230
  # end
225
231
  #
@@ -229,7 +235,7 @@ module ActionView
229
235
 
230
236
  # Adds to the Set of allowed shorthand CSS properties for the +sanitize+ and +sanitize_css+ helpers.
231
237
  #
232
- # Rails::Initializer.run do |config|
238
+ # class Application < Rails::Application
233
239
  # config.action_view.sanitized_shorthand_css_properties = 'expression'
234
240
  # end
235
241
  #
@@ -239,7 +245,7 @@ module ActionView
239
245
 
240
246
  # Adds to the Set of allowed protocols for the +sanitize+ helper.
241
247
  #
242
- # Rails::Initializer.run do |config|
248
+ # class Application < Rails::Application
243
249
  # config.action_view.sanitized_allowed_protocols = 'ssh', 'feed'
244
250
  # end
245
251
  #
@@ -2,9 +2,11 @@ require 'action_view/helpers/javascript_helper'
2
2
  require 'active_support/json'
3
3
 
4
4
  module ActionView
5
+ # = Action View Scriptaculous Helpers
5
6
  module Helpers
6
- # Provides a set of helpers for calling Scriptaculous JavaScript
7
- # functions, including those which create Ajax controls and visual effects.
7
+ # Provides a set of helpers for calling Scriptaculous[http://script.aculo.us/]
8
+ # JavaScript functions, including those which create Ajax controls and visual
9
+ # effects.
8
10
  #
9
11
  # To be able to use these helpers, you must include the Prototype
10
12
  # JavaScript framework and the Scriptaculous JavaScript library in your
@@ -12,12 +14,11 @@ module ActionView
12
14
  # for more information on including the necessary JavaScript.
13
15
  #
14
16
  # The Scriptaculous helpers' behavior can be tweaked with various options.
17
+ #
15
18
  # See the documentation at http://script.aculo.us for more information on
16
19
  # using these helpers in your application.
17
20
  module ScriptaculousHelper
18
- unless const_defined? :TOGGLE_EFFECTS
19
- TOGGLE_EFFECTS = [:toggle_appear, :toggle_slide, :toggle_blind]
20
- end
21
+ TOGGLE_EFFECTS = [:toggle_appear, :toggle_slide, :toggle_blind]
21
22
 
22
23
  # Returns a JavaScript snippet to be used on the Ajax callbacks for
23
24
  # starting visual effects.
@@ -2,6 +2,7 @@ require 'active_support/core_ext/object/blank'
2
2
  require 'set'
3
3
 
4
4
  module ActionView
5
+ # = Action View Tag Helpers
5
6
  module Helpers #:nodoc:
6
7
  # Provides methods to generate HTML tags programmatically when you can't use
7
8
  # a Builder. By default, they output XHTML compliant tags.
@@ -121,7 +122,7 @@ module ActionView
121
122
  attrs << %(#{key}="#{key}") if value
122
123
  elsif !value.nil?
123
124
  final_value = value.is_a?(Array) ? value.join(" ") : value
124
- final_value = escape_once(final_value) if escape
125
+ final_value = html_escape(final_value) if escape
125
126
  attrs << %(#{key}="#{final_value}")
126
127
  end
127
128
  end
@@ -3,10 +3,11 @@ require 'active_support/core_ext/string/filters'
3
3
  require 'action_view/helpers/tag_helper'
4
4
 
5
5
  module ActionView
6
+ # = Action View Text Helpers
6
7
  module Helpers #:nodoc:
7
8
  # The TextHelper module provides a set of methods for filtering, formatting
8
9
  # and transforming strings, which can reduce the amount of inline Ruby code in
9
- # your views. These helper methods extend ActionView making them callable
10
+ # your views. These helper methods extend Action View making them callable
10
11
  # within your template files.
11
12
  module TextHelper
12
13
  # The preferred method of outputting text in your views is to use the
@@ -40,6 +41,10 @@ module ActionView
40
41
  #
41
42
  # Pass a <tt>:separator</tt> to truncate +text+ at a natural break.
42
43
  #
44
+ # The result is not marked as HTML-safe, so will be subject to the default escaping when
45
+ # used in views, unless wrapped by <tt>raw()</tt>. Care should be taken if +text+ contains HTML tags
46
+ # or entities, because truncation may produce invalid HTML (such as unbalanced or incomplete tags).
47
+ #
43
48
  # ==== Examples
44
49
  #
45
50
  # truncate("Once upon a time in a world far far away")
@@ -48,33 +53,16 @@ module ActionView
48
53
  # truncate("Once upon a time in a world far far away", :length => 17)
49
54
  # # => "Once upon a ti..."
50
55
  #
51
- # truncate("Once upon a time in a world far far away", :lenght => 17, :separator => ' ')
56
+ # truncate("Once upon a time in a world far far away", :length => 17, :separator => ' ')
52
57
  # # => "Once upon a..."
53
58
  #
54
59
  # truncate("And they found that many people were sleeping better.", :length => 25, :omission => '... (continued)')
55
60
  # # => "And they f... (continued)"
56
61
  #
57
- # You can still use <tt>truncate</tt> with the old API that accepts the
58
- # +length+ as its optional second and the +ellipsis+ as its
59
- # optional third parameter:
60
- # truncate("Once upon a time in a world far far away", 14)
61
- # # => "Once upon a..."
62
- #
63
- # truncate("And they found that many people were sleeping better.", 25, "... (continued)")
64
- # # => "And they f... (continued)"
65
- def truncate(text, *args)
66
- options = args.extract_options!
67
- unless args.empty?
68
- ActiveSupport::Deprecation.warn('truncate takes an option hash instead of separate ' +
69
- 'length and omission arguments', caller)
70
-
71
- options[:length] = args[0] || 30
72
- options[:omission] = args[1] || "..."
73
- end
74
-
62
+ # truncate("<p>Once upon a time in a world far far away</p>")
63
+ # # => "<p>Once upon a time in a wo..."
64
+ def truncate(text, options = {})
75
65
  options.reverse_merge!(:length => 30)
76
-
77
- text = sanitize(text) unless text.html_safe? || options[:safe]
78
66
  text.truncate(options.delete(:length), options) if text
79
67
  end
80
68
 
@@ -106,13 +94,13 @@ module ActionView
106
94
  end
107
95
  options.reverse_merge!(:highlighter => '<strong class="highlight">\1</strong>')
108
96
 
109
- text = sanitize(text) unless text.html_safe? || options[:safe]
97
+ text = sanitize(text) unless options[:sanitize] == false
110
98
  if text.blank? || phrases.blank?
111
99
  text
112
100
  else
113
101
  match = Array(phrases).map { |p| Regexp.escape(p) }.join('|')
114
102
  text.gsub(/(#{match})(?!(?:[^<]*?)(?:["'])[^<>]*>)/i, options[:highlighter])
115
- end
103
+ end.html_safe
116
104
  end
117
105
 
118
106
  # Extracts an excerpt from +text+ that matches the first instance of +phrase+.
@@ -220,89 +208,6 @@ module ActionView
220
208
  end * "\n"
221
209
  end
222
210
 
223
- # Returns the text with all the Textile[http://www.textism.com/tools/textile] codes turned into HTML tags.
224
- #
225
- # You can learn more about Textile's syntax at its website[http://www.textism.com/tools/textile].
226
- # <i>This method is only available if RedCloth[http://redcloth.org/] is available</i>.
227
- #
228
- # ==== Examples
229
- # textilize("*This is Textile!* Rejoice!")
230
- # # => "<p><strong>This is Textile!</strong> Rejoice!</p>"
231
- #
232
- # textilize("I _love_ ROR(Ruby on Rails)!")
233
- # # => "<p>I <em>love</em> <acronym title="Ruby on Rails">ROR</acronym>!</p>"
234
- #
235
- # textilize("h2. Textile makes markup -easy- simple!")
236
- # # => "<h2>Textile makes markup <del>easy</del> simple!</h2>"
237
- #
238
- # textilize("Visit the Rails website "here":http://www.rubyonrails.org/.)
239
- # # => "<p>Visit the Rails website <a href="http://www.rubyonrails.org/">here</a>.</p>"
240
- #
241
- # textilize("This is worded <strong>strongly</strong>")
242
- # # => "<p>This is worded <strong>strongly</strong></p>"
243
- #
244
- # textilize("This is worded <strong>strongly</strong>", :filter_html)
245
- # # => "<p>This is worded &lt;strong&gt;strongly&lt;/strong&gt;</p>"
246
- #
247
- def textilize(text, *options)
248
- options ||= [:hard_breaks]
249
- text = sanitize(text) unless text.html_safe? || options.delete(:safe)
250
-
251
- if text.blank?
252
- ""
253
- else
254
- textilized = RedCloth.new(text, options)
255
- textilized.to_html
256
- end.html_safe
257
- end
258
-
259
- # Returns the text with all the Textile codes turned into HTML tags,
260
- # but without the bounding <p> tag that RedCloth adds.
261
- #
262
- # You can learn more about Textile's syntax at its website[http://www.textism.com/tools/textile].
263
- # <i>This method is only available if RedCloth[http://redcloth.org/] is available</i>.
264
- #
265
- # ==== Examples
266
- # textilize_without_paragraph("*This is Textile!* Rejoice!")
267
- # # => "<strong>This is Textile!</strong> Rejoice!"
268
- #
269
- # textilize_without_paragraph("I _love_ ROR(Ruby on Rails)!")
270
- # # => "I <em>love</em> <acronym title="Ruby on Rails">ROR</acronym>!"
271
- #
272
- # textilize_without_paragraph("h2. Textile makes markup -easy- simple!")
273
- # # => "<h2>Textile makes markup <del>easy</del> simple!</h2>"
274
- #
275
- # textilize_without_paragraph("Visit the Rails website "here":http://www.rubyonrails.org/.)
276
- # # => "Visit the Rails website <a href="http://www.rubyonrails.org/">here</a>."
277
- def textilize_without_paragraph(text, *options)
278
- textiled = textilize(text, *options)
279
- if textiled[0..2] == "<p>" then textiled = textiled[3..-1] end
280
- if textiled[-4..-1] == "</p>" then textiled = textiled[0..-5] end
281
- return textiled
282
- end
283
-
284
- # Returns the text with all the Markdown codes turned into HTML tags.
285
- # <i>This method requires BlueCloth[http://www.deveiate.org/projects/BlueCloth]
286
- # to be available</i>.
287
- #
288
- # ==== Examples
289
- # markdown("We are using __Markdown__ now!")
290
- # # => "<p>We are using <strong>Markdown</strong> now!</p>"
291
- #
292
- # markdown("We like to _write_ `code`, not just _read_ it!")
293
- # # => "<p>We like to <em>write</em> <code>code</code>, not just <em>read</em> it!</p>"
294
- #
295
- # markdown("The [Markdown website](http://daringfireball.net/projects/markdown/) has more information.")
296
- # # => "<p>The <a href="http://daringfireball.net/projects/markdown/">Markdown website</a>
297
- # # has more information.</p>"
298
- #
299
- # markdown('![The ROR logo](http://rubyonrails.com/images/rails.png "Ruby on Rails")')
300
- # # => '<p><img src="http://rubyonrails.com/images/rails.png" alt="The ROR logo" title="Ruby on Rails" /></p>'
301
- def markdown(text, *options)
302
- text = sanitize(text) unless text.html_safe? || options.delete(:safe)
303
- (text.blank? ? "" : BlueCloth.new(text).to_html).html_safe
304
- end
305
-
306
211
  # Returns +text+ transformed into HTML using simple formatting rules.
307
212
  # Two or more consecutive newlines(<tt>\n\n</tt>) are considered as a
308
213
  # paragraph and wrapped in <tt><p></tt> tags. One newline (<tt>\n</tt>) is
@@ -325,9 +230,9 @@ module ActionView
325
230
  # simple_format("Look ma! A class!", :class => 'description')
326
231
  # # => "<p class='description'>Look ma! A class!</p>"
327
232
  def simple_format(text, html_options={}, options={})
328
- text = '' if text.nil?
233
+ text = ''.html_safe if text.nil?
329
234
  start_tag = tag('p', html_options, true)
330
- text = sanitize(text) unless text.html_safe? || options[:safe]
235
+ text = sanitize(text) unless options[:sanitize] == false
331
236
  text.gsub!(/\r\n?/, "\n") # \r\n and \r -> \n
332
237
  text.gsub!(/\n\n+/, "</p>\n\n#{start_tag}") # 2+ newline -> paragraph
333
238
  text.gsub!(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br
@@ -571,7 +476,11 @@ module ActionView
571
476
  link_text = block_given?? yield(href) : href
572
477
  href = 'http://' + href unless scheme
573
478
 
574
- content_tag(:a, link_text, link_attributes.merge('href' => href), !(options[:safe] || text.html_safe?)) + punctuation.reverse.join('')
479
+ unless options[:sanitize] == false
480
+ link_text = sanitize(link_text)
481
+ href = sanitize(href)
482
+ end
483
+ content_tag(:a, link_text, link_attributes.merge('href' => href), !!options[:sanitize]) + punctuation.reverse.join('')
575
484
  end
576
485
  end.html_safe
577
486
  end
@@ -586,7 +495,11 @@ module ActionView
586
495
  text.html_safe
587
496
  else
588
497
  display_text = (block_given?) ? yield(text) : text
589
- display_text = sanitize(display_text) unless options[:safe]
498
+
499
+ unless options[:sanitize] == false
500
+ text = sanitize(text)
501
+ display_text = sanitize(display_text) unless text == display_text
502
+ end
590
503
  mail_to text, display_text, html_options
591
504
  end
592
505
  end