ramaze 2011.01.30 → 2011.07.25

Sign up to get free protection for your applications and to get access to all the features.
Files changed (229) hide show
  1. data/.gitignore +2 -1
  2. data/.mailmap +2 -0
  3. data/.rvmrc +1 -0
  4. data/README.md +119 -197
  5. data/Rakefile +14 -97
  6. data/bin/ramaze +6 -14
  7. data/doc/AUTHORS +8 -4
  8. data/doc/CHANGELOG +3784 -3339
  9. data/examples/app/chat/start.rb +2 -2
  10. data/lib/proto/app.rb +2 -3
  11. data/lib/proto/config.ru +4 -5
  12. data/lib/proto/controller/init.rb +11 -4
  13. data/lib/proto/controller/main.rb +12 -7
  14. data/lib/proto/layout/default.xhtml +56 -23
  15. data/lib/proto/model/init.rb +3 -1
  16. data/lib/proto/public/css/grid.css +107 -0
  17. data/lib/proto/public/css/layout.css +81 -0
  18. data/lib/proto/public/css/reset.css +123 -0
  19. data/lib/proto/public/css/text.css +109 -0
  20. data/lib/proto/public/images/bg.png +0 -0
  21. data/lib/proto/spec/main.rb +2 -2
  22. data/lib/proto/start.rb +11 -1
  23. data/lib/proto/view/index.xhtml +27 -23
  24. data/lib/ramaze.rb +0 -1
  25. data/lib/ramaze/app.rb +85 -12
  26. data/lib/ramaze/app_graph.rb +107 -0
  27. data/lib/ramaze/bin/console.rb +87 -0
  28. data/lib/ramaze/bin/create.rb +94 -0
  29. data/lib/ramaze/bin/helper.rb +107 -0
  30. data/lib/ramaze/bin/restart.rb +95 -0
  31. data/lib/ramaze/bin/runner.rb +141 -0
  32. data/lib/ramaze/bin/start.rb +206 -0
  33. data/lib/ramaze/bin/status.rb +152 -0
  34. data/lib/ramaze/bin/stop.rb +112 -0
  35. data/lib/ramaze/cache.rb +9 -4
  36. data/lib/ramaze/cache/localmemcache.rb +10 -13
  37. data/lib/ramaze/cache/lru.rb +49 -7
  38. data/lib/ramaze/cache/memcache.rb +170 -92
  39. data/lib/ramaze/cache/sequel.rb +301 -118
  40. data/lib/ramaze/controller.rb +108 -9
  41. data/lib/ramaze/controller/default.rb +15 -2
  42. data/lib/ramaze/current.rb +14 -2
  43. data/lib/ramaze/dependencies.rb +46 -0
  44. data/lib/ramaze/files.rb +38 -3
  45. data/lib/ramaze/gestalt.rb +12 -12
  46. data/lib/ramaze/helper.rb +0 -2
  47. data/lib/ramaze/helper/auth.rb +30 -23
  48. data/lib/ramaze/helper/blue_form.rb +175 -126
  49. data/lib/ramaze/helper/csrf.rb +76 -91
  50. data/lib/ramaze/helper/email.rb +105 -0
  51. data/lib/ramaze/helper/erector.rb +16 -15
  52. data/lib/ramaze/helper/gestalt.rb +2 -2
  53. data/lib/ramaze/helper/layout.rb +89 -73
  54. data/lib/ramaze/helper/link.rb +7 -6
  55. data/lib/ramaze/helper/localize.rb +6 -5
  56. data/lib/ramaze/helper/markaby.rb +25 -23
  57. data/lib/ramaze/helper/maruku.rb +3 -3
  58. data/lib/ramaze/helper/paginate.rb +19 -27
  59. data/lib/ramaze/helper/remarkably.rb +3 -3
  60. data/lib/ramaze/helper/request_accessor.rb +3 -3
  61. data/lib/ramaze/helper/send_file.rb +12 -8
  62. data/lib/ramaze/helper/simple_captcha.rb +5 -6
  63. data/lib/ramaze/helper/stack.rb +7 -4
  64. data/lib/ramaze/helper/tagz.rb +10 -11
  65. data/lib/ramaze/helper/thread.rb +19 -16
  66. data/lib/ramaze/helper/ultraviolet.rb +7 -4
  67. data/lib/ramaze/helper/user.rb +40 -21
  68. data/lib/ramaze/helper/xhtml.rb +29 -20
  69. data/lib/ramaze/log.rb +3 -11
  70. data/lib/ramaze/log/analogger.rb +5 -4
  71. data/lib/ramaze/log/growl.rb +9 -7
  72. data/lib/ramaze/log/hub.rb +3 -5
  73. data/lib/ramaze/log/informer.rb +15 -12
  74. data/lib/ramaze/log/knotify.rb +3 -5
  75. data/lib/ramaze/log/logger.rb +3 -5
  76. data/lib/ramaze/log/logging.rb +6 -8
  77. data/lib/ramaze/log/rotatinginformer.rb +27 -17
  78. data/lib/ramaze/log/syslog.rb +7 -7
  79. data/lib/ramaze/log/xosd.rb +3 -5
  80. data/lib/ramaze/middleware_compiler.rb +27 -4
  81. data/lib/ramaze/reloader.rb +50 -12
  82. data/lib/ramaze/reloader/watch_inotify.rb +4 -5
  83. data/lib/ramaze/reloader/watch_stat.rb +3 -3
  84. data/lib/ramaze/request.rb +18 -8
  85. data/lib/ramaze/response.rb +38 -7
  86. data/lib/ramaze/rest.rb +36 -0
  87. data/lib/ramaze/setup.rb +101 -31
  88. data/lib/ramaze/spec.rb +1 -1
  89. data/lib/ramaze/spec/bacon.rb +6 -3
  90. data/lib/ramaze/spec/helper/bacon.rb +0 -1
  91. data/lib/ramaze/version.rb +1 -1
  92. data/lib/ramaze/view.rb +2 -11
  93. data/lib/ramaze/view/erector.rb +46 -31
  94. data/lib/ramaze/view/erubis.rb +7 -3
  95. data/lib/ramaze/view/ezamar.rb +7 -3
  96. data/lib/ramaze/view/gestalt.rb +9 -3
  97. data/lib/ramaze/view/haml.rb +7 -3
  98. data/lib/ramaze/view/liquid.rb +3 -3
  99. data/lib/ramaze/view/lokar.rb +7 -3
  100. data/lib/ramaze/view/mustache.rb +11 -5
  101. data/lib/ramaze/view/nagoro.rb +3 -3
  102. data/lib/ramaze/view/sass.rb +1 -1
  103. data/lib/ramaze/view/slippers.rb +40 -13
  104. data/lib/ramaze/view/tagz.rb +9 -5
  105. data/ramaze.gemspec +23 -128
  106. data/spec/helper.rb +5 -0
  107. data/spec/ramaze/bin/app/config.ru +11 -0
  108. data/spec/ramaze/bin/create.rb +28 -0
  109. data/spec/ramaze/bin/runner.rb +30 -0
  110. data/spec/ramaze/bin/start.rb +38 -0
  111. data/spec/ramaze/cache/memcache.rb +10 -3
  112. data/spec/ramaze/cache/sequel.rb +7 -0
  113. data/spec/ramaze/controller/provide_inheritance.rb +0 -10
  114. data/spec/ramaze/dispatcher/file.rb +19 -15
  115. data/spec/ramaze/helper/auth.rb +10 -9
  116. data/spec/ramaze/helper/blue_form.rb +121 -68
  117. data/spec/ramaze/helper/email.rb +69 -0
  118. data/spec/ramaze/helper/layout.rb +12 -15
  119. data/spec/ramaze/helper/layout/alternative.xhtml +5 -0
  120. data/spec/ramaze/helper/user.rb +2 -0
  121. data/spec/ramaze/log/growl.rb +14 -1
  122. data/spec/{contrib → ramaze}/rest.rb +1 -1
  123. data/spec/ramaze/session/memcache.rb +2 -2
  124. data/spec/ramaze/view/sass.rb +1 -1
  125. data/tasks/bacon.rake +3 -3
  126. data/tasks/gem.rake +17 -18
  127. data/tasks/rcov.rake +2 -3
  128. data/tasks/release.rake +8 -65
  129. data/tasks/setup.rake +10 -8
  130. data/tasks/todo.rake +9 -5
  131. data/tasks/yard.rake +3 -2
  132. metadata +105 -397
  133. data/MANIFEST +0 -532
  134. data/TODO.md +0 -19
  135. data/benchmark/bench_templates/bench.rb +0 -67
  136. data/benchmark/bench_templates/view/large.erb +0 -79
  137. data/benchmark/bench_templates/view/large.haml +0 -41
  138. data/benchmark/bench_templates/view/large.lok +0 -79
  139. data/benchmark/bench_templates/view/large.xhtml +0 -79
  140. data/benchmark/bench_templates/view/small.erb +0 -21
  141. data/benchmark/bench_templates/view/small.haml +0 -12
  142. data/benchmark/bench_templates/view/small.lok +0 -21
  143. data/benchmark/bench_templates/view/small.xhtml +0 -21
  144. data/benchmark/results.txt +0 -131
  145. data/benchmark/run.rb +0 -355
  146. data/benchmark/suite/minimal.rb +0 -11
  147. data/benchmark/suite/no_informer.rb +0 -7
  148. data/benchmark/suite/no_sessions.rb +0 -9
  149. data/benchmark/suite/no_template.rb +0 -7
  150. data/benchmark/suite/simple.rb +0 -5
  151. data/benchmark/suite/template_erubis.rb +0 -8
  152. data/benchmark/suite/template_etanni.rb +0 -8
  153. data/benchmark/suite/template_ezamar.rb +0 -8
  154. data/benchmark/suite/template_haml.rb +0 -13
  155. data/benchmark/suite/template_liquid.rb +0 -11
  156. data/benchmark/suite/template_markaby.rb +0 -9
  157. data/benchmark/suite/template_nagoro.rb +0 -8
  158. data/benchmark/suite/template_redcloth.rb +0 -13
  159. data/benchmark/suite/template_tenjin.rb +0 -8
  160. data/benchmark/test.rb +0 -35
  161. data/doc/FAQ +0 -92
  162. data/doc/INSTALL +0 -92
  163. data/doc/TODO +0 -29
  164. data/doc/meta/announcement.txt +0 -119
  165. data/doc/meta/configuration.txt +0 -163
  166. data/doc/meta/internals.txt +0 -278
  167. data/doc/meta/users.kml +0 -64
  168. data/doc/tutorial/todolist.html +0 -1512
  169. data/doc/tutorial/todolist.txt +0 -920
  170. data/examples/app/sourceview/public/coderay.css +0 -104
  171. data/examples/app/sourceview/public/images/file.gif +0 -0
  172. data/examples/app/sourceview/public/images/folder.gif +0 -0
  173. data/examples/app/sourceview/public/images/tv-collapsable-last.gif +0 -0
  174. data/examples/app/sourceview/public/images/tv-collapsable.gif +0 -0
  175. data/examples/app/sourceview/public/images/tv-expandable-last.gif +0 -0
  176. data/examples/app/sourceview/public/images/tv-expandable.gif +0 -0
  177. data/examples/app/sourceview/public/images/tv-item-last.gif +0 -0
  178. data/examples/app/sourceview/public/images/tv-item.gif +0 -0
  179. data/examples/app/sourceview/public/jquery.js +0 -11
  180. data/examples/app/sourceview/public/jquery.treeview.css +0 -48
  181. data/examples/app/sourceview/public/jquery.treeview.js +0 -223
  182. data/examples/app/sourceview/public/sourceview.js +0 -52
  183. data/examples/app/sourceview/start.rb +0 -79
  184. data/examples/app/sourceview/view/index.haml +0 -59
  185. data/examples/helpers/httpdigest.rb +0 -107
  186. data/lib/proto/public/css/screen.css +0 -30
  187. data/lib/proto/public/js/jquery.js +0 -7179
  188. data/lib/ramaze/contrib/addressable_route.rb +0 -56
  189. data/lib/ramaze/contrib/app_graph.rb +0 -64
  190. data/lib/ramaze/contrib/email.rb +0 -88
  191. data/lib/ramaze/contrib/facebook.rb +0 -23
  192. data/lib/ramaze/contrib/facebook/facebook.rb +0 -171
  193. data/lib/ramaze/contrib/gettext.rb +0 -113
  194. data/lib/ramaze/contrib/gettext/mo.rb +0 -155
  195. data/lib/ramaze/contrib/gettext/parser.rb +0 -46
  196. data/lib/ramaze/contrib/gettext/po.rb +0 -109
  197. data/lib/ramaze/contrib/gzip_filter.rb +0 -1
  198. data/lib/ramaze/contrib/maruku_uv.rb +0 -59
  199. data/lib/ramaze/contrib/profiling.rb +0 -36
  200. data/lib/ramaze/contrib/rest.rb +0 -23
  201. data/lib/ramaze/contrib/sequel/create_join.rb +0 -26
  202. data/lib/ramaze/contrib/sequel/form_field.rb +0 -129
  203. data/lib/ramaze/contrib/sequel/image.rb +0 -196
  204. data/lib/ramaze/contrib/sequel/relation.rb +0 -98
  205. data/lib/ramaze/helper/httpdigest.rb +0 -96
  206. data/lib/ramaze/tool/bin.rb +0 -340
  207. data/lib/ramaze/tool/create.rb +0 -48
  208. data/lib/ramaze/tool/project_creator.rb +0 -120
  209. data/lib/ramaze/view/less.rb +0 -12
  210. data/lib/ramaze/view/maruku.rb +0 -15
  211. data/lib/ramaze/view/redcloth.rb +0 -21
  212. data/spec/contrib/addressable_route.rb +0 -30
  213. data/spec/examples/helpers/httpdigest.rb +0 -64
  214. data/spec/examples/templates/template_redcloth.rb +0 -13
  215. data/spec/ramaze/bin/ramaze.rb +0 -96
  216. data/spec/ramaze/helper/httpdigest.rb +0 -176
  217. data/spec/ramaze/view/less.rb +0 -60
  218. data/spec/ramaze/view/less/file.css.less +0 -8
  219. data/spec/ramaze/view/redcloth.rb +0 -66
  220. data/spec/ramaze/view/redcloth/external.redcloth +0 -8
  221. data/tasks/copyright.rake +0 -21
  222. data/tasks/gem_setup.rake +0 -112
  223. data/tasks/git.rake +0 -46
  224. data/tasks/grancher.rake +0 -12
  225. data/tasks/jquery.rake +0 -15
  226. data/tasks/manifest.rake +0 -4
  227. data/tasks/metric_changes.rake +0 -24
  228. data/tasks/reversion.rake +0 -8
  229. data/tasks/traits.rake +0 -21
@@ -2,7 +2,24 @@
2
2
  # All files in this distribution are subject to the terms of the Ruby license.
3
3
 
4
4
  module Ramaze
5
- # TODO: Describe what this class does other than initailizing the Controller system.
5
+ ##
6
+ # Ramaze::Controller is the base controller of all controllers when developing
7
+ # applications in Ramaze. It acts as a nice wrapper around Innate::Node and
8
+ # allows for a more traditional MVC approach.
9
+ #
10
+ # == Example
11
+ #
12
+ # class Posts < Ramaze::Controller
13
+ # map '/posts'
14
+ #
15
+ # def index
16
+ #
17
+ # end
18
+ # end
19
+ #
20
+ # @author Michael Fellinger
21
+ # @since 04-01-2009
22
+ #
6
23
  class Controller
7
24
  include Innate::Traited
8
25
  include Innate::Node
@@ -18,6 +35,27 @@ module Ramaze
18
35
  trait :app => :pristine
19
36
  trait :skip_controller_map => false
20
37
 
38
+ ##
39
+ # Hash containing the names of two common controller names and the URIs they
40
+ # should be mapped to.
41
+ #
42
+ # @author Michael Fellinger
43
+ # @since 04-01-2009
44
+ #
45
+ IRREGULAR_MAPPING = {
46
+ 'Controller' => nil,
47
+ 'MainController' => '/'
48
+ }
49
+
50
+ ##
51
+ # Modifies the extending class so that it's properly set up to be used as a
52
+ # controller.
53
+ #
54
+ # @author Michael Fellinger
55
+ # @since 04-01-2009
56
+ # @param [Class] into The class that extended Ramaze::Controller (or a sub
57
+ # class).
58
+ #
21
59
  def self.inherited(into)
22
60
  Innate::Node.included(into)
23
61
  into.helper(:layout)
@@ -25,6 +63,13 @@ module Ramaze
25
63
  into.trait :skip_node_map => true
26
64
  end
27
65
 
66
+ ##
67
+ # Sets all the controllers up and loads a default controller in case no
68
+ # custom ones have been specified.
69
+ #
70
+ # @author Michael Fellinger
71
+ # @since 04-01-2009
72
+ #
28
73
  def self.setup
29
74
  case CONTROLLER_LIST.size
30
75
  when 0
@@ -46,28 +91,59 @@ module Ramaze
46
91
  end
47
92
  end
48
93
 
94
+ ##
95
+ # Method that's used to setup each controller, called by
96
+ # Ramaze::Controller.setup.
97
+ #
98
+ # @author Michael Fellinger
99
+ # @since 04-01-2009
100
+ #
49
101
  def self.setup_procedure
50
102
  unless ancestral_trait[:provide_set]
51
- engine(:Etanni)
103
+ engine(:etanni)
52
104
  trait(:provide_set => false)
53
105
  end
54
106
 
55
107
  map(generate_mapping(name)) unless trait[:skip_controller_map]
56
108
  end
57
109
 
110
+ ##
111
+ # Sets the view engine to use for pages with a content type of text/html.
112
+ #
113
+ # @example
114
+ # class Posts < Ramaze::Controller
115
+ # engine :etanni
116
+ # end
117
+ #
118
+ # @author Michael Fellinger
119
+ # @since 04-01-2009
120
+ # @param [#to_sym] name The name of the view engine to use.
121
+ #
58
122
  def self.engine(name)
59
123
  provide(:html, name.to_sym)
60
124
  end
61
125
 
126
+ ##
127
+ # Returns the URI a controller is mapped to.
128
+ #
129
+ # @author Michael Fellinger
130
+ # @since 04-01-2009
131
+ # @return [String]
132
+ #
62
133
  def self.mapping
63
134
  Ramaze.to(self)
64
135
  end
65
136
 
66
- IRREGULAR_MAPPING = {
67
- 'Controller' => nil,
68
- 'MainController' => '/'
69
- }
70
-
137
+ ##
138
+ # Generates a URI for the full namespace of a class. If a class is named
139
+ # A::B::C the URI would be /a/b/c.
140
+ #
141
+ # @author Michael Fellinger
142
+ # @since 04-01-2009
143
+ # @param [String] klass_name The name of the class for which to generate
144
+ # the mapping, defaults to the current class.
145
+ # @return [String]
146
+ #
71
147
  def self.generate_mapping(klass_name = self.name)
72
148
  chunks = klass_name.to_s.split(/::/)
73
149
  return if chunks.empty?
@@ -79,6 +155,15 @@ module Ramaze
79
155
  '/' << chunks.map{|chunk| chunk.snake_case }.join('/')
80
156
  end
81
157
 
158
+ ##
159
+ # Maps the current class to the specified location.
160
+ #
161
+ # @author Michael Fellinger
162
+ # @since 04-01-2009
163
+ # @param [String] location The URI to map the controller to.
164
+ # @param [String] app_name The name of the application the controller
165
+ # belongs to.
166
+ #
82
167
  def self.map(location, app_name = nil)
83
168
  if app_name
84
169
  trait :app => app_name
@@ -91,13 +176,27 @@ module Ramaze
91
176
  App.find_or_create(app_name).map(location, self)
92
177
  end
93
178
 
179
+ ##
180
+ # Returns the application to which the controller belongs to.
181
+ #
182
+ # @author Michael Fellinger
183
+ # @since 04-01-2009
184
+ # @return [Ramaze::App]
185
+ #
94
186
  def self.app
95
187
  App[ancestral_trait[:app]]
96
188
  end
97
189
 
190
+ ##
191
+ # Returns all the options for the application the controller belongs to.
192
+ #
193
+ # @author Michael Fellinger
194
+ # @since 04-01-2009
195
+ # @return [Innate::Options]
196
+ #
98
197
  def self.options
99
198
  return unless app = self.app
100
199
  app.options
101
200
  end
102
- end
103
- end
201
+ end # Controller
202
+ end # Ramaze
@@ -1,12 +1,25 @@
1
1
  module Ramaze
2
2
  Log.debug "Default controller invoked"
3
3
 
4
+ ##
5
+ # The default controller that is loaded if no other controllers have been
6
+ # defined.
7
+ #
8
+ # @author Michael Fellinger
9
+ # @since 30-03-2009
10
+ #
4
11
  class DefaultController < Ramaze::Controller
5
12
  map '/'
6
13
 
14
+ ##
15
+ # Shows an ASCII lobster using Rack::Lobster::LobsterString.
16
+ #
17
+ # @author Michael Fellinger
18
+ # @since 06-04-2009
19
+ #
7
20
  def lobster
8
21
  require 'rack/lobster'
9
22
  respond Rack::Lobster::LobsterString
10
23
  end
11
- end
12
- end
24
+ end # DefaultController
25
+ end # Ramaze
@@ -1,7 +1,19 @@
1
1
  module Ramaze
2
+ ##
3
+ # Class that's used to point to the current action. This can be useful if you
4
+ # want to access data such as the session() method without having to include
5
+ # Innate::Trinity (which can pollute your namespace and/or cause collisions).
6
+ #
7
+ # @author Michael Fellinger
8
+ # @since 25-03-2009
9
+ #
2
10
  class Current < Innate::Current
11
+ ##
12
+ # @author Michael Fellinger
13
+ # @since 25-03-2009
14
+ # @see Innate::Current#setup
3
15
  def setup(env, request = Request, response = Response, session = Session)
4
16
  super
5
17
  end
6
- end
7
- end
18
+ end # Current
19
+ end # Ramaze
@@ -0,0 +1,46 @@
1
+ module Ramaze
2
+ # Array containing the names and versions of all the gems required by Ramaze
3
+ # along with the name of how the gem should be required.
4
+ DEPENDENCIES = [
5
+ {:name => 'innate', :version => ['>= 2010.03']}
6
+ ]
7
+
8
+ # Array containing all the development dependencies.
9
+ DEVELOPMENT_DEPENDENCIES = [
10
+ {:name => 'bacon' , :version => ['>= 1.1.0']},
11
+ {:name => 'dalli' , :version => ['>= 1.0.5']},
12
+ {:name => 'erector' , :version => ['>= 0.8.2']},
13
+ {:name => 'erubis' , :version => ['>= 2.7.0']},
14
+ {:name => 'ezamar' , :version => ['>= 2009.06']},
15
+ {:name => 'sass' , :version => ['>= 3.1.4']},
16
+ {:name => 'haml' , :version => ['>= 3.1.2']},
17
+ {:name => 'hpricot' , :version => ['>= 0.8.4']},
18
+ {:name => 'liquid' , :version => ['>= 2.2.2']},
19
+ {:name => 'locale' , :version => ['>= 2.0.5']},
20
+ {:name => 'lokar' , :version => ['>= 0.2.1']},
21
+ {:name => 'maruku' , :version => ['>= 0.6.0']},
22
+ {:name => 'mustache' , :version => ['>= 0.99.4']},
23
+ {:name => 'nagoro' , :version => ['>= 2009.05']},
24
+ {:name => 'rack-contrib', :version => ['>= 1.1.0'], :lib => 'rack/contrib'},
25
+ {:name => 'rack-test' , :version => ['>= 0.6.0'], :lib => 'rack/test'},
26
+ {:name => 'Remarkably' , :version => ['>= 0.6.1'], :lib => 'remarkably'},
27
+ {:name => 'sequel' , :version => ['>= 3.25.0']},
28
+ {:name => 'slippers' , :version => ['>= 0.0.14']},
29
+ {:name => 'sqlite3' , :version => ['>= 1.3.3']},
30
+ {:name => 'tagz' , :version => ['>= 9.0.0']},
31
+ {:name => 'tenjin' , :version => ['>= 0.6.1']},
32
+ {:name => 'yard' , :version => ['>= 0.7.2']},
33
+ ]
34
+
35
+ if !RUBY_PLATFORM.include?('darwin')
36
+ DEVELOPMENT_DEPENDENCIES.push(
37
+ {:name => 'localmemcache', :version => ['>= 0.4.4']}
38
+ )
39
+ end
40
+
41
+ if RUBY_PLATFORM.include?('darwin')
42
+ DEVELOPMENT_DEPENDENCIES.push(
43
+ {:name => 'ruby-growl', :version => ['>= 3.0']}
44
+ )
45
+ end
46
+ end # Ramaze
data/lib/ramaze/files.rb CHANGED
@@ -1,24 +1,59 @@
1
1
  module Ramaze
2
- # Serving multiple public directories made easy.
2
+ ##
3
+ # Class that makes it possible to easily use multiple public directories in
4
+ # your Ramaze application.
5
+ #
6
+ # @author Michael Fellinger
7
+ # @since 14-03-2009
8
+ #
3
9
  class Files
10
+ ##
11
+ # Creates a new instance of the class, stores the given root directories and
12
+ # syncs the changes with Rack::Cascade.
13
+ #
14
+ # @author Michael Fellinger
15
+ # @since 14-03-2009
16
+ # @param [Array] *roots A set of root directories that contain a number of
17
+ # public directories.
18
+ #
4
19
  def initialize(*roots)
5
20
  @roots = roots.flatten.map{|root| File.expand_path(root.to_s) }
6
21
  sync
7
22
  end
8
23
 
24
+ ##
25
+ # Allows this class to be called as a Rack middleware.
26
+ #
27
+ # @author Michael Fellinger
28
+ # @since 14-03-2009
29
+ # @param [Hash] env Hash containing all the environment details.
30
+ #
9
31
  def call(env)
10
32
  @cascade.call(env)
11
33
  end
12
34
 
35
+ ##
36
+ # Adds a new path to the list of root directories.
37
+ #
38
+ # @author Michael Fellinger
39
+ # @since 14-03-2009
40
+ # @param [String] path The path to add to the existing root directories.
41
+ #
13
42
  def <<(path)
14
43
  @roots << File.expand_path(path.to_s)
15
44
  @roots.uniq!
16
45
  sync
17
46
  end
18
47
 
48
+ ##
49
+ # Syncs the class with Rack::Cascade.
50
+ #
51
+ # @author Michael Fellinger
52
+ # @since 14-03-2009
53
+ #
19
54
  def sync
20
55
  file_apps = @roots.map{|root| Rack::File.new(root) }
21
56
  @cascade = Rack::Cascade.new(file_apps)
22
57
  end
23
- end
24
- end
58
+ end # Files
59
+ end # Ramaze
@@ -2,13 +2,11 @@
2
2
  # All files in this distribution are subject to the terms of the Ruby license.
3
3
 
4
4
  module Ramaze
5
-
6
5
  ##
7
6
  # Gestalt is the custom HTML/XML builder for Ramaze, based on a very simple
8
7
  # DSL it will build your markup.
9
8
  #
10
9
  # @example
11
- #
12
10
  # html =
13
11
  # Gestalt.build do
14
12
  # html do
@@ -28,7 +26,7 @@ module Ramaze
28
26
  # The default way to start building your markup.
29
27
  # Takes a block and returns the markup.
30
28
  #
31
- # @param [Block] block
29
+ # @param [Block] block
32
30
  #
33
31
  def self.build(&block)
34
32
  self.new(&block).to_s
@@ -62,17 +60,19 @@ module Ramaze
62
60
  ##
63
61
  # Workaround for Kernel#p to make <p /> tags possible.
64
62
  #
65
- # @param [Hash] args Extra arguments that should be processed before creating the paragraph tag.
63
+ # @param [Hash] args Extra arguments that should be processed before
64
+ # creating the paragraph tag.
66
65
  # @param [Block] block
67
66
  #
68
67
  def p(*args, &block)
69
68
  _gestalt_call_tag :p, args, &block
70
69
  end
71
-
70
+
72
71
  ##
73
72
  # Workaround for Kernel#select to make <select></select> work.
74
73
  #
75
- # @param [Hash] args Extra arguments that should be processed before creating the select tag.
74
+ # @param [Hash] args Extra arguments that should be processed before
75
+ # creating the select tag.
76
76
  # @param [Block] block
77
77
  #
78
78
  def select(*args, &block)
@@ -80,7 +80,7 @@ module Ramaze
80
80
  end
81
81
 
82
82
  ##
83
- # TODO: Describe this method, I'm not exactly sure what it does - Yorick
83
+ # Calls a particular tag based on the specified parameters.
84
84
  #
85
85
  # @param [String] name
86
86
  # @param [Hash] args
@@ -103,8 +103,6 @@ module Ramaze
103
103
  # Build a tag for `name`, using `args` and an optional block that
104
104
  # will be yielded.
105
105
  #
106
- # TODO: Describe this method since I'm not exactly sure what it does - Yorick
107
- #
108
106
  # @param [String] name
109
107
  # @param [Hash] attr
110
108
  # @param [Hash] text
@@ -139,7 +137,7 @@ module Ramaze
139
137
  end
140
138
 
141
139
  ##
142
- # TODO: Describe this method since I'm not exactly sure what it does - Yorick
140
+ # Shortcut for building tags,
143
141
  #
144
142
  # @param [String] name
145
143
  # @param [Hash] args
@@ -153,9 +151,11 @@ module Ramaze
153
151
  # Convert the final output of Gestalt to a string.
154
152
  # This method has the following alias: "to_str".
155
153
  #
154
+ # @return [String]
155
+ #
156
156
  def to_s
157
157
  @out.join
158
158
  end
159
159
  alias to_str to_s
160
- end
161
- end
160
+ end # Gestalt
161
+ end # Ramaze
data/lib/ramaze/helper.rb CHANGED
@@ -1,9 +1,7 @@
1
1
  # Copyright (c) 2009 Michael Fellinger m.fellinger@gmail.com
2
2
  # All files in this distribution are subject to the terms of the Ruby license.
3
-
4
3
  require 'innate/helper'
5
4
 
6
- # TODO: Describe what this module does besides loading a few default helper.
7
5
  module Ramaze
8
6
  Helper = Innate::Helper
9
7
  Innate::HelpersHelper.options.paths << File.dirname(__FILE__)
@@ -3,39 +3,42 @@
3
3
 
4
4
  module Ramaze
5
5
  module Helper
6
-
7
- # A simple way to do authentication without a model.
8
- # Please have a look at the docs of Auth#auth_login.
9
- #
10
- # If you want to do authentication with a model see Helper::User instead.
11
-
12
6
  ##
13
7
  # The Auth helper can be used for authentication without using a model.
14
- # This can be useful when working with very basic applications that don't require database access.
8
+ # This can be useful when working with very basic applications that don't
9
+ # require database access.
15
10
  #
16
- # If you're looking for a way to do authentication using a model you should take a look at Helper::User instead.
11
+ # If you're looking for a way to do authentication using a model you should
12
+ # take a look at Helper::User instead.
17
13
  #
18
14
  module Auth
19
15
  Helper::LOOKUP << self
20
16
  include Ramaze::Traited
21
17
 
22
- trait :auth_table => {}
23
- trait :auth_hashify => lambda{|pass| Digest::SHA1.hexdigest(pass) }
18
+ trait :auth_table => {}
19
+ trait :auth_hashify => lambda { |pass| Digest::SHA1.hexdigest(pass) }
24
20
  trait :auth_post_only => false
25
21
 
26
22
  def self.included(into)
27
23
  into.helper(:stack)
28
24
  end
29
-
25
+
30
26
  ##
31
- # Log a user in based on the :username and :password key in the request hash.
27
+ # Log a user in based on the :username and :password key in the request
28
+ # hash.
32
29
  #
33
- # @return [String] The login template in case the user's login data was incorrect.
30
+ # @return [String] The login template in case the user's login data was
31
+ # incorrect.
34
32
  #
35
33
  def login
36
- return auth_template if trait[:auth_post_only] and !request.post?
34
+ if trait[:auth_post_only] and !request.post?
35
+ return auth_template
36
+ end
37
+
37
38
  @username, password = request[:username, :password]
39
+
38
40
  answer(request.referer) if auth_login(@username, password)
41
+
39
42
  return auth_template
40
43
  end
41
44
 
@@ -44,20 +47,22 @@ module Ramaze
44
47
  #
45
48
  def logout
46
49
  auth_logout
47
- answer(request.referer)
50
+ redirect_referrer
48
51
  end
49
52
 
50
53
  private
51
54
 
52
55
  ##
53
- # Validate the user's session and redirect him/her to the login page in case the user isn't logged in.
56
+ # Validate the user's session and redirect him/her to the login page in
57
+ # case the user isn't logged in.
54
58
  #
55
59
  def login_required
56
60
  call(r(:login)) unless logged_in?
57
61
  end
58
62
 
59
63
  ##
60
- # Validate the user's session and return a boolean that indicates if the user is logged in or not.
64
+ # Validate the user's session and return a boolean that indicates if the
65
+ # user is logged in or not.
61
66
  #
62
67
  # @return [true false] Whether user is logged in right now
63
68
  #
@@ -67,7 +72,8 @@ module Ramaze
67
72
 
68
73
  ##
69
74
  # Try to log the user in based on the username and password.
70
- # This method is called by the login() method and shouldn't be called directly.
75
+ # This method is called by the login() method and shouldn't be called
76
+ # directly.
71
77
  #
72
78
  # @param [String] user The users's username.
73
79
  # @param [String] pass The user's password.
@@ -75,7 +81,8 @@ module Ramaze
75
81
  def auth_login(user, pass)
76
82
  return unless user and pass
77
83
  return if user.empty? or pass.empty?
78
- return unless table = ancestral_trait[:auth_table]
84
+
85
+ return unless table = ancestral_trait[:auth_table]
79
86
  return unless hashify = ancestral_trait[:auth_hashify]
80
87
 
81
88
  if table.respond_to?(:to_sym) or table.respond_to?(:to_str)
@@ -87,7 +94,7 @@ module Ramaze
87
94
  return unless table[user] == hashify.call(pass)
88
95
 
89
96
  session[:logged_in] = true
90
- session[:username] = user
97
+ session[:username] = user
91
98
  end
92
99
 
93
100
  ##
@@ -113,6 +120,6 @@ module Ramaze
113
120
  </form>
114
121
  TEMPLATE
115
122
  end
116
- end
117
- end
118
- end
123
+ end # Auth
124
+ end # Helper
125
+ end # Ramaze