ramaze 0.3.5 → 0.3.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (204) hide show
  1. data/Rakefile +5 -20
  2. data/bin/ramaze +0 -4
  3. data/doc/AUTHORS +5 -0
  4. data/doc/meta/announcement.txt +2 -1
  5. data/doc/tutorial/todolist.html +20 -21
  6. data/doc/tutorial/todolist.mkd +10 -9
  7. data/examples/blog/{src/controller.rb → controller/main.rb} +2 -0
  8. data/examples/blog/{src/model.rb → model/entry.rb} +0 -0
  9. data/examples/blog/spec/blog.rb +3 -3
  10. data/examples/blog/start.rb +2 -3
  11. data/examples/blog/view/edit.xhtml +17 -0
  12. data/examples/blog/view/index.xhtml +17 -0
  13. data/examples/blog/view/layout.xhtml +11 -0
  14. data/examples/blog/view/new.xhtml +16 -0
  15. data/examples/facebook.rb +15 -8
  16. data/examples/identity.rb +1 -1
  17. data/examples/memleak_detector.rb +1 -1
  18. data/examples/rammit/src/model.rb +1 -1
  19. data/examples/rapaste/controller/paste.rb +7 -7
  20. data/examples/rapaste/model/paste.rb +1 -3
  21. data/examples/rapaste/public/css/display.css +2 -1
  22. data/examples/rapaste/start.rb +2 -3
  23. data/examples/sourceview/sourceview.rb +1 -1
  24. data/examples/templates/template/external.tenjin +28 -0
  25. data/examples/templates/template_amrita2.rb +0 -3
  26. data/examples/templates/template_tenjin.rb +57 -0
  27. data/examples/todolist/spec/todolist.rb +13 -2
  28. data/examples/todolist/src/controller/main.rb +1 -1
  29. data/examples/todolist/template/index.xhtml +1 -1
  30. data/examples/wiktacular/spec/wiktacular.rb +18 -0
  31. data/examples/wiktacular/src/controller.rb +2 -2
  32. data/examples/wiktacular/src/model.rb +8 -2
  33. data/lib/proto/public/css/ramaze_error.css +4 -0
  34. data/lib/proto/public/dispatch.fcgi +11 -0
  35. data/lib/proto/spec/main.rb +1 -1
  36. data/lib/proto/start.ru +8 -0
  37. data/lib/proto/view/error.xhtml +2 -0
  38. data/lib/ramaze.rb +28 -5
  39. data/lib/ramaze/action.rb +9 -2
  40. data/lib/ramaze/action/render.rb +40 -24
  41. data/lib/ramaze/adapter.rb +10 -17
  42. data/lib/ramaze/adapter/base.rb +8 -12
  43. data/lib/ramaze/adapter/cgi.rb +14 -13
  44. data/lib/ramaze/adapter/ebb.rb +34 -0
  45. data/lib/ramaze/adapter/evented_mongrel.rb +1 -1
  46. data/lib/ramaze/adapter/fcgi.rb +14 -14
  47. data/lib/ramaze/adapter/lsws.rb +15 -11
  48. data/lib/ramaze/adapter/mongrel.rb +2 -1
  49. data/lib/ramaze/adapter/scgi.rb +24 -0
  50. data/lib/ramaze/adapter/swiftiplied_mongrel.rb +1 -1
  51. data/lib/ramaze/adapter/thin.rb +4 -5
  52. data/lib/ramaze/adapter/webrick.rb +5 -5
  53. data/lib/ramaze/cache.rb +1 -1
  54. data/lib/ramaze/cache/memcached.rb +1 -1
  55. data/lib/ramaze/contrib.rb +70 -10
  56. data/lib/ramaze/contrib/auto_params.rb +1 -1
  57. data/lib/ramaze/contrib/email.rb +15 -15
  58. data/lib/ramaze/contrib/facebook.rb +2 -2
  59. data/lib/ramaze/contrib/facebook/facebook.rb +7 -4
  60. data/lib/ramaze/contrib/file_cache.rb +65 -0
  61. data/lib/ramaze/contrib/gettext.rb +56 -55
  62. data/lib/ramaze/contrib/profiling.rb +36 -0
  63. data/lib/ramaze/contrib/sequel_cache.rb +92 -0
  64. data/lib/ramaze/controller.rb +80 -47
  65. data/lib/ramaze/controller/error.rb +10 -5
  66. data/lib/ramaze/controller/resolve.rb +36 -48
  67. data/lib/ramaze/current.rb +70 -0
  68. data/lib/ramaze/{trinity → current}/request.rb +62 -15
  69. data/lib/ramaze/current/response.rb +19 -0
  70. data/lib/ramaze/{trinity → current}/session.rb +32 -110
  71. data/lib/ramaze/current/session/flash.rb +67 -0
  72. data/lib/ramaze/current/session/hash.rb +65 -0
  73. data/lib/ramaze/dispatcher.rb +1 -28
  74. data/lib/ramaze/dispatcher/action.rb +6 -3
  75. data/lib/ramaze/dispatcher/directory.rb +1 -1
  76. data/lib/ramaze/dispatcher/error.rb +26 -5
  77. data/lib/ramaze/dispatcher/file.rb +13 -2
  78. data/lib/ramaze/gestalt.rb +3 -1
  79. data/lib/ramaze/global.rb +6 -3
  80. data/lib/ramaze/global/globalstruct.rb +3 -1
  81. data/lib/ramaze/helper.rb +66 -20
  82. data/lib/ramaze/helper/aspect.rb +25 -17
  83. data/lib/ramaze/helper/auth.rb +4 -3
  84. data/lib/ramaze/helper/cache.rb +5 -4
  85. data/lib/ramaze/helper/cgi.rb +11 -9
  86. data/lib/ramaze/helper/flash.rb +28 -3
  87. data/lib/ramaze/helper/formatting.rb +1 -3
  88. data/lib/ramaze/helper/identity.rb +2 -3
  89. data/lib/ramaze/helper/inform.rb +7 -6
  90. data/lib/ramaze/helper/link.rb +15 -17
  91. data/lib/ramaze/helper/markaby.rb +2 -4
  92. data/lib/ramaze/helper/maruku.rb +1 -1
  93. data/lib/ramaze/helper/nitroform.rb +4 -4
  94. data/lib/ramaze/helper/pager.rb +4 -6
  95. data/lib/ramaze/helper/partial.rb +24 -21
  96. data/lib/ramaze/helper/redirect.rb +8 -5
  97. data/lib/ramaze/helper/{file.rb → sendfile.rb} +1 -3
  98. data/lib/ramaze/helper/sequel.rb +1 -3
  99. data/lib/ramaze/helper/stack.rb +1 -3
  100. data/lib/ramaze/helper/tagz.rb +19 -0
  101. data/lib/ramaze/helper/user.rb +63 -0
  102. data/lib/ramaze/inform.rb +2 -24
  103. data/lib/ramaze/log.rb +28 -0
  104. data/lib/ramaze/{inform → log}/analogger.rb +3 -3
  105. data/lib/ramaze/{inform → log}/growl.rb +2 -2
  106. data/lib/ramaze/{inform → log}/hub.rb +4 -6
  107. data/lib/ramaze/{inform → log}/informer.rb +4 -4
  108. data/lib/ramaze/{inform → log}/knotify.rb +2 -2
  109. data/lib/ramaze/log/logger.rb +22 -0
  110. data/lib/ramaze/{inform/informing.rb → log/logging.rb} +16 -16
  111. data/lib/ramaze/{inform → log}/syslog.rb +0 -0
  112. data/lib/ramaze/{inform → log}/xosd.rb +2 -2
  113. data/lib/ramaze/route.rb +64 -36
  114. data/lib/ramaze/snippets/array/put_within.rb +13 -0
  115. data/lib/ramaze/snippets/binding/locals.rb +13 -0
  116. data/lib/ramaze/snippets/kernel/__dir__.rb +10 -8
  117. data/lib/ramaze/snippets/kernel/aquire.rb +1 -1
  118. data/lib/ramaze/snippets/kernel/constant.rb +1 -1
  119. data/lib/ramaze/snippets/object/pretty.rb +6 -0
  120. data/lib/ramaze/snippets/object/scope.rb +11 -0
  121. data/lib/ramaze/snippets/object/thread_accessor.rb +5 -0
  122. data/lib/ramaze/snippets/ordered_set.rb +1 -1
  123. data/lib/ramaze/snippets/proc/locals.rb +11 -0
  124. data/lib/ramaze/snippets/ramaze/thread_accessor.rb +44 -0
  125. data/lib/ramaze/snippets/string/esc.rb +29 -0
  126. data/lib/ramaze/snippets/string/start_with.rb +7 -0
  127. data/lib/ramaze/snippets/string/unindent.rb +6 -1
  128. data/lib/ramaze/snippets/struct/values_at.rb +1 -5
  129. data/lib/ramaze/sourcereload.rb +16 -14
  130. data/lib/ramaze/spec.rb +1 -0
  131. data/lib/ramaze/spec/helper.rb +11 -3
  132. data/lib/ramaze/spec/helper/browser.rb +25 -1
  133. data/lib/ramaze/spec/helper/pretty_output.rb +11 -11
  134. data/lib/ramaze/template.rb +5 -4
  135. data/lib/ramaze/template/amrita2.rb +2 -3
  136. data/lib/ramaze/template/ezamar/element.rb +2 -3
  137. data/lib/ramaze/template/ezamar/morpher.rb +1 -2
  138. data/lib/ramaze/template/ezamar/render_partial.rb +1 -1
  139. data/lib/ramaze/template/haml.rb +5 -2
  140. data/lib/ramaze/template/markaby.rb +2 -0
  141. data/lib/ramaze/template/tagz.rb +79 -0
  142. data/lib/ramaze/template/tenjin.rb +34 -0
  143. data/lib/ramaze/tool/create.rb +0 -3
  144. data/lib/ramaze/tool/localize.rb +107 -105
  145. data/lib/ramaze/tool/mime.rb +0 -2
  146. data/lib/ramaze/trinity.rb +1 -26
  147. data/lib/ramaze/version.rb +1 -1
  148. data/lib/vendor/bacon.rb +47 -41
  149. data/rake_tasks/conf.rake +18 -0
  150. data/rake_tasks/darcs.rake +5 -0
  151. data/rake_tasks/maintenance.rake +37 -24
  152. data/rake_tasks/spec.rake +1 -1
  153. data/spec/contrib/auto_params.rb +3 -1
  154. data/spec/contrib/profiling.rb +26 -0
  155. data/spec/examples/templates/template_redcloth.rb +1 -1
  156. data/spec/examples/templates/template_tenjin.rb +28 -0
  157. data/spec/helper.rb +0 -1
  158. data/spec/ramaze/action/layout.rb +28 -0
  159. data/spec/ramaze/controller/actionless_templates.rb +32 -0
  160. data/spec/ramaze/controller/template/other_wrapper.xhtml +1 -0
  161. data/spec/ramaze/controller/template_resolving.rb +37 -0
  162. data/spec/ramaze/{trinity → current}/request.rb +12 -2
  163. data/spec/ramaze/current/session.rb +97 -0
  164. data/spec/ramaze/dispatcher/directory.rb +2 -1
  165. data/spec/ramaze/dispatcher/file.rb +8 -3
  166. data/spec/ramaze/dispatcher/public/file name.txt +1 -0
  167. data/spec/ramaze/gestalt.rb +11 -0
  168. data/spec/ramaze/helper/aspect.rb +28 -22
  169. data/spec/ramaze/helper/cgi.rb +2 -2
  170. data/spec/ramaze/helper/flash.rb +33 -15
  171. data/spec/ramaze/helper/formatting.rb +2 -2
  172. data/spec/ramaze/helper/link.rb +46 -18
  173. data/spec/ramaze/helper/pager.rb +8 -5
  174. data/spec/ramaze/helper/partial.rb +8 -1
  175. data/spec/ramaze/helper/template/recursive_local_ivars.xhtml +7 -0
  176. data/spec/ramaze/helper/user.rb +46 -0
  177. data/spec/ramaze/{inform → log}/informer.rb +0 -0
  178. data/spec/ramaze/{inform → log}/syslog.rb +1 -1
  179. data/spec/ramaze/request.rb +14 -10
  180. data/spec/ramaze/route.rb +23 -0
  181. data/spec/ramaze/template.rb +48 -1
  182. data/spec/ramaze/template/haml.rb +6 -16
  183. data/spec/ramaze/template/haml/locals.haml +2 -1
  184. data/spec/ramaze/template/tagz.rb +62 -0
  185. data/spec/ramaze/template/tagz/external.tagz +8 -0
  186. data/spec/ramaze/template/tagz/sum.tagz +1 -0
  187. data/spec/ramaze/template/tenjin.rb +49 -0
  188. data/spec/ramaze/template/tenjin/external.tenjin +1 -0
  189. data/spec/snippets/string/unindent.rb +15 -0
  190. metadata +509 -475
  191. data/doc/README.html +0 -729
  192. data/doc/changes.txt +0 -5757
  193. data/doc/changes.xml +0 -5759
  194. data/examples/blog/src/view.rb +0 -16
  195. data/examples/blog/template/edit.xhtml +0 -19
  196. data/examples/blog/template/index.xhtml +0 -19
  197. data/examples/blog/template/new.xhtml +0 -18
  198. data/examples/wiktacular/mkd/newpagename/current.mkd +0 -1
  199. data/examples/wiktacular/mkd/newpagename/current.mkd.bak +0 -1
  200. data/lib/ramaze/contrib/email.rb-darcs-backup0 +0 -81
  201. data/lib/ramaze/template/bijou.rb +0 -39
  202. data/lib/ramaze/trinity/response.rb +0 -32
  203. data/spec/ramaze/template/bijou.rb +0 -25
  204. data/spec/ramaze/trinity/session.rb +0 -29
@@ -0,0 +1,36 @@
1
+ require "ruby-prof"
2
+
3
+ module Ramaze
4
+ module Dispatcher
5
+ class ActionProfiler < Action
6
+ def self.process(path)
7
+ if RubyProf.running?
8
+ super
9
+ else
10
+ result = RubyProf.profile { super }
11
+ output = StringIO.new
12
+ printer = RubyProf::FlatPrinter.new(result)
13
+ options = {
14
+ :min_percent => Contrib::Profiling.trait[:min_percent],
15
+ :print_file => false
16
+ }
17
+ printer.print(output, options)
18
+ output.string.split("\n").each do |line|
19
+ Log.info(line)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ module Contrib
27
+ class Profiling
28
+ trait :min_percent => 1
29
+
30
+ def self.startup
31
+ Dispatcher::FILTER.delete(Dispatcher::Action)
32
+ Dispatcher::FILTER << Dispatcher::ActionProfiler
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,92 @@
1
+ #
2
+ # drop-in replacement for Ramaze's built-in MemoryCache built on the Sequel.
3
+ # to use with sessions do
4
+ #
5
+ # Ramaze::Global::cache_alternative[:sessions] = Ramaze::SequelCache
6
+ #
7
+ # to use with everything do
8
+ #
9
+ # Ramaze::Global::cache = Ramaze::SequelCache
10
+ #
11
+
12
+ class Ramaze::SequelCache
13
+ class Table < Sequel::Model(:ramaze_cache_t)
14
+ set_schema do
15
+ primary_key :id
16
+ string :key
17
+ string :value
18
+ index :key, :unique => true
19
+ end
20
+
21
+ ## use sequel's built-in serialize function if you like execptions: the
22
+ ## serialized data blows up the sql
23
+ ## serialize :value, :format => :marshal
24
+
25
+ transform :value => [
26
+ lambda{|value| Marshal.load(Base64.decode64(value))},
27
+ lambda{|value| Base64.encode64(Marshal.dump(value))},
28
+ ]
29
+ end
30
+
31
+ def table() Table end
32
+ def t() Table end
33
+
34
+ def self.[] key
35
+ record = Table.find :key => key
36
+ record ? record.value : nil
37
+ end
38
+
39
+ def self.[]= key, value
40
+ begin
41
+ Table.create :key => key, :value => value
42
+ rescue
43
+ Table.filter(:key => key).update :value => value
44
+ unless Table.find(:key => key)
45
+ Table.create :key => key, :value => value rescue nil
46
+ end
47
+ end
48
+ # ruby always returns 'value' for []= !
49
+ rescue
50
+ nil
51
+ end
52
+
53
+ def self.values_at *keys
54
+ keys.map{|key| Table[key]}
55
+ end
56
+
57
+ def self.delete *keys
58
+ keys.map do |key|
59
+ record = Table[key]
60
+ record.delete if record
61
+ end
62
+ end
63
+
64
+ def self.clear
65
+ Table.delete_all
66
+ end
67
+
68
+ def self.new
69
+ self
70
+ end
71
+
72
+ def self.to_sym
73
+ name.split(%r/::/).last.to_sym
74
+ end
75
+ end
76
+
77
+
78
+
79
+
80
+ if $0 == __FILE__
81
+ case ARGV.first
82
+ when /create|up/
83
+ Ramaze::SequelCache::Table.create_table!
84
+ when /drop|down/
85
+ Ramaze::SequelCache::Table.drop_table
86
+ else
87
+ abort "usage: ruby #{ __FILE__ } create/up | drop/down"
88
+ end
89
+ else
90
+ Ramaze::SequelCache::Table.create_table! unless
91
+ Ramaze::SequelCache::Table.table_exists?
92
+ end
@@ -13,10 +13,9 @@ module Ramaze
13
13
  # The Controller is responsible for combining and rendering actions.
14
14
 
15
15
  class Controller
16
- include Ramaze::Helper
17
- extend Ramaze::Helper
16
+ include Helper::Methods
18
17
 
19
- helper :redirect, :link, :file, :flash, :cgi
18
+ helper :redirect, :link, :sendfile, :flash, :cgi, :partial
20
19
 
21
20
  # Whether or not to map this controller on startup automatically
22
21
 
@@ -26,27 +25,19 @@ module Ramaze
26
25
 
27
26
  trait[:map] ||= nil
28
27
 
29
- # Modules that are excluded from the Action lookup
30
-
31
- trait :exclude_action_modules => [Kernel, Object, PP::ObjectMixin]
32
-
33
28
  # Caches patterns for the given path.
34
29
 
35
30
  trait :pattern_cache => Hash.new{|h,k| h[k] = Controller.pattern_for(k) }
36
31
 
37
32
  class << self
38
- include Ramaze::Helper
39
- extend Ramaze::Helper
40
-
41
33
  # When Controller is subclassed the resulting class is placed in
42
34
  # Global.controllers and a new trait :actions_cached is set on it.
43
35
 
44
36
  def inherited controller
45
37
  controller.trait :actions_cached => {}
46
- controller.trait :layout => {:all => nil, :deny => Set.new}
47
38
  Global.controllers << controller
48
39
  if map = controller.mapping
49
- Inform.dev("mapping #{map} => #{controller}")
40
+ Log.dev("mapping #{map} => #{controller}")
50
41
  Global.mapping[map] ||= controller
51
42
  end
52
43
  end
@@ -56,26 +47,22 @@ module Ramaze
56
47
  # they are not assigned yet.
57
48
 
58
49
  def startup options = {}
59
- Inform.dev("found Controllers: #{Global.controllers.inspect}")
50
+ Log.dev("found Controllers: #{Global.controllers.inspect}")
60
51
 
61
- { 'Template' => Global.template_root,
62
- 'Public' => Global.public_root }.each do |type, path|
63
- unless File.directory?(path)
64
- Inform.warn("#{type} root: #{path} doesn't exist")
65
- else
66
- Inform.info("#{type} root: #{File.expand_path path}")
67
- end
68
- end
52
+ check_path("Public root: '%s' doesn't exist", Global.public_root)
53
+ check_path("Template root: '%s' doesn't exist", Global.template_root)
69
54
 
70
55
  require 'ramaze/controller/main' if Global.mapping.empty?
71
56
 
72
- Inform.debug("mapped Controllers: #{Global.mapping.inspect}")
57
+ Log.debug("mapped Controllers: #{Global.mapping.inspect}")
73
58
  end
74
59
 
75
60
  # checks paths for existance and logs a warning if it doesn't exist yet.
76
61
 
77
- def check_path(path, message)
78
- Inform.warn(message) unless File.directory?(path)
62
+ def check_path(message, *paths)
63
+ paths.each do |path|
64
+ Log.warn(message % path) unless File.directory?(path)
65
+ end
79
66
  end
80
67
 
81
68
  # if trait[:automap] is set and controller is not in Global.mapping yet
@@ -86,7 +73,7 @@ module Ramaze
86
73
  global_mapping = Global.mapping.invert[self]
87
74
  return global_mapping if global_mapping
88
75
  if ancestral_trait[:automap]
89
- name = self.to_s.gsub('Controller', '').split('::').last
76
+ name = self.to_s.gsub('Controller', '').gsub('::', '/')
90
77
  name == 'Main' ? '/' : "/#{name.snake_case}"
91
78
  end
92
79
  end
@@ -122,23 +109,26 @@ module Ramaze
122
109
  # the layout-action where @content may or may not be used, returning
123
110
  # whatever the layout returns.
124
111
 
125
- def layout(meth_or_hash)
126
- if meth_or_hash.respond_to?(:to_hash)
127
- meth_or_hash.each do |layout_name, *actions|
128
- layout_name = R(self, layout_name) if layout_name.to_s !~ /\A\//
129
- actions.flatten.each do |action|
130
- trait[:layout][action.to_s] = layout_name
112
+ def layout(*meth_or_hash)
113
+ if meth_or_hash.empty?
114
+ trait[:layout] ||= ( ancestral_trait[:layout] || {:all => nil, :deny => Set.new} ).dup
115
+ else
116
+ meth_or_hash = meth_or_hash.first
117
+ if meth_or_hash.respond_to?(:to_hash)
118
+ meth_or_hash.each do |layout_name, *actions|
119
+ actions.flatten.each do |action|
120
+ layout[action.to_s] = layout_name
121
+ end
131
122
  end
123
+ else
124
+ layout[:all] = meth_or_hash
132
125
  end
133
- else
134
- layout_name = R(self, meth_or_hash) if meth_or_hash.to_s !~ /\A\//
135
- trait[:layout][:all] = layout_name || meth_or_hash
136
126
  end
137
127
  end
138
128
 
139
129
  def deny_layout(*actions)
140
130
  actions.each do |action|
141
- trait[:layout][:deny] << action.to_s
131
+ layout[:deny] << action.to_s
142
132
  end
143
133
  end
144
134
 
@@ -146,13 +136,12 @@ module Ramaze
146
136
  # if no argument is given.
147
137
  # Runs every given path through Controller::check_path
148
138
 
149
- def template_root path = nil
150
- if path and path = path.to_s
151
- message = "#{self}.template_root is #{path} which does not exist"
152
- check_path(path, message)
153
- @template_root = path
154
- else
139
+ def template_root *args
140
+ if args.empty?
155
141
  @template_root
142
+ else
143
+ check_path("#{self}.template_root: '%s' doesn't exist", *args)
144
+ @template_root = args.flatten
156
145
  end
157
146
  end
158
147
 
@@ -163,6 +152,10 @@ module Ramaze
163
152
  # class MainController
164
153
  # template :index, OtherController, :list
165
154
  # template :foo, :bar
155
+ # template :bar, :file => '/absolute/path'
156
+ # template :baz, :file => 'relative/path'
157
+ # template :abc, :controller => OtherController
158
+ # template :xyz, :controller => OtherController, :action => 'list'
166
159
  #
167
160
  # def index
168
161
  # 'will use template from OtherController#list'
@@ -171,18 +164,58 @@ module Ramaze
171
164
  # def foo
172
165
  # 'will use template from self#bar'
173
166
  # end
167
+ #
168
+ # def bar
169
+ # 'will use template from /absolute/path'
170
+ # end
171
+ #
172
+ # def baz
173
+ # 'will use template from relative/path'
174
+ # end
175
+ #
176
+ # def abc
177
+ # 'will use template from OtherController#index'
178
+ # end
179
+ #
180
+ # def xyz
181
+ # 'will use template from OtherController#list'
182
+ # end
174
183
  # end
175
184
 
176
- def template(this, from, that = nil)
177
- from, that = self, from unless that
178
- trait "#{this}_template" => [from, that.to_s]
185
+ def template(this, *argv)
186
+ case argv.first
187
+ when Hash
188
+ options, *ignored = argv
189
+ controller = options[:controller] || options['controller']
190
+ action = options[:action] || options['action']
191
+ file = options[:file] || options['file']
192
+ info = {}
193
+ if file
194
+ file = file.to_s
195
+ unless Pathname(file).absolute?
196
+ root = [template_root || Global.template_root].flatten.first
197
+ file = File.join(root, file)
198
+ end
199
+ info[:file] = file
200
+ else
201
+ controller ||= self
202
+ action = (action || 'index').to_s
203
+ info[:controller] = controller
204
+ info[:action] = action
205
+ end
206
+ trait "#{this}_template" => info
207
+ else
208
+ controller, action, *ignored = argv
209
+ controller, action = self, controller unless action
210
+ trait "#{this}_template" => {:controller => controller, :action => action}
211
+ end
179
212
  end
180
213
 
181
214
  def engine(name)
182
- name = Ramaze::Template.const_get(name)
215
+ name = Template.const_get(name)
183
216
  rescue NameError => ex
184
- Inform.warn ex
185
- Inform.warn "Try to use passed engine directly"
217
+ Log.warn ex
218
+ Log.warn "Try to use passed engine directly"
186
219
  ensure
187
220
  trait :engine => name
188
221
  end
@@ -12,15 +12,20 @@ module Ramaze
12
12
  # holds the exception thrown.
13
13
 
14
14
  def error
15
- error = Ramaze::Dispatcher::Error.current
15
+ error = Dispatcher::Error.current
16
16
  title = error.message
17
17
 
18
18
  unless Action.current.template
19
19
  response['Content-Type'] = 'text/plain'
20
- return [title, "", error.backtrace].flatten.join("\n")
20
+ respond %(
21
+ #{error.message}
22
+ #{error.backtrace.join("\n ")}
23
+
24
+ #{PP.pp request, '', 200}
25
+ ).ui
21
26
  end
22
27
 
23
- backtrace_size = Ramaze::Global.backtrace_size
28
+ backtrace_size = Global.backtrace_size
24
29
  @backtrace = error.backtrace[0..20].map do |line|
25
30
  file, lineno, meth = *Ramaze.parse_backtrace(line)
26
31
  lines = Ramaze.caller_lines(file, lineno, backtrace_size)
@@ -31,11 +36,11 @@ module Ramaze
31
36
  # for backwards-compat with old error.zmr
32
37
  @colors = [255] * @backtrace.size
33
38
 
34
- @title = CGI.escapeHTML(title)
39
+ @title = ::CGI.escapeHTML(title)
35
40
  @editor = (ENV['EDITOR'] || 'vim')
36
41
  title
37
42
  rescue Object => ex
38
- Inform.error(ex)
43
+ Log.error(ex)
39
44
  end
40
45
  end
41
46
  end
@@ -3,24 +3,24 @@
3
3
 
4
4
  module Ramaze
5
5
  class Controller
6
- FILTER = [ :cached, :routed, :default ] unless defined?(FILTER)
6
+ FILTER = [ :cached, :default ] unless defined?(FILTER)
7
7
 
8
8
  class << self
9
9
 
10
10
  # Resolve an absolute path in the application by passing it to each
11
11
  # element of Ramaze::Controller::FILTER.
12
- # Elements in exclude_filter are excluded from handling.
13
12
  # If an element does not respond to call it will be sent to self
14
13
  # instead, in either case with path as argument.
15
14
 
16
- def resolve(path, *exclude_filter)
17
- (FILTER - exclude_filter.flatten).each do |filter|
18
- answer =
19
- if filter.respond_to?(:call)
20
- filter.call(path)
21
- else
22
- send(filter.to_s, path)
23
- end
15
+ def resolve(path, routed = false)
16
+ @routed = routed
17
+
18
+ FILTER.each do |filter|
19
+ answer = if filter.respond_to?(:call)
20
+ filter.call(path)
21
+ else
22
+ send(filter.to_s, path)
23
+ end
24
24
  return answer if answer
25
25
  end
26
26
 
@@ -35,7 +35,7 @@ module Ramaze
35
35
  if found.respond_to?(:relaxed_hash)
36
36
  return found.dup
37
37
  else
38
- Inform.warn("Found faulty `#{path}' in Cache.resolved, deleting it for sanity.")
38
+ Log.warn("Found faulty `#{path}' in Cache.resolved, deleting it for sanity.")
39
39
  Cache.resolved.delete path
40
40
  end
41
41
  end
@@ -43,33 +43,6 @@ module Ramaze
43
43
  nil
44
44
  end
45
45
 
46
- # Routing filter
47
- # Loops over Route.trait[:routes] to find a matching route
48
-
49
- def routed(path)
50
- Route.trait[:routes].each do |key, val|
51
- if key.is_a?(Regexp)
52
- if md = path.match(key)
53
- new_path = val % md.to_a[1..-1]
54
- return resolve(new_path, :routed)
55
- end
56
-
57
- elsif val.respond_to?(:call)
58
- if new_path = val.call(path, request)
59
- return resolve(new_path, :routed)
60
- end
61
-
62
- elsif val.is_a?(String)
63
- return resolve(val, :routed) if path == key
64
-
65
- else
66
- Inform.error "Invalid route #{key} => #{val}"
67
- end
68
- end
69
-
70
- nil
71
- end
72
-
73
46
  # Default element of FILTER.
74
47
  # The default handler that tries to find the best match for the given
75
48
  # path in terms of Controller/method/template and given arguments.
@@ -91,7 +64,12 @@ module Ramaze
91
64
  action = controller.resolve_action(method, *params)
92
65
  template = action.template
93
66
 
94
- valid_action = (action.method or (params.empty? && template))
67
+ valid_action =
68
+ if Action.stack.size > 0 || Global.actionless_templates
69
+ action.method or (params.empty? && template)
70
+ else
71
+ action.method
72
+ end
95
73
 
96
74
  if valid_action
97
75
  Cache.resolved[path] = action
@@ -100,6 +78,11 @@ module Ramaze
100
78
  end
101
79
  end
102
80
 
81
+ if !@routed and new_path = Route.resolve(path)
82
+ Log.dev("Routing from `#{path}' to `#{new_path}'")
83
+ return resolve(new_path, true)
84
+ end
85
+
103
86
  raise_no_action(first_controller, path) if first_controller
104
87
  raise_no_controller(path)
105
88
  end
@@ -109,9 +92,12 @@ module Ramaze
109
92
 
110
93
  def resolve_action(path, *parameter)
111
94
  path, parameter = path.to_s, parameter.map{|e| e.to_s}
112
- if alternate_template = trait["#{path}_template"]
113
- t_controller, t_path = *alternate_template
114
- template = t_controller.resolve_template(t_path)
95
+ if info = trait["#{path}_template"]
96
+ template = info[:file]
97
+ unless template
98
+ controller, action = info.values_at :controller, :action
99
+ template = controller.resolve_template(action)
100
+ end
115
101
  end
116
102
 
117
103
  method, params = resolve_method(path, *parameter)
@@ -146,8 +132,11 @@ module Ramaze
146
132
  # controller.
147
133
 
148
134
  def template_paths
149
- @template_root ||= Global.template_root / Global.mapping.invert[self]
150
- [ @template_root ]
135
+ if paths = template_root
136
+ paths
137
+ else
138
+ template_root(Global.template_root / Global.mapping.invert[self])
139
+ end
151
140
  end
152
141
 
153
142
  # Based on methodname and arity, tries to find the right method on current controller.
@@ -168,14 +157,13 @@ module Ramaze
168
157
 
169
158
  # methodnames that may be used for current controller.
170
159
  def action_methods
171
- exclude = Controller.trait[:exclude_action_modules]
160
+ ancs = ancestors.select{|ancestor|
161
+ ancestor <= Ramaze::Controller
162
+ } + Helper::LOOKUP.to_a
172
163
 
173
- ancs = (ancestors - exclude).select{|a| a.is_a?(Module) }
174
164
  meths = ancs.map{|a|
175
165
  a.instance_methods(false).map{|iv| iv.to_s }
176
166
  }.flatten.uniq
177
- # fix for facets/more/paramix
178
- meths - ancs.map{|a| a.to_s}
179
167
  end
180
168
 
181
169
  # Generate all possible permutations for given path.