actionview 4.1.0.beta1
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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +274 -0
- data/MIT-LICENSE +21 -0
- data/README.rdoc +34 -0
- data/lib/action_view.rb +97 -0
- data/lib/action_view/base.rb +205 -0
- data/lib/action_view/buffers.rb +49 -0
- data/lib/action_view/context.rb +36 -0
- data/lib/action_view/dependency_tracker.rb +93 -0
- data/lib/action_view/digestor.rb +116 -0
- data/lib/action_view/flows.rb +76 -0
- data/lib/action_view/helpers.rb +64 -0
- data/lib/action_view/helpers/active_model_helper.rb +49 -0
- data/lib/action_view/helpers/asset_tag_helper.rb +322 -0
- data/lib/action_view/helpers/asset_url_helper.rb +355 -0
- data/lib/action_view/helpers/atom_feed_helper.rb +203 -0
- data/lib/action_view/helpers/cache_helper.rb +200 -0
- data/lib/action_view/helpers/capture_helper.rb +216 -0
- data/lib/action_view/helpers/controller_helper.rb +25 -0
- data/lib/action_view/helpers/csrf_helper.rb +30 -0
- data/lib/action_view/helpers/date_helper.rb +1075 -0
- data/lib/action_view/helpers/debug_helper.rb +39 -0
- data/lib/action_view/helpers/form_helper.rb +1876 -0
- data/lib/action_view/helpers/form_options_helper.rb +843 -0
- data/lib/action_view/helpers/form_tag_helper.rb +746 -0
- data/lib/action_view/helpers/javascript_helper.rb +75 -0
- data/lib/action_view/helpers/number_helper.rb +425 -0
- data/lib/action_view/helpers/output_safety_helper.rb +38 -0
- data/lib/action_view/helpers/record_tag_helper.rb +108 -0
- data/lib/action_view/helpers/rendering_helper.rb +90 -0
- data/lib/action_view/helpers/sanitize_helper.rb +256 -0
- data/lib/action_view/helpers/tag_helper.rb +176 -0
- data/lib/action_view/helpers/tags.rb +41 -0
- data/lib/action_view/helpers/tags/base.rb +148 -0
- data/lib/action_view/helpers/tags/check_box.rb +64 -0
- data/lib/action_view/helpers/tags/checkable.rb +16 -0
- data/lib/action_view/helpers/tags/collection_check_boxes.rb +44 -0
- data/lib/action_view/helpers/tags/collection_helpers.rb +85 -0
- data/lib/action_view/helpers/tags/collection_radio_buttons.rb +36 -0
- data/lib/action_view/helpers/tags/collection_select.rb +28 -0
- data/lib/action_view/helpers/tags/color_field.rb +25 -0
- data/lib/action_view/helpers/tags/date_field.rb +13 -0
- data/lib/action_view/helpers/tags/date_select.rb +72 -0
- data/lib/action_view/helpers/tags/datetime_field.rb +22 -0
- data/lib/action_view/helpers/tags/datetime_local_field.rb +19 -0
- data/lib/action_view/helpers/tags/datetime_select.rb +8 -0
- data/lib/action_view/helpers/tags/email_field.rb +8 -0
- data/lib/action_view/helpers/tags/file_field.rb +8 -0
- data/lib/action_view/helpers/tags/grouped_collection_select.rb +29 -0
- data/lib/action_view/helpers/tags/hidden_field.rb +8 -0
- data/lib/action_view/helpers/tags/label.rb +65 -0
- data/lib/action_view/helpers/tags/month_field.rb +13 -0
- data/lib/action_view/helpers/tags/number_field.rb +18 -0
- data/lib/action_view/helpers/tags/password_field.rb +12 -0
- data/lib/action_view/helpers/tags/radio_button.rb +31 -0
- data/lib/action_view/helpers/tags/range_field.rb +8 -0
- data/lib/action_view/helpers/tags/search_field.rb +24 -0
- data/lib/action_view/helpers/tags/select.rb +41 -0
- data/lib/action_view/helpers/tags/tel_field.rb +8 -0
- data/lib/action_view/helpers/tags/text_area.rb +18 -0
- data/lib/action_view/helpers/tags/text_field.rb +29 -0
- data/lib/action_view/helpers/tags/time_field.rb +13 -0
- data/lib/action_view/helpers/tags/time_select.rb +8 -0
- data/lib/action_view/helpers/tags/time_zone_select.rb +20 -0
- data/lib/action_view/helpers/tags/url_field.rb +8 -0
- data/lib/action_view/helpers/tags/week_field.rb +13 -0
- data/lib/action_view/helpers/text_helper.rb +447 -0
- data/lib/action_view/helpers/translation_helper.rb +111 -0
- data/lib/action_view/helpers/url_helper.rb +625 -0
- data/lib/action_view/layouts.rb +426 -0
- data/lib/action_view/locale/en.yml +56 -0
- data/lib/action_view/log_subscriber.rb +44 -0
- data/lib/action_view/lookup_context.rb +249 -0
- data/lib/action_view/model_naming.rb +12 -0
- data/lib/action_view/path_set.rb +77 -0
- data/lib/action_view/railtie.rb +49 -0
- data/lib/action_view/record_identifier.rb +84 -0
- data/lib/action_view/renderer/abstract_renderer.rb +47 -0
- data/lib/action_view/renderer/partial_renderer.rb +492 -0
- data/lib/action_view/renderer/renderer.rb +50 -0
- data/lib/action_view/renderer/streaming_template_renderer.rb +103 -0
- data/lib/action_view/renderer/template_renderer.rb +96 -0
- data/lib/action_view/rendering.rb +145 -0
- data/lib/action_view/routing_url_for.rb +109 -0
- data/lib/action_view/tasks/dependencies.rake +17 -0
- data/lib/action_view/template.rb +340 -0
- data/lib/action_view/template/error.rb +141 -0
- data/lib/action_view/template/handlers.rb +53 -0
- data/lib/action_view/template/handlers/builder.rb +26 -0
- data/lib/action_view/template/handlers/erb.rb +145 -0
- data/lib/action_view/template/handlers/raw.rb +11 -0
- data/lib/action_view/template/resolver.rb +329 -0
- data/lib/action_view/template/text.rb +34 -0
- data/lib/action_view/template/types.rb +57 -0
- data/lib/action_view/test_case.rb +272 -0
- data/lib/action_view/testing/resolvers.rb +50 -0
- data/lib/action_view/vendor/html-scanner.rb +20 -0
- data/lib/action_view/vendor/html-scanner/html/document.rb +68 -0
- data/lib/action_view/vendor/html-scanner/html/node.rb +532 -0
- data/lib/action_view/vendor/html-scanner/html/sanitizer.rb +188 -0
- data/lib/action_view/vendor/html-scanner/html/selector.rb +830 -0
- data/lib/action_view/vendor/html-scanner/html/tokenizer.rb +107 -0
- data/lib/action_view/vendor/html-scanner/html/version.rb +11 -0
- data/lib/action_view/version.rb +11 -0
- data/lib/action_view/view_paths.rb +96 -0
- metadata +218 -0
@@ -0,0 +1,426 @@
|
|
1
|
+
require "action_view/rendering"
|
2
|
+
require "active_support/core_ext/module/remove_method"
|
3
|
+
|
4
|
+
module ActionView
|
5
|
+
# Layouts reverse the common pattern of including shared headers and footers in many templates to isolate changes in
|
6
|
+
# repeated setups. The inclusion pattern has pages that look like this:
|
7
|
+
#
|
8
|
+
# <%= render "shared/header" %>
|
9
|
+
# Hello World
|
10
|
+
# <%= render "shared/footer" %>
|
11
|
+
#
|
12
|
+
# This approach is a decent way of keeping common structures isolated from the changing content, but it's verbose
|
13
|
+
# and if you ever want to change the structure of these two includes, you'll have to change all the templates.
|
14
|
+
#
|
15
|
+
# With layouts, you can flip it around and have the common structure know where to insert changing content. This means
|
16
|
+
# that the header and footer are only mentioned in one place, like this:
|
17
|
+
#
|
18
|
+
# // The header part of this layout
|
19
|
+
# <%= yield %>
|
20
|
+
# // The footer part of this layout
|
21
|
+
#
|
22
|
+
# And then you have content pages that look like this:
|
23
|
+
#
|
24
|
+
# hello world
|
25
|
+
#
|
26
|
+
# At rendering time, the content page is computed and then inserted in the layout, like this:
|
27
|
+
#
|
28
|
+
# // The header part of this layout
|
29
|
+
# hello world
|
30
|
+
# // The footer part of this layout
|
31
|
+
#
|
32
|
+
# == Accessing shared variables
|
33
|
+
#
|
34
|
+
# Layouts have access to variables specified in the content pages and vice versa. This allows you to have layouts with
|
35
|
+
# references that won't materialize before rendering time:
|
36
|
+
#
|
37
|
+
# <h1><%= @page_title %></h1>
|
38
|
+
# <%= yield %>
|
39
|
+
#
|
40
|
+
# ...and content pages that fulfill these references _at_ rendering time:
|
41
|
+
#
|
42
|
+
# <% @page_title = "Welcome" %>
|
43
|
+
# Off-world colonies offers you a chance to start a new life
|
44
|
+
#
|
45
|
+
# The result after rendering is:
|
46
|
+
#
|
47
|
+
# <h1>Welcome</h1>
|
48
|
+
# Off-world colonies offers you a chance to start a new life
|
49
|
+
#
|
50
|
+
# == Layout assignment
|
51
|
+
#
|
52
|
+
# You can either specify a layout declaratively (using the #layout class method) or give
|
53
|
+
# it the same name as your controller, and place it in <tt>app/views/layouts</tt>.
|
54
|
+
# If a subclass does not have a layout specified, it inherits its layout using normal Ruby inheritance.
|
55
|
+
#
|
56
|
+
# For instance, if you have PostsController and a template named <tt>app/views/layouts/posts.html.erb</tt>,
|
57
|
+
# that template will be used for all actions in PostsController and controllers inheriting
|
58
|
+
# from PostsController.
|
59
|
+
#
|
60
|
+
# If you use a module, for instance Weblog::PostsController, you will need a template named
|
61
|
+
# <tt>app/views/layouts/weblog/posts.html.erb</tt>.
|
62
|
+
#
|
63
|
+
# Since all your controllers inherit from ApplicationController, they will use
|
64
|
+
# <tt>app/views/layouts/application.html.erb</tt> if no other layout is specified
|
65
|
+
# or provided.
|
66
|
+
#
|
67
|
+
# == Inheritance Examples
|
68
|
+
#
|
69
|
+
# class BankController < ActionController::Base
|
70
|
+
# # bank.html.erb exists
|
71
|
+
#
|
72
|
+
# class ExchangeController < BankController
|
73
|
+
# # exchange.html.erb exists
|
74
|
+
#
|
75
|
+
# class CurrencyController < BankController
|
76
|
+
#
|
77
|
+
# class InformationController < BankController
|
78
|
+
# layout "information"
|
79
|
+
#
|
80
|
+
# class TellerController < InformationController
|
81
|
+
# # teller.html.erb exists
|
82
|
+
#
|
83
|
+
# class EmployeeController < InformationController
|
84
|
+
# # employee.html.erb exists
|
85
|
+
# layout nil
|
86
|
+
#
|
87
|
+
# class VaultController < BankController
|
88
|
+
# layout :access_level_layout
|
89
|
+
#
|
90
|
+
# class TillController < BankController
|
91
|
+
# layout false
|
92
|
+
#
|
93
|
+
# In these examples, we have three implicit lookup scenarios:
|
94
|
+
# * The BankController uses the "bank" layout.
|
95
|
+
# * The ExchangeController uses the "exchange" layout.
|
96
|
+
# * The CurrencyController inherits the layout from BankController.
|
97
|
+
#
|
98
|
+
# However, when a layout is explicitly set, the explicitly set layout wins:
|
99
|
+
# * The InformationController uses the "information" layout, explicitly set.
|
100
|
+
# * The TellerController also uses the "information" layout, because the parent explicitly set it.
|
101
|
+
# * The EmployeeController uses the "employee" layout, because it set the layout to nil, resetting the parent configuration.
|
102
|
+
# * The VaultController chooses a layout dynamically by calling the <tt>access_level_layout</tt> method.
|
103
|
+
# * The TillController does not use a layout at all.
|
104
|
+
#
|
105
|
+
# == Types of layouts
|
106
|
+
#
|
107
|
+
# Layouts are basically just regular templates, but the name of this template needs not be specified statically. Sometimes
|
108
|
+
# you want to alternate layouts depending on runtime information, such as whether someone is logged in or not. This can
|
109
|
+
# be done either by specifying a method reference as a symbol or using an inline method (as a proc).
|
110
|
+
#
|
111
|
+
# The method reference is the preferred approach to variable layouts and is used like this:
|
112
|
+
#
|
113
|
+
# class WeblogController < ActionController::Base
|
114
|
+
# layout :writers_and_readers
|
115
|
+
#
|
116
|
+
# def index
|
117
|
+
# # fetching posts
|
118
|
+
# end
|
119
|
+
#
|
120
|
+
# private
|
121
|
+
# def writers_and_readers
|
122
|
+
# logged_in? ? "writer_layout" : "reader_layout"
|
123
|
+
# end
|
124
|
+
# end
|
125
|
+
#
|
126
|
+
# Now when a new request for the index action is processed, the layout will vary depending on whether the person accessing
|
127
|
+
# is logged in or not.
|
128
|
+
#
|
129
|
+
# If you want to use an inline method, such as a proc, do something like this:
|
130
|
+
#
|
131
|
+
# class WeblogController < ActionController::Base
|
132
|
+
# layout proc { |controller| controller.logged_in? ? "writer_layout" : "reader_layout" }
|
133
|
+
# end
|
134
|
+
#
|
135
|
+
# If an argument isn't given to the proc, it's evaluated in the context of
|
136
|
+
# the current controller anyway.
|
137
|
+
#
|
138
|
+
# class WeblogController < ActionController::Base
|
139
|
+
# layout proc { logged_in? ? "writer_layout" : "reader_layout" }
|
140
|
+
# end
|
141
|
+
#
|
142
|
+
# Of course, the most common way of specifying a layout is still just as a plain template name:
|
143
|
+
#
|
144
|
+
# class WeblogController < ActionController::Base
|
145
|
+
# layout "weblog_standard"
|
146
|
+
# end
|
147
|
+
#
|
148
|
+
# The template will be looked always in <tt>app/views/layouts/</tt> folder. But you can point
|
149
|
+
# <tt>layouts</tt> folder direct also. <tt>layout "layouts/demo"</tt> is the same as <tt>layout "demo"</tt>.
|
150
|
+
#
|
151
|
+
# Setting the layout to nil forces it to be looked up in the filesystem and fallbacks to the parent behavior if none exists.
|
152
|
+
# Setting it to nil is useful to re-enable template lookup overriding a previous configuration set in the parent:
|
153
|
+
#
|
154
|
+
# class ApplicationController < ActionController::Base
|
155
|
+
# layout "application"
|
156
|
+
# end
|
157
|
+
#
|
158
|
+
# class PostsController < ApplicationController
|
159
|
+
# # Will use "application" layout
|
160
|
+
# end
|
161
|
+
#
|
162
|
+
# class CommentsController < ApplicationController
|
163
|
+
# # Will search for "comments" layout and fallback "application" layout
|
164
|
+
# layout nil
|
165
|
+
# end
|
166
|
+
#
|
167
|
+
# == Conditional layouts
|
168
|
+
#
|
169
|
+
# If you have a layout that by default is applied to all the actions of a controller, you still have the option of rendering
|
170
|
+
# a given action or set of actions without a layout, or restricting a layout to only a single action or a set of actions. The
|
171
|
+
# <tt>:only</tt> and <tt>:except</tt> options can be passed to the layout call. For example:
|
172
|
+
#
|
173
|
+
# class WeblogController < ActionController::Base
|
174
|
+
# layout "weblog_standard", except: :rss
|
175
|
+
#
|
176
|
+
# # ...
|
177
|
+
#
|
178
|
+
# end
|
179
|
+
#
|
180
|
+
# This will assign "weblog_standard" as the WeblogController's layout for all actions except for the +rss+ action, which will
|
181
|
+
# be rendered directly, without wrapping a layout around the rendered view.
|
182
|
+
#
|
183
|
+
# Both the <tt>:only</tt> and <tt>:except</tt> condition can accept an arbitrary number of method references, so
|
184
|
+
# #<tt>except: [ :rss, :text_only ]</tt> is valid, as is <tt>except: :rss</tt>.
|
185
|
+
#
|
186
|
+
# == Using a different layout in the action render call
|
187
|
+
#
|
188
|
+
# If most of your actions use the same layout, it makes perfect sense to define a controller-wide layout as described above.
|
189
|
+
# Sometimes you'll have exceptions where one action wants to use a different layout than the rest of the controller.
|
190
|
+
# You can do this by passing a <tt>:layout</tt> option to the <tt>render</tt> call. For example:
|
191
|
+
#
|
192
|
+
# class WeblogController < ActionController::Base
|
193
|
+
# layout "weblog_standard"
|
194
|
+
#
|
195
|
+
# def help
|
196
|
+
# render action: "help", layout: "help"
|
197
|
+
# end
|
198
|
+
# end
|
199
|
+
#
|
200
|
+
# This will override the controller-wide "weblog_standard" layout, and will render the help action with the "help" layout instead.
|
201
|
+
module Layouts
|
202
|
+
extend ActiveSupport::Concern
|
203
|
+
|
204
|
+
include ActionView::Rendering
|
205
|
+
|
206
|
+
included do
|
207
|
+
class_attribute :_layout, :_layout_conditions, :instance_accessor => false
|
208
|
+
self._layout = nil
|
209
|
+
self._layout_conditions = {}
|
210
|
+
_write_layout_method
|
211
|
+
end
|
212
|
+
|
213
|
+
delegate :_layout_conditions, to: :class
|
214
|
+
|
215
|
+
module ClassMethods
|
216
|
+
def inherited(klass) # :nodoc:
|
217
|
+
super
|
218
|
+
klass._write_layout_method
|
219
|
+
end
|
220
|
+
|
221
|
+
# This module is mixed in if layout conditions are provided. This means
|
222
|
+
# that if no layout conditions are used, this method is not used
|
223
|
+
module LayoutConditions # :nodoc:
|
224
|
+
private
|
225
|
+
|
226
|
+
# Determines whether the current action has a layout definition by
|
227
|
+
# checking the action name against the :only and :except conditions
|
228
|
+
# set by the <tt>layout</tt> method.
|
229
|
+
#
|
230
|
+
# ==== Returns
|
231
|
+
# * <tt> Boolean</tt> - True if the action has a layout definition, false otherwise.
|
232
|
+
def _conditional_layout?
|
233
|
+
return unless super
|
234
|
+
|
235
|
+
conditions = _layout_conditions
|
236
|
+
|
237
|
+
if only = conditions[:only]
|
238
|
+
only.include?(action_name)
|
239
|
+
elsif except = conditions[:except]
|
240
|
+
!except.include?(action_name)
|
241
|
+
else
|
242
|
+
true
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
# Specify the layout to use for this class.
|
248
|
+
#
|
249
|
+
# If the specified layout is a:
|
250
|
+
# String:: the String is the template name
|
251
|
+
# Symbol:: call the method specified by the symbol, which will return the template name
|
252
|
+
# false:: There is no layout
|
253
|
+
# true:: raise an ArgumentError
|
254
|
+
# nil:: Force default layout behavior with inheritance
|
255
|
+
#
|
256
|
+
# ==== Parameters
|
257
|
+
# * <tt>layout</tt> - The layout to use.
|
258
|
+
#
|
259
|
+
# ==== Options (conditions)
|
260
|
+
# * :only - A list of actions to apply this layout to.
|
261
|
+
# * :except - Apply this layout to all actions but this one.
|
262
|
+
def layout(layout, conditions = {})
|
263
|
+
include LayoutConditions unless conditions.empty?
|
264
|
+
|
265
|
+
conditions.each {|k, v| conditions[k] = Array(v).map {|a| a.to_s} }
|
266
|
+
self._layout_conditions = conditions
|
267
|
+
|
268
|
+
self._layout = layout
|
269
|
+
_write_layout_method
|
270
|
+
end
|
271
|
+
|
272
|
+
# Creates a _layout method to be called by _default_layout .
|
273
|
+
#
|
274
|
+
# If a layout is not explicitly mentioned then look for a layout with the controller's name.
|
275
|
+
# if nothing is found then try same procedure to find super class's layout.
|
276
|
+
def _write_layout_method # :nodoc:
|
277
|
+
remove_possible_method(:_layout)
|
278
|
+
|
279
|
+
prefixes = _implied_layout_name =~ /\blayouts/ ? [] : ["layouts"]
|
280
|
+
default_behavior = "lookup_context.find_all('#{_implied_layout_name}', #{prefixes.inspect}).first || super"
|
281
|
+
name_clause = if name
|
282
|
+
default_behavior
|
283
|
+
else
|
284
|
+
<<-RUBY
|
285
|
+
super
|
286
|
+
RUBY
|
287
|
+
end
|
288
|
+
|
289
|
+
layout_definition = case _layout
|
290
|
+
when String
|
291
|
+
_layout.inspect
|
292
|
+
when Symbol
|
293
|
+
<<-RUBY
|
294
|
+
#{_layout}.tap do |layout|
|
295
|
+
return #{default_behavior} if layout.nil?
|
296
|
+
unless layout.is_a?(String) || !layout
|
297
|
+
raise ArgumentError, "Your layout method :#{_layout} returned \#{layout}. It " \
|
298
|
+
"should have returned a String, false, or nil"
|
299
|
+
end
|
300
|
+
end
|
301
|
+
RUBY
|
302
|
+
when Proc
|
303
|
+
define_method :_layout_from_proc, &_layout
|
304
|
+
protected :_layout_from_proc
|
305
|
+
<<-RUBY
|
306
|
+
result = _layout_from_proc(#{_layout.arity == 0 ? '' : 'self'})
|
307
|
+
return #{default_behavior} if result.nil?
|
308
|
+
result
|
309
|
+
RUBY
|
310
|
+
when false
|
311
|
+
nil
|
312
|
+
when true
|
313
|
+
raise ArgumentError, "Layouts must be specified as a String, Symbol, Proc, false, or nil"
|
314
|
+
when nil
|
315
|
+
name_clause
|
316
|
+
end
|
317
|
+
|
318
|
+
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
319
|
+
def _layout
|
320
|
+
if _conditional_layout?
|
321
|
+
#{layout_definition}
|
322
|
+
else
|
323
|
+
#{name_clause}
|
324
|
+
end
|
325
|
+
end
|
326
|
+
private :_layout
|
327
|
+
RUBY
|
328
|
+
end
|
329
|
+
|
330
|
+
private
|
331
|
+
|
332
|
+
# If no layout is supplied, look for a template named the return
|
333
|
+
# value of this method.
|
334
|
+
#
|
335
|
+
# ==== Returns
|
336
|
+
# * <tt>String</tt> - A template name
|
337
|
+
def _implied_layout_name # :nodoc:
|
338
|
+
controller_path
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
def _normalize_options(options) # :nodoc:
|
343
|
+
super
|
344
|
+
|
345
|
+
if _include_layout?(options)
|
346
|
+
layout = options.delete(:layout) { :default }
|
347
|
+
options[:layout] = _layout_for_option(layout)
|
348
|
+
end
|
349
|
+
end
|
350
|
+
|
351
|
+
attr_internal_writer :action_has_layout
|
352
|
+
|
353
|
+
def initialize(*) # :nodoc:
|
354
|
+
@_action_has_layout = true
|
355
|
+
super
|
356
|
+
end
|
357
|
+
|
358
|
+
# Controls whether an action should be rendered using a layout.
|
359
|
+
# If you want to disable any <tt>layout</tt> settings for the
|
360
|
+
# current action so that it is rendered without a layout then
|
361
|
+
# either override this method in your controller to return false
|
362
|
+
# for that action or set the <tt>action_has_layout</tt> attribute
|
363
|
+
# to false before rendering.
|
364
|
+
def action_has_layout?
|
365
|
+
@_action_has_layout
|
366
|
+
end
|
367
|
+
|
368
|
+
private
|
369
|
+
|
370
|
+
def _conditional_layout?
|
371
|
+
true
|
372
|
+
end
|
373
|
+
|
374
|
+
# This will be overwritten by _write_layout_method
|
375
|
+
def _layout; end
|
376
|
+
|
377
|
+
# Determine the layout for a given name, taking into account the name type.
|
378
|
+
#
|
379
|
+
# ==== Parameters
|
380
|
+
# * <tt>name</tt> - The name of the template
|
381
|
+
def _layout_for_option(name)
|
382
|
+
case name
|
383
|
+
when String then _normalize_layout(name)
|
384
|
+
when Proc then name
|
385
|
+
when true then Proc.new { _default_layout(true) }
|
386
|
+
when :default then Proc.new { _default_layout(false) }
|
387
|
+
when false, nil then nil
|
388
|
+
else
|
389
|
+
raise ArgumentError,
|
390
|
+
"String, Proc, :default, true, or false, expected for `layout'; you passed #{name.inspect}"
|
391
|
+
end
|
392
|
+
end
|
393
|
+
|
394
|
+
def _normalize_layout(value)
|
395
|
+
value.is_a?(String) && value !~ /\blayouts/ ? "layouts/#{value}" : value
|
396
|
+
end
|
397
|
+
|
398
|
+
# Returns the default layout for this controller.
|
399
|
+
# Optionally raises an exception if the layout could not be found.
|
400
|
+
#
|
401
|
+
# ==== Parameters
|
402
|
+
# * <tt>require_layout</tt> - If set to true and layout is not found,
|
403
|
+
# an ArgumentError exception is raised (defaults to false)
|
404
|
+
#
|
405
|
+
# ==== Returns
|
406
|
+
# * <tt>template</tt> - The template object for the default layout (or nil)
|
407
|
+
def _default_layout(require_layout = false)
|
408
|
+
begin
|
409
|
+
value = _layout if action_has_layout?
|
410
|
+
rescue NameError => e
|
411
|
+
raise e, "Could not render layout: #{e.message}"
|
412
|
+
end
|
413
|
+
|
414
|
+
if require_layout && action_has_layout? && !value
|
415
|
+
raise ArgumentError,
|
416
|
+
"There was no default layout for #{self.class} in #{view_paths.inspect}"
|
417
|
+
end
|
418
|
+
|
419
|
+
_normalize_layout(value)
|
420
|
+
end
|
421
|
+
|
422
|
+
def _include_layout?(options)
|
423
|
+
(options.keys & [:text, :inline, :partial]).empty? || options.key?(:layout)
|
424
|
+
end
|
425
|
+
end
|
426
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
"en":
|
2
|
+
# Used in distance_of_time_in_words(), distance_of_time_in_words_to_now(), time_ago_in_words()
|
3
|
+
datetime:
|
4
|
+
distance_in_words:
|
5
|
+
half_a_minute: "half a minute"
|
6
|
+
less_than_x_seconds:
|
7
|
+
one: "less than 1 second"
|
8
|
+
other: "less than %{count} seconds"
|
9
|
+
x_seconds:
|
10
|
+
one: "1 second"
|
11
|
+
other: "%{count} seconds"
|
12
|
+
less_than_x_minutes:
|
13
|
+
one: "less than a minute"
|
14
|
+
other: "less than %{count} minutes"
|
15
|
+
x_minutes:
|
16
|
+
one: "1 minute"
|
17
|
+
other: "%{count} minutes"
|
18
|
+
about_x_hours:
|
19
|
+
one: "about 1 hour"
|
20
|
+
other: "about %{count} hours"
|
21
|
+
x_days:
|
22
|
+
one: "1 day"
|
23
|
+
other: "%{count} days"
|
24
|
+
about_x_months:
|
25
|
+
one: "about 1 month"
|
26
|
+
other: "about %{count} months"
|
27
|
+
x_months:
|
28
|
+
one: "1 month"
|
29
|
+
other: "%{count} months"
|
30
|
+
about_x_years:
|
31
|
+
one: "about 1 year"
|
32
|
+
other: "about %{count} years"
|
33
|
+
over_x_years:
|
34
|
+
one: "over 1 year"
|
35
|
+
other: "over %{count} years"
|
36
|
+
almost_x_years:
|
37
|
+
one: "almost 1 year"
|
38
|
+
other: "almost %{count} years"
|
39
|
+
prompts:
|
40
|
+
year: "Year"
|
41
|
+
month: "Month"
|
42
|
+
day: "Day"
|
43
|
+
hour: "Hour"
|
44
|
+
minute: "Minute"
|
45
|
+
second: "Seconds"
|
46
|
+
|
47
|
+
helpers:
|
48
|
+
select:
|
49
|
+
# Default value for :prompt => true in FormOptionsHelper
|
50
|
+
prompt: "Please select"
|
51
|
+
|
52
|
+
# Default translation keys for submit and button FormHelper
|
53
|
+
submit:
|
54
|
+
create: 'Create %{model}'
|
55
|
+
update: 'Update %{model}'
|
56
|
+
submit: 'Save %{model}'
|