hanami-view 1.3.0.beta1 → 2.0.0.alpha2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +21 -0
  3. data/LICENSE +20 -0
  4. data/README.md +20 -862
  5. data/hanami-view.gemspec +26 -16
  6. data/lib/hanami-view.rb +3 -1
  7. data/lib/hanami/view.rb +208 -223
  8. data/lib/hanami/view/application_configuration.rb +77 -0
  9. data/lib/hanami/view/application_context.rb +35 -0
  10. data/lib/hanami/view/application_view.rb +89 -0
  11. data/lib/hanami/view/context.rb +97 -0
  12. data/lib/hanami/view/context_helpers/content_helpers.rb +26 -0
  13. data/lib/hanami/view/decorated_attributes.rb +82 -0
  14. data/lib/hanami/view/errors.rb +19 -56
  15. data/lib/hanami/view/exposure.rb +126 -0
  16. data/lib/hanami/view/exposures.rb +74 -0
  17. data/lib/hanami/view/part.rb +217 -0
  18. data/lib/hanami/view/part_builder.rb +140 -0
  19. data/lib/hanami/view/path.rb +68 -0
  20. data/lib/hanami/view/render_environment.rb +62 -0
  21. data/lib/hanami/view/render_environment_missing.rb +44 -0
  22. data/lib/hanami/view/rendered.rb +55 -0
  23. data/lib/hanami/view/renderer.rb +79 -0
  24. data/lib/hanami/view/scope.rb +189 -0
  25. data/lib/hanami/view/scope_builder.rb +98 -0
  26. data/lib/hanami/view/standalone_view.rb +396 -0
  27. data/lib/hanami/view/tilt.rb +78 -0
  28. data/lib/hanami/view/tilt/erb.rb +26 -0
  29. data/lib/hanami/view/tilt/erbse.rb +21 -0
  30. data/lib/hanami/view/tilt/haml.rb +26 -0
  31. data/lib/hanami/view/version.rb +5 -5
  32. metadata +113 -63
  33. data/LICENSE.md +0 -22
  34. data/lib/hanami/layout.rb +0 -172
  35. data/lib/hanami/presenter.rb +0 -98
  36. data/lib/hanami/view/configuration.rb +0 -504
  37. data/lib/hanami/view/dsl.rb +0 -347
  38. data/lib/hanami/view/escape.rb +0 -225
  39. data/lib/hanami/view/inheritable.rb +0 -54
  40. data/lib/hanami/view/rendering.rb +0 -294
  41. data/lib/hanami/view/rendering/layout_finder.rb +0 -128
  42. data/lib/hanami/view/rendering/layout_registry.rb +0 -69
  43. data/lib/hanami/view/rendering/layout_scope.rb +0 -274
  44. data/lib/hanami/view/rendering/null_layout.rb +0 -52
  45. data/lib/hanami/view/rendering/null_local.rb +0 -82
  46. data/lib/hanami/view/rendering/null_template.rb +0 -83
  47. data/lib/hanami/view/rendering/options.rb +0 -24
  48. data/lib/hanami/view/rendering/partial.rb +0 -31
  49. data/lib/hanami/view/rendering/partial_file.rb +0 -29
  50. data/lib/hanami/view/rendering/partial_finder.rb +0 -75
  51. data/lib/hanami/view/rendering/partial_templates_finder.rb +0 -73
  52. data/lib/hanami/view/rendering/registry.rb +0 -134
  53. data/lib/hanami/view/rendering/scope.rb +0 -108
  54. data/lib/hanami/view/rendering/subscope.rb +0 -56
  55. data/lib/hanami/view/rendering/template.rb +0 -69
  56. data/lib/hanami/view/rendering/template_finder.rb +0 -55
  57. data/lib/hanami/view/rendering/template_name.rb +0 -50
  58. data/lib/hanami/view/rendering/templates_finder.rb +0 -144
  59. data/lib/hanami/view/rendering/view_finder.rb +0 -37
  60. data/lib/hanami/view/template.rb +0 -57
data/lib/hanami/layout.rb DELETED
@@ -1,172 +0,0 @@
1
- require 'hanami/utils/class_attribute'
2
- require 'hanami/view/rendering/layout_registry'
3
- require 'hanami/view/rendering/layout_scope'
4
- require 'hanami/view/rendering/null_layout'
5
-
6
- module Hanami
7
- # Layout
8
- #
9
- # @since 0.1.0
10
- #
11
- # @see Hanami::Layout::ClassMethods
12
- module Layout
13
- # Register a layout
14
- #
15
- # @api private
16
- # @since 0.1.0
17
- #
18
- # @example
19
- # require 'hanami/view'
20
- #
21
- # class ApplicationLayout
22
- # include Hanami::Layout
23
- # end
24
- def self.included(base)
25
- conf = Hanami::View::Configuration.for(base)
26
- conf.add_layout(base)
27
-
28
- base.class_eval do
29
- extend Hanami::View::Dsl.dup
30
- extend ClassMethods
31
-
32
- include Utils::ClassAttribute
33
- class_attribute :configuration
34
-
35
- self.configuration = conf.duplicate
36
- end
37
-
38
- conf.copy!(base)
39
- end
40
-
41
- # Class level API
42
- #
43
- # @since 0.1.0
44
- module ClassMethods
45
- # Template name suffix
46
- #
47
- # @api private
48
- # @since 0.1.0
49
- #
50
- # @see Hanami::Layout::ClassMethods#suffix
51
- # @see Hanami::Layout::ClassMethods#template
52
- SUFFIX = '_layout'.freeze
53
-
54
- # A registry that holds all the registered layouts.
55
- #
56
- # @api private
57
- # @since 0.1.0
58
- #
59
- # @see Hanami::View::Rendering::LayoutRegistry
60
- def registry
61
- @registry ||= View::Rendering::LayoutRegistry.new(self)
62
- end
63
-
64
- # Template name
65
- #
66
- # @api private
67
- # @since 0.1.0
68
- #
69
- # @see Hanami::Layout::ClassMethods#SUFFIX
70
- # @see Hanami::Layout::ClassMethods#suffix
71
- #
72
- # @example
73
- # # Given a template 'templates/application.html.erb'
74
- #
75
- # class ApplicationLayout
76
- # include Hanami::Layout
77
- # end
78
- #
79
- # ApplicationLayout.template # => 'application'
80
- def template
81
- super.sub(suffix, '')
82
- end
83
-
84
- # Template name suffix
85
- #
86
- # @api private
87
- # @since 0.1.0
88
- #
89
- # @see Hanami::Layout::ClassMethods#SUFFIX
90
- # @see Hanami::Layout::ClassMethods#template
91
- def suffix
92
- SUFFIX
93
- end
94
-
95
- protected
96
-
97
- # Loading mechanism hook.
98
- #
99
- # @api private
100
- # @since 0.1.0
101
- #
102
- # @see Hanami::View.load!
103
- def load!
104
- load_registry!
105
- configuration.freeze
106
- end
107
-
108
- private
109
-
110
- # @api private
111
- def load_registry!
112
- @registry = nil
113
- registry.freeze
114
- end
115
- end
116
-
117
- # Initialize a layout
118
- #
119
- # @param scope [Hanami::View::Rendering::Scope] view rendering scope
120
- # @param rendered [String] the output of the view rendering process
121
- #
122
- # @api private
123
- # @since 0.1.0
124
- #
125
- # @see Hanami::View::Rendering#render
126
- def initialize(scope, rendered)
127
- @scope, @rendered = View::Rendering::LayoutScope.new(self, scope), rendered
128
- end
129
-
130
- # Render the layout
131
- #
132
- # @return [String] the output of the rendering process
133
- #
134
- # @api private
135
- # @since 0.1.0
136
- #
137
- # @see Hanami::View::Rendering#render
138
- def render
139
- template.render(@scope, &Proc.new{@rendered})
140
- end
141
-
142
- # It tries to invoke a method for the view or a local for the given key.
143
- # If the lookup fails, it returns a null object.
144
- #
145
- # @return [Object,Hanami::View::Rendering::NullLocal] the returning value
146
- #
147
- # @since 1.1.0
148
- #
149
- # @example Safe method navigation
150
- # class ApplicationLayout
151
- # include Hanami::Layout
152
- #
153
- # def render_flash
154
- # return if local(:flash).nil?
155
- #
156
- # # ...
157
- # end
158
- # end
159
- def local(key)
160
- @scope.local(key)
161
- end
162
-
163
- protected
164
- # The template for the current format
165
- #
166
- # @api private
167
- # @since 0.1.0
168
- def template
169
- self.class.registry.resolve({format: @scope.format})
170
- end
171
- end
172
- end
@@ -1,98 +0,0 @@
1
- require 'hanami/view/escape'
2
-
3
- module Hanami
4
- # Presenter pattern implementation
5
- #
6
- # It delegates to the wrapped object the missing method invocations.
7
- #
8
- # The output of concrete and delegated methods is escaped as XSS prevention.
9
- #
10
- # @since 0.1.0
11
- #
12
- # @example Basic usage
13
- # require 'hanami/view'
14
- #
15
- # class Map
16
- # attr_reader :locations
17
- #
18
- # def initialize(locations)
19
- # @locations = locations
20
- # end
21
- #
22
- # def location_names
23
- # @locations.join(', ')
24
- # end
25
- # end
26
- #
27
- # class MapPresenter
28
- # include Hanami::Presenter
29
- #
30
- # def count
31
- # locations.count
32
- # end
33
- #
34
- # def location_names
35
- # super.upcase
36
- # end
37
- #
38
- # def inspect_object
39
- # @object.inspect
40
- # end
41
- # end
42
- #
43
- # map = Map.new(['Rome', 'Boston'])
44
- # presenter = MapPresenter.new(map)
45
- #
46
- # # access a map method
47
- # puts presenter.locations # => ['Rome', 'Boston']
48
- #
49
- # # access presenter concrete methods
50
- # puts presenter.count # => 1
51
- #
52
- # # uses super to access original object implementation
53
- # puts presenter.location_names # => 'ROME, BOSTON'
54
- #
55
- # # it has private access to the original object
56
- # puts presenter.inspect_object # => #<Map:0x007fdeada0b2f0 @locations=["Rome", "Boston"]>
57
- #
58
- # @example Escape
59
- # require 'hanami/view'
60
- #
61
- # User = Struct.new(:first_name, :last_name)
62
- #
63
- # class UserPresenter
64
- # include Hanami::Presenter
65
- #
66
- # def full_name
67
- # [first_name, last_name].join(' ')
68
- # end
69
- #
70
- # def raw_first_name
71
- # _raw first_name
72
- # end
73
- # end
74
- #
75
- # first_name = '<script>alert('xss')</script>'
76
- #
77
- # user = User.new(first_name, nil)
78
- # presenter = UserPresenter.new(user)
79
- #
80
- # presenter.full_name
81
- # # => "&lt;script&gt;alert(&apos;xss&apos;)&lt;&#x2F;script&gt;"
82
- #
83
- # presenter.raw_full_name
84
- # # => "<script>alert('xss')</script>"
85
- module Presenter
86
- # Inject escape logic into the given class.
87
- #
88
- # @since 0.4.0
89
- # @api private
90
- #
91
- # @see Hanami::View::Escape
92
- def self.included(base)
93
- base.class_eval do
94
- include ::Hanami::View::Escape::Presentable
95
- end
96
- end
97
- end
98
- end
@@ -1,504 +0,0 @@
1
- require 'set'
2
- require 'hanami/utils/class'
3
- require 'hanami/utils/kernel'
4
- require 'hanami/utils/string'
5
- require 'hanami/utils/load_paths'
6
- require 'hanami/view/rendering/layout_finder'
7
- require 'hanami/view/rendering/partial_templates_finder'
8
-
9
- module Hanami
10
- module View
11
- # Configuration for the framework, controllers and actions.
12
- #
13
- # Hanami::Controller has its own global configuration that can be manipulated
14
- # via `Hanami::View.configure`.
15
- #
16
- # Every time that `Hanami::View` and `Hanami::Layout` are included, that
17
- # global configuration is being copied to the recipient. The copy will
18
- # inherit all the settings from the original, but all the subsequent changes
19
- # aren't reflected from the parent to the children, and viceversa.
20
- #
21
- # This architecture allows to have a global configuration that capture the
22
- # most common cases for an application, and let views and layouts
23
- # layouts to specify exceptions.
24
- #
25
- # @since 0.2.0
26
- class Configuration
27
- # Default root
28
- #
29
- # @since 0.2.0
30
- # @api private
31
- DEFAULT_ROOT = '.'.freeze
32
-
33
- # Default encoding
34
- #
35
- # @since 0.5.0
36
- # @api private
37
- DEFAULT_ENCODING = Encoding::UTF_8
38
-
39
- attr_reader :load_paths
40
- attr_reader :views
41
- attr_reader :layouts
42
- attr_reader :modules
43
- attr_reader :partials
44
-
45
- # Return the original configuration of the framework instance associated
46
- # with the given class.
47
- #
48
- # When multiple instances of Hanami::View are used in the same application,
49
- # we want to make sure that a controller or an action will receive the
50
- # expected configuration.
51
- #
52
- # @param base [Class] a view or a layout
53
- #
54
- # @return [Hanami::Controller::Configuration] the configuration associated
55
- # to the given class.
56
- #
57
- # @since 0.2.0
58
- # @api private
59
- #
60
- # @example Direct usage of the framework
61
- # require 'hanami/view'
62
- #
63
- # class Show
64
- # include Hanami::View
65
- # end
66
- #
67
- # Hanami::View::Configuration.for(Show)
68
- # # => will return from Hanami::View
69
- #
70
- # @example Multiple instances of the framework
71
- # require 'hanami/view'
72
- #
73
- # module MyApp
74
- # View = Hanami::View.duplicate(self)
75
- #
76
- # module Views::Dashboard
77
- # class Index
78
- # include MyApp::View
79
- # end
80
- # end
81
- # end
82
- #
83
- # class Show
84
- # include Hanami::Action
85
- # end
86
- #
87
- # Hanami::View::Configuration.for(Show)
88
- # # => will return from Hanami::View
89
- #
90
- # Hanami::View::Configuration.for(MyApp::Views::Dashboard::Index)
91
- # # => will return from MyApp::View
92
- def self.for(base)
93
- # TODO this implementation is similar to Hanami::Controller::Configuration consider to extract it into Hanami::Utils
94
- namespace = Utils::String.namespace(base)
95
- framework = Utils::Class.load("#{namespace}::View") || Utils::Class.load!('Hanami::View')
96
- framework.configuration
97
- end
98
-
99
- # Initialize a configuration instance
100
- #
101
- # @return [Hanami::View::Configuration] a new configuration's instance
102
- #
103
- # @since 0.2.0
104
- def initialize
105
- @namespace = Object
106
- reset!
107
- end
108
-
109
- # Set the Ruby namespace where to lookup for views.
110
- #
111
- # When multiple instances of the framework are used, we want to make sure
112
- # that if a `MyApp` wants a `Dashboard::Index` view, we are loading the
113
- # right one.
114
- #
115
- # If not set, this value defaults to `Object`.
116
- #
117
- # This is part of a DSL, for this reason when this method is called with
118
- # an argument, it will set the corresponding instance variable. When
119
- # called without, it will return the already set value, or the default.
120
- #
121
- # @overload namespace(value)
122
- # Sets the given value
123
- # @param value [Class, Module, String] a valid Ruby namespace identifier
124
- #
125
- # @overload namespace
126
- # Gets the value
127
- # @return [Class, Module, String]
128
- #
129
- # @since 0.2.0
130
- #
131
- # @example Getting the value
132
- # require 'hanami/view'
133
- #
134
- # Hanami::View.configuration.namespace # => Object
135
- #
136
- # @example Setting the value
137
- # require 'hanami/view'
138
- #
139
- # Hanami::View.configure do
140
- # namespace 'MyApp::Views'
141
- # end
142
- def namespace(value = nil)
143
- if value
144
- @namespace = value
145
- else
146
- @namespace
147
- end
148
- end
149
-
150
- # Set the root path where to search for templates
151
- #
152
- # If not set, this value defaults to the current directory.
153
- #
154
- # This is part of a DSL, for this reason when this method is called with
155
- # an argument, it will set the corresponding instance variable. When
156
- # called without, it will return the already set value, or the default.
157
- #
158
- # @overload root(value)
159
- # Sets the given value
160
- # @param value [String,Pathname,#to_pathname] an object that can be
161
- # coerced to Pathname
162
- # @raise [Errno::ENOENT] if the given path doesn't exist
163
- #
164
- # @overload root
165
- # Gets the value
166
- # @return [Pathname]
167
- #
168
- # @since 0.2.0
169
- #
170
- # @see Hanami::View::Dsl#root
171
- # @see http://www.ruby-doc.org/stdlib-2.1.2/libdoc/pathname/rdoc/Pathname.html
172
- # @see http://rdoc.info/gems/hanami-utils/Hanami/Utils/Kernel#Pathname-class_method
173
- #
174
- # @example Getting the value
175
- # require 'hanami/view'
176
- #
177
- # Hanami::View.configuration.root # => #<Pathname:.>
178
- #
179
- # @example Setting the value
180
- # require 'hanami/view'
181
- #
182
- # Hanami::View.configure do
183
- # root '/path/to/templates'
184
- # end
185
- #
186
- # Hanami::View.configuration.root # => #<Pathname:/path/to/templates>
187
- def root(value = nil)
188
- if value
189
- @root = Utils::Kernel.Pathname(value).realpath
190
- else
191
- @root
192
- end
193
- end
194
-
195
- # Set the global layout
196
- #
197
- # If not set, this value defaults to `nil`, while at the rendering time
198
- # it will use `Hanami::View::Rendering::NullLayout`.
199
- #
200
- # This is part of a DSL, for this reason when this method is called with
201
- # an argument, it will set the corresponding instance variable. When
202
- # called without, it will return the already set value, or the default.
203
- #
204
- # @overload layout(value)
205
- # Sets the given value
206
- # @param value [Symbol] the name of the layout
207
- #
208
- # @overload layout
209
- # Gets the value
210
- # @return [Class]
211
- #
212
- # @since 0.2.0
213
- #
214
- # @see Hanami::View::Dsl#layout
215
- #
216
- # @example Getting the value
217
- # require 'hanami/view'
218
- #
219
- # Hanami::View.configuration.layout # => nil
220
- #
221
- # @example Setting the value
222
- # require 'hanami/view'
223
- #
224
- # Hanami::View.configure do
225
- # layout :application
226
- # end
227
- #
228
- # Hanami::View.configuration.layout # => ApplicationLayout
229
- #
230
- # @example Setting the value in a namespaced app
231
- # require 'hanami/view'
232
- #
233
- # module MyApp
234
- # View = Hanami::View.duplicate(self) do
235
- # layout :application
236
- # end
237
- # end
238
- #
239
- # MyApp::View.configuration.layout # => MyApp::ApplicationLayout
240
- def layout(value = nil)
241
- if value.nil?
242
- Rendering::LayoutFinder.find(@layout, @namespace)
243
- else
244
- @layout = value
245
- end
246
- end
247
-
248
- # Default encoding for templates
249
- #
250
- # This is part of a DSL, for this reason when this method is called with
251
- # an argument, it will set the corresponding instance variable. When
252
- # called without, it will return the already set value, or the default.
253
- #
254
- # @overload default_encoding(value)
255
- # Sets the given value
256
- # @param value [String,Encoding] a string representation of the encoding,
257
- # or an Encoding constant
258
- #
259
- # @raise [ArgumentError] if the given value isn't a supported encoding
260
- #
261
- # @overload default_encoding
262
- # Gets the value
263
- # @return [Encoding]
264
- #
265
- # @since 0.5.0
266
- #
267
- # @example Set UTF-8 As A String
268
- # require 'hanami/view'
269
- #
270
- # Hanami::View.configure do
271
- # default_encoding 'utf-8'
272
- # end
273
- #
274
- # @example Set UTF-8 As An Encoding Constant
275
- # require 'hanami/view'
276
- #
277
- # Hanami::View.configure do
278
- # default_encoding Encoding::UTF_8
279
- # end
280
- #
281
- # @example Raise An Error For Unknown Encoding
282
- # require 'hanami/view'
283
- #
284
- # Hanami::View.configure do
285
- # default_encoding 'foo'
286
- # end
287
- #
288
- # # => ArgumentError
289
- def default_encoding(value = nil)
290
- if value.nil?
291
- @default_encoding
292
- else
293
- @default_encoding = Encoding.find(value)
294
- end
295
- end
296
-
297
- # Prepare the views.
298
- #
299
- # The given block will be yielded when `Hanami::View` will be included by
300
- # a view.
301
- #
302
- # This method can be called multiple times.
303
- #
304
- # @param blk [Proc] the code block
305
- #
306
- # @return [void]
307
- #
308
- # @raise [ArgumentError] if called without passing a block
309
- #
310
- # @since 0.3.0
311
- #
312
- # @see Hanami::View.configure
313
- # @see Hanami::View.duplicate
314
- #
315
- # @example Including shared utilities
316
- # require 'hanami/view'
317
- #
318
- # module UrlHelpers
319
- # def comments_path
320
- # '/'
321
- # end
322
- # end
323
- #
324
- # Hanami::View.configure do
325
- # prepare do
326
- # include UrlHelpers
327
- # end
328
- # end
329
- #
330
- # Hanami::View.load!
331
- #
332
- # module Comments
333
- # class New
334
- # # The following include will cause UrlHelpers to be included too.
335
- # # This makes `comments_path` available in the view context
336
- # include Hanami::View
337
- #
338
- # def form
339
- # %(<form action="#{ comments_path }" method="POST"></form>)
340
- # end
341
- # end
342
- # end
343
- #
344
- # @example Preparing multiple times
345
- # require 'hanami/view'
346
- #
347
- # Hanami::View.configure do
348
- # prepare do
349
- # include UrlHelpers
350
- # end
351
- #
352
- # prepare do
353
- # format :json
354
- # end
355
- # end
356
- #
357
- # Hanami::View.configure do
358
- # prepare do
359
- # include FormattingHelpers
360
- # end
361
- # end
362
- #
363
- # Hanami::View.load!
364
- #
365
- # module Articles
366
- # class Index
367
- # # The following include will cause the inclusion of:
368
- # # * UrlHelpers
369
- # # * FormattingHelpers
370
- # #
371
- # # It also sets the view to render only JSON
372
- # include Hanami::View
373
- # end
374
- # end
375
- def prepare(&blk)
376
- if block_given?
377
- @modules.push(blk)
378
- else
379
- raise ArgumentError.new('Please provide a block')
380
- end
381
- end
382
-
383
- # Add a view to the registry
384
- #
385
- # @since 0.2.0
386
- # @api private
387
- def add_view(view)
388
- @views.add(view)
389
- end
390
-
391
- # Add a layout to the registry
392
- #
393
- # @since 0.2.0
394
- # @api private
395
- def add_layout(layout)
396
- @layouts.add(layout)
397
- end
398
-
399
- # Duplicate by copying the settings in a new instance.
400
- #
401
- # @return [Hanami::View::Configuration] a copy of the configuration
402
- #
403
- # @since 0.2.0
404
- # @api private
405
- def duplicate
406
- Configuration.new.tap do |c|
407
- c.namespace = namespace
408
- c.root = root
409
- c.layout = @layout # lazy loading of the class
410
- c.default_encoding = default_encoding
411
- c.load_paths = load_paths.dup
412
- c.modules = modules.dup
413
- end
414
- end
415
-
416
- # Load the configuration for the current framework
417
- #
418
- # @since 0.2.0
419
- # @api private
420
- def load!
421
- views.each { |v| v.__send__(:load!) }
422
- layouts.each { |l| l.__send__(:load!) }
423
- load_partials!
424
- freeze
425
- end
426
-
427
- # Load partials for each partial template file found under the
428
- # given load paths
429
- #
430
- # @since 0.7.0
431
- # @api private
432
- def load_partials!
433
- Hanami::View::Rendering::PartialTemplatesFinder.new(self).find.each do |partial|
434
- add_partial(partial)
435
- end
436
- end
437
-
438
- # Load partials for each partial template file found under the
439
- # given load paths
440
- #
441
- # @since 0.7.0
442
- # @api private
443
- def find_partial(relative_partial_path, template_name, format)
444
- partials_for_view = partials.has_key?(relative_partial_path) ? partials[relative_partial_path] : partials[template_name]
445
- partials_for_view ? partials_for_view[format.to_sym] : nil
446
- end
447
-
448
- # Add a partial to the registry
449
- #
450
- # @since 0.7.0
451
- # @api private
452
- def add_partial(partial)
453
- @partials[partial.key][partial.format.to_sym] = partial.template
454
- end
455
-
456
- # Reset all the values to the defaults
457
- #
458
- # @since 0.2.0
459
- # @api private
460
- def reset!
461
- root DEFAULT_ROOT
462
- default_encoding DEFAULT_ENCODING
463
-
464
- @partials = Hash.new { |h, k| h[k] = Hash.new }
465
- @views = Set.new
466
- @layouts = Set.new
467
- @load_paths = Utils::LoadPaths.new(root)
468
- @layout = nil
469
- @modules = []
470
- end
471
-
472
- # Copy the configuration for the given action
473
- #
474
- # @param base [Class] the target action
475
- #
476
- # @return void
477
- #
478
- # @since 0.3.0
479
- # @api private
480
- def copy!(base)
481
- modules.each do |mod|
482
- base.class_eval(&mod)
483
- end
484
- end
485
-
486
- # @api private
487
- alias_method :unload!, :reset!
488
-
489
- protected
490
- # @api private
491
- attr_writer :namespace
492
- # @api private
493
- attr_writer :root
494
- # @api private
495
- attr_writer :load_paths
496
- # @api private
497
- attr_writer :layout
498
- # @api private
499
- attr_writer :default_encoding
500
- # @api private
501
- attr_writer :modules
502
- end
503
- end
504
- end