ramaze 0.1.3 → 0.1.4

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 (149) hide show
  1. data/bin/ramaze +58 -26
  2. data/doc/AUTHORS +2 -0
  3. data/doc/CHANGELOG +401 -0
  4. data/doc/README +14 -9
  5. data/doc/README.html +737 -0
  6. data/doc/TODO +14 -14
  7. data/doc/changes.txt +401 -0
  8. data/doc/changes.xml +401 -0
  9. data/doc/meta/announcement.txt +28 -15
  10. data/doc/meta/configuration.txt +3 -3
  11. data/doc/meta/internals.txt +2 -2
  12. data/doc/meta/users.kml +62 -0
  13. data/doc/readme_chunks/examples.txt +1 -1
  14. data/doc/readme_chunks/features.txt +13 -8
  15. data/doc/tutorial/todolist.html +2 -2
  16. data/doc/tutorial/todolist.mkd +2 -2
  17. data/examples/blog/README +3 -0
  18. data/examples/blog/spec/blog.rb +101 -0
  19. data/examples/blog/{main.rb → start.rb} +0 -0
  20. data/examples/caching.rb +16 -5
  21. data/examples/layout.rb +41 -0
  22. data/examples/templates/template_amrita2.rb +1 -1
  23. data/examples/templates/template_erubis.rb +1 -1
  24. data/examples/templates/template_ezamar.rb +1 -1
  25. data/examples/templates/template_haml.rb +1 -1
  26. data/examples/templates/template_liquid.rb +1 -1
  27. data/examples/templates/template_markaby.rb +1 -1
  28. data/examples/templates/template_remarkably.rb +1 -1
  29. data/examples/todolist/README +1 -0
  30. data/{spec/examples → examples/todolist/spec}/todolist.rb +3 -3
  31. data/examples/todolist/{main.rb → start.rb} +0 -0
  32. data/examples/whywiki/{main.rb → start.rb} +0 -0
  33. data/examples/wiktacular/README +2 -0
  34. data/examples/wiktacular/spec/wiktacular.rb +146 -0
  35. data/examples/wiktacular/src/controller.rb +11 -0
  36. data/examples/wiktacular/src/model.rb +5 -1
  37. data/examples/wiktacular/{main.rb → start.rb} +0 -1
  38. data/examples/wiktacular/template/edit.xhtml +1 -2
  39. data/examples/wiktacular/template/html_layout.xhtml +27 -0
  40. data/examples/wiktacular/template/index.xhtml +8 -10
  41. data/examples/wiktacular/template/new.xhtml +1 -2
  42. data/lib/proto/{main.rb → start.rb} +0 -0
  43. data/lib/proto/template/index.xhtml +1 -1
  44. data/lib/ramaze/action/render.rb +58 -4
  45. data/lib/ramaze/action.rb +20 -0
  46. data/lib/ramaze/adapter/cgi.rb +7 -4
  47. data/lib/ramaze/adapter/fcgi.rb +6 -4
  48. data/lib/ramaze/adapter/mongrel.rb +4 -0
  49. data/lib/ramaze/adapter/webrick.rb +20 -9
  50. data/lib/ramaze/adapter.rb +3 -1
  51. data/lib/ramaze/cache/memcached.rb +2 -26
  52. data/lib/ramaze/cache.rb +8 -4
  53. data/lib/ramaze/controller/resolve.rb +26 -8
  54. data/lib/ramaze/controller.rb +44 -7
  55. data/lib/ramaze/dispatcher/action.rb +5 -1
  56. data/lib/ramaze/dispatcher/directory.rb +115 -0
  57. data/lib/ramaze/dispatcher/error.rb +19 -5
  58. data/lib/ramaze/dispatcher/file.rb +2 -2
  59. data/lib/ramaze/dispatcher.rb +52 -39
  60. data/lib/ramaze/global/dsl.rb +3 -2
  61. data/lib/ramaze/global/globalstruct.rb +26 -4
  62. data/lib/ramaze/global.rb +20 -11
  63. data/lib/ramaze/helper/aspect.rb +29 -11
  64. data/lib/ramaze/helper/auth.rb +2 -2
  65. data/lib/ramaze/helper/cache.rb +2 -0
  66. data/lib/ramaze/helper/identity.rb +21 -6
  67. data/lib/ramaze/helper/link.rb +1 -1
  68. data/lib/ramaze/helper/pager.rb +158 -100
  69. data/lib/ramaze/helper/partial.rb +22 -0
  70. data/lib/ramaze/helper/redirect.rb +1 -2
  71. data/lib/ramaze/helper/stack.rb +1 -1
  72. data/lib/ramaze/inform/informer.rb +20 -0
  73. data/lib/ramaze/inform/syslog.rb +5 -0
  74. data/lib/ramaze/snippets/kernel/__dir__.rb +21 -0
  75. data/lib/ramaze/snippets/kernel/aquire.rb +22 -12
  76. data/lib/ramaze/snippets/numeric/human_readable_filesize_format.rb +33 -0
  77. data/lib/ramaze/snippets/ramaze/caller_lines.rb +1 -1
  78. data/lib/ramaze/snippets/struct/values_at.rb +11 -4
  79. data/lib/ramaze/sourcereload.rb +29 -1
  80. data/{spec → lib/ramaze/spec}/helper/context.rb +0 -0
  81. data/{spec → lib/ramaze/spec}/helper/layout.rb +1 -1
  82. data/{spec → lib/ramaze/spec}/helper/minimal.rb +0 -0
  83. data/{spec → lib/ramaze/spec}/helper/mock_http.rb +0 -0
  84. data/{spec → lib/ramaze/spec}/helper/requester.rb +0 -0
  85. data/{spec → lib/ramaze/spec}/helper/simple_http.rb +0 -0
  86. data/{spec → lib/ramaze/spec}/helper/wrap.rb +0 -0
  87. data/lib/ramaze/spec/helper.rb +60 -0
  88. data/lib/ramaze/store/default.rb +3 -0
  89. data/lib/ramaze/template/ezamar/render_partial.rb +3 -0
  90. data/lib/ramaze/template/sass.rb +45 -0
  91. data/lib/ramaze/template.rb +1 -1
  92. data/lib/ramaze/tool/create.rb +5 -5
  93. data/lib/ramaze/tool/localize.rb +26 -5
  94. data/lib/ramaze/tool/mime.rb +7 -0
  95. data/lib/ramaze/trinity/response.rb +15 -0
  96. data/lib/ramaze/trinity/session.rb +1 -1
  97. data/lib/ramaze/version.rb +1 -1
  98. data/lib/ramaze.rb +5 -0
  99. data/rake_tasks/conf.rake +4 -4
  100. data/rake_tasks/maintaince.rake +12 -7
  101. data/rake_tasks/spec.rake +7 -4
  102. data/spec/examples/caching.rb +6 -8
  103. data/spec/helper.rb +3 -60
  104. data/spec/ramaze/action/basics.rb +17 -0
  105. data/spec/ramaze/action/cache.rb +28 -0
  106. data/spec/ramaze/action/layout.rb +110 -0
  107. data/spec/ramaze/action/render.rb +14 -0
  108. data/spec/ramaze/action/template/bar.xhtml +1 -0
  109. data/spec/ramaze/action/template/other_wrapper.xhtml +1 -0
  110. data/spec/ramaze/action/template/single_wrapper.xhtml +1 -0
  111. data/spec/ramaze/controller/template/edit/content.xhtml +1 -0
  112. data/spec/ramaze/controller/template/edit.xhtml +1 -0
  113. data/spec/ramaze/controller/template_resolving.rb +2 -2
  114. data/spec/ramaze/dispatcher/directory.rb +53 -0
  115. data/spec/ramaze/dispatcher/file.rb +0 -3
  116. data/spec/ramaze/error.rb +17 -2
  117. data/spec/ramaze/helper/aspect.rb +14 -20
  118. data/spec/ramaze/helper/pager.rb +83 -1
  119. data/spec/ramaze/helper/partial.rb +1 -1
  120. data/spec/ramaze/helper/template/test_template.xhtml +1 -0
  121. data/spec/ramaze/inform/informer.rb +37 -5
  122. data/spec/ramaze/localize.rb +1 -1
  123. data/spec/ramaze/template/haml.rb +5 -5
  124. data/spec/ramaze/template/sass/file.css.sass +5 -0
  125. data/spec/ramaze/template/sass.rb +46 -0
  126. data/spec/ramaze/template.rb +1 -1
  127. data/spec/ramaze/trinity/session.rb +27 -0
  128. data/spec/snippets/kernel/__dir__.rb +8 -0
  129. data/spec/snippets/kernel/aquire.rb +71 -0
  130. data/spec/snippets/kernel/constant.rb +27 -0
  131. data/spec/snippets/numeric/human_readable_filesize_format.rb +11 -0
  132. data/spec/snippets/ramaze/caller_info.rb +39 -0
  133. data/spec/snippets/ramaze/caller_lines.rb +27 -0
  134. data/spec/snippets/string/DIVIDE.rb +18 -0
  135. data/spec/snippets/string/camel_case.rb +25 -0
  136. data/spec/snippets/string/color.rb +11 -0
  137. data/spec/snippets/string/snake_case.rb +17 -0
  138. data/spec/snippets/struct/fill.rb +27 -0
  139. data/spec/snippets/struct/values_at.rb +39 -0
  140. metadata +71 -31
  141. data/examples/todolist/todolist.db +0 -5
  142. data/examples/wiktacular/src/page.rb +0 -66
  143. data/lib/ramaze/helper/feed.rb +0 -135
  144. data/lib/ramaze/helper/form.rb +0 -204
  145. data/lib/ramaze/snippets/openstruct/temp.rb +0 -13
  146. data/lib/ramaze/store/yaml.rb +0 -170
  147. data/spec/ramaze/helper/feed.rb +0 -127
  148. data/spec/ramaze/helper/form.rb +0 -146
  149. data/spec/ramaze/store/yaml.rb +0 -76
@@ -11,6 +11,10 @@ module Ramaze
11
11
  # actions in your controllers.
12
12
 
13
13
  class Error
14
+
15
+ # The class of exception is matched when an error occurs and the status
16
+ # code is set. The absolute URLs are used as fallback in case of a total
17
+ # failure.
14
18
  HANDLE_ERROR = {
15
19
  Exception => [ 500, '/error' ],
16
20
  Ramaze::Error::NoAction => [ 404, '/error' ],
@@ -20,10 +24,16 @@ module Ramaze
20
24
  class << self
21
25
  trait :last_error => nil
22
26
 
27
+ # Takes exception, of metainfo only :controller is used at the moment.
28
+ # Then goes on to try and find the correct response status and path.
29
+ # In case metainfo has a controller we try to get the action for the
30
+ # path on it, dispatching there if we find one.
31
+ # Otherwise a plain-text error message is set as response.
23
32
  def process(error, metainfo = {})
24
33
  log_error(error)
25
34
 
26
35
  Thread.current[:exception] = error
36
+ response = Response.current
27
37
 
28
38
  key = error.class.ancestors.find{|a| HANDLE_ERROR[a]}
29
39
  status, path = *HANDLE_ERROR[key || Exception]
@@ -32,23 +42,25 @@ module Ramaze
32
42
  if controller = metainfo[:controller]
33
43
  begin
34
44
  action = Controller.resolve(controller.mapping + path)
35
- return Dispatcher.build_response(action.render, status)
36
- rescue Ramaze::Error
45
+ return response.build(action.render, status)
46
+ rescue Ramaze::Error => e
37
47
  Inform.debug("No custom error page found on #{controller}, going to #{path}")
38
48
  end
39
49
  end
40
50
 
41
51
  unless error.message =~ %r(`#{path.split('/').last}')
42
- Response.current.status = status
52
+ response.status = status
43
53
  return Dispatcher.dispatch_to(path) if path and Global.error_page
44
54
  end
45
55
 
46
- Dispatcher.build_response(error.message, status)
56
+ response.build(error.message, status)
47
57
  rescue Object => ex
48
58
  Inform.error(ex)
49
- Dispatcher.build_response(ex.message, status)
59
+ response.build(ex.message, status)
50
60
  end
51
61
 
62
+ # Only logs new errors with full backtrace, repeated errors are shown
63
+ # only with their message.
52
64
  def log_error error
53
65
  error_message = error.message
54
66
 
@@ -60,6 +72,8 @@ module Ramaze
60
72
  end
61
73
  end
62
74
 
75
+ # Handle to current exception.
76
+ # Only works inside request/response cycle.
63
77
  def current
64
78
  Thread.current[:exception]
65
79
  end
@@ -15,14 +15,14 @@ module Ramaze
15
15
 
16
16
  def process(path)
17
17
  return unless file = open_file(path)
18
- Dispatcher.build_response(file, Ramaze::STATUS_CODE['OK'])
18
+ Response.current.build(file, Ramaze::STATUS_CODE['OK'])
19
19
  end
20
20
 
21
21
  # returns file-handle with the open file on success, setting the
22
22
  # Content-Type as found in Tool::MIME
23
23
 
24
24
  def open_file(path)
25
- file = Global.public_root/path
25
+ file = ::File.join(Global.public_root, path =~ /\/$/ ? path + 'index' : path)
26
26
 
27
27
  if ::File.file?(file)
28
28
  response = Response.current
@@ -10,6 +10,7 @@ require 'ramaze/tool/mime'
10
10
  require 'ramaze/dispatcher/action'
11
11
  require 'ramaze/dispatcher/error'
12
12
  require 'ramaze/dispatcher/file'
13
+ require 'ramaze/dispatcher/directory'
13
14
 
14
15
  module Ramaze
15
16
 
@@ -19,53 +20,63 @@ module Ramaze
19
20
  module Dispatcher
20
21
 
21
22
  # requests are passed to every
23
+ FILTER = [ Dispatcher::File, Dispatcher::Directory,
24
+ Dispatcher::Action ] unless defined?(FILTER)
22
25
 
23
- FILTER = [ Dispatcher::File, Dispatcher::Action ] unless defined?(FILTER)
24
-
26
+ # Response codes to cache the output of for repeated requests.
25
27
  trait :shielded => [ STATUS_CODE["Not Found"] ]
26
28
 
27
29
  class << self
28
30
  include Trinity
29
31
 
32
+ # Entry point for Adapter#respond, takes a Rack::Request and
33
+ # Rack::Response, sets up the environment and the goes on to dispatch
34
+ # for the given path from rack_request.
30
35
  def handle rack_request, rack_response
31
36
  setup_environment(rack_request, rack_response)
32
37
 
33
38
  path = request.path_info.squeeze('/')
34
39
  Inform.info("Request from #{request.remote_addr}: #{path}")
35
40
 
36
- if Global.shield
37
- shielded_dispatch(path)
38
- else
39
- dispatch(path)
40
- end
41
+ general_dispatch path
41
42
  rescue Object => error
42
- Dispatcher::Error.process(error, :path => path, :request => request)
43
+ meta = { :path => path,
44
+ :request => request,
45
+ :controller => Thread.current[:controller] }
46
+ Dispatcher::Error.process(error, meta)
43
47
  end
44
48
 
45
- def dispatch(path)
46
- catch(:respond) do
47
- redirection = catch(:redirect) do
48
- found = filter(path)
49
- throw(:respond, found)
49
+ # protcets against recursive dispatch and reassigns the path_info in the
50
+ # request, the rest of the request is kept intact.
51
+ def dispatch_to(path)
52
+ if request.path_info == path
53
+ if error = Thread.current[:exception]
54
+ raise error
55
+ else
56
+ raise "Recursive redirect from #{path} to #{path}"
50
57
  end
51
-
52
- body, status, head = redirection.values_at(:body, :status, :head)
53
- Inform.info("Redirect to `#{head['Location']}'")
54
- throw(:respond, build_response(body, status, head))
55
58
  end
56
- end
57
-
58
- def dispatch_to path
59
- raise "Redirect to #{path} from #{path}" if request.path_info == path
60
59
  request.path_info = path
60
+ general_dispatch path
61
+ end
61
62
 
63
+ # splits up the dispatch based on Global.shield
64
+ def general_dispatch(path)
62
65
  if Global.shield
63
- shielded_dispatch(path)
66
+ shielded_dispatch path
64
67
  else
65
- dispatch(path)
68
+ dispatch path
66
69
  end
67
70
  end
68
71
 
72
+ # Protects somewhat against hammering of erroring paths, since error-pages
73
+ # take a while to build in the default mode it is possible to decrease
74
+ # overall speed quite a bit by hitting Ramaze with such paths.
75
+ # shielded_dispatch checks the path and caches erronous responses so they
76
+ # won't be recreated but simply pushed out again without stopping at the
77
+ # Controller.
78
+ # Please note that this is just minor protection and the best option is to
79
+ # create a performant error-page instead.
69
80
  def shielded_dispatch(path)
70
81
  shield_cache = Cache.shield
71
82
  handled = shield_cache[path]
@@ -80,10 +91,25 @@ module Ramaze
80
91
  end
81
92
  end
82
93
 
94
+ # filters the path until a response or redirect is thrown or a filter is
95
+ # successful, builds a response from the returned hash in case of throws.
96
+ def dispatch(path)
97
+ catch(:respond) do
98
+ redirection = catch(:redirect) do
99
+ found = filter(path)
100
+ throw(:respond, found)
101
+ end
102
+
103
+ body, status, head = redirection.values_at(:body, :status, :head)
104
+ Inform.info("Redirect to `#{head['Location']}'")
105
+ throw(:respond, response.build(body, status, head))
106
+ end
107
+ end
108
+
83
109
  # Calls .process(path) on every class in Dispatcher::FILTER until one
84
110
  # returns something else than false/nil.
85
111
 
86
- def filter path
112
+ def filter(path)
87
113
  result = nil
88
114
  FILTER.each do |dispatcher|
89
115
  result = dispatcher.process(path)
@@ -92,24 +118,11 @@ module Ramaze
92
118
 
93
119
  meta = {
94
120
  :path => path,
95
- :controller => Thread.current[:failed_controller]
121
+ :controller => Thread.current[:controller]
96
122
  }
97
123
  Dispatcher::Error.process(result, meta)
98
124
  end
99
125
 
100
- # build a response, default values are from the current response.
101
-
102
- def build_response body = response.body, status = response.status, head = response.header
103
- set_cookie if Global.cookies
104
- head.each do |key, value|
105
- response[key] = value
106
- end
107
-
108
- response.body, response.status = body, status
109
-
110
- return response
111
- end
112
-
113
126
  # finalizes the session and assigns the key to the response via
114
127
  # set_cookie.
115
128
 
@@ -128,7 +141,7 @@ module Ramaze
128
141
  def setup_environment rack_request, rack_response
129
142
  this = Thread.current
130
143
  this[:request] = rack_request
131
- this[:session] = Session.new(request)
144
+ this[:session] = Session.new(request) if Global.sessions
132
145
  this[:response] = rack_response
133
146
  end
134
147
  end
@@ -2,7 +2,7 @@
2
2
  # All files in this distribution are subject to the terms of the Ruby license.
3
3
 
4
4
  module Ramaze
5
- CLIOption = Struct.new('CLIOption', :name, :default, :doc, :cli)
5
+ CLIOption = Struct.new('CLIOption', :name, :default, :doc, :cli, :short)
6
6
  OPTIONS = {}
7
7
  CLI_OPTIONS = []
8
8
 
@@ -24,10 +24,11 @@ module Ramaze
24
24
  def o(doc, options = {})
25
25
  cli_given = options.has_key?(:cli)
26
26
  cli = options.delete(:cli)
27
+ short = options.delete(:short)
27
28
  name, default = options.to_a.flatten
28
29
 
29
30
  if cli_given
30
- option = CLIOption.new(name, default, doc, cli)
31
+ option = CLIOption.new(name, default, doc, cli, short)
31
32
  CLI_OPTIONS << option
32
33
  end
33
34
 
@@ -7,8 +7,10 @@ module Ramaze
7
7
  end
8
8
  end
9
9
 
10
+ # Class for Ramaze::Global instance.
10
11
  class GlobalStruct
11
12
 
13
+ # mapping of :adapter => to the right class-name.
12
14
  ADAPTER_ALIAS = {
13
15
  :webrick => :WEBrick,
14
16
  :mongrel => :Mongrel,
@@ -16,6 +18,7 @@ module Ramaze
16
18
  :fcgi => :Fcgi,
17
19
  }
18
20
 
21
+ # mapping of :cache => to the right class-name.
19
22
  CACHE_ALIAS = {
20
23
  :memcached => :MemcachedCache,
21
24
  :memory => :MemoryCache,
@@ -23,21 +26,21 @@ module Ramaze
23
26
  }
24
27
 
25
28
  class << self
26
- def setup options = {}
27
- self.fill(options)
28
- end
29
+ alias setup fill
29
30
  end
30
31
 
32
+ # Called from Ramaze::start, sets all the options.
31
33
  def startup(options = {})
32
34
  options.each do |key, value|
33
35
  if (method(key) rescue false)
34
- self[key] = value
36
+ send("#{key}=", value)
35
37
  else
36
38
  create_member(key, value)
37
39
  end
38
40
  end
39
41
  end
40
42
 
43
+ # batch-assignment of key/value from hash, yields self if a block is given.
41
44
  def setup(hash = {})
42
45
  hash.each do |key, value|
43
46
  self.send("#{key}=", value)
@@ -45,8 +48,11 @@ module Ramaze
45
48
  yield(self) if block_given?
46
49
  end
47
50
 
51
+
48
52
  # Object wraps
49
53
 
54
+ # get right classname, require the file for given adapter and answer with
55
+ # the actual class.
50
56
  def adapter
51
57
  if internal = self[:adapter]
52
58
  class_name = ADAPTER_ALIAS[internal.to_sym]
@@ -55,28 +61,44 @@ module Ramaze
55
61
  end
56
62
  end
57
63
 
64
+ # get right classname, require the file for given cache and answer with
65
+ # the actual class.
58
66
  def cache
59
67
  cache_name = self[:cache].to_sym
60
68
  class_name = CACHE_ALIAS[cache_name] || cache_name
61
69
  cache = Ramaze.const_get(class_name)
62
70
  end
63
71
 
72
+ # a range built from port and the number of spawns.
64
73
  def ports
65
74
  (port.to_i..(port.to_i + (spawn.to_i - 1)))
66
75
  end
67
76
 
77
+ # reassigns the interval in the instance of SourceReload that is running or
78
+ # just waiting.
68
79
  def sourcereload=(interval)
69
80
  self[:sourcereload] = interval
70
81
  sri = Thread.main[:sourcereload]
71
82
  sri.interval = interval if sri
72
83
  end
73
84
 
85
+ def template_root=(tr)
86
+ self[:template_root] = File.expand_path(tr)
87
+ end
88
+
89
+ def public_root=(pr)
90
+ self[:public_root] = File.expand_path(pr)
91
+ end
92
+
93
+
74
94
  # External helpers
75
95
 
96
+ # Answers with values for given keys by sending each to self
76
97
  def values_at(*keys)
77
98
  keys.map{|key| __send__(key)}
78
99
  end
79
100
 
101
+ # Creates a new attr_accessor like method-pair.
80
102
  def create_member key, value = nil
81
103
  Inform.warn "Create #{key}=#{value.inspect} on Global"
82
104
 
data/lib/ramaze/global.rb CHANGED
@@ -18,7 +18,7 @@ module Ramaze
18
18
  :backtrace_size => 10, :cli => 10
19
19
 
20
20
  o "Turn benchmarking every request on.",
21
- :benchmarking => false, :cli => false
21
+ :benchmarking => false, :cli => false, :short => :b
22
22
 
23
23
  o "Use this for general caching and as base for Cache.new.",
24
24
  :cache => :memory, :cli => [:memory, :memcached, :yaml]
@@ -26,9 +26,6 @@ module Ramaze
26
26
  o "Turn on naive caching of all requests.",
27
27
  :cache_all => false, :cli => false
28
28
 
29
- o "Turn on cookies for all requests.",
30
- :cookies => true, :cli => true
31
-
32
29
  o "Compile Templates",
33
30
  :compile => false, :cli => false
34
31
 
@@ -36,11 +33,17 @@ module Ramaze
36
33
  :controllers => Set.new
37
34
 
38
35
  o "Start Ramaze within an IRB session",
39
- :console => false, :cli => false
36
+ :console => false, :cli => false, :short => :c
40
37
 
41
38
  o "Turn on customized error pages.",
42
39
  :error_page => true, :cli => true
43
40
 
41
+ o "Caching actions to the filesystem in Global.public_root",
42
+ :file_cache => false, :cli => false
43
+
44
+ o "Base directory for meta information of file-caching",
45
+ :file_cache_meta_dir => "cache_meta", :cli => "cache_meta"
46
+
44
47
  o "Specify what IP Ramaze will respond to - 0.0.0.0 for all",
45
48
  :host => "0.0.0.0", :cli => '0.0.0.0'
46
49
 
@@ -51,10 +54,10 @@ module Ramaze
51
54
  :origin => :main
52
55
 
53
56
  o "Specify port",
54
- :port => 7000, :cli => 7000
57
+ :port => 7000, :cli => 7000, :short => :p
55
58
 
56
- o "Specify the public directory of your application serving static files",
57
- :public_root => File.expand_path('./public')
59
+ o "Specify directory to serve static files",
60
+ :public_root => './public', :cli => './public'
58
61
 
59
62
  o "Record all Request objects by assigning a filtering Proc to me.",
60
63
  :record => false
@@ -62,6 +65,9 @@ module Ramaze
62
65
  o "Don't wait until all adapter-threads are finished or killed.",
63
66
  :run_loose => false, :cli => false
64
67
 
68
+ o "Turn on session for all requests.",
69
+ :sessions => true, :cli => true
70
+
65
71
  o "Turn on BF/DoS protection for error-responses",
66
72
  :shield => false, :cli => false
67
73
 
@@ -72,13 +78,16 @@ module Ramaze
72
78
  :sourcereload => 3, :cli => 3
73
79
 
74
80
  o "How many adapters Ramaze should spawn.",
75
- :spawn => 1, :cli => 1
81
+ :spawn => 1, :cli => 1, :short => :s
76
82
 
77
83
  o "Test before start if adapters will be able to connect",
78
84
  :test_connections => true, :cli => true
79
85
 
80
- o "Specify template root for dynamic files relative to main.rb",
81
- :template_root => 'template'
86
+ o "Specify directory to serve dynamic files",
87
+ :template_root => './template', :cli => './template'
88
+
89
+ o "Enable directory listing",
90
+ :list_directories => false, :cli => false
82
91
  end
83
92
 
84
93
  require 'ramaze/global/globalstruct'
@@ -6,19 +6,27 @@ module Ramaze
6
6
  # A helper that provides the means to wrap actions of the controller with
7
7
  # other methods.
8
8
  #
9
- # For examples please look at the test/tc_aspect.rb
9
+ # For examples please look at the spec/ramaze/helper/aspect.rb
10
10
  #
11
11
  # This is not a default helper due to the possible performance-issues.
12
12
  # However, it should be only an overhead of about 6-8 calls, so if you
13
13
  # want this feature it shouldn't have too large impact ;)
14
+ #
15
+ # Like every other helper, you can use it in your controller with:
16
+ #
17
+ # helper :aspect
14
18
 
15
19
  module AspectHelper
20
+
21
+ # Define traits on class this module is included into.
22
+
16
23
  def self.included(klass)
17
24
  klass.trait[:aspects] ||= { :before => {}, :after => {} }
18
25
  end
19
26
 
20
27
  private
21
28
 
29
+ # run block before given actions.
22
30
  def before(*meths, &block)
23
31
  aspects = trait[:aspects][:before]
24
32
  meths.each do |meth|
@@ -27,12 +35,13 @@ module Ramaze
27
35
  end
28
36
  alias pre before
29
37
 
38
+ # Run block before all actions.
30
39
  def before_all(&block)
31
- meths = instance_methods(false)
32
- before(*meths, &block)
40
+ trait[:aspects][:before][:all] = block
33
41
  end
34
42
  alias pre_all before_all
35
43
 
44
+ # run block after given actions.
36
45
  def after(*meths, &block)
37
46
  aspects = trait[:aspects][:after]
38
47
  meths.each do |meth|
@@ -41,34 +50,43 @@ module Ramaze
41
50
  end
42
51
  alias post after
43
52
 
53
+ # Run block after all actions.
44
54
  def after_all(&block)
45
- meths = instance_methods(false)
46
- after(*meths, &block)
55
+ trait[:aspects][:after][:all] = block
47
56
  end
48
57
  alias post_all after_all
49
58
 
59
+ # run block before and after given actions.
50
60
  def wrap(*meths, &block)
51
61
  before(*meths, &block)
52
62
  after(*meths, &block)
53
63
  end
54
64
 
65
+ # run block before and after all actions.
55
66
  def wrap_all(&block)
56
- meths = instance_methods(false)
57
- wrap(*meths, &block)
67
+ trait[:aspects][:before][:all] = block
68
+ trait[:aspects][:after][:all] = block
58
69
  end
59
70
  end
60
71
 
61
72
  class Action
73
+
74
+ # overwrites the default Action hook and runs the neccesary blocks in its
75
+ # scope.
62
76
  def before_process
63
77
  return unless aspects = controller.ancestral_trait[:aspects]
64
- block = aspects[:before][method]
65
- instance.instance_eval(&block) if block
78
+ [ aspects[:before][name], aspects[:before][:all] ].compact.map do |block|
79
+ instance.instance_eval(&block) if block
80
+ end
66
81
  end
67
82
 
83
+ # overwrites the default Action hook and runs the neccesary blocks in its
84
+ # scope.
68
85
  def after_process
69
86
  return unless aspects = controller.ancestral_trait[:aspects]
70
- block = aspects[:after][method]
71
- instance.instance_eval(&block) if block
87
+ [ aspects[:after][name], aspects[:after][:all] ].compact.map do |block|
88
+ instance.instance_eval(&block) if block
89
+ end
72
90
  end
73
91
  end
74
92
  end