mack 0.5.5.4 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +34 -0
- data/README +1 -1
- data/bin/mack +7 -2
- data/lib/controller/controller.rb +371 -0
- data/lib/controller/cookie_jar.rb +2 -1
- data/lib/controller/filter.rb +3 -2
- data/lib/controller/request.rb +30 -26
- data/lib/controller/session.rb +5 -0
- data/lib/distributed/utils/rinda.rb +1 -1
- data/lib/errors/errors.rb +5 -3
- data/lib/generators/mack_application_generator/mack_application_generator.rb +4 -0
- data/lib/generators/mack_application_generator/manifest.yml +40 -7
- data/lib/generators/mack_application_generator/templates/Rakefile.template +5 -1
- data/lib/generators/mack_application_generator/templates/app/controllers/default_controller.rb.template +2 -1
- data/lib/generators/mack_application_generator/templates/app/helpers/controllers/default_controller_helper.rb.template +7 -0
- data/lib/generators/mack_application_generator/templates/app/helpers/views/application_helper.rb.template +7 -0
- data/lib/generators/mack_application_generator/templates/config/app_config/default.yml.template +2 -1
- data/lib/generators/mack_application_generator/templates/config/database.yml.template +11 -10
- data/lib/generators/mack_application_generator/templates/test/functional/default_controller_spec.rb.template +9 -0
- data/lib/generators/mack_application_generator/templates/test/functional/default_controller_test.rb.template +10 -0
- data/lib/generators/mack_application_generator/templates/test/spec.opts.template +2 -0
- data/lib/generators/mack_application_generator/templates/test/spec_helper.rb.template +8 -0
- data/lib/generators/mack_application_generator/templates/test/test_helper.rb.template +2 -1
- data/lib/initialization/application.rb +46 -0
- data/lib/initialization/configuration.rb +23 -38
- data/lib/initialization/console.rb +5 -2
- data/lib/initialization/helpers.rb +31 -0
- data/lib/initialization/logging.rb +69 -15
- data/lib/initialization/orm_support.rb +10 -4
- data/lib/initialization/plugins.rb +1 -1
- data/lib/mack.rb +18 -76
- data/lib/mack_tasks.rb +4 -1
- data/lib/rendering/engine/erubis.rb +1 -1
- data/lib/rendering/engine/registry.rb +5 -5
- data/lib/rendering/type/action.rb +3 -2
- data/lib/rendering/type/base.rb +1 -1
- data/lib/rendering/type/layout.rb +2 -2
- data/lib/rendering/type/partial.rb +1 -1
- data/lib/rendering/type/public.rb +1 -1
- data/lib/rendering/type/template.rb +1 -1
- data/lib/rendering/type/url.rb +4 -4
- data/lib/rendering/type/xml.rb +3 -2
- data/lib/rendering/view_template.rb +7 -7
- data/lib/routing/route_map.rb +27 -5
- data/lib/routing/urls.rb +1 -0
- data/lib/runner.rb +52 -17
- data/lib/tasks/cachetastic_tasks.rake +2 -2
- data/lib/tasks/mack_server_tasks.rake +2 -4
- data/lib/tasks/mack_update_tasks.rake +26 -0
- data/lib/tasks/rake_rules.rake +6 -2
- data/lib/tasks/test_tasks.rake +28 -10
- data/lib/testing/helpers.rb +187 -0
- data/lib/testing/response.rb +49 -0
- data/lib/testing/rspec.rb +20 -0
- data/lib/testing/test_assertions.rb +55 -0
- data/lib/{test_extensions → testing}/test_case.rb +9 -7
- data/lib/utils/crypt/keeper.rb +1 -1
- data/lib/utils/server.rb +2 -2
- data/lib/view_helpers/html_helpers.rb +4 -0
- metadata +26 -40
- data/lib/controller/base.rb +0 -345
- data/lib/generators/mack_application_generator/templates/app/helpers/application_helper.rb.template +0 -2
- data/lib/generators/mack_application_generator/templates/config/thin.ru.template +0 -1
- data/lib/generators/mack_application_generator/templates/config/thin.yml.template +0 -8
- data/lib/rendering/engine/haml.rb +0 -18
- data/lib/rendering/engine/markaby.rb +0 -28
- data/lib/test_extensions/test_assertions.rb +0 -55
- data/lib/test_extensions/test_helpers.rb +0 -192
@@ -0,0 +1,49 @@
|
|
1
|
+
module Mack
|
2
|
+
module Testing
|
3
|
+
class Response
|
4
|
+
|
5
|
+
attr_accessor :responses
|
6
|
+
|
7
|
+
def initialize(responses)
|
8
|
+
self.responses = [responses].flatten
|
9
|
+
end
|
10
|
+
|
11
|
+
def method_missing(sym, *args)
|
12
|
+
self.responses.last.send(sym, *args)
|
13
|
+
end
|
14
|
+
|
15
|
+
def successful?
|
16
|
+
self.responses.first.successful?
|
17
|
+
end
|
18
|
+
|
19
|
+
def redirect?
|
20
|
+
self.responses.first.redirect?
|
21
|
+
end
|
22
|
+
|
23
|
+
def not_found?
|
24
|
+
self.responses.first.not_found?
|
25
|
+
end
|
26
|
+
|
27
|
+
def server_error?
|
28
|
+
self.responses.first.server_error?
|
29
|
+
end
|
30
|
+
|
31
|
+
def forbidden?
|
32
|
+
self.responses.first.forbidden?
|
33
|
+
end
|
34
|
+
|
35
|
+
def status
|
36
|
+
self.responses.first.status
|
37
|
+
end
|
38
|
+
|
39
|
+
def redirected_to?(loc)
|
40
|
+
self.location == loc
|
41
|
+
end
|
42
|
+
|
43
|
+
def location
|
44
|
+
self.responses.first.location
|
45
|
+
end
|
46
|
+
|
47
|
+
end # Response
|
48
|
+
end # Testing
|
49
|
+
end # Mack
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "helpers")
|
2
|
+
|
3
|
+
module Spec # :nodoc:
|
4
|
+
module Example # :nodoc:
|
5
|
+
module ExampleMethods # :nodoc:
|
6
|
+
include Mack::Routes::Urls
|
7
|
+
include Mack::Testing::Helpers
|
8
|
+
|
9
|
+
alias_method :mack_spec_execute, :execute
|
10
|
+
|
11
|
+
def execute(options, instance_variables)
|
12
|
+
in_session do
|
13
|
+
@__res = mack_spec_execute(options, instance_variables)
|
14
|
+
end
|
15
|
+
@__res
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
module Mack
|
3
|
+
module Testing
|
4
|
+
module TestCaseAssertions
|
5
|
+
|
6
|
+
# Takes either a Symbol or a Fixnum and assert the response matches it.
|
7
|
+
# The symbols it will match are :success, :redirect, :not_found, :error.
|
8
|
+
# If a Fixnum is passed it will assert the response status equals that Fixnum
|
9
|
+
def assert_response(status)
|
10
|
+
if status.is_a?(Symbol)
|
11
|
+
case status
|
12
|
+
when :success
|
13
|
+
assert(response.successful?)
|
14
|
+
when :redirect
|
15
|
+
assert(response.redirect?)
|
16
|
+
when :not_found
|
17
|
+
assert(response.not_found?)
|
18
|
+
when :error
|
19
|
+
assert(response.server_error?)
|
20
|
+
else
|
21
|
+
assert(false)
|
22
|
+
end
|
23
|
+
elsif status.is_a?(Fixnum)
|
24
|
+
assert_equal(status, response.status)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Asserts that the request has been redirected to the specified url.
|
29
|
+
def assert_redirected_to(url)
|
30
|
+
assert response.redirected_to?(url)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Asserts that the specified cookie has been set to the specified value.
|
34
|
+
def assert_cookie(name, value)
|
35
|
+
assert cookies[name.to_s]
|
36
|
+
assert_equal value, cookies[name.to_s]
|
37
|
+
end
|
38
|
+
|
39
|
+
# Asserts that there is no cookie set for the specified cookie
|
40
|
+
def assert_no_cookie(name)
|
41
|
+
assert !cookies[name.to_s]
|
42
|
+
end
|
43
|
+
|
44
|
+
def assert_difference(object, method = nil, difference = 1)
|
45
|
+
start_count = object.send(method)
|
46
|
+
yield
|
47
|
+
object.reload if object.respond_to? :reload
|
48
|
+
assert_equal start_count + difference, object.send(method)
|
49
|
+
end
|
50
|
+
|
51
|
+
end # TestAssertions
|
52
|
+
end # Testing
|
53
|
+
end # Mack
|
54
|
+
|
55
|
+
Test::Unit::TestCase.send(:include, Mack::Testing::TestCaseAssertions)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module Test
|
1
|
+
module Test # :nodoc:
|
2
2
|
module Unit # :nodoc:
|
3
3
|
class TestCase # :nodoc:
|
4
4
|
|
@@ -14,12 +14,14 @@ module Test
|
|
14
14
|
# run a cleanup method if it exists
|
15
15
|
def run(result, &progress_block) # :nodoc:
|
16
16
|
super_run(result) do |state, name|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
in_session do
|
18
|
+
if state == Test::Unit::TestCase::STARTED
|
19
|
+
cleanup if self.respond_to?(:cleanup)
|
20
|
+
log_start(name)
|
21
|
+
else
|
22
|
+
cleanup if self.respond_to?(:cleanup)
|
23
|
+
log_end(name)
|
24
|
+
end
|
23
25
|
end
|
24
26
|
end
|
25
27
|
end
|
data/lib/utils/crypt/keeper.rb
CHANGED
@@ -31,7 +31,7 @@ module Mack
|
|
31
31
|
if worker.nil?
|
32
32
|
worker_klass = key.to_s.camelcase + "Worker"
|
33
33
|
if Mack::Utils::Crypt.const_defined?(worker_klass)
|
34
|
-
worker = "Mack::Utils::Crypt::#{worker_klass}".
|
34
|
+
worker = "Mack::Utils::Crypt::#{worker_klass}".constantize.new
|
35
35
|
else
|
36
36
|
worker = Mack::Utils::Crypt::DefaultWorker.new
|
37
37
|
end
|
data/lib/utils/server.rb
CHANGED
@@ -16,9 +16,9 @@ module Mack
|
|
16
16
|
# This will reload any edited classes if the cache_classes config setting is set to true.
|
17
17
|
app = Rack::Reloader.new(app, 1) unless app_config.mack.cache_classes
|
18
18
|
# TODO: Not sure about this logger, investigate better ones.
|
19
|
-
# TODO: Depends on
|
19
|
+
# TODO: Depends on Mack.logger already being configured.
|
20
20
|
# This makes it a drag run this 'standalone' in another Ruby program.
|
21
|
-
# app = Rack::CommonLogger.new(app,
|
21
|
+
# app = Rack::CommonLogger.new(app, Mack.logger)
|
22
22
|
app
|
23
23
|
end
|
24
24
|
|
@@ -84,6 +84,10 @@ module Mack
|
|
84
84
|
non_content_tag(:img, {:src => image_src}.merge(options))
|
85
85
|
end
|
86
86
|
|
87
|
+
# Builds an HTML submit tag
|
88
|
+
def submit_tag(value = "Submit", options = {})
|
89
|
+
non_content_tag(:input, {:type => :submit, :value => value}.merge(options))
|
90
|
+
end
|
87
91
|
|
88
92
|
# Wraps an image tag with a link tag.
|
89
93
|
#
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- markbates
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-07-16 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -22,13 +22,13 @@ dependencies:
|
|
22
22
|
version: 0.3.0
|
23
23
|
version:
|
24
24
|
- !ruby/object:Gem::Dependency
|
25
|
-
name:
|
25
|
+
name: mack-more
|
26
26
|
version_requirement:
|
27
27
|
version_requirements: !ruby/object:Gem::Requirement
|
28
28
|
requirements:
|
29
29
|
- - "="
|
30
30
|
- !ruby/object:Gem::Version
|
31
|
-
version: 0.
|
31
|
+
version: 0.6.0
|
32
32
|
version:
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: application_configuration
|
@@ -37,7 +37,7 @@ dependencies:
|
|
37
37
|
requirements:
|
38
38
|
- - "="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.
|
40
|
+
version: 1.5.0
|
41
41
|
version:
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: cachetastic
|
@@ -46,7 +46,7 @@ dependencies:
|
|
46
46
|
requirements:
|
47
47
|
- - "="
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: 1.
|
49
|
+
version: 1.7.2
|
50
50
|
version:
|
51
51
|
- !ruby/object:Gem::Dependency
|
52
52
|
name: log4r
|
@@ -64,7 +64,7 @@ dependencies:
|
|
64
64
|
requirements:
|
65
65
|
- - "="
|
66
66
|
- !ruby/object:Gem::Version
|
67
|
-
version: 0.8.
|
67
|
+
version: 0.8.2
|
68
68
|
version:
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: builder
|
@@ -100,25 +100,7 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - "="
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 2.6.
|
104
|
-
version:
|
105
|
-
- !ruby/object:Gem::Dependency
|
106
|
-
name: markaby
|
107
|
-
version_requirement:
|
108
|
-
version_requirements: !ruby/object:Gem::Requirement
|
109
|
-
requirements:
|
110
|
-
- - "="
|
111
|
-
- !ruby/object:Gem::Version
|
112
|
-
version: 0.5.0
|
113
|
-
version:
|
114
|
-
- !ruby/object:Gem::Dependency
|
115
|
-
name: haml
|
116
|
-
version_requirement:
|
117
|
-
version_requirements: !ruby/object:Gem::Requirement
|
118
|
-
requirements:
|
119
|
-
- - "="
|
120
|
-
- !ruby/object:Gem::Version
|
121
|
-
version: 1.8.2
|
103
|
+
version: 2.6.2
|
122
104
|
version:
|
123
105
|
- !ruby/object:Gem::Dependency
|
124
106
|
name: genosaurus
|
@@ -127,7 +109,7 @@ dependencies:
|
|
127
109
|
requirements:
|
128
110
|
- - "="
|
129
111
|
- !ruby/object:Gem::Version
|
130
|
-
version: 1.1
|
112
|
+
version: 1.2.1
|
131
113
|
version:
|
132
114
|
- !ruby/object:Gem::Dependency
|
133
115
|
name: rcov
|
@@ -139,13 +121,13 @@ dependencies:
|
|
139
121
|
version: 0.8.1.2.0
|
140
122
|
version:
|
141
123
|
- !ruby/object:Gem::Dependency
|
142
|
-
name:
|
124
|
+
name: rspec
|
143
125
|
version_requirement:
|
144
126
|
version_requirements: !ruby/object:Gem::Requirement
|
145
127
|
requirements:
|
146
128
|
- - "="
|
147
129
|
- !ruby/object:Gem::Version
|
148
|
-
version:
|
130
|
+
version: 1.1.4
|
149
131
|
version:
|
150
132
|
description: Mack is a powerful, yet simple, web application framework. It takes some cues from the likes of Rails and Merb, so it's not entirely unfamiliar. Mack hopes to provide developers a great framework for building, and deploying, portal and distributed applications.
|
151
133
|
email: mark@mackframework.com
|
@@ -159,7 +141,7 @@ extra_rdoc_files:
|
|
159
141
|
- CHANGELOG
|
160
142
|
files:
|
161
143
|
- README
|
162
|
-
- lib/controller/
|
144
|
+
- lib/controller/controller.rb
|
163
145
|
- lib/controller/cookie_jar.rb
|
164
146
|
- lib/controller/filter.rb
|
165
147
|
- lib/controller/request.rb
|
@@ -175,7 +157,8 @@ files:
|
|
175
157
|
- lib/generators/mack_application_generator/mack_application_generator.rb
|
176
158
|
- lib/generators/mack_application_generator/manifest.yml
|
177
159
|
- lib/generators/mack_application_generator/templates/app/controllers/default_controller.rb.template
|
178
|
-
- lib/generators/mack_application_generator/templates/app/helpers/
|
160
|
+
- lib/generators/mack_application_generator/templates/app/helpers/controllers/default_controller_helper.rb.template
|
161
|
+
- lib/generators/mack_application_generator/templates/app/helpers/views/application_helper.rb.template
|
179
162
|
- lib/generators/mack_application_generator/templates/app/views/default/index.html.erb.template
|
180
163
|
- lib/generators/mack_application_generator/templates/app/views/layouts/application.html.erb.template
|
181
164
|
- lib/generators/mack_application_generator/templates/config/app_config/default.yml.template
|
@@ -186,21 +169,23 @@ files:
|
|
186
169
|
- lib/generators/mack_application_generator/templates/config/initializers/gems.rb.template
|
187
170
|
- lib/generators/mack_application_generator/templates/config/initializers/mime_types.rb.template
|
188
171
|
- lib/generators/mack_application_generator/templates/config/routes.rb.template
|
189
|
-
- lib/generators/mack_application_generator/templates/config/thin.ru.template
|
190
|
-
- lib/generators/mack_application_generator/templates/config/thin.yml.template
|
191
172
|
- lib/generators/mack_application_generator/templates/public/favicon.ico.template
|
192
173
|
- lib/generators/mack_application_generator/templates/public/stylesheets/scaffold.css.template
|
193
174
|
- lib/generators/mack_application_generator/templates/Rakefile.template
|
194
|
-
- lib/generators/mack_application_generator/templates/test/functional.template
|
175
|
+
- lib/generators/mack_application_generator/templates/test/functional/default_controller_spec.rb.template
|
176
|
+
- lib/generators/mack_application_generator/templates/test/functional/default_controller_test.rb.template
|
177
|
+
- lib/generators/mack_application_generator/templates/test/spec.opts.template
|
178
|
+
- lib/generators/mack_application_generator/templates/test/spec_helper.rb.template
|
195
179
|
- lib/generators/mack_application_generator/templates/test/test_helper.rb.template
|
196
|
-
- lib/generators/mack_application_generator/templates/test/unit.template
|
197
180
|
- lib/generators/mack_application_generator/templates/vendor/plugins.template
|
198
181
|
- lib/generators/plugin_generator/plugin_generator.rb
|
199
182
|
- lib/generators/plugin_generator/templates/vendor/plugins/%=@plugin_name%/init.rb.template
|
200
183
|
- lib/generators/plugin_generator/templates/vendor/plugins/%=@plugin_name%/lib/%=@plugin_name%.rb.template
|
201
184
|
- lib/generators/plugin_generator/templates/vendor/plugins/%=@plugin_name%/lib/tasks/%=@plugin_name%_tasks.rake.template
|
185
|
+
- lib/initialization/application.rb
|
202
186
|
- lib/initialization/configuration.rb
|
203
187
|
- lib/initialization/console.rb
|
188
|
+
- lib/initialization/helpers.rb
|
204
189
|
- lib/initialization/logging.rb
|
205
190
|
- lib/initialization/orm_support.rb
|
206
191
|
- lib/initialization/plugins.rb
|
@@ -210,8 +195,6 @@ files:
|
|
210
195
|
- lib/rendering/engine/base.rb
|
211
196
|
- lib/rendering/engine/builder.rb
|
212
197
|
- lib/rendering/engine/erubis.rb
|
213
|
-
- lib/rendering/engine/haml.rb
|
214
|
-
- lib/rendering/engine/markaby.rb
|
215
198
|
- lib/rendering/engine/registry.rb
|
216
199
|
- lib/rendering/type/action.rb
|
217
200
|
- lib/rendering/type/base.rb
|
@@ -236,12 +219,15 @@ files:
|
|
236
219
|
- lib/tasks/mack_ring_server_tasks.rake
|
237
220
|
- lib/tasks/mack_server_tasks.rake
|
238
221
|
- lib/tasks/mack_tasks.rake
|
222
|
+
- lib/tasks/mack_update_tasks.rake
|
239
223
|
- lib/tasks/rake_helpers.rb
|
240
224
|
- lib/tasks/rake_rules.rake
|
241
225
|
- lib/tasks/test_tasks.rake
|
242
|
-
- lib/
|
243
|
-
- lib/
|
244
|
-
- lib/
|
226
|
+
- lib/testing/helpers.rb
|
227
|
+
- lib/testing/response.rb
|
228
|
+
- lib/testing/rspec.rb
|
229
|
+
- lib/testing/test_assertions.rb
|
230
|
+
- lib/testing/test_case.rb
|
245
231
|
- lib/utils/crypt/default_worker.rb
|
246
232
|
- lib/utils/crypt/keeper.rb
|
247
233
|
- lib/utils/gem_manager.rb
|
data/lib/controller/base.rb
DELETED
@@ -1,345 +0,0 @@
|
|
1
|
-
require 'erubis'
|
2
|
-
module Mack
|
3
|
-
module Controller # :nodoc:
|
4
|
-
# All controllers in a Mack application have to extend this class. I'll be honest, if they don't extend this class
|
5
|
-
# then, well, things just won't work very well!
|
6
|
-
#
|
7
|
-
# Example:
|
8
|
-
# class MyAwesomeController < Mack::Controller::Base
|
9
|
-
# def index
|
10
|
-
# render(:text, "Hello World!")
|
11
|
-
# end
|
12
|
-
# end
|
13
|
-
class Base
|
14
|
-
|
15
|
-
# See Mack::Request for more information.
|
16
|
-
attr_reader :request
|
17
|
-
# See Mack::Response for more information.
|
18
|
-
attr_reader :response
|
19
|
-
# The 'underscore' version of the controller requested. Example: 'my_awesome_controller'
|
20
|
-
attr_reader :controller_name
|
21
|
-
# The name of the action being requested.
|
22
|
-
attr_reader :action_name
|
23
|
-
# See Mack::CookieJar for more information.
|
24
|
-
attr_reader :cookies
|
25
|
-
|
26
|
-
def initialize(request, response, cookies)
|
27
|
-
@request = request
|
28
|
-
@response = response
|
29
|
-
@render_options = {}
|
30
|
-
@render_performed = false
|
31
|
-
@controller_name = params(:controller)
|
32
|
-
@action_name = params(:action)
|
33
|
-
@cookies = cookies
|
34
|
-
@wants_list = []
|
35
|
-
end
|
36
|
-
|
37
|
-
# Gives access to all the parameters for this request.
|
38
|
-
def params(key)
|
39
|
-
self.request.params(key)
|
40
|
-
end
|
41
|
-
|
42
|
-
# Gives access to the session. See Mack::Session for more information.
|
43
|
-
def session
|
44
|
-
self.request.session
|
45
|
-
end
|
46
|
-
|
47
|
-
# This does the heavy lifting for controllers. It calls the action, and then completes the rendering
|
48
|
-
# of the action to a String to send back to Rack.
|
49
|
-
def run
|
50
|
-
run_filters(:before)
|
51
|
-
# check to see if this controller responds to this action.
|
52
|
-
# only run public methods!
|
53
|
-
if self.public_methods.include?(self.action_name)
|
54
|
-
# call the action and capture the results to a variable.
|
55
|
-
self.send(self.action_name)
|
56
|
-
else
|
57
|
-
# there is no action on this controller, so call the render method
|
58
|
-
# which will check the view directory and run action.html.erb if it exists.
|
59
|
-
render(:action, self.action_name)
|
60
|
-
end
|
61
|
-
run_filters(:after)
|
62
|
-
# do the work of rendering.
|
63
|
-
@final_rendered_action = do_render
|
64
|
-
run_filters(:after_render)
|
65
|
-
@final_rendered_action
|
66
|
-
end
|
67
|
-
|
68
|
-
# This will redirect the request to the specified url. A default status of
|
69
|
-
# 302, Moved Temporarily, is set if no status is specified. A simple HTML
|
70
|
-
# page is rendered in case the redirect does not occur. A server side
|
71
|
-
# redirect is also possible by using the option :server_side => true.
|
72
|
-
# When a server side redirect occurs the url must be a 'local' url, not an
|
73
|
-
# external url. The 'original' url of the request will NOT change.
|
74
|
-
def redirect_to(url, options = {})
|
75
|
-
options = {:status => 302}.merge(options)
|
76
|
-
raise Rack::ForwardRequest.new(url) if options[:server_side]
|
77
|
-
response.status = options[:status]
|
78
|
-
response[:location] = url
|
79
|
-
render(:text, redirect_html(request.path_info, url, options[:status]))
|
80
|
-
end
|
81
|
-
|
82
|
-
# In an action wants will run blocks of code based on the content type that has
|
83
|
-
# been requested.
|
84
|
-
#
|
85
|
-
# Examples:
|
86
|
-
# class MyAwesomeController < Mack::Controller::Base
|
87
|
-
# def hello
|
88
|
-
# wants(:html) do
|
89
|
-
# render(:text, "<html>Hello World</html>")
|
90
|
-
# end
|
91
|
-
# wants(:xml) do
|
92
|
-
# render(:text, "<xml><greeting>Hello World</greeting></xml>")
|
93
|
-
# end
|
94
|
-
# end
|
95
|
-
# end
|
96
|
-
#
|
97
|
-
# If you were to go to: /my_awesome/hello you would get:
|
98
|
-
# "<html>Hello World</html>"
|
99
|
-
#
|
100
|
-
# If you were to go to: /my_awesome/hello.html you would get:
|
101
|
-
# "<html>Hello World</html>"
|
102
|
-
#
|
103
|
-
# If you were to go to: /my_awesome/hello.xml you would get:
|
104
|
-
# "<xml><greeting>Hello World</greeting></xml>"
|
105
|
-
def wants(header_type, &block)
|
106
|
-
header_type = header_type.to_sym
|
107
|
-
if header_type == params(:format).to_sym
|
108
|
-
yield
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
# Returns true/false depending on whether the render action has been called yet.
|
113
|
-
def render_performed?
|
114
|
-
@render_performed
|
115
|
-
end
|
116
|
-
|
117
|
-
# Gives access to the MACK_DEFAULT_LOGGER.
|
118
|
-
def logger
|
119
|
-
MACK_DEFAULT_LOGGER
|
120
|
-
end
|
121
|
-
|
122
|
-
# This method can be called from within an action. This 'registers' the render that you
|
123
|
-
# would like to happen once the action is completed.
|
124
|
-
#
|
125
|
-
# It's important to note that calling render in an action does NOT end the processing of
|
126
|
-
# the action. The action will continue to process unless you explicity put 'return' before the
|
127
|
-
# render call.
|
128
|
-
#
|
129
|
-
# If you call render twice in an action then a Mack::Errors::DoubleRender error will be thrown.
|
130
|
-
#
|
131
|
-
# An implicit render will happen if one is not specified in the action.
|
132
|
-
#
|
133
|
-
# Only :action and :text will get layouts wrapped around them.
|
134
|
-
#
|
135
|
-
# You can also specify the response status code as part of the options hash.
|
136
|
-
#
|
137
|
-
# Examples:
|
138
|
-
# class MyAwesomeController < Mack::Controller::Base
|
139
|
-
# # This will render the text 'Hello World!' to the screen.
|
140
|
-
# def index
|
141
|
-
# render(:text, "Hello World!")
|
142
|
-
# end
|
143
|
-
#
|
144
|
-
# # This will render Mack::Configuration.root/views/my_awesome_controller/foo.html.erb
|
145
|
-
# def show
|
146
|
-
# render(:action, :foo)
|
147
|
-
# end
|
148
|
-
#
|
149
|
-
# # This will raise a Mack::Errors::DoubleRender error.
|
150
|
-
# def edit
|
151
|
-
# render(:text, "Hello World!")
|
152
|
-
# render(:action, :foo)
|
153
|
-
# end
|
154
|
-
#
|
155
|
-
# # This will render Mack::Configuration.root/views/my_awesome_controller/delete.html.erb
|
156
|
-
# def delete
|
157
|
-
# end
|
158
|
-
#
|
159
|
-
# # This will render the text 'Hello World!' to the screen. Assuming that
|
160
|
-
# # there is no file: Mack::Configuration.root/views/my_awesome_controller/update.html.erb
|
161
|
-
# # The reason for this is if the view for the action doesn't exist, and the
|
162
|
-
# # last thing returned from the action is a String, that string will be returned.
|
163
|
-
# def update
|
164
|
-
# "Hello World!"
|
165
|
-
# end
|
166
|
-
#
|
167
|
-
# # This will raise a Mack::Errors::InvalidRenderType error. Assuming that
|
168
|
-
# # there is no file: Mack::Configuration.root/views/my_awesome_controller/create.html.erb
|
169
|
-
# def create
|
170
|
-
# @user = User.find(1)
|
171
|
-
# end
|
172
|
-
#
|
173
|
-
# # This will raise a Errno::ENOENT error. Assuming that
|
174
|
-
# # there is no file: Mack::Configuration.root/views/my_awesome_controller/bar.html.erb
|
175
|
-
# def bar
|
176
|
-
# render(:action, "bar")
|
177
|
-
# end
|
178
|
-
#
|
179
|
-
# # This will render a file from the public directory. Files served from the
|
180
|
-
# # public directory do NOT get layouts. The default file extension for files
|
181
|
-
# # served from the public directory is .html. This can be overridden with the
|
182
|
-
# # :ext => ".<ext>" option.
|
183
|
-
# def show_public_file
|
184
|
-
# render(:public, "my/files/foo")
|
185
|
-
# end
|
186
|
-
#
|
187
|
-
# # This will render a file from the public directory. Files served from the
|
188
|
-
# # public directory do NOT get layouts. The default file extension for files
|
189
|
-
# # served from the public directory is .html. This can be overridden with the
|
190
|
-
# # :ext => ".<ext>" option.
|
191
|
-
# def show_public_xml_file
|
192
|
-
# render(:public, "my/files/foo", :ext => ".xml")
|
193
|
-
# end
|
194
|
-
#
|
195
|
-
# # This will render a partial. In this case it will look for:
|
196
|
-
# # Mack::Configuration.root/views/my_awesome_controller/_latest_news.html.erb
|
197
|
-
# # Partials do NOT get wrapped in layouts.
|
198
|
-
# def latest_news
|
199
|
-
# render(:partial, :latest_news)
|
200
|
-
# end
|
201
|
-
#
|
202
|
-
# # This will render a partial. In this case it will look for:
|
203
|
-
# # Mack::Configuration.root/views/some_other/_old_news.html.erb
|
204
|
-
# # Partials do NOT get wrapped in layouts.
|
205
|
-
# def latest_news
|
206
|
-
# render(:partial, "some_other/old_news")
|
207
|
-
# end
|
208
|
-
#
|
209
|
-
# # This will render a url. If the url does not return a status code of '200',
|
210
|
-
# # an empty string will be returned by default. The default method for rendering
|
211
|
-
# # urls is a get.
|
212
|
-
# def yahoo
|
213
|
-
# render(:url, "http://www.yahoo.com")
|
214
|
-
# end
|
215
|
-
#
|
216
|
-
# # This will render a url. If the url does not return a status code of '200',
|
217
|
-
# # a Mack::Errors::UnsuccessfulRenderUrl exception will be raised.
|
218
|
-
# def idontexist
|
219
|
-
# render(:url, "http://www.idontexist.com", :raise_exception => true)
|
220
|
-
# end
|
221
|
-
#
|
222
|
-
# # This will render a url with a post.
|
223
|
-
# def post_to_somewhere
|
224
|
-
# render(:url, "http://www.mackframework.com/post_to_me", :method => :post,
|
225
|
-
# :parameters => {:id => 1, :user => "markbates"})
|
226
|
-
# end
|
227
|
-
#
|
228
|
-
# # This will render a 'local' url. If a domain is not present render url will
|
229
|
-
# # reach out for the config parameter "mack::site_domain" and prepend that
|
230
|
-
# # to the url. This can be overridden locally with the :domain option.
|
231
|
-
# def get_index
|
232
|
-
# render(:url, "/")
|
233
|
-
# end
|
234
|
-
#
|
235
|
-
# # This will render 'application/404' and set the response status code to 404
|
236
|
-
# def to_the_unknown
|
237
|
-
# return render(:action, '/application/404', :status => 404)
|
238
|
-
# end
|
239
|
-
#
|
240
|
-
# end
|
241
|
-
def render(render_type = :action, render_value = self.action_name, options = {})
|
242
|
-
raise Mack::Errors::DoubleRender.new if render_performed?
|
243
|
-
response.status = options[:status] unless options[:status].nil?
|
244
|
-
options = {:content_type => Mack::Utils::MimeTypes[params(:format)], :layout => layout}.merge(options)
|
245
|
-
response["Content-Type"] = options[:content_type]
|
246
|
-
options.delete(:content_type)
|
247
|
-
@view_template = Mack::Rendering::ViewTemplate.new(render_type, render_value,
|
248
|
-
{:format => params(:format).to_sym, :controller => self}.merge(options))
|
249
|
-
@render_performed = true
|
250
|
-
end
|
251
|
-
|
252
|
-
private
|
253
|
-
def do_render
|
254
|
-
render unless @view_template
|
255
|
-
@rendered_action = @view_template.compile_and_render
|
256
|
-
end
|
257
|
-
|
258
|
-
def layout
|
259
|
-
:application
|
260
|
-
end
|
261
|
-
|
262
|
-
def run_filters(type)
|
263
|
-
filters = self.class.controller_filters[type]
|
264
|
-
return true if filters.empty?
|
265
|
-
filters.each do |filter|
|
266
|
-
if filter.run?(self.action_name.to_sym)
|
267
|
-
r = self.send(filter.filter_method)
|
268
|
-
raise Mack::Errors::FilterChainHalted.new(filter.filter_method) unless r
|
269
|
-
end
|
270
|
-
end
|
271
|
-
end
|
272
|
-
|
273
|
-
public
|
274
|
-
class << self
|
275
|
-
|
276
|
-
# See Mack::Controller::Filter for more information.
|
277
|
-
def before_filter(meth, options = {})
|
278
|
-
add_filter(:before, meth, options)
|
279
|
-
end
|
280
|
-
|
281
|
-
# See Mack::Controller::Filter for more information.
|
282
|
-
def after_filter(meth, options = {})
|
283
|
-
add_filter(:after, meth, options)
|
284
|
-
end
|
285
|
-
|
286
|
-
# See Mack::Controller::Filter for more information.
|
287
|
-
def after_render_filter(meth, options = {})
|
288
|
-
add_filter(:after_render, meth, options)
|
289
|
-
end
|
290
|
-
|
291
|
-
def add_filter(type, meth, options) # :nodoc:
|
292
|
-
controller_filters[type.to_sym] << Mack::Controller::Filter.new(meth, self, options)
|
293
|
-
end
|
294
|
-
|
295
|
-
def controller_filters # :nodoc:
|
296
|
-
unless @controller_filters
|
297
|
-
@controller_filters = {:before => [], :after => [], :after_render => []}
|
298
|
-
# inherit filters from the superclass, if any, to this parent
|
299
|
-
sc = self.superclass
|
300
|
-
if sc.class_is_a?(Mack::Controller::Base)
|
301
|
-
ch = sc.controller_filters
|
302
|
-
[:before, :after, :after_render].each do |v|
|
303
|
-
@controller_filters[v] << ch[v]
|
304
|
-
@controller_filters[v].flatten!
|
305
|
-
@controller_filters[v].uniq!
|
306
|
-
end
|
307
|
-
end
|
308
|
-
end
|
309
|
-
@controller_filters
|
310
|
-
end
|
311
|
-
|
312
|
-
# Sets a layout to be used by a particular controller.
|
313
|
-
#
|
314
|
-
# Example:
|
315
|
-
# class MyAwesomeController < Mack::Controller::Base
|
316
|
-
# # Sets all actions to use: "#{Mack::Configuration.root}/app/views/layouts/dark.html.erb" as they're layout.
|
317
|
-
# layout :dark
|
318
|
-
#
|
319
|
-
# def index
|
320
|
-
# # Sets this action to use: "#{Mack::Configuration.root}/app/views/layouts/bright.html.erb" as it's layout.
|
321
|
-
# render(:text, "Welcome...", :layout => :bright)
|
322
|
-
# end
|
323
|
-
#
|
324
|
-
# def index
|
325
|
-
# # This will no use a layout.
|
326
|
-
# render(:text, "Welcome...", :layout => false)
|
327
|
-
# end
|
328
|
-
# end
|
329
|
-
#
|
330
|
-
# The default layout is "#{Mack::Configuration.root}/app/views/layouts/application.html.erb".
|
331
|
-
#
|
332
|
-
# If a layout is specified, and it doesn't exist a Mack::Errors::UnknownLayout error will be raised.
|
333
|
-
def layout(lay)
|
334
|
-
self.class_eval do
|
335
|
-
define_method(:layout) do
|
336
|
-
lay
|
337
|
-
end
|
338
|
-
end
|
339
|
-
end # layout
|
340
|
-
|
341
|
-
end # class << self
|
342
|
-
|
343
|
-
end # Base
|
344
|
-
end # Controller
|
345
|
-
end # Mack
|