actionview 6.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of actionview might be problematic. Click here for more details.

Files changed (113) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +271 -0
  3. data/MIT-LICENSE +21 -0
  4. data/README.rdoc +40 -0
  5. data/lib/action_view.rb +98 -0
  6. data/lib/action_view/base.rb +312 -0
  7. data/lib/action_view/buffers.rb +67 -0
  8. data/lib/action_view/cache_expiry.rb +54 -0
  9. data/lib/action_view/context.rb +32 -0
  10. data/lib/action_view/dependency_tracker.rb +175 -0
  11. data/lib/action_view/digestor.rb +126 -0
  12. data/lib/action_view/flows.rb +76 -0
  13. data/lib/action_view/gem_version.rb +17 -0
  14. data/lib/action_view/helpers.rb +66 -0
  15. data/lib/action_view/helpers/active_model_helper.rb +55 -0
  16. data/lib/action_view/helpers/asset_tag_helper.rb +488 -0
  17. data/lib/action_view/helpers/asset_url_helper.rb +470 -0
  18. data/lib/action_view/helpers/atom_feed_helper.rb +205 -0
  19. data/lib/action_view/helpers/cache_helper.rb +271 -0
  20. data/lib/action_view/helpers/capture_helper.rb +216 -0
  21. data/lib/action_view/helpers/controller_helper.rb +36 -0
  22. data/lib/action_view/helpers/csp_helper.rb +26 -0
  23. data/lib/action_view/helpers/csrf_helper.rb +35 -0
  24. data/lib/action_view/helpers/date_helper.rb +1200 -0
  25. data/lib/action_view/helpers/debug_helper.rb +36 -0
  26. data/lib/action_view/helpers/form_helper.rb +2569 -0
  27. data/lib/action_view/helpers/form_options_helper.rb +896 -0
  28. data/lib/action_view/helpers/form_tag_helper.rb +920 -0
  29. data/lib/action_view/helpers/javascript_helper.rb +95 -0
  30. data/lib/action_view/helpers/number_helper.rb +456 -0
  31. data/lib/action_view/helpers/output_safety_helper.rb +70 -0
  32. data/lib/action_view/helpers/rendering_helper.rb +101 -0
  33. data/lib/action_view/helpers/sanitize_helper.rb +171 -0
  34. data/lib/action_view/helpers/tag_helper.rb +314 -0
  35. data/lib/action_view/helpers/tags.rb +44 -0
  36. data/lib/action_view/helpers/tags/base.rb +196 -0
  37. data/lib/action_view/helpers/tags/check_box.rb +66 -0
  38. data/lib/action_view/helpers/tags/checkable.rb +18 -0
  39. data/lib/action_view/helpers/tags/collection_check_boxes.rb +36 -0
  40. data/lib/action_view/helpers/tags/collection_helpers.rb +119 -0
  41. data/lib/action_view/helpers/tags/collection_radio_buttons.rb +31 -0
  42. data/lib/action_view/helpers/tags/collection_select.rb +30 -0
  43. data/lib/action_view/helpers/tags/color_field.rb +27 -0
  44. data/lib/action_view/helpers/tags/date_field.rb +15 -0
  45. data/lib/action_view/helpers/tags/date_select.rb +74 -0
  46. data/lib/action_view/helpers/tags/datetime_field.rb +32 -0
  47. data/lib/action_view/helpers/tags/datetime_local_field.rb +21 -0
  48. data/lib/action_view/helpers/tags/datetime_select.rb +10 -0
  49. data/lib/action_view/helpers/tags/email_field.rb +10 -0
  50. data/lib/action_view/helpers/tags/file_field.rb +10 -0
  51. data/lib/action_view/helpers/tags/grouped_collection_select.rb +31 -0
  52. data/lib/action_view/helpers/tags/hidden_field.rb +10 -0
  53. data/lib/action_view/helpers/tags/label.rb +81 -0
  54. data/lib/action_view/helpers/tags/month_field.rb +15 -0
  55. data/lib/action_view/helpers/tags/number_field.rb +20 -0
  56. data/lib/action_view/helpers/tags/password_field.rb +14 -0
  57. data/lib/action_view/helpers/tags/placeholderable.rb +24 -0
  58. data/lib/action_view/helpers/tags/radio_button.rb +33 -0
  59. data/lib/action_view/helpers/tags/range_field.rb +10 -0
  60. data/lib/action_view/helpers/tags/search_field.rb +27 -0
  61. data/lib/action_view/helpers/tags/select.rb +43 -0
  62. data/lib/action_view/helpers/tags/tel_field.rb +10 -0
  63. data/lib/action_view/helpers/tags/text_area.rb +24 -0
  64. data/lib/action_view/helpers/tags/text_field.rb +34 -0
  65. data/lib/action_view/helpers/tags/time_field.rb +15 -0
  66. data/lib/action_view/helpers/tags/time_select.rb +10 -0
  67. data/lib/action_view/helpers/tags/time_zone_select.rb +22 -0
  68. data/lib/action_view/helpers/tags/translator.rb +39 -0
  69. data/lib/action_view/helpers/tags/url_field.rb +10 -0
  70. data/lib/action_view/helpers/tags/week_field.rb +15 -0
  71. data/lib/action_view/helpers/text_helper.rb +486 -0
  72. data/lib/action_view/helpers/translation_helper.rb +145 -0
  73. data/lib/action_view/helpers/url_helper.rb +676 -0
  74. data/lib/action_view/layouts.rb +433 -0
  75. data/lib/action_view/locale/en.yml +56 -0
  76. data/lib/action_view/log_subscriber.rb +96 -0
  77. data/lib/action_view/lookup_context.rb +316 -0
  78. data/lib/action_view/model_naming.rb +14 -0
  79. data/lib/action_view/path_set.rb +95 -0
  80. data/lib/action_view/railtie.rb +105 -0
  81. data/lib/action_view/record_identifier.rb +112 -0
  82. data/lib/action_view/renderer/abstract_renderer.rb +108 -0
  83. data/lib/action_view/renderer/partial_renderer.rb +563 -0
  84. data/lib/action_view/renderer/partial_renderer/collection_caching.rb +103 -0
  85. data/lib/action_view/renderer/renderer.rb +68 -0
  86. data/lib/action_view/renderer/streaming_template_renderer.rb +105 -0
  87. data/lib/action_view/renderer/template_renderer.rb +108 -0
  88. data/lib/action_view/rendering.rb +171 -0
  89. data/lib/action_view/routing_url_for.rb +146 -0
  90. data/lib/action_view/tasks/cache_digests.rake +25 -0
  91. data/lib/action_view/template.rb +393 -0
  92. data/lib/action_view/template/error.rb +161 -0
  93. data/lib/action_view/template/handlers.rb +92 -0
  94. data/lib/action_view/template/handlers/builder.rb +25 -0
  95. data/lib/action_view/template/handlers/erb.rb +84 -0
  96. data/lib/action_view/template/handlers/erb/erubi.rb +87 -0
  97. data/lib/action_view/template/handlers/html.rb +11 -0
  98. data/lib/action_view/template/handlers/raw.rb +11 -0
  99. data/lib/action_view/template/html.rb +43 -0
  100. data/lib/action_view/template/inline.rb +22 -0
  101. data/lib/action_view/template/raw_file.rb +28 -0
  102. data/lib/action_view/template/resolver.rb +394 -0
  103. data/lib/action_view/template/sources.rb +13 -0
  104. data/lib/action_view/template/sources/file.rb +17 -0
  105. data/lib/action_view/template/text.rb +35 -0
  106. data/lib/action_view/template/types.rb +57 -0
  107. data/lib/action_view/test_case.rb +300 -0
  108. data/lib/action_view/testing/resolvers.rb +67 -0
  109. data/lib/action_view/unbound_template.rb +32 -0
  110. data/lib/action_view/version.rb +10 -0
  111. data/lib/action_view/view_paths.rb +129 -0
  112. data/lib/assets/compiled/rails-ujs.js +746 -0
  113. metadata +260 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '09307c25b4aca33f07c78f0eb2b2e1dcb83316272272340495d9bdb71200b66c'
4
+ data.tar.gz: c721b0700848cd657d418b9369ce575abfc12205e764cbdd04aa4f23320b80be
5
+ SHA512:
6
+ metadata.gz: acd68ab05735381289baf92c2895b30dc73b8e25e36ea9b5496104e66d46d630e352785750518404da5c71cade47b8987effe98fcc7e35d6d108dfba51bb2b4f
7
+ data.tar.gz: d6e8f0d10ff2d4048c7ad3469584153f6faf284853b7f1afd191dbd3b3b469295855655c5ac59b986c52a894a7c774d11f0a09e747a492ad6d3b0e5edfb0bf27
@@ -0,0 +1,271 @@
1
+ ## Rails 6.0.0 (August 16, 2019) ##
2
+
3
+ * ActionView::Helpers::SanitizeHelper: support rails-html-sanitizer 1.1.0.
4
+
5
+ *Juanito Fatas*
6
+
7
+
8
+ ## Rails 6.0.0.rc2 (July 22, 2019) ##
9
+
10
+ * Fix `select_tag` so that it doesn't change `options` when `include_blank` is present.
11
+
12
+ *Younes SERRAJ*
13
+
14
+
15
+ ## Rails 6.0.0.rc1 (April 24, 2019) ##
16
+
17
+ * Fix partial caching skips same item issue
18
+
19
+ If we render cached collection partials with repeated items, those repeated items
20
+ will get skipped. For example, if you have 5 identical items in your collection, Rails
21
+ only renders the first one when `cached` is set to true. But it should render all
22
+ 5 items instead.
23
+
24
+ Fixes #35114.
25
+
26
+ *Stan Lo*
27
+
28
+ * Only clear ActionView cache in development on file changes
29
+
30
+ To speed up development mode, view caches are only cleared when files in
31
+ the view paths have changed. Applications which have implemented custom
32
+ `ActionView::Resolver` subclasses may need to add their own cache clearing.
33
+
34
+ *John Hawthorn*
35
+
36
+ * Fix `ActionView::FixtureResolver` so that it handles template variants correctly.
37
+
38
+ *Edward Rudd*
39
+
40
+
41
+ ## Rails 6.0.0.beta3 (March 11, 2019) ##
42
+
43
+ * Only accept formats from registered mime types
44
+
45
+ A lack of filtering on mime types could allow an attacker to read
46
+ arbitrary files on the target server or to perform a denial of service
47
+ attack.
48
+
49
+ Fixes CVE-2019-5418
50
+ Fixes CVE-2019-5419
51
+
52
+ *John Hawthorn*, *Eileen M. Uchitelle*, *Aaron Patterson*
53
+
54
+
55
+ ## Rails 6.0.0.beta2 (February 25, 2019) ##
56
+
57
+ * `ActionView::Template.finalize_compiled_template_methods` is deprecated with
58
+ no replacement.
59
+
60
+ *tenderlove*
61
+
62
+ * `config.action_view.finalize_compiled_template_methods` is deprecated with
63
+ no replacement.
64
+
65
+ *tenderlove*
66
+
67
+ * Ensure unique DOM IDs for collection inputs with float values.
68
+
69
+ Fixes #34974.
70
+
71
+ *Mark Edmondson*
72
+
73
+
74
+ ## Rails 6.0.0.beta1 (January 18, 2019) ##
75
+
76
+ * [Rename npm package](https://github.com/rails/rails/pull/34905) from
77
+ [`rails-ujs`](https://www.npmjs.com/package/rails-ujs) to
78
+ [`@rails/ujs`](https://www.npmjs.com/package/@rails/ujs).
79
+
80
+ *Javan Makhmali*
81
+
82
+ * Remove deprecated `image_alt` helper.
83
+
84
+ *Rafael Mendonça França*
85
+
86
+ * Fix the need of `#protect_against_forgery?` method defined in
87
+ `ActionView::Base` subclasses. This prevents the use of forms and buttons.
88
+
89
+ *Genadi Samokovarov*
90
+
91
+ * Fix UJS permanently showing disabled text in a[data-remote][data-disable-with] elements within forms.
92
+
93
+ Fixes #33889.
94
+
95
+ *Wolfgang Hobmaier*
96
+
97
+ * Prevent non-primary mouse keys from triggering Rails UJS click handlers.
98
+ Firefox fires click events even if the click was triggered by non-primary mouse keys such as right- or scroll-wheel-clicks.
99
+ For example, right-clicking a link such as the one described below (with an underlying ajax request registered on click) should not cause that request to occur.
100
+
101
+ ```
102
+ <%= link_to 'Remote', remote_path, class: 'remote', remote: true, data: { type: :json } %>
103
+ ```
104
+
105
+ Fixes #34541.
106
+
107
+ *Wolfgang Hobmaier*
108
+
109
+ * Prevent `ActionView::TextHelper#word_wrap` from unexpectedly stripping white space from the _left_ side of lines.
110
+
111
+ For example, given input like this:
112
+
113
+ ```
114
+ This is a paragraph with an initial indent,
115
+ followed by additional lines that are not indented,
116
+ and finally terminated with a blockquote:
117
+ "A pithy saying"
118
+ ```
119
+
120
+ Calling `word_wrap` should not trim the indents on the first and last lines.
121
+
122
+ Fixes #34487.
123
+
124
+ *Lyle Mullican*
125
+
126
+ * Add allocations to template rendering instrumentation.
127
+
128
+ Adds the allocations for template and partial rendering to the server output on render.
129
+
130
+ ```
131
+ Rendered posts/_form.html.erb (Duration: 7.1ms | Allocations: 6004)
132
+ Rendered posts/new.html.erb within layouts/application (Duration: 8.3ms | Allocations: 6654)
133
+ Completed 200 OK in 858ms (Views: 848.4ms | ActiveRecord: 0.4ms | Allocations: 1539564)
134
+ ```
135
+
136
+ *Eileen M. Uchitelle*, *Aaron Patterson*
137
+
138
+ * Respect the `only_path` option passed to `url_for` when the options are passed in as an array
139
+
140
+ Fixes #33237.
141
+
142
+ *Joel Ambass*
143
+
144
+ * Deprecate calling private model methods from view helpers.
145
+
146
+ For example, in methods like `options_from_collection_for_select`
147
+ and `collection_select` it is possible to call private methods from
148
+ the objects used.
149
+
150
+ Fixes #33546.
151
+
152
+ *Ana María Martínez Gómez*
153
+
154
+ * Fix issue with `button_to`'s `to_form_params`
155
+
156
+ `button_to` was throwing exception when invoked with `params` hash that
157
+ contains symbol and string keys. The reason for the exception was that
158
+ `to_form_params` was comparing the given symbol and string keys.
159
+
160
+ The issue is fixed by turning all keys to strings inside
161
+ `to_form_params` before comparing them.
162
+
163
+ *Georgi Georgiev*
164
+
165
+ * Mark arrays of translations as trusted safe by using the `_html` suffix.
166
+
167
+ Example:
168
+
169
+ en:
170
+ foo_html:
171
+ - "One"
172
+ - "<strong>Two</strong>"
173
+ - "Three &#128075; &#128578;"
174
+
175
+ *Juan Broullon*
176
+
177
+ * Add `year_format` option to date_select tag. This option makes it possible to customize year
178
+ names. Lambda should be passed to use this option.
179
+
180
+ Example:
181
+
182
+ date_select('user_birthday', '', start_year: 1998, end_year: 2000, year_format: ->year { "Heisei #{year - 1988}" })
183
+
184
+ The HTML produced:
185
+
186
+ <select id="user_birthday__1i" name="user_birthday[(1i)]">
187
+ <option value="1998">Heisei 10</option>
188
+ <option value="1999">Heisei 11</option>
189
+ <option value="2000">Heisei 12</option>
190
+ </select>
191
+ /* The rest is omitted */
192
+
193
+ *Koki Ryu*
194
+
195
+ * Fix JavaScript views rendering does not work with Firefox when using
196
+ Content Security Policy.
197
+
198
+ Fixes #32577.
199
+
200
+ *Yuji Yaginuma*
201
+
202
+ * Add the `nonce: true` option for `javascript_include_tag` helper to
203
+ support automatic nonce generation for Content Security Policy.
204
+ Works the same way as `javascript_tag nonce: true` does.
205
+
206
+ *Yaroslav Markin*
207
+
208
+ * Remove `ActionView::Helpers::RecordTagHelper`.
209
+
210
+ *Yoshiyuki Hirano*
211
+
212
+ * Disable `ActionView::Template` finalizers in test environment.
213
+
214
+ Template finalization can be expensive in large view test suites.
215
+ Add a configuration option,
216
+ `action_view.finalize_compiled_template_methods`, and turn it off in
217
+ the test environment.
218
+
219
+ *Simon Coffey*
220
+
221
+ * Extract the `confirm` call in its own, overridable method in `rails_ujs`.
222
+
223
+ Example:
224
+
225
+ Rails.confirm = function(message, element) {
226
+ return (my_bootstrap_modal_confirm(message));
227
+ }
228
+
229
+ *Mathieu Mahé*
230
+
231
+ * Enable select tag helper to mark `prompt` option as `selected` and/or `disabled` for `required`
232
+ field.
233
+
234
+ Example:
235
+
236
+ select :post,
237
+ :category,
238
+ ["lifestyle", "programming", "spiritual"],
239
+ { selected: "", disabled: "", prompt: "Choose one" },
240
+ { required: true }
241
+
242
+ Placeholder option would be selected and disabled.
243
+
244
+ The HTML produced:
245
+
246
+ <select required="required" name="post[category]" id="post_category">
247
+ <option disabled="disabled" selected="selected" value="">Choose one</option>
248
+ <option value="lifestyle">lifestyle</option>
249
+ <option value="programming">programming</option>
250
+ <option value="spiritual">spiritual</option></select>
251
+
252
+ *Sergey Prikhodko*
253
+
254
+ * Don't enforce UTF-8 by default.
255
+
256
+ With the disabling of TLS 1.0 by most major websites, continuing to run
257
+ IE8 or lower becomes increasingly difficult so default to not enforcing
258
+ UTF-8 encoding as it's not relevant to other browsers.
259
+
260
+ *Andrew White*
261
+
262
+ * Change translation key of `submit_tag` from `module_name_class_name` to `module_name/class_name`.
263
+
264
+ *Rui Onodera*
265
+
266
+ * Rails 6 requires Ruby 2.5.0 or newer.
267
+
268
+ *Jeremy Daer*, *Kasper Timm Hansen*
269
+
270
+
271
+ Please check [5-2-stable](https://github.com/rails/rails/blob/5-2-stable/actionview/CHANGELOG.md) for previous changes.
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2004-2019 David Heinemeier Hansson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
@@ -0,0 +1,40 @@
1
+ = Action View
2
+
3
+ Action View is a framework for handling view template lookup and rendering, and provides
4
+ view helpers that assist when building HTML forms, Atom feeds and more.
5
+ Template formats that Action View handles are ERB (embedded Ruby, typically
6
+ used to inline short Ruby snippets inside HTML), and XML Builder.
7
+
8
+ You can read more about Action View in the {Action View Overview}[https://edgeguides.rubyonrails.org/action_view_overview.html] guide.
9
+
10
+ == Download and installation
11
+
12
+ The latest version of Action View can be installed with RubyGems:
13
+
14
+ $ gem install actionview
15
+
16
+ Source code can be downloaded as part of the Rails project on GitHub:
17
+
18
+ * https://github.com/rails/rails/tree/master/actionview
19
+
20
+
21
+ == License
22
+
23
+ Action View is released under the MIT license:
24
+
25
+ * https://opensource.org/licenses/MIT
26
+
27
+
28
+ == Support
29
+
30
+ API documentation is at
31
+
32
+ * https://api.rubyonrails.org
33
+
34
+ Bug reports for the Ruby on Rails project can be filed here:
35
+
36
+ * https://github.com/rails/rails/issues
37
+
38
+ Feature requests should be discussed on the rails-core mailing list here:
39
+
40
+ * https://groups.google.com/forum/?fromgroups#!forum/rubyonrails-core
@@ -0,0 +1,98 @@
1
+ # frozen_string_literal: true
2
+
3
+ #--
4
+ # Copyright (c) 2004-2019 David Heinemeier Hansson
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining
7
+ # a copy of this software and associated documentation files (the
8
+ # "Software"), to deal in the Software without restriction, including
9
+ # without limitation the rights to use, copy, modify, merge, publish,
10
+ # distribute, sublicense, and/or sell copies of the Software, and to
11
+ # permit persons to whom the Software is furnished to do so, subject to
12
+ # the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be
15
+ # included in all copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ #++
25
+
26
+ require "active_support"
27
+ require "active_support/rails"
28
+ require "action_view/version"
29
+
30
+ module ActionView
31
+ extend ActiveSupport::Autoload
32
+
33
+ ENCODING_FLAG = '#.*coding[:=]\s*(\S+)[ \t]*'
34
+
35
+ eager_autoload do
36
+ autoload :Base
37
+ autoload :Context
38
+ autoload :Digestor
39
+ autoload :Helpers
40
+ autoload :LookupContext
41
+ autoload :Layouts
42
+ autoload :PathSet
43
+ autoload :RecordIdentifier
44
+ autoload :Rendering
45
+ autoload :RoutingUrlFor
46
+ autoload :Template
47
+ autoload :UnboundTemplate
48
+ autoload :ViewPaths
49
+
50
+ autoload_under "renderer" do
51
+ autoload :Renderer
52
+ autoload :AbstractRenderer
53
+ autoload :PartialRenderer
54
+ autoload :TemplateRenderer
55
+ autoload :StreamingTemplateRenderer
56
+ end
57
+
58
+ autoload_at "action_view/template/resolver" do
59
+ autoload :Resolver
60
+ autoload :PathResolver
61
+ autoload :OptimizedFileSystemResolver
62
+ autoload :FallbackFileSystemResolver
63
+ end
64
+
65
+ autoload_at "action_view/buffers" do
66
+ autoload :OutputBuffer
67
+ autoload :StreamingBuffer
68
+ end
69
+
70
+ autoload_at "action_view/flows" do
71
+ autoload :OutputFlow
72
+ autoload :StreamingFlow
73
+ end
74
+
75
+ autoload_at "action_view/template/error" do
76
+ autoload :MissingTemplate
77
+ autoload :ActionViewError
78
+ autoload :EncodingError
79
+ autoload :TemplateError
80
+ autoload :WrongEncodingError
81
+ end
82
+ end
83
+
84
+ autoload :CacheExpiry
85
+ autoload :TestCase
86
+
87
+ def self.eager_load!
88
+ super
89
+ ActionView::Helpers.eager_load!
90
+ ActionView::Template.eager_load!
91
+ end
92
+ end
93
+
94
+ require "active_support/core_ext/string/output_safety"
95
+
96
+ ActiveSupport.on_load(:i18n) do
97
+ I18n.load_path << File.expand_path("action_view/locale/en.yml", __dir__)
98
+ end
@@ -0,0 +1,312 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/module/attr_internal"
4
+ require "active_support/core_ext/module/attribute_accessors"
5
+ require "active_support/ordered_options"
6
+ require "active_support/deprecation"
7
+ require "action_view/log_subscriber"
8
+ require "action_view/helpers"
9
+ require "action_view/context"
10
+ require "action_view/template"
11
+ require "action_view/lookup_context"
12
+
13
+ module ActionView #:nodoc:
14
+ # = Action View Base
15
+ #
16
+ # Action View templates can be written in several ways.
17
+ # If the template file has a <tt>.erb</tt> extension, then it uses the erubi[https://rubygems.org/gems/erubi]
18
+ # template system which can embed Ruby into an HTML document.
19
+ # If the template file has a <tt>.builder</tt> extension, then Jim Weirich's Builder::XmlMarkup library is used.
20
+ #
21
+ # == ERB
22
+ #
23
+ # You trigger ERB by using embeddings such as <tt><% %></tt>, <tt><% -%></tt>, and <tt><%= %></tt>. The <tt><%= %></tt> tag set is used when you want output. Consider the
24
+ # following loop for names:
25
+ #
26
+ # <b>Names of all the people</b>
27
+ # <% @people.each do |person| %>
28
+ # Name: <%= person.name %><br/>
29
+ # <% end %>
30
+ #
31
+ # The loop is setup in regular embedding tags <tt><% %></tt>, and the name is written using the output embedding tag <tt><%= %></tt>. Note that this
32
+ # is not just a usage suggestion. Regular output functions like print or puts won't work with ERB templates. So this would be wrong:
33
+ #
34
+ # <%# WRONG %>
35
+ # Hi, Mr. <% puts "Frodo" %>
36
+ #
37
+ # If you absolutely must write from within a function use +concat+.
38
+ #
39
+ # When on a line that only contains whitespaces except for the tag, <tt><% %></tt> suppresses leading and trailing whitespace,
40
+ # including the trailing newline. <tt><% %></tt> and <tt><%- -%></tt> are the same.
41
+ # Note however that <tt><%= %></tt> and <tt><%= -%></tt> are different: only the latter removes trailing whitespaces.
42
+ #
43
+ # === Using sub templates
44
+ #
45
+ # Using sub templates allows you to sidestep tedious replication and extract common display structures in shared templates. The
46
+ # classic example is the use of a header and footer (even though the Action Pack-way would be to use Layouts):
47
+ #
48
+ # <%= render "shared/header" %>
49
+ # Something really specific and terrific
50
+ # <%= render "shared/footer" %>
51
+ #
52
+ # As you see, we use the output embeddings for the render methods. The render call itself will just return a string holding the
53
+ # result of the rendering. The output embedding writes it to the current template.
54
+ #
55
+ # But you don't have to restrict yourself to static includes. Templates can share variables amongst themselves by using instance
56
+ # variables defined using the regular embedding tags. Like this:
57
+ #
58
+ # <% @page_title = "A Wonderful Hello" %>
59
+ # <%= render "shared/header" %>
60
+ #
61
+ # Now the header can pick up on the <tt>@page_title</tt> variable and use it for outputting a title tag:
62
+ #
63
+ # <title><%= @page_title %></title>
64
+ #
65
+ # === Passing local variables to sub templates
66
+ #
67
+ # You can pass local variables to sub templates by using a hash with the variable names as keys and the objects as values:
68
+ #
69
+ # <%= render "shared/header", { headline: "Welcome", person: person } %>
70
+ #
71
+ # These can now be accessed in <tt>shared/header</tt> with:
72
+ #
73
+ # Headline: <%= headline %>
74
+ # First name: <%= person.first_name %>
75
+ #
76
+ # The local variables passed to sub templates can be accessed as a hash using the <tt>local_assigns</tt> hash. This lets you access the
77
+ # variables as:
78
+ #
79
+ # Headline: <%= local_assigns[:headline] %>
80
+ #
81
+ # This is useful in cases where you aren't sure if the local variable has been assigned. Alternatively, you could also use
82
+ # <tt>defined? headline</tt> to first check if the variable has been assigned before using it.
83
+ #
84
+ # === Template caching
85
+ #
86
+ # By default, Rails will compile each template to a method in order to render it. When you alter a template,
87
+ # Rails will check the file's modification time and recompile it in development mode.
88
+ #
89
+ # == Builder
90
+ #
91
+ # Builder templates are a more programmatic alternative to ERB. They are especially useful for generating XML content. An XmlMarkup object
92
+ # named +xml+ is automatically made available to templates with a <tt>.builder</tt> extension.
93
+ #
94
+ # Here are some basic examples:
95
+ #
96
+ # xml.em("emphasized") # => <em>emphasized</em>
97
+ # xml.em { xml.b("emph & bold") } # => <em><b>emph &amp; bold</b></em>
98
+ # xml.a("A Link", "href" => "http://onestepback.org") # => <a href="http://onestepback.org">A Link</a>
99
+ # xml.target("name" => "compile", "option" => "fast") # => <target option="fast" name="compile"\>
100
+ # # NOTE: order of attributes is not specified.
101
+ #
102
+ # Any method with a block will be treated as an XML markup tag with nested markup in the block. For example, the following:
103
+ #
104
+ # xml.div do
105
+ # xml.h1(@person.name)
106
+ # xml.p(@person.bio)
107
+ # end
108
+ #
109
+ # would produce something like:
110
+ #
111
+ # <div>
112
+ # <h1>David Heinemeier Hansson</h1>
113
+ # <p>A product of Danish Design during the Winter of '79...</p>
114
+ # </div>
115
+ #
116
+ # Here is a full-length RSS example actually used on Basecamp:
117
+ #
118
+ # xml.rss("version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/") do
119
+ # xml.channel do
120
+ # xml.title(@feed_title)
121
+ # xml.link(@url)
122
+ # xml.description "Basecamp: Recent items"
123
+ # xml.language "en-us"
124
+ # xml.ttl "40"
125
+ #
126
+ # @recent_items.each do |item|
127
+ # xml.item do
128
+ # xml.title(item_title(item))
129
+ # xml.description(item_description(item)) if item_description(item)
130
+ # xml.pubDate(item_pubDate(item))
131
+ # xml.guid(@person.firm.account.url + @recent_items.url(item))
132
+ # xml.link(@person.firm.account.url + @recent_items.url(item))
133
+ #
134
+ # xml.tag!("dc:creator", item.author_name) if item_has_creator?(item)
135
+ # end
136
+ # end
137
+ # end
138
+ # end
139
+ #
140
+ # For more information on Builder please consult the {source
141
+ # code}[https://github.com/jimweirich/builder].
142
+ class Base
143
+ include Helpers, ::ERB::Util, Context
144
+
145
+ # Specify the proc used to decorate input tags that refer to attributes with errors.
146
+ cattr_accessor :field_error_proc, default: Proc.new { |html_tag, instance| "<div class=\"field_with_errors\">#{html_tag}</div>".html_safe }
147
+
148
+ # How to complete the streaming when an exception occurs.
149
+ # This is our best guess: first try to close the attribute, then the tag.
150
+ cattr_accessor :streaming_completion_on_exception, default: %("><script>window.location = "/500.html"</script></html>)
151
+
152
+ # Specify whether rendering within namespaced controllers should prefix
153
+ # the partial paths for ActiveModel objects with the namespace.
154
+ # (e.g., an Admin::PostsController would render @post using /admin/posts/_post.erb)
155
+ cattr_accessor :prefix_partial_path_with_controller_namespace, default: true
156
+
157
+ # Specify default_formats that can be rendered.
158
+ cattr_accessor :default_formats
159
+
160
+ # Specify whether an error should be raised for missing translations
161
+ cattr_accessor :raise_on_missing_translations, default: false
162
+
163
+ # Specify whether submit_tag should automatically disable on click
164
+ cattr_accessor :automatically_disable_submit_tag, default: true
165
+
166
+ class_attribute :_routes
167
+ class_attribute :logger
168
+
169
+ class << self
170
+ delegate :erb_trim_mode=, to: "ActionView::Template::Handlers::ERB"
171
+
172
+ def cache_template_loading
173
+ ActionView::Resolver.caching?
174
+ end
175
+
176
+ def cache_template_loading=(value)
177
+ ActionView::Resolver.caching = value
178
+ end
179
+
180
+ def xss_safe? #:nodoc:
181
+ true
182
+ end
183
+
184
+ def with_empty_template_cache # :nodoc:
185
+ subclass = Class.new(self) {
186
+ # We can't implement these as self.class because subclasses will
187
+ # share the same template cache as superclasses, so "changed?" won't work
188
+ # correctly.
189
+ define_method(:compiled_method_container) { subclass }
190
+ define_singleton_method(:compiled_method_container) { subclass }
191
+ }
192
+ end
193
+
194
+ def changed?(other) # :nodoc:
195
+ compiled_method_container != other.compiled_method_container
196
+ end
197
+ end
198
+
199
+ attr_reader :view_renderer, :lookup_context
200
+ attr_internal :config, :assigns
201
+
202
+ delegate :formats, :formats=, :locale, :locale=, :view_paths, :view_paths=, to: :lookup_context
203
+
204
+ def assign(new_assigns) # :nodoc:
205
+ @_assigns = new_assigns.each { |key, value| instance_variable_set("@#{key}", value) }
206
+ end
207
+
208
+ # :stopdoc:
209
+
210
+ def self.build_lookup_context(context)
211
+ case context
212
+ when ActionView::Renderer
213
+ context.lookup_context
214
+ when Array
215
+ ActionView::LookupContext.new(context)
216
+ when ActionView::PathSet
217
+ ActionView::LookupContext.new(context)
218
+ when nil
219
+ ActionView::LookupContext.new([])
220
+ else
221
+ raise NotImplementedError, context.class.name
222
+ end
223
+ end
224
+
225
+ def self.empty
226
+ with_view_paths([])
227
+ end
228
+
229
+ def self.with_view_paths(view_paths, assigns = {}, controller = nil)
230
+ with_context ActionView::LookupContext.new(view_paths), assigns, controller
231
+ end
232
+
233
+ def self.with_context(context, assigns = {}, controller = nil)
234
+ new context, assigns, controller
235
+ end
236
+
237
+ NULL = Object.new
238
+
239
+ # :startdoc:
240
+
241
+ def initialize(lookup_context = nil, assigns = {}, controller = nil, formats = NULL) #:nodoc:
242
+ @_config = ActiveSupport::InheritableOptions.new
243
+
244
+ unless formats == NULL
245
+ ActiveSupport::Deprecation.warn <<~eowarn.squish
246
+ Passing formats to ActionView::Base.new is deprecated
247
+ eowarn
248
+ end
249
+
250
+ case lookup_context
251
+ when ActionView::LookupContext
252
+ @lookup_context = lookup_context
253
+ else
254
+ ActiveSupport::Deprecation.warn <<~eowarn.squish
255
+ ActionView::Base instances should be constructed with a lookup context,
256
+ assignments, and a controller.
257
+ eowarn
258
+ @lookup_context = self.class.build_lookup_context(lookup_context)
259
+ end
260
+
261
+ @view_renderer = ActionView::Renderer.new @lookup_context
262
+ @current_template = nil
263
+
264
+ @cache_hit = {}
265
+ assign(assigns)
266
+ assign_controller(controller)
267
+ _prepare_context
268
+ end
269
+
270
+ def _run(method, template, locals, buffer, &block)
271
+ _old_output_buffer, _old_virtual_path, _old_template = @output_buffer, @virtual_path, @current_template
272
+ @current_template = template
273
+ @output_buffer = buffer
274
+ send(method, locals, buffer, &block)
275
+ ensure
276
+ @output_buffer, @virtual_path, @current_template = _old_output_buffer, _old_virtual_path, _old_template
277
+ end
278
+
279
+ def compiled_method_container
280
+ if self.class == ActionView::Base
281
+ ActiveSupport::Deprecation.warn <<~eowarn.squish
282
+ ActionView::Base instances must implement `compiled_method_container`
283
+ or use the class method `with_empty_template_cache` for constructing
284
+ an ActionView::Base instances that has an empty cache.
285
+ eowarn
286
+ end
287
+
288
+ self.class
289
+ end
290
+
291
+ def in_rendering_context(options)
292
+ old_view_renderer = @view_renderer
293
+ old_lookup_context = @lookup_context
294
+
295
+ if !lookup_context.html_fallback_for_js && options[:formats]
296
+ formats = Array(options[:formats])
297
+ if formats == [:js]
298
+ formats << :html
299
+ end
300
+ @lookup_context = lookup_context.with_prepended_formats(formats)
301
+ @view_renderer = ActionView::Renderer.new @lookup_context
302
+ end
303
+
304
+ yield @view_renderer
305
+ ensure
306
+ @view_renderer = old_view_renderer
307
+ @lookup_context = old_lookup_context
308
+ end
309
+
310
+ ActiveSupport.run_load_hooks(:action_view, self)
311
+ end
312
+ end