ramaze 0.1.0 → 0.1.1
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.
- data/Rakefile +4 -12
- data/bin/ramaze +95 -171
- data/doc/CHANGELOG +387 -4
- data/doc/README +81 -13
- data/doc/meta/announcement.txt +51 -8
- data/doc/meta/configuration.txt +17 -34
- data/doc/meta/internals.txt +34 -4
- data/doc/migrate/1110_to_1111.txt +131 -0
- data/doc/readme_chunks/features.txt +81 -12
- data/doc/readme_chunks/installing.txt +0 -1
- data/doc/tutorial/todolist.html +293 -65
- data/doc/tutorial/{todolist.txt → todolist.mkd} +251 -51
- data/examples/blog/main.rb +1 -1
- data/examples/blog/src/model.rb +0 -1
- data/examples/hello.rb +2 -5
- data/examples/templates/template/external.haml +5 -5
- data/examples/templates/template/external.liquid +1 -1
- data/examples/templates/template/external.mab +8 -8
- data/examples/templates/template/external.rem +30 -0
- data/examples/templates/template/external.rhtml +6 -7
- data/examples/templates/template/external.zmr +13 -9
- data/examples/templates/template_amrita2.rb +8 -8
- data/examples/templates/template_erubis.rb +11 -11
- data/examples/templates/template_ezamar.rb +9 -11
- data/examples/templates/template_haml.rb +13 -13
- data/examples/templates/template_liquid.rb +10 -10
- data/examples/templates/template_markaby.rb +13 -10
- data/examples/templates/template_remarkably.rb +59 -0
- data/examples/todolist/main.rb +1 -7
- data/examples/todolist/src/controller/main.rb +26 -13
- data/examples/todolist/src/element/page.rb +5 -0
- data/examples/whywiki/main.rb +1 -1
- data/lib/proto/main.rb +0 -8
- data/lib/proto/public/css/ramaze_error.css +12 -4
- data/lib/proto/public/error.zmr +6 -25
- data/lib/ramaze.rb +35 -245
- data/lib/ramaze/action.rb +21 -0
- data/lib/ramaze/adapter.rb +94 -29
- data/lib/ramaze/adapter/base.rb +57 -0
- data/lib/ramaze/adapter/mongrel.rb +12 -19
- data/lib/ramaze/adapter/webrick.rb +21 -20
- data/lib/ramaze/cache.rb +47 -3
- data/lib/ramaze/cache/memcached.rb +22 -0
- data/lib/ramaze/cache/yaml_store.rb +19 -0
- data/lib/ramaze/controller.rb +47 -271
- data/lib/ramaze/controller/error.rb +43 -0
- data/lib/ramaze/controller/render.rb +90 -0
- data/lib/ramaze/controller/resolve.rb +147 -0
- data/lib/ramaze/dispatcher.rb +41 -9
- data/lib/ramaze/dispatcher/file.rb +1 -1
- data/lib/ramaze/global.rb +73 -158
- data/lib/ramaze/global/dsl.rb +29 -0
- data/lib/ramaze/global/globalstruct.rb +90 -0
- data/lib/ramaze/helper.rb +1 -1
- data/lib/ramaze/helper/aspect.rb +39 -179
- data/lib/ramaze/helper/cache.rb +8 -9
- data/lib/ramaze/helper/cgi.rb +23 -0
- data/lib/ramaze/helper/file.rb +3 -0
- data/lib/ramaze/helper/inform.rb +3 -0
- data/lib/ramaze/helper/link.rb +56 -63
- data/lib/ramaze/helper/nitroform.rb +4 -0
- data/lib/ramaze/helper/redirect.rb +1 -1
- data/lib/ramaze/inform.rb +6 -2
- data/lib/ramaze/inform/analogger.rb +5 -1
- data/lib/ramaze/inform/hub.rb +1 -1
- data/lib/ramaze/inform/informing.rb +7 -0
- data/lib/ramaze/snippets/kernel/aquire.rb +2 -0
- data/lib/ramaze/snippets/kernel/constant.rb +2 -0
- data/lib/ramaze/snippets/kernel/pretty_inspect.rb +2 -0
- data/lib/ramaze/snippets/object/traits.rb +4 -0
- data/lib/ramaze/snippets/openstruct/temp.rb +3 -0
- data/lib/ramaze/snippets/string/DIVIDE.rb +2 -0
- data/lib/ramaze/snippets/string/camel_case.rb +2 -0
- data/lib/ramaze/snippets/string/color.rb +2 -0
- data/lib/ramaze/snippets/string/each.rb +2 -0
- data/lib/ramaze/snippets/string/snake_case.rb +3 -0
- data/lib/ramaze/snippets/struct/fill.rb +8 -2
- data/lib/ramaze/snippets/struct/values_at.rb +16 -0
- data/lib/ramaze/snippets/symbol/to_proc.rb +3 -0
- data/lib/ramaze/sourcereload.rb +89 -0
- data/lib/ramaze/template.rb +21 -12
- data/lib/ramaze/template/amrita2.rb +6 -6
- data/lib/ramaze/template/erubis.rb +4 -9
- data/lib/ramaze/template/ezamar.rb +13 -57
- data/lib/ramaze/template/ezamar/element.rb +10 -12
- data/lib/ramaze/template/ezamar/engine.rb +40 -101
- data/lib/ramaze/template/ezamar/morpher.rb +3 -3
- data/lib/ramaze/template/haml.rb +3 -6
- data/lib/ramaze/template/liquid.rb +4 -9
- data/lib/ramaze/template/markaby.rb +16 -22
- data/lib/ramaze/template/remarkably.rb +28 -0
- data/lib/ramaze/tool/mime.rb +2 -0
- data/lib/ramaze/tool/record.rb +6 -0
- data/lib/ramaze/trinity/request.rb +44 -54
- data/lib/ramaze/trinity/response.rb +1 -1
- data/lib/ramaze/trinity/session.rb +15 -37
- data/lib/ramaze/version.rb +1 -1
- data/rake_tasks/gem.rake +2 -2
- data/rake_tasks/maintaince.rake +42 -1
- data/rake_tasks/spec.rake +45 -0
- data/spec/examples/caching.rb +1 -1
- data/spec/examples/simple.rb +1 -1
- data/spec/examples/templates/template_amrita2.rb +1 -0
- data/spec/examples/templates/template_erubis.rb +2 -1
- data/spec/examples/templates/template_ezamar.rb +1 -1
- data/spec/examples/templates/template_haml.rb +2 -1
- data/spec/examples/templates/template_liquid.rb +2 -1
- data/spec/examples/templates/template_markaby.rb +2 -1
- data/spec/examples/templates/template_remarkably.rb +22 -0
- data/spec/examples/todolist.rb +125 -0
- data/spec/helper.rb +2 -23
- data/spec/helper/minimal.rb +20 -0
- data/spec/helper/mock_http.rb +24 -30
- data/spec/helper/simple_http.rb +2 -2
- data/spec/helper/wrap.rb +6 -9
- data/spec/ramaze/adapter.rb +1 -1
- data/spec/ramaze/adapter/record.rb +31 -0
- data/spec/ramaze/cache.rb +41 -54
- data/spec/ramaze/controller.rb +121 -137
- data/spec/ramaze/controller/template/list.xhtml +1 -0
- data/spec/ramaze/controller/template/other/greet/other.xhtml +1 -0
- data/spec/ramaze/controller/template_resolving.rb +27 -3
- data/spec/ramaze/element.rb +11 -7
- data/spec/ramaze/error.rb +1 -1
- data/spec/ramaze/gestalt.rb +2 -0
- data/spec/ramaze/helper/aspect.rb +30 -21
- data/spec/ramaze/helper/auth.rb +1 -1
- data/spec/ramaze/helper/cache.rb +2 -1
- data/spec/ramaze/helper/form.rb +14 -11
- data/spec/ramaze/helper/link.rb +18 -41
- data/spec/ramaze/localize.rb +29 -2
- data/spec/ramaze/morpher.rb +23 -12
- data/spec/ramaze/params.rb +46 -24
- data/spec/ramaze/request.rb +6 -2
- data/spec/ramaze/store/yaml.rb +5 -0
- data/spec/ramaze/template.rb +22 -27
- data/spec/ramaze/template/amrita2.rb +1 -2
- data/spec/ramaze/template/erubis.rb +1 -1
- data/spec/ramaze/template/ezamar.rb +1 -2
- data/spec/ramaze/template/haml.rb +2 -2
- data/spec/ramaze/template/haml/with_vars.haml +1 -1
- data/spec/ramaze/template/liquid.rb +1 -1
- data/spec/ramaze/template/markaby.rb +1 -1
- data/spec/ramaze/template/remarkably.rb +56 -0
- data/spec/ramaze/template/remarkably/external.rem +8 -0
- data/spec/ramaze/template/remarkably/sum.rem +1 -0
- metadata +38 -63
- data/doc/README.html +0 -637
- data/doc/allison/LICENSE +0 -184
- data/doc/allison/README +0 -37
- data/doc/allison/allison.css +0 -299
- data/doc/allison/allison.gif +0 -0
- data/doc/allison/allison.js +0 -307
- data/doc/allison/allison.rb +0 -287
- data/doc/allison/cache/BODY +0 -588
- data/doc/allison/cache/CLASS_INDEX +0 -4
- data/doc/allison/cache/CLASS_PAGE +0 -1
- data/doc/allison/cache/FILE_INDEX +0 -4
- data/doc/allison/cache/FILE_PAGE +0 -1
- data/doc/allison/cache/FONTS +0 -1
- data/doc/allison/cache/FR_INDEX_BODY +0 -1
- data/doc/allison/cache/IMGPATH +0 -1
- data/doc/allison/cache/INDEX +0 -1
- data/doc/allison/cache/JAVASCRIPT +0 -307
- data/doc/allison/cache/METHOD_INDEX +0 -4
- data/doc/allison/cache/METHOD_LIST +0 -1
- data/doc/allison/cache/SRC_PAGE +0 -1
- data/doc/allison/cache/STYLE +0 -321
- data/doc/allison/cache/URL +0 -1
- data/doc/changes.txt +0 -3375
- data/doc/changes.xml +0 -3378
- data/examples/todolist/conf/benchmark.yaml +0 -35
- data/examples/todolist/conf/debug.yaml +0 -34
- data/examples/todolist/conf/live.yaml +0 -33
- data/examples/todolist/conf/silent.yaml +0 -31
- data/examples/todolist/conf/stage.yaml +0 -33
- data/examples/todolist/public/css/coderay.css +0 -105
- data/examples/todolist/public/css/ramaze_error.css +0 -42
- data/lib/proto/conf/benchmark.yaml +0 -21
- data/lib/proto/conf/debug.yaml +0 -21
- data/lib/proto/conf/live.yaml +0 -21
- data/lib/proto/conf/silent.yaml +0 -21
- data/lib/proto/conf/stage.yaml +0 -21
- data/lib/proto/public/css/coderay.css +0 -105
- data/lib/ramaze/http_status.rb +0 -66
- data/lib/ramaze/snippets/hash/keys_to_sym.rb +0 -19
- data/lib/ramaze/snippets/kernel/method.rb +0 -26
- data/lib/ramaze/snippets/method/name.rb +0 -22
- data/lib/ramaze/snippets/ramaze/autoreload.rb +0 -135
- data/lib/ramaze/snippets/rdoc/usage_no_exit.rb +0 -65
- data/spec/all.rb +0 -32
- data/spec/ramaze/conf/locale_de.yaml +0 -6
- data/spec/ramaze/conf/locale_en.yaml +0 -6
- data/spec/ramaze/dependencies.rb +0 -16
- data/spec/ramaze/global.rb +0 -44
data/lib/ramaze/controller.rb
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
# Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
|
|
2
2
|
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
3
|
|
|
4
|
+
require 'ramaze/helper'
|
|
4
5
|
require 'ramaze/template'
|
|
6
|
+
require 'ramaze/action'
|
|
5
7
|
|
|
6
|
-
|
|
8
|
+
require 'ramaze/controller/resolve'
|
|
9
|
+
require 'ramaze/controller/render'
|
|
10
|
+
require 'ramaze/controller/error'
|
|
7
11
|
|
|
8
|
-
|
|
9
|
-
def to_s
|
|
10
|
-
%{#<Action method=#{method.inspect}, params=#{params.inspect} template=#{template.inspect}>}
|
|
11
|
-
end
|
|
12
|
-
end
|
|
12
|
+
module Ramaze
|
|
13
13
|
|
|
14
14
|
# The Controller is responsible for combining and rendering actions.
|
|
15
15
|
|
|
@@ -17,28 +17,22 @@ module Ramaze
|
|
|
17
17
|
include Ramaze::Helper
|
|
18
18
|
extend Ramaze::Helper
|
|
19
19
|
|
|
20
|
-
helper :redirect, :link, :file
|
|
20
|
+
helper :redirect, :link, :file, :flash, :cgi
|
|
21
21
|
|
|
22
|
-
trait
|
|
23
|
-
|
|
24
|
-
# Path to the ramaze-internal public directory for error-pages and the like.
|
|
25
|
-
# It acts just as a shadow.
|
|
26
|
-
trait :ramaze_public => ( ::Ramaze::BASEDIR / 'proto' / 'public' )
|
|
22
|
+
trait[:template_extensions] ||= {}
|
|
27
23
|
|
|
28
24
|
# Whether or not to map this controller on startup automatically
|
|
29
25
|
|
|
30
|
-
trait
|
|
26
|
+
trait[:automap] ||= true
|
|
31
27
|
|
|
32
28
|
# Place to map the Controller to, this is something like '/' or '/foo'
|
|
33
29
|
|
|
34
|
-
trait
|
|
30
|
+
trait[:map] ||= nil
|
|
35
31
|
|
|
36
32
|
trait :exclude_action_modules => [Kernel, Object, PP::ObjectMixin]
|
|
37
33
|
|
|
38
34
|
trait :pattern_cache => Hash.new{|h,k| h[k] = Controller.pattern_for(k) }
|
|
39
35
|
|
|
40
|
-
trait :action_cache => Global.cache.new
|
|
41
|
-
|
|
42
36
|
class << self
|
|
43
37
|
include Ramaze::Helper
|
|
44
38
|
extend Ramaze::Helper
|
|
@@ -48,20 +42,29 @@ module Ramaze
|
|
|
48
42
|
Global.controllers << controller
|
|
49
43
|
end
|
|
50
44
|
|
|
51
|
-
def
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
45
|
+
def startup options = {}
|
|
46
|
+
Inform.debug("found Controllers: #{Global.controllers.inspect}")
|
|
47
|
+
|
|
48
|
+
Cache.add :actions, :patterns
|
|
49
|
+
|
|
50
|
+
Global.controllers.each do |controller|
|
|
51
|
+
if map = controller.mapping
|
|
52
|
+
Inform.debug("mapping #{map} => #{controller}")
|
|
53
|
+
Global.mapping[map] ||= controller
|
|
55
54
|
end
|
|
56
55
|
end
|
|
56
|
+
|
|
57
|
+
Inform.debug("mapped Controllers: #{Global.mapping.inspect}")
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def check_path(path, message)
|
|
61
|
+
Inform.warn(message) unless File.directory?(path)
|
|
57
62
|
end
|
|
58
63
|
|
|
59
64
|
def mapping
|
|
60
65
|
global_mapping = Global.mapping.invert[self]
|
|
61
66
|
return global_mapping if global_mapping
|
|
62
|
-
if
|
|
63
|
-
map
|
|
64
|
-
elsif ancestral_trait[:automap]
|
|
67
|
+
if ancestral_trait[:automap]
|
|
65
68
|
name = self.to_s.gsub('Controller', '').split('::').last
|
|
66
69
|
%w[Main Base Index].include?(name) ? '/' : "/#{name.snake_case}"
|
|
67
70
|
end
|
|
@@ -73,266 +76,39 @@ module Ramaze
|
|
|
73
76
|
end
|
|
74
77
|
end
|
|
75
78
|
|
|
76
|
-
def
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
controller, action = *resolve(path)
|
|
82
|
-
controller.render(action)
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
# #ramaze - 9.5.2007
|
|
87
|
-
#
|
|
88
|
-
# manveru | if no possible controller is found, it's a NoController error
|
|
89
|
-
# manveru | that would be a 404 then
|
|
90
|
-
# Kashia | aye
|
|
91
|
-
# manveru | if some controller are found but no actions on them, it's NoAction Error for the first controller found, again, 404
|
|
92
|
-
# manveru | everything further down is considered 500
|
|
93
|
-
|
|
94
|
-
def resolve(path)
|
|
95
|
-
#Inform.debug("resolve_controller('#{path}')")
|
|
96
|
-
mapping = Global.mapping
|
|
97
|
-
controllers = Global.controllers
|
|
98
|
-
|
|
99
|
-
raise_no_controller(path) if controllers.empty? or mapping.empty?
|
|
100
|
-
|
|
101
|
-
patterns = Controller.trait[:pattern_cache][path]
|
|
102
|
-
first_controller = nil
|
|
103
|
-
|
|
104
|
-
patterns.each do |controller, method, params|
|
|
105
|
-
if controller = mapping[controller]
|
|
106
|
-
first_controller ||= controller
|
|
107
|
-
|
|
108
|
-
action = controller.resolve_action(method, *params)
|
|
109
|
-
template = action.template
|
|
110
|
-
|
|
111
|
-
action.method ||= File.basename(template, File.extname(template)) if template
|
|
112
|
-
|
|
113
|
-
return controller, action if action.method
|
|
114
|
-
end
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
raise_no_action(first_controller, path) if first_controller
|
|
118
|
-
raise_no_controller(path)
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
def resolve_action(path, *parameter)
|
|
122
|
-
path, parameter = path.to_s, parameter.map(&:to_s)
|
|
123
|
-
possible_path = trait["#{path}_template".to_sym]
|
|
124
|
-
template = resolve(possible_path).last.template if possible_path
|
|
125
|
-
|
|
126
|
-
method, params = resolve_method(path, *parameter)
|
|
127
|
-
|
|
128
|
-
if method or parameter.empty?
|
|
129
|
-
template ||= resolve_template(path)
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
Action.new(method, params, template)
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
def resolve_template(action)
|
|
136
|
-
action = action.to_s
|
|
137
|
-
action_converted = action.split('__').inject{|s,v| s/v}
|
|
138
|
-
actions = [action, action_converted].compact
|
|
139
|
-
|
|
140
|
-
paths = template_paths.map{|pa| actions.map{|a| pa/a } }.flatten.uniq
|
|
141
|
-
glob = "{#{paths.join(',')}}.{#{extension_order.join(',')}}"
|
|
142
|
-
|
|
143
|
-
Dir[glob].first
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
def template_paths
|
|
147
|
-
klass_public = trait[:public]
|
|
148
|
-
ramaze_public = Controller.trait[:ramaze_public]
|
|
149
|
-
|
|
150
|
-
first_path =
|
|
151
|
-
if template_root = class_trait[:template_root]
|
|
152
|
-
template_root
|
|
153
|
-
else
|
|
154
|
-
Global.template_root / Global.mapping.invert[self]
|
|
155
|
-
end
|
|
156
|
-
[ first_path, klass_public, ramaze_public].compact
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
def resolve_method(name, *params)
|
|
160
|
-
if method = action_methods.delete(name)
|
|
161
|
-
arity = instance_method(method).arity
|
|
162
|
-
if params.size == arity or arity < 0
|
|
163
|
-
return method, params
|
|
164
|
-
end
|
|
165
|
-
end
|
|
166
|
-
return nil, []
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
def action_methods
|
|
170
|
-
exclude = Controller.trait[:exclude_action_modules]
|
|
171
|
-
|
|
172
|
-
ancs = (ancestors - exclude).select{|a| a.is_a?(Module)}
|
|
173
|
-
ancs.map{|a| a.instance_methods(false).map(&:to_s)}.flatten.uniq
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
def pattern_for(path)
|
|
177
|
-
atoms = path.split('/').grep(/\S/)
|
|
178
|
-
atoms.unshift('')
|
|
179
|
-
patterns, joiners = [], ['/']
|
|
180
|
-
|
|
181
|
-
atoms.size.times do |enum|
|
|
182
|
-
enum += 1
|
|
183
|
-
joiners << '__' if enum == 3
|
|
184
|
-
|
|
185
|
-
joiners.each do |joinus|
|
|
186
|
-
pattern = atoms.dup
|
|
187
|
-
|
|
188
|
-
controller = pattern[0, enum].join(joinus)
|
|
189
|
-
controller.gsub!(/^__/, '/')
|
|
190
|
-
controller = "/" if controller == ""
|
|
191
|
-
|
|
192
|
-
pattern = pattern[enum..-1]
|
|
193
|
-
args, temp = [], []
|
|
194
|
-
|
|
195
|
-
patterns << [controller, 'index', atoms[enum..-1]]
|
|
196
|
-
|
|
197
|
-
until pattern.empty?
|
|
198
|
-
args << pattern.shift
|
|
199
|
-
patterns << [controller, args.join( '__' ), pattern.dup]
|
|
200
|
-
end
|
|
201
|
-
end
|
|
202
|
-
end
|
|
203
|
-
|
|
204
|
-
patterns.reverse!
|
|
205
|
-
end
|
|
206
|
-
|
|
207
|
-
def extension_order
|
|
208
|
-
t_extensions = Controller.trait[:template_extensions]
|
|
209
|
-
engine = trait[:engine]
|
|
210
|
-
c_extensions = t_extensions.reject{|k,v| v != engine}.keys
|
|
211
|
-
all_extensions = t_extensions.keys
|
|
212
|
-
(c_extensions + all_extensions).uniq
|
|
213
|
-
end
|
|
214
|
-
|
|
215
|
-
def render(action = {})
|
|
216
|
-
action = Action.fill(action) if action.is_a?(Hash)
|
|
217
|
-
Inform.debug("The Action: #{action}")
|
|
218
|
-
|
|
219
|
-
action.method = action.method.to_s
|
|
220
|
-
action.params.compact!
|
|
221
|
-
|
|
222
|
-
if cached?(action)
|
|
223
|
-
cached_render(action)
|
|
79
|
+
def template_root path = nil
|
|
80
|
+
if path
|
|
81
|
+
message = "#{self}.template_root is #{path} which does not exist"
|
|
82
|
+
check_path(path, message)
|
|
83
|
+
@template_root = path
|
|
224
84
|
else
|
|
225
|
-
|
|
226
|
-
end
|
|
227
|
-
end
|
|
228
|
-
|
|
229
|
-
def cached?(action)
|
|
230
|
-
actions_cached = trait[:actions_cached]
|
|
231
|
-
|
|
232
|
-
[ Global.cache_all,
|
|
233
|
-
trait[:cache_all],
|
|
234
|
-
actions_cached.map{|k| k.to_s}.include?(action.method),
|
|
235
|
-
].any?
|
|
236
|
-
end
|
|
237
|
-
|
|
238
|
-
def uncached_render(action)
|
|
239
|
-
controller = self.new
|
|
240
|
-
controller.instance_variable_set('@action', action.method)
|
|
241
|
-
Thread.current[:controller] = controller
|
|
242
|
-
|
|
243
|
-
options = {
|
|
244
|
-
:file => action.template,
|
|
245
|
-
:binding => controller.instance_eval{ binding },
|
|
246
|
-
:action => action.method,
|
|
247
|
-
:parameter => action.params,
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
engine = select_engine(options[:file])
|
|
251
|
-
engine.transform(controller, options)
|
|
252
|
-
end
|
|
253
|
-
|
|
254
|
-
def cached_render action
|
|
255
|
-
action_cache = Controller.trait[:action_cache]
|
|
256
|
-
|
|
257
|
-
if out = action_cache[action]
|
|
258
|
-
Inform.debug("Using Cached version for #{action}")
|
|
259
|
-
return out
|
|
85
|
+
@template_root
|
|
260
86
|
end
|
|
261
|
-
|
|
262
|
-
Inform.debug("Compiling Action: #{action}")
|
|
263
|
-
action_cache[action] = uncached_render(action)
|
|
264
87
|
end
|
|
265
88
|
|
|
266
|
-
def
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
ext = File.extname(file).gsub(/^\./, '')
|
|
275
|
-
ext_engine = engines[ext]
|
|
276
|
-
return ext_engine ? ext_engine : default
|
|
277
|
-
end
|
|
278
|
-
|
|
279
|
-
# This method is called by templating-engines to register themselves with
|
|
280
|
-
# a list of extensions that will be looked up on #render of an action.
|
|
281
|
-
|
|
282
|
-
def register_engine engine, *extensions
|
|
283
|
-
extensions.flatten.each do |ext|
|
|
284
|
-
trait[:template_extensions][ext] = engine
|
|
89
|
+
def public_root path = nil
|
|
90
|
+
if path
|
|
91
|
+
message = "#{self}.public_root is #{path} which does not exist"
|
|
92
|
+
check_path(path, message)
|
|
93
|
+
@public_root = path
|
|
94
|
+
else
|
|
95
|
+
@public_root
|
|
285
96
|
end
|
|
286
97
|
end
|
|
287
98
|
|
|
288
|
-
def
|
|
289
|
-
|
|
99
|
+
def template(this, from, that = nil)
|
|
100
|
+
from, that = self, from unless that
|
|
101
|
+
trait "#{this}_template" => [from, that.to_s]
|
|
290
102
|
end
|
|
291
103
|
|
|
292
|
-
def
|
|
293
|
-
|
|
294
|
-
end
|
|
295
|
-
end
|
|
296
|
-
|
|
297
|
-
# the default error-page handler. you can overwrite this method
|
|
298
|
-
# in your controller and create your own error-template for use.
|
|
299
|
-
#
|
|
300
|
-
# Error-pages can be in whatever the templating-engine of your controller
|
|
301
|
-
# is set to.
|
|
302
|
-
# Thread.current[:exception]
|
|
303
|
-
# holds the exception thrown.
|
|
304
|
-
|
|
305
|
-
def error
|
|
306
|
-
error = Thread.current[:exception]
|
|
307
|
-
@backtrace = error.backtrace[0..20]
|
|
308
|
-
title = error.message
|
|
309
|
-
|
|
310
|
-
@colors = []
|
|
311
|
-
min = 200
|
|
312
|
-
max = 255
|
|
313
|
-
step = -((max - min) / @backtrace.size).abs
|
|
314
|
-
max.step(min, step) do |color|
|
|
315
|
-
@colors << color
|
|
104
|
+
def current
|
|
105
|
+
Thread.current[:controller]
|
|
316
106
|
end
|
|
317
107
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
file, lineno, meth = *Ramaze.parse_backtrace(line)
|
|
322
|
-
lines = Ramaze.caller_lines(file, lineno, backtrace_size)
|
|
323
|
-
|
|
324
|
-
[ lines, lines.object_id.abs, file, lineno, meth ]
|
|
108
|
+
def handle path
|
|
109
|
+
controller, action = *resolve(path)
|
|
110
|
+
controller.render(action)
|
|
325
111
|
end
|
|
326
|
-
|
|
327
|
-
@title = CGI.escapeHTML(title)
|
|
328
|
-
require 'coderay'
|
|
329
|
-
@coderay = true
|
|
330
|
-
title
|
|
331
|
-
rescue LoadError => ex
|
|
332
|
-
@coderay = false
|
|
333
|
-
title
|
|
334
|
-
rescue Object => ex
|
|
335
|
-
Inform.error(ex)
|
|
336
112
|
end
|
|
337
113
|
|
|
338
114
|
private
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
|
|
2
|
+
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
|
+
|
|
4
|
+
module Ramaze
|
|
5
|
+
class Controller
|
|
6
|
+
# The default error-page handler. you can overwrite this method
|
|
7
|
+
# in your controller and create your own error-template for use.
|
|
8
|
+
#
|
|
9
|
+
# Error-pages can be in whatever the templating-engine of your controller
|
|
10
|
+
# is set to.
|
|
11
|
+
# Thread.current[:exception]
|
|
12
|
+
# holds the exception thrown.
|
|
13
|
+
|
|
14
|
+
def error
|
|
15
|
+
error = Thread.current[:exception]
|
|
16
|
+
@backtrace = error.backtrace[0..20]
|
|
17
|
+
title = error.message
|
|
18
|
+
|
|
19
|
+
@colors = []
|
|
20
|
+
min = 200
|
|
21
|
+
max = 255
|
|
22
|
+
step = -((max - min) / @backtrace.size).abs
|
|
23
|
+
max.step(min, step) do |color|
|
|
24
|
+
@colors << color
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
backtrace_size = Ramaze::Global.backtrace_size
|
|
28
|
+
|
|
29
|
+
@backtrace.map! do |line|
|
|
30
|
+
file, lineno, meth = *Ramaze.parse_backtrace(line)
|
|
31
|
+
lines = Ramaze.caller_lines(file, lineno, backtrace_size)
|
|
32
|
+
|
|
33
|
+
[ lines, lines.object_id.abs, file, lineno, meth ]
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
@title = CGI.escapeHTML(title)
|
|
37
|
+
@editor = (ENV['EDITOR'] || 'vim')
|
|
38
|
+
title
|
|
39
|
+
rescue Object => ex
|
|
40
|
+
Inform.error(ex)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
|
|
2
|
+
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
|
+
|
|
4
|
+
module Ramaze
|
|
5
|
+
class Controller
|
|
6
|
+
class << self
|
|
7
|
+
def render(action = {})
|
|
8
|
+
action = Action.fill(action) if action.is_a?(Hash)
|
|
9
|
+
Inform.debug("The Action: #{action}")
|
|
10
|
+
|
|
11
|
+
action.method = action.method.to_s if action.method
|
|
12
|
+
action.params.compact!
|
|
13
|
+
|
|
14
|
+
if cached?(action)
|
|
15
|
+
cached_render(action)
|
|
16
|
+
else
|
|
17
|
+
uncached_render(action)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def cached?(action)
|
|
22
|
+
actions_cached = trait[:actions_cached]
|
|
23
|
+
|
|
24
|
+
[ Global.cache_all,
|
|
25
|
+
trait[:cache_all],
|
|
26
|
+
actions_cached.map{|k| k.to_s}.include?(action.method),
|
|
27
|
+
].any?
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def uncached_render(action)
|
|
31
|
+
controller = self.new
|
|
32
|
+
controller.instance_variable_set('@action', action)
|
|
33
|
+
Thread.current[:controller] = controller
|
|
34
|
+
|
|
35
|
+
action.binding = controller.instance_eval{ binding }
|
|
36
|
+
action.controller = controller
|
|
37
|
+
|
|
38
|
+
before = before_process(action)
|
|
39
|
+
|
|
40
|
+
engine = select_engine(action.template)
|
|
41
|
+
answer = engine.transform(action)
|
|
42
|
+
|
|
43
|
+
after = after_process(action)
|
|
44
|
+
[before, answer, after].join
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def before_process(action)
|
|
48
|
+
''
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def after_process(action)
|
|
52
|
+
''
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def cached_render action
|
|
56
|
+
action_cache = Cache.actions
|
|
57
|
+
|
|
58
|
+
if out = action_cache[action]
|
|
59
|
+
Inform.debug("Using Cached version for #{action}")
|
|
60
|
+
return out
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
Inform.debug("Compiling Action: #{action}")
|
|
64
|
+
action_cache[action] = uncached_render(action)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def select_engine(file)
|
|
68
|
+
trait_engine = class_trait[:engine]
|
|
69
|
+
default = [trait_engine, Template::Ezamar].compact.first
|
|
70
|
+
return default unless file
|
|
71
|
+
|
|
72
|
+
engines = Controller.trait[:template_extensions]
|
|
73
|
+
return default if engines.empty?
|
|
74
|
+
|
|
75
|
+
ext = File.extname(file).gsub(/^\./, '')
|
|
76
|
+
ext_engine = engines[ext]
|
|
77
|
+
return ext_engine ? ext_engine : default
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# This method is called by templating-engines to register themselves with
|
|
81
|
+
# a list of extensions that will be looked up on #render of an action.
|
|
82
|
+
|
|
83
|
+
def register_engine engine, *extensions
|
|
84
|
+
extensions.flatten.each do |ext|
|
|
85
|
+
trait[:template_extensions][ext] = engine
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|