racket-mvc 0.4.0 → 0.5.0

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 (52) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +7 -5
  3. data/lib/racket.rb +25 -7
  4. data/lib/racket/application.rb +70 -136
  5. data/lib/racket/controller.rb +95 -38
  6. data/lib/racket/current.rb +1 -1
  7. data/lib/racket/helpers/file.rb +7 -5
  8. data/lib/racket/helpers/routing.rb +5 -5
  9. data/lib/racket/helpers/sass.rb +11 -11
  10. data/lib/racket/helpers/view.rb +8 -5
  11. data/lib/racket/plugins/base.rb +1 -1
  12. data/lib/racket/plugins/sass.rb +1 -1
  13. data/lib/racket/request.rb +3 -3
  14. data/lib/racket/response.rb +1 -1
  15. data/lib/racket/router.rb +31 -12
  16. data/lib/racket/session.rb +3 -3
  17. data/lib/racket/settings/application.rb +27 -33
  18. data/lib/racket/settings/base.rb +19 -8
  19. data/lib/racket/settings/controller.rb +9 -7
  20. data/lib/racket/settings/defaults.rb +81 -0
  21. data/lib/racket/utils.rb +19 -15
  22. data/lib/racket/utils/application.rb +4 -114
  23. data/lib/racket/utils/application/handler_stack.rb +163 -0
  24. data/lib/racket/utils/application/logger.rb +72 -0
  25. data/lib/racket/utils/application/registry_builder.rb +88 -0
  26. data/lib/racket/utils/application/stateless_services.rb +73 -0
  27. data/lib/racket/utils/exceptions.rb +3 -3
  28. data/lib/racket/utils/file_system.rb +75 -47
  29. data/lib/racket/utils/helpers.rb +35 -13
  30. data/lib/racket/utils/routing.rb +62 -46
  31. data/lib/racket/utils/views.rb +19 -187
  32. data/lib/racket/utils/views/renderer.rb +75 -0
  33. data/lib/racket/utils/views/template_cache.rb +126 -0
  34. data/lib/racket/utils/views/template_locator.rb +83 -0
  35. data/lib/racket/utils/views/template_resolver.rb +112 -0
  36. data/lib/racket/version.rb +2 -2
  37. data/lib/racket/view_manager.rb +12 -4
  38. data/rake/utils.rb +5 -5
  39. data/spec/_custom.rb +69 -19
  40. data/spec/_default.rb +60 -44
  41. data/spec/_plugin.rb +12 -14
  42. data/spec/_template_cache.rb +176 -0
  43. data/spec/racket.rb +10 -13
  44. data/spec/test_custom_app/controllers/sub1/custom_sub_controller_1.rb +1 -1
  45. data/spec/test_custom_app/controllers/sub3/custom_sub_controller_3.rb +19 -1
  46. data/spec/test_custom_app/controllers/sub5/custom_sub_controller_5.rb +8 -0
  47. data/spec/test_custom_app/files/stuff.rb +3 -0
  48. data/spec/test_custom_app/files/triplet.erb +5 -0
  49. data/spec/test_custom_app/templates/sub5/text.erb +3 -0
  50. data/spec/test_default_app/controllers/default_root_controller.rb +3 -0
  51. data/spec/test_default_app/controllers/sub1/default_sub_controller_1.rb +1 -1
  52. metadata +52 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 63dc217836153cda7cd00f43dfe894a519c4de5d
4
- data.tar.gz: 22bca87d176624f95ff10c8007526c0d2b2f4ca0
3
+ metadata.gz: f002bf3d26fa193c944ca3aa0d7bc5e8f27bbfc1
4
+ data.tar.gz: 695e4a0a56af342f2026f961678f15dfd5415967
5
5
  SHA512:
6
- metadata.gz: 332598c7ab0f25fceb9a21356d13d96700f3bb1ba592a71a46b048f365ff7066078230348e7a6432430015f7c6293531b75c3ed560c4a1ad02f0c315363a5046
7
- data.tar.gz: 33a1208769de0e009036df394fea74a5fa6630b035f35bb7f952f0887873514050a6739dcd126446b2bf1ac2cab1f0eff64d83abd62c38a52c019593fc9e613b
6
+ metadata.gz: 722cc5b195717ecc4707e9625231265e4644d35ad740dc38602dc15dee5985d35537c2337a5069e2e5ca15666a303fc9cc2608f911b77872f4e88b4bddf30cbb
7
+ data.tar.gz: 3e797ae053f8657891bb24903f0626b8ac3056ddbbbd2c663dff9310520882b497dc7c9c1e3d3d1301fdc744a99ae1dce7edc26c1f63cc450ca61674b21f02b4
data/README.md CHANGED
@@ -23,14 +23,16 @@ Let us just say it is good _enough_ for my needs at the moment. I plan to add mo
23
23
  whenever I am finished porting most of my old apps from Ramaze.
24
24
 
25
25
  ## Where are the tests?
26
- Have a look in the `spec` directory. The code base have tests covering 100 per cent of the code and I am planning on keeping it that way. At the moment the code is tested on the following platforms (using [Travis CI](https://travis-ci.org/)):
26
+ Have a look in the `spec` directory. The code base have tests covering (almost) 100 per cent of the code and I am planning on keeping it that way. At the moment the code is tested on the following platforms (using [Travis CI](https://travis-ci.org/)):
27
27
 
28
28
  - 1.9.3
29
29
  - 2.0.0
30
- - 2.1.7
31
- - 2.2.3
32
- - jruby-19mode
33
- - jruby-head
30
+ - 2.1.10
31
+ - 2.2.5
32
+ - 2.3.1
33
+ - jruby-1.7.26
34
+ - jruby-9.0.5.0
35
+ - jruby-9.1.5.0
34
36
  - rbx-2
35
37
 
36
38
  I am using [bacon](https://github.com/chneukirchen/bacon) and [rack-test](https://github.com/brynary/rack-test) for testing. Run the tests by typing `rake test`in the root directory. Code coverage reports are provided by [simplecov](https://rubygems.org/gems/simplecov). After the tests have run the an HTML report can be found in the `coverage` directory.
@@ -1,5 +1,5 @@
1
1
  # Racket - The noisy Rack MVC framework
2
- # Copyright (C) 2015 Lars Olsson <lasso@lassoweb.se>
2
+ # Copyright (C) 2015-2016 Lars Olsson <lasso@lassoweb.se>
3
3
  #
4
4
  # This file is part of Racket.
5
5
  #
@@ -33,22 +33,40 @@ require_relative 'racket/utils.rb'
33
33
 
34
34
  # Racket main namespace
35
35
  module Racket
36
- # Requires a file using the current application directory as a base path.
36
+ class << self
37
+ alias kernel_require require
38
+ end
39
+
40
+ # Requires a file relative to the current Racket application dir. Will raise an exception if no
41
+ # Racket application is initialized.
37
42
  #
38
- # @param [Object] args
43
+ # @param [Array] args
39
44
  # @return nil
40
45
  def require(*args)
41
- Application.require(*args)
42
- nil
46
+ raise 'You must have a running Racket application before calling Racket.require' unless
47
+ Controller.context
48
+ (kernel_require resource_path(*args)) && nil
49
+ end
50
+
51
+ # Returns the path to a resource relative to the Racket application dir. Will raise an exception
52
+ # if no Racket is initialized.
53
+ #
54
+ # @param [Array] args
55
+ # @return [Pathname]
56
+ def resource_path(*args)
57
+ context = Controller.context
58
+ raise 'You must have a running Racket application before calling Racket.resource_path' unless
59
+ context
60
+ context.utils.build_path(*args)
43
61
  end
44
62
 
45
63
  # Returns the current version of Racket.
46
64
  #
47
65
  # @return [String]
48
66
  def version
49
- require_relative 'racket/version.rb'
67
+ Kernel.require_relative 'racket/version.rb'
50
68
  Version.current
51
69
  end
52
70
 
53
- module_function :require, :version
71
+ module_function :require, :resource_path, :version
54
72
  end
@@ -1,5 +1,5 @@
1
1
  # Racket - The noisy Rack MVC framework
2
- # Copyright (C) 2015 Lars Olsson <lasso@lassoweb.se>
2
+ # Copyright (C) 2015-2016 Lars Olsson <lasso@lassoweb.se>
3
3
  #
4
4
  # This file is part of Racket.
5
5
  #
@@ -19,72 +19,46 @@
19
19
  module Racket
20
20
  # Racket main application class.
21
21
  class Application
22
- @settings = nil
23
-
24
- class << self
25
- attr_reader :router, :settings
22
+ # Initializes a new Racket::Application object with default settings.
23
+ #
24
+ # @return [Class]
25
+ def self.default
26
+ new
26
27
  end
27
28
 
28
- # Returns the internal application object. When called for the first time this method will use
29
- # Rack::Builder to construct the application.
29
+ # Initializes a new Racket::Application object with settings specified by +settings+.
30
30
  #
31
- # @return [Rack::Builder]
32
- def self.application
33
- @application ||= Utils.build_application(self)
31
+ # @param [Hash] settings
32
+ # @return [Class]
33
+ def self.using(settings)
34
+ new(settings)
34
35
  end
35
36
 
36
- # Applies settings.
37
- def self.apply_settings(settings)
38
- fail 'Application has already been initialized!' if @settings
39
- @settings = Settings::Application.new(settings)
40
- end
37
+ attr_reader :registry
41
38
 
42
- def self.calculate_url_path(file)
43
- url_path = "/#{file.relative_path_from(@settings.controller_dir).dirname}"
44
- url_path = '' if url_path == '/.'
45
- url_path
39
+ # Initializes the Racket application.
40
+ #
41
+ # @param [Hash] settings
42
+ # @return [Class]
43
+ def initialize(settings = {})
44
+ @registry = Utils::Application::RegistryBuilder.new(settings).registry
45
+ @registry.handler_stack # Makes sure all plugins and helpers are loaded before any controllers
46
+ load_controllers
46
47
  end
47
48
 
48
49
  # Called whenever Rack sends a request to the application.
49
50
  #
50
51
  # @param [Hash] env Rack environment
51
52
  # @return [Array] A Rack response array
52
- def self.call(env)
53
- application.call(env.dup)
53
+ def call(env)
54
+ @registry.handler_stack.call(env.dup)
54
55
  end
55
56
 
56
57
  # Returns whether the application runs in dev mode.
57
58
  #
58
59
  # @return [true|false]
59
- def self.dev_mode?
60
- @settings.mode == :dev
61
- end
62
-
63
- # Returns a route to the specified controller/action/parameter combination.
64
- #
65
- # @param [Class] controller
66
- # @param [Symbol] action
67
- # @param [Array] params
68
- # @return [String]
69
- def self.get_route(controller, action = nil, *params)
70
- @router.get_route(controller, action, params)
71
- end
72
-
73
- # Initializes a new Racket::Application object with default settings.
74
- #
75
- # @return [Class]
76
- def self.default
77
- init
78
- end
79
-
80
- # Writes a message to the logger if there is one present.
81
- #
82
- # @param [String] message
83
- # @param [Symbol] level
84
- # @return nil
85
- def self.inform(message, level)
86
- logger = @settings.logger
87
- (logger.send(level, message) if logger) && nil
60
+ def dev_mode?
61
+ @registry.application_settings.mode == :dev
88
62
  end
89
63
 
90
64
  # Sends a message to the logger.
@@ -92,8 +66,8 @@ module Racket
92
66
  # @param [String] message
93
67
  # @param [Symbol] level
94
68
  # @return nil
95
- def self.inform_all(message, level = :info)
96
- inform(message, level)
69
+ def inform_all(message, level = :info)
70
+ @registry.application_logger.inform_all(message, level)
97
71
  end
98
72
 
99
73
  # Sends a message to the logger, but only if the application is running in dev mode.
@@ -101,112 +75,72 @@ module Racket
101
75
  # @param [String] message
102
76
  # @param [Symbol] level
103
77
  # @return nil
104
- def self.inform_dev(message, level = :debug)
105
- (inform(message, level) if dev_mode?) && nil
106
- end
107
-
108
- # Initializes the Racket application.
109
- #
110
- # @param [Hash] settings
111
- # @return [Class]
112
- def self.init(settings = {})
113
- apply_settings(settings)
114
- application # This will make sure all plugins and helpers are loaded before any controllers
115
- setup_static_server
116
- reload
117
- self
118
- end
119
-
120
- # Loads controllers and associates each controller with a route.
121
- #
122
- # @return [nil]
123
- def self.load_controllers
124
- inform_dev('Loading controllers.')
125
- @settings.store(:last_added_controller, [])
126
- load_controller_files
127
- @settings.delete(:last_added_controller)
128
- inform_dev('Done loading controllers.') && nil
129
- end
130
-
131
- # Loads a controller file.
132
- #
133
- # @param [String] file Relative path from controller dir
134
- # @return nil
135
- def self.load_controller_file(file)
136
- ::Kernel.require file
137
- klass = @settings.fetch(:last_added_controller).pop
138
- # Helpers may do stuff based on route, make sure it is available before applying helpers.
139
- @router.map(calculate_url_path(file), klass)
140
- Utils.apply_helpers(klass) && nil
141
- end
142
-
143
- def self.load_controller_files
144
- Utils.paths_by_longest_path(@settings.controller_dir, File.join('**', '*.rb')).each do |path|
145
- load_controller_file(path)
146
- end
78
+ def inform_dev(message, level = :debug)
79
+ @registry.application_logger.inform_dev(message, level)
147
80
  end
148
81
 
149
- # Reloads the application, making any changes to the controller configuration visible
150
- # to the application.
151
- #
152
- # @return [nil]
153
- def self.reload
154
- setup_routes
155
- @view_manager = nil
156
- end
82
+ alias kernel_require require
157
83
 
158
84
  # Requires a file using the current application directory as a base path.
159
85
  #
160
86
  # @param [Object] args
161
87
  # @return [nil]
162
- def self.require(*args)
163
- (::Kernel.require Utils.build_path(*args)) && nil
88
+ def require(*args)
89
+ (kernel_require @registry.utils.build_path(*args)) && nil
164
90
  end
165
91
 
166
- # Serves a static file (if Racket is configured to serve static files).
92
+ private
93
+
94
+ # Calculates the url path for the specified (controller) file
167
95
  #
168
- # @param [Hash] env Rack environment
169
- # @return [Array|nil] A Rack response array if Rack::File handled the file, nil otherwise.
170
- def self.serve_static_file(env)
171
- @static_server ? @static_server.call(env) : nil
96
+ # @param [Pathname] file
97
+ # @return [String]
98
+ def calculate_url_path(file)
99
+ controller_dir = @registry.application_settings.controller_dir
100
+ url_path = "/#{file.relative_path_from(controller_dir).dirname}"
101
+ url_path = '' if url_path == '/.'
102
+ url_path
172
103
  end
173
104
 
174
- # Initializes routing.
105
+ # Returns a list of relative file paths representing controllers,
106
+ # sorted by path length (longest first).
175
107
  #
176
- # @return [nil]
177
- def self.setup_routes
178
- @router = Router.new
179
- load_controllers
108
+ # return [Array]
109
+ def controller_files
110
+ controller_dir = @registry.application_settings.controller_dir
111
+ glob = File.join('**', '*.rb')
112
+ Utils::FileSystem.matching_paths(controller_dir, glob).map do |path|
113
+ Utils::FileSystem::SizedPath.new(path)
114
+ end.sort.map(&:path)
180
115
  end
181
116
 
182
- # Initializes static server (if a public dir is specified).
117
+ # Loads controllers and associates each controller with a route.
183
118
  #
184
119
  # @return [nil]
185
- def self.setup_static_server
186
- @static_server = nil
187
- return nil unless (public_dir = @settings.public_dir) &&
188
- Utils.dir_readable?(Pathname.new(public_dir))
189
- inform_dev("Setting up static server to serve files from #{public_dir}.")
190
- (@static_server = Rack::File.new(public_dir)) && nil
120
+ def load_controllers
121
+ inform_dev('Loading controllers.')
122
+ Controller.context = @registry.controller_context
123
+ load_controller_files
124
+ inform_dev('Done loading controllers.') && nil
191
125
  end
192
126
 
193
- # Initializes a new Racket::Application object with settings specified by +settings+.
127
+ # Loads a controller file.
194
128
  #
195
- # @param [Hash] settings
196
- # @return [Class]
197
- def self.using(settings)
198
- init(settings)
129
+ # @param [String] file Relative path from controller dir
130
+ # @return nil
131
+ def load_controller_file(file)
132
+ kernel_require file
133
+ klass = @registry.application_settings.fetch(:last_added_controller).pop
134
+ # Helpers may do stuff based on route, make sure it is available before applying helpers.
135
+ @registry.router.map(calculate_url_path(file), klass)
136
+ @registry.utils.apply_helpers(klass) && nil
199
137
  end
200
138
 
201
- # Returns the view cache of the currently running application.
202
- #
203
- # @return [Racket::ViewManager]
204
- def self.view_manager
205
- @view_manager ||= ViewManager.new(@settings.layout_dir, @settings.view_dir)
139
+ def load_controller_files
140
+ settings = @registry.application_settings
141
+ settings.store(:last_added_controller, [])
142
+ controller_files.each { |path| load_controller_file(path) }
143
+ settings.delete(:last_added_controller)
206
144
  end
207
-
208
- private_class_method :application, :calculate_url_path, :inform, :init, :load_controller_file,
209
- :load_controller_files, :load_controllers, :setup_routes,
210
- :setup_static_server
211
145
  end
212
146
  end
@@ -1,5 +1,5 @@
1
1
  # Racket - The noisy Rack MVC framework
2
- # Copyright (C) 2015 Lars Olsson <lasso@lassoweb.se>
2
+ # Copyright (C) 2015-2016 Lars Olsson <lasso@lassoweb.se>
3
3
  #
4
4
  # This file is part of Racket.
5
5
  #
@@ -19,17 +19,6 @@
19
19
  module Racket
20
20
  # Base controller class. Your controllers should inherit this class.
21
21
  class Controller
22
- def self.__helper_cache
23
- settings = Controller.settings
24
- helper_cache =
25
- settings.fetch(
26
- :helper_cache,
27
- Utils::Helpers::HelperCache.new(Application.settings.helper_dir)
28
- )
29
- settings.store(:helper_cache, helper_cache) unless settings.present?(:helper_cache)
30
- helper_cache
31
- end
32
-
33
22
  # Adds a hook to one or more actions.
34
23
  #
35
24
  # @param [Symbol] type
@@ -40,7 +29,7 @@ module Racket
40
29
  meths = public_instance_methods(false)
41
30
  meths &= methods.map(&:to_sym) unless methods.empty?
42
31
  __update_hooks("#{type}_hooks".to_sym, meths, blk)
43
- Application.inform_dev("Adding #{type} hook #{blk} for actions #{meths} for #{self}.")
32
+ context.logger.inform_dev("Adding #{type} hook #{blk} for actions #{meths} for #{self}.")
44
33
  end
45
34
 
46
35
  # Updates hooks in settings object.
@@ -73,6 +62,30 @@ module Racket
73
62
  __register_hook(:before, methods, blk) if block_given?
74
63
  end
75
64
 
65
+ # Returns the current context.
66
+ #
67
+ # @return [Module]
68
+ def self.context
69
+ Controller.instance_variable_get(:@context)
70
+ end
71
+
72
+ # Injects context in Controller class. Context represents
73
+ # the current application state.
74
+ #
75
+ # @param [Module] context
76
+ def self.context=(context)
77
+ raise 'Context should only be set on Controller class' unless self == Controller
78
+ @context = context
79
+ end
80
+
81
+ # Returns the route representing the parameters.
82
+ #
83
+ # @param [Symbol|nil] action
84
+ # @param [Array] params
85
+ def self.get_route(action = nil, *params)
86
+ context.get_route(self, action, params)
87
+ end
88
+
76
89
  # Adds one or more helpers to the controller. All controllers get some default helpers
77
90
  # (:routing and :view by default), but if you have your own helpers you want to load this
78
91
  # is the preferred method.
@@ -88,53 +101,87 @@ module Racket
88
101
  unless settings.fetch(:helpers)
89
102
  # No helpers has been loaded yet. Load the default helpers first.
90
103
  helper_modules.merge!(
91
- __helper_cache.load_helpers(Application.settings.default_controller_helpers)
104
+ context.helper_cache.load_helpers(settings.fetch(:default_controller_helpers))
92
105
  )
93
106
  end
94
107
  # Load new helpers
95
108
  __load_helpers(helpers.map(&:to_sym), helper_modules)
96
109
  end
97
110
 
98
- # Loads new helpers and stores the list of helpers associated with the currenct controller
99
- # in the settings.
111
+ # :@private
112
+ def self.inherited(klass)
113
+ settings.fetch(:last_added_controller).push(klass)
114
+ end
115
+
116
+ # Returns the layout settings for the current controller.
100
117
  #
101
- # @param [Array] helpers Requested helpers
102
- # @param [Array] helper_modules Helper modules already loaded
103
- # @return nil
104
- def self.__load_helpers(helpers, helper_modules)
105
- helpers.reject! { |helper| helper_modules.key?(helper) }
106
- helper_modules.merge!(__helper_cache.load_helpers(helpers))
107
- setting(:helpers, helper_modules) && nil
118
+ # @return [Hash]
119
+ def self.layout_settings
120
+ template_settings = settings.fetch(:template_settings)
121
+ template_settings[:common].merge(template_settings[:layout])
108
122
  end
109
123
 
110
- # :nodoc:
111
- def self.inherited(klass)
112
- Application.settings.fetch(:last_added_controller).push(klass)
124
+ # Add a setting for the current controller class
125
+ #
126
+ # @param [Symbol] key
127
+ # @param [Object] val
128
+ def self.setting(key, val)
129
+ settings.store(key, val)
113
130
  end
114
131
 
115
- # Returns the settings associated with the current controller class.
132
+ # Returns the settings for the current controller class
116
133
  #
117
134
  # @return [Racket::Settings::Controller]
118
135
  def self.settings
119
- @settings ||= Settings::Controller.new(self)
136
+ @settings ||= Racket::Settings::Controller.new(self)
120
137
  end
121
138
 
122
- # Creates/updates a setting for the current controller class.
139
+ # Add a setting used by Tilt when rendering views/layouts.
123
140
  #
124
141
  # @param [Symbol] key
125
142
  # @param [Object] value
126
- # @return [nil]
127
- def self.setting(key, value)
128
- settings.store(key, value)
143
+ # @param [Symbol] type One of +:common+, +:layout+ or +:view+
144
+ def self.template_setting(key, value, type = :common)
145
+ # If controller has no template settings on its own, copy the template settings
146
+ # from its "closest" parent (might even be application settings)
147
+ # @todo - How about template options that are unmarshallable?
148
+ settings.store(
149
+ :template_settings, Marshal.load(Marshal.dump(settings.fetch(:template_settings)))
150
+ ) unless settings.present?(:template_settings)
151
+
152
+ # Fetch current settings (guaranteed to be in controller by now)
153
+ template_settings = settings.fetch(:template_settings)
154
+
155
+ # Update settings
156
+ template_settings[type][key] = value
157
+ settings.store(:template_settings, template_settings)
129
158
  end
130
159
 
131
- private_class_method :__helper_cache, :__load_helpers, :__register_hook, :__update_hooks
160
+ # Returns the view settings for the current controller.
161
+ #
162
+ # @return [Hash]
163
+ def self.view_settings
164
+ template_settings = settings.fetch(:template_settings)
165
+ template_settings[:common].merge(template_settings[:view])
166
+ end
132
167
 
133
- # Returns the settings for a controller instance.
168
+ # Loads new helpers and stores the list of helpers associated with the currenct controller
169
+ # in the settings.
134
170
  #
135
- # @return [Racket::Settings::Controller]
136
- def settings
137
- self.class.settings
171
+ # @param [Array] helpers Requested helpers
172
+ # @param [Array] helper_modules Helper modules already loaded
173
+ # @return nil
174
+ def self.__load_helpers(helpers, helper_modules)
175
+ helpers.reject! { |helper| helper_modules.key?(helper) }
176
+ helper_modules.merge!(context.helper_cache.load_helpers(helpers))
177
+ setting(:helpers, helper_modules) && nil
178
+ end
179
+
180
+ private_class_method :__load_helpers, :__register_hook, :__update_hooks
181
+
182
+ # Returns layout settings associated with the current controller
183
+ def layout_settings
184
+ self.class.layout_settings
138
185
  end
139
186
 
140
187
  # Redirects the client. After hooks are run.
@@ -178,6 +225,16 @@ module Racket
178
225
  throw :response, [status, headers, body]
179
226
  end
180
227
 
228
+ # Returns settings associated with the current controller
229
+ def settings
230
+ self.class.settings
231
+ end
232
+
233
+ # Returns view settings associated with the current controller
234
+ def view_settings
235
+ self.class.view_settings
236
+ end
237
+
181
238
  # Calls hooks, action and renderer.
182
239
  #
183
240
  # @return [String]
@@ -185,7 +242,7 @@ module Racket
185
242
  __run_hook(:before)
186
243
  __run_action
187
244
  __run_hook(:after)
188
- Application.view_manager.render(self)
245
+ self.class.context.view_manager.render(self)
189
246
  end
190
247
 
191
248
  private