Pistos-ramaze 2009.04.08 → 2009.06.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (227) hide show
  1. data/.gitignore +3 -0
  2. data/MANIFEST +37 -22
  3. data/{README.markdown → README.md} +5 -24
  4. data/Rakefile +33 -26
  5. data/benchmark/bench_templates/bench.rb +67 -0
  6. data/benchmark/bench_templates/view/large.erb +79 -0
  7. data/benchmark/bench_templates/view/large.haml +41 -0
  8. data/benchmark/bench_templates/view/large.xhtml +79 -0
  9. data/benchmark/bench_templates/view/small.erb +21 -0
  10. data/benchmark/bench_templates/view/small.haml +12 -0
  11. data/benchmark/bench_templates/view/small.xhtml +21 -0
  12. data/benchmark/run.rb +14 -21
  13. data/benchmark/suite/minimal.rb +3 -5
  14. data/benchmark/suite/no_informer.rb +0 -2
  15. data/benchmark/suite/no_sessions.rb +3 -4
  16. data/benchmark/suite/no_template.rb +1 -3
  17. data/benchmark/suite/simple.rb +1 -3
  18. data/benchmark/suite/template_erubis.rb +0 -2
  19. data/benchmark/suite/template_etanni.rb +8 -0
  20. data/benchmark/suite/template_ezamar.rb +1 -3
  21. data/benchmark/suite/template_haml.rb +0 -2
  22. data/benchmark/suite/template_liquid.rb +0 -2
  23. data/benchmark/suite/template_markaby.rb +0 -2
  24. data/benchmark/suite/template_nagoro.rb +1 -3
  25. data/benchmark/suite/template_redcloth.rb +0 -2
  26. data/benchmark/suite/template_tenjin.rb +0 -2
  27. data/bin/ramaze +11 -163
  28. data/doc/AUTHORS +15 -8
  29. data/doc/CHANGELOG +10094 -12262
  30. data/doc/meta/announcement.txt +93 -46
  31. data/doc/tutorial/todolist.html +22 -58
  32. data/doc/tutorial/todolist.txt +20 -39
  33. data/examples/app/auth/layout/{auth.nag → auth.xhtml} +0 -0
  34. data/examples/app/auth/view/{index.nag → index.xhtml} +0 -0
  35. data/examples/app/auth/view/{login.nag → login.xhtml} +0 -0
  36. data/examples/app/auth/view/{secret.nag → secret.xhtml} +0 -0
  37. data/examples/app/blog/app.rb +1 -1
  38. data/examples/app/blog/controller/comment.rb +1 -1
  39. data/examples/app/blog/controller/entry.rb +12 -3
  40. data/examples/app/blog/model/init.rb +5 -0
  41. data/examples/app/blog/model/tag.rb +2 -2
  42. data/examples/app/blog/view/entry/index.nag +3 -3
  43. data/examples/app/blog/view/feed.atom.nag +1 -1
  44. data/examples/app/blog/view/feed.rss.nag +1 -1
  45. data/examples/app/blog/view/index.nag +1 -1
  46. data/examples/app/blog/view/tag/index.nag +1 -1
  47. data/examples/app/chat/layout/{default.nag → default.xhtml} +0 -0
  48. data/examples/app/chat/view/{chat.nag → chat.xhtml} +0 -0
  49. data/examples/app/chat/view/{index.nag → index.xhtml} +0 -0
  50. data/examples/app/localization/locale/de.yaml +5 -0
  51. data/examples/app/localization/locale/en.yaml +5 -0
  52. data/examples/app/localization/locale/ja.yaml +5 -0
  53. data/examples/app/localization/start.rb +33 -20
  54. data/examples/app/wikore/spec/wikore.rb +4 -6
  55. data/examples/app/wikore/src/controller.rb +9 -11
  56. data/examples/app/wikore/src/model.rb +7 -10
  57. data/examples/app/wikore/start.rb +1 -1
  58. data/examples/app/wikore/{template → view}/index.xhtml +0 -0
  59. data/examples/helpers/cache.rb +6 -4
  60. data/examples/misc/css.rb +6 -12
  61. data/examples/misc/rapp.rb +28 -17
  62. data/lib/proto/app.rb +14 -0
  63. data/lib/proto/config.ru +8 -5
  64. data/lib/proto/controller/init.rb +3 -3
  65. data/lib/proto/spec/main.rb +9 -11
  66. data/lib/proto/start.rb +6 -10
  67. data/lib/ramaze.rb +8 -9
  68. data/lib/ramaze/app.rb +4 -3
  69. data/lib/ramaze/cache/localmemcache.rb +2 -2
  70. data/lib/ramaze/cache/memcache.rb +26 -1
  71. data/lib/ramaze/cache/sequel.rb +24 -9
  72. data/lib/ramaze/contrib/addressable_route.rb +56 -0
  73. data/lib/ramaze/contrib/email.rb +2 -0
  74. data/lib/ramaze/contrib/facebook/facebook.rb +4 -4
  75. data/lib/ramaze/contrib/sequel/create_join.rb +1 -0
  76. data/lib/ramaze/contrib/sequel/form_field.rb +4 -4
  77. data/lib/ramaze/contrib/sequel/image.rb +9 -11
  78. data/lib/ramaze/contrib/sequel/relation.rb +17 -3
  79. data/lib/ramaze/controller.rb +26 -18
  80. data/lib/ramaze/gestalt.rb +4 -1
  81. data/lib/ramaze/helper.rb +1 -0
  82. data/lib/ramaze/helper/auth.rb +0 -5
  83. data/lib/ramaze/helper/cache.rb +65 -25
  84. data/lib/ramaze/helper/form.rb +14 -2
  85. data/lib/ramaze/helper/formatting.rb +3 -1
  86. data/lib/ramaze/helper/gestalt.rb +32 -0
  87. data/lib/ramaze/helper/identity.rb +3 -3
  88. data/lib/ramaze/helper/layout.rb +97 -0
  89. data/lib/ramaze/helper/link.rb +6 -25
  90. data/lib/ramaze/helper/localize.rb +13 -3
  91. data/lib/ramaze/helper/paginate.rb +4 -2
  92. data/lib/ramaze/helper/ultraviolet.rb +2 -0
  93. data/lib/ramaze/helper/user.rb +3 -3
  94. data/lib/ramaze/log/rotatinginformer.rb +10 -10
  95. data/lib/ramaze/request.rb +3 -5
  96. data/lib/ramaze/setup.rb +22 -9
  97. data/lib/ramaze/spec.rb +8 -12
  98. data/lib/ramaze/spec/bacon.rb +34 -0
  99. data/lib/ramaze/spec/helper/template_examples.rb +15 -22
  100. data/lib/ramaze/tool/bin.rb +340 -0
  101. data/lib/ramaze/tool/project_creator.rb +1 -1
  102. data/lib/ramaze/version.rb +1 -1
  103. data/lib/ramaze/view.rb +6 -11
  104. data/lib/ramaze/view/erubis.rb +2 -2
  105. data/lib/ramaze/view/ezamar.rb +2 -2
  106. data/lib/ramaze/view/gestalt.rb +14 -0
  107. data/lib/ramaze/view/haml.rb +2 -1
  108. data/lib/ramaze/view/liquid.rb +45 -11
  109. data/lib/ramaze/view/maruku.rb +2 -1
  110. data/lib/ramaze/view/nagoro/render_partial.rb +9 -9
  111. data/lib/ramaze/view/sass.rb +1 -1
  112. data/lib/ramaze/view/tenjin.rb +7 -4
  113. data/lib/vendor/etag.rb +4 -2
  114. data/lib/vendor/route_exceptions.rb +9 -15
  115. data/ramaze.gemspec +56 -9
  116. data/spec/contrib/addressable_route.rb +30 -0
  117. data/spec/contrib/rest.rb +2 -2
  118. data/spec/examples/caching.rb +5 -7
  119. data/spec/examples/css.rb +3 -3
  120. data/spec/examples/element.rb +4 -3
  121. data/spec/examples/hello.rb +3 -3
  122. data/spec/examples/helpers/httpdigest.rb +44 -69
  123. data/spec/examples/linking.rb +3 -3
  124. data/spec/examples/simple.rb +3 -3
  125. data/spec/examples/templates/template_erubis.rb +8 -4
  126. data/spec/examples/templates/template_ezamar.rb +9 -4
  127. data/spec/examples/templates/template_haml.rb +8 -4
  128. data/spec/examples/templates/template_liquid.rb +8 -4
  129. data/spec/examples/templates/template_markaby.rb +9 -5
  130. data/spec/examples/templates/template_nagoro.rb +9 -5
  131. data/spec/examples/templates/template_redcloth.rb +8 -4
  132. data/spec/examples/templates/template_remarkably.rb +8 -4
  133. data/spec/examples/templates/template_tenjin.rb +8 -4
  134. data/spec/helper.rb +1 -2
  135. data/spec/ramaze/action/render.rb +4 -1
  136. data/spec/ramaze/app.rb +5 -2
  137. data/spec/ramaze/bin/ramaze.rb +96 -0
  138. data/spec/ramaze/cache/localmemcache.rb +1 -1
  139. data/spec/ramaze/cache/memcache.rb +7 -1
  140. data/spec/ramaze/cache/sequel.rb +1 -1
  141. data/spec/ramaze/controller/actionless_templates.rb +2 -2
  142. data/spec/ramaze/controller/lonely_mapping.rb +18 -0
  143. data/spec/ramaze/controller/mapping.rb +4 -15
  144. data/spec/ramaze/controller/provide_inheritance.rb +5 -2
  145. data/spec/ramaze/controller/resolve.rb +2 -2
  146. data/spec/ramaze/controller/subclass.rb +2 -2
  147. data/spec/ramaze/controller/template_resolving.rb +2 -2
  148. data/spec/ramaze/dispatcher/directory.rb +5 -2
  149. data/spec/ramaze/dispatcher/file.rb +28 -26
  150. data/spec/ramaze/error.rb +3 -3
  151. data/spec/ramaze/files.rb +5 -2
  152. data/spec/ramaze/gestalt.rb +26 -17
  153. data/spec/ramaze/helper/auth.rb +30 -41
  154. data/spec/ramaze/helper/bench.rb +6 -2
  155. data/spec/ramaze/helper/cache.rb +45 -5
  156. data/spec/ramaze/helper/flash.rb +11 -15
  157. data/spec/ramaze/helper/form.rb +6 -3
  158. data/spec/ramaze/helper/formatting.rb +4 -1
  159. data/spec/ramaze/helper/gestalt.rb +4 -1
  160. data/spec/ramaze/helper/gravatar.rb +4 -1
  161. data/spec/ramaze/helper/httpdigest.rb +51 -66
  162. data/spec/ramaze/helper/layout.rb +79 -0
  163. data/spec/ramaze/helper/layout/default.xhtml +5 -0
  164. data/spec/ramaze/helper/link.rb +33 -12
  165. data/spec/ramaze/helper/localize.rb +9 -4
  166. data/spec/ramaze/helper/maruku.rb +5 -2
  167. data/spec/ramaze/helper/pager.rb +2 -2
  168. data/spec/ramaze/helper/paginate.rb +5 -2
  169. data/spec/ramaze/helper/request_accessor.rb +5 -2
  170. data/spec/ramaze/helper/sequel_form.rb +7 -2
  171. data/spec/ramaze/helper/simple_captcha.rb +10 -14
  172. data/spec/ramaze/helper/stack.rb +32 -40
  173. data/spec/ramaze/helper/user.rb +19 -14
  174. data/spec/ramaze/helper/xhtml.rb +4 -1
  175. data/spec/ramaze/log/informer.rb +1 -1
  176. data/spec/ramaze/log/logging.rb +4 -1
  177. data/spec/ramaze/log/syslog.rb +6 -6
  178. data/spec/ramaze/params.rb +5 -6
  179. data/spec/ramaze/request.rb +16 -1
  180. data/spec/ramaze/session/memcache.rb +66 -0
  181. data/spec/ramaze/struct.rb +4 -1
  182. data/spec/ramaze/view.rb +2 -2
  183. data/spec/ramaze/view/erubis.rb +2 -2
  184. data/spec/ramaze/view/ezamar.rb +2 -2
  185. data/spec/ramaze/view/gestalt.rb +94 -0
  186. data/spec/ramaze/view/gestalt/external.ges +8 -0
  187. data/spec/ramaze/view/haml.rb +2 -2
  188. data/spec/ramaze/view/liquid.rb +2 -2
  189. data/spec/ramaze/view/nagoro.rb +2 -2
  190. data/spec/ramaze/view/redcloth.rb +2 -2
  191. data/spec/ramaze/view/remarkably.rb +2 -2
  192. data/spec/ramaze/view/sass.rb +2 -2
  193. data/spec/ramaze/view/tagz.rb +2 -2
  194. data/spec/ramaze/view/tenjin.rb +2 -2
  195. data/spec/snippets/array/put_within.rb +30 -25
  196. data/spec/snippets/binding/locals.rb +4 -1
  197. data/spec/snippets/numeric/filesize_format.rb +4 -1
  198. data/spec/snippets/numeric/time.rb +5 -2
  199. data/spec/snippets/object/__dir__.rb +4 -1
  200. data/spec/snippets/ordered_set.rb +4 -1
  201. data/spec/snippets/ramaze/acquire.rb +4 -1
  202. data/spec/snippets/ramaze/dictionary.rb +4 -1
  203. data/spec/snippets/ramaze/struct.rb +4 -1
  204. data/spec/snippets/string/camel_case.rb +4 -1
  205. data/spec/snippets/string/color.rb +4 -1
  206. data/spec/snippets/string/snake_case.rb +4 -1
  207. data/spec/snippets/string/unindent.rb +4 -1
  208. data/spec/snippets/thread/into.rb +4 -1
  209. data/tasks/bacon.rake +5 -3
  210. data/tasks/changelog.rake +3 -1
  211. data/tasks/{gem_installer.rake → gem_setup.rake} +45 -22
  212. data/tasks/release.rake +12 -27
  213. data/tasks/setup.rake +6 -0
  214. data/tasks/todo.rake +2 -4
  215. metadata +205 -31
  216. data/CHANGELOG +0 -16546
  217. data/benchmark/suite/template_builder.rb +0 -12
  218. data/doc/tutorial/todolist.mkd +0 -787
  219. data/examples/helpers/provide.rb +0 -23
  220. data/lib/proto/view/page.xhtml +0 -27
  221. data/lib/ramaze/snippets/divide.rb +0 -22
  222. data/lib/ramaze/snippets/kernel/constant.rb +0 -41
  223. data/lib/ramaze/snippets/object/acquire.rb +0 -37
  224. data/lib/ramaze/snippets/string/each.rb +0 -19
  225. data/spec/ramaze/helper/partial.rb +0 -40
  226. data/spec/snippets/kernel/constant.rb +0 -23
  227. data/tasks/install_dependencies.rake +0 -6
@@ -7,39 +7,20 @@ module Ramaze
7
7
  module Helper
8
8
  # This is a modification of Innate::Helper::Link to respect the routing of
9
9
  # Ramaze
10
+ #
10
11
  # NOTE: The A/R/Rs methods have been deprecated.
11
12
  module Link
12
-
13
- # @return [String]
14
- # @see Innate::Helper#anchor
15
- def A(*args)
16
- Ramaze.deprecated('Ramaze::Helper::Link#A', 'Ramaze::Helper::Link#a')
17
- a(*args)
18
- end
19
-
20
- # @return [String]
21
- # @see Innate::Helper#route
22
- def R(arg, *args)
23
- Ramaze.deprecated('Ramaze::Helper::Link#R', 'Ramaze::Helper::Link#r')
24
- (arg < Controller ? arg.r(*args) : r(arg, *args)).to_s
25
- end
26
-
27
- # @return [String]
28
- # @see Innate::Helper#route
29
- def Rs(*args)
30
- Ramaze.deprecated('Ramaze::Helper::Link#Rs', 'Ramaze::Helper::Link#r')
31
- r(*args).to_s
32
- end
33
-
34
13
  def route_location(klass)
35
- Ramaze.to(klass) || Ramaze.to(klass.class)
14
+ prefix = Ramaze.options.prefix
15
+ location = Ramaze.to(klass) || Ramaze.to(klass.class)
16
+ [prefix, location].join('/')
36
17
  end
37
18
 
38
19
  # Give it a path with character to split at and one to join the crumbs with.
39
20
  # It will generate a list of links that act as pointers to previous pages on
40
21
  # this path.
41
22
  #
42
- # Example:
23
+ # @example usage
43
24
  # breadcrumbs('/path/to/somewhere')
44
25
  #
45
26
  # # results in this, newlines added for readability:
@@ -51,7 +32,7 @@ module Ramaze
51
32
  # Optionally a href prefix can be specified which generate link
52
33
  # names a above, but with the prefix prepended to the href path.
53
34
  #
54
- # Example:
35
+ # @example usage
55
36
  # breadcrumbs('/path/to/somewhere', '/', '/', '/mycontroller/action')
56
37
  #
57
38
  # # results in this, newlines added for readability:
@@ -19,7 +19,12 @@ module Ramaze
19
19
  end
20
20
 
21
21
  def locales
22
- Parser.new(request).locales(ancestral_trait[:localize_locale])
22
+ locales = request.env['localize.locales']
23
+ return locales if locales
24
+
25
+ fallback = ancestral_trait[:localize_locale]
26
+ locales = Parser.new(request).locales(fallback)
27
+ request.env['localize.locales'] = locales
23
28
  end
24
29
 
25
30
  class Dictionary
@@ -105,7 +110,7 @@ module Ramaze
105
110
  end
106
111
 
107
112
  def parse
108
- parse_params || parse_cookie || parse_header
113
+ parse_params || parse_session || parse_cookie || parse_header
109
114
  end
110
115
 
111
116
  def parse_params(key = 'lang')
@@ -113,13 +118,18 @@ module Ramaze
113
118
  ::Locale::Tag.parse(lang)
114
119
  end
115
120
 
121
+ def parse_session(key = :lang)
122
+ return unless lang = Current.session[key]
123
+ ::Locale::Tag.parse(lang)
124
+ end
125
+
116
126
  def parse_cookie(key = 'lang')
117
127
  return unless lang = request.cookies[key]
118
128
  ::Locale::Tag.parse(lang)
119
129
  end
120
130
 
121
131
  def parse_header
122
- request.accept_language_with_weight.map{|lang|
132
+ request.accept_language.map{|lang|
123
133
  ::Locale::Tag.parse(lang) }
124
134
  end
125
135
  end
@@ -134,7 +134,7 @@ module Ramaze
134
134
  end
135
135
 
136
136
  out << '</div>'
137
- out.map{|e| e.to_s}.join("\n")
137
+ out.join
138
138
  end
139
139
 
140
140
  # Useful to omit pager if it's of no use.
@@ -154,6 +154,8 @@ module Ramaze
154
154
  def last_page; @pager.last_page; end
155
155
  def last_page?; @pager.last_page?; end
156
156
  def next_page; @pager.next_page; end
157
+ def empty?; @pager.empty?; end
158
+ def count; @pager.count; end
157
159
 
158
160
  private
159
161
 
@@ -173,7 +175,7 @@ module Ramaze
173
175
 
174
176
  action = Current.action
175
177
  params = request.params.merge(@var.to_s => n)
176
- hash[:href] = action.node.r(action.name, params)
178
+ hash[:href] = action.node.r(action.path, params)
177
179
 
178
180
  g.a(hash){ text }
179
181
  end
@@ -1,6 +1,8 @@
1
1
  module Ramaze
2
2
  module Helper
3
3
  module Ultraviolet
4
+ include Innate::Traited
5
+
4
6
  trait :ultraviolet => {
5
7
  :output => 'xhtml',
6
8
  :syntax => nil, # syntax_name, nil|false indicates automatic detection
@@ -170,7 +170,7 @@ module Ramaze
170
170
  # @return [Ramaze::Helper::User::Wrapper] wrapped return value from
171
171
  # model or callback
172
172
  # @see Ramaze::Helper::User#user_login
173
- # @autor manveru
173
+ # @author manveru
174
174
  def _login(creds = _persistence)
175
175
  if @_user = _would_login?(creds)
176
176
  self._persistence = creds
@@ -195,7 +195,7 @@ module Ramaze
195
195
 
196
196
  # @api internal
197
197
  # @see Ramaze::Helper::User#user_logout
198
- # @autor manveru
198
+ # @author manveru
199
199
  def _logout
200
200
  _persistence.clear
201
201
  Current.request.env['ramaze.helper.user'] = nil
@@ -204,7 +204,7 @@ module Ramaze
204
204
  # @return [true false] whether the current user is logged in.
205
205
  # @api internal
206
206
  # @see Ramaze::Helper::User#logged_in?
207
- # @autor manveru
207
+ # @author manveru
208
208
  def _logged_in?
209
209
  !!_user
210
210
  end
@@ -1,16 +1,16 @@
1
1
  module Ramaze
2
-
2
+
3
3
  module Logger
4
4
 
5
5
  # A customized logger (based on Informer) that creates multiple log files based on time
6
6
 
7
7
  class RotatingInformer
8
-
8
+ include Innate::Traited
9
9
  include Logging
10
10
 
11
11
  attr_accessor :time_format, :log_levels
12
12
  attr_reader :base_dir
13
-
13
+
14
14
  # parameter for Time.now.strftime
15
15
  trait :timestamp => "%Y-%m-%d %H:%M:%S"
16
16
 
@@ -47,24 +47,24 @@ module Ramaze
47
47
  def initialize(base_dir, time_format = '%Y-%m-%d.log', log_levels = [:debug, :error, :info, :warn])
48
48
  # Verify and set base directory
49
49
  send :base_dir=, base_dir, true
50
-
50
+
51
51
  @time_format = time_format
52
52
  @log_levels = log_levels
53
-
53
+
54
54
  # Keep track of log shutdown (to prevent StackErrors due to recursion)
55
55
  @in_shutdown = false
56
56
  end
57
57
 
58
58
  # Set the base directory for log files
59
- #
59
+ #
60
60
  # If this method is called with the raise_exception
61
61
  # parameter set to true the method will raise an exception
62
62
  # if the specified directory does not exist or is unwritable.
63
- #
63
+ #
64
64
  # If raise_exception is set to false, the method will just
65
65
  # silently fail if the specified directory does not exist
66
66
  # or is unwritable
67
-
67
+
68
68
  def base_dir=(directory, raise_exception = false)
69
69
  # Expand directory path
70
70
  base_dir = File.expand_path(directory)
@@ -85,7 +85,7 @@ module Ramaze
85
85
  raise Exception.new("#{base_dir} does not exist.") if raise_exception
86
86
  end
87
87
  end
88
-
88
+
89
89
  # Close the file we log to if it isn't closed already.
90
90
 
91
91
  def shutdown
@@ -106,7 +106,7 @@ module Ramaze
106
106
  return unless @log_levels.include?(tag)
107
107
 
108
108
  # Update current log
109
- update_current_log
109
+ update_current_log
110
110
 
111
111
  messages.flatten!
112
112
 
@@ -1,17 +1,14 @@
1
- # Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
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
3
 
4
4
  module Ramaze
5
5
  # The purpose of this class is to act as a simple wrapper for Rack::Request
6
6
  # and provide some convinient methods for our own use.
7
7
  class Request < Innate::Request
8
- # Currently active request out of STATE[:request]
9
- def self.current; Current.request; end
10
8
 
11
9
  # you can access the original @request via this method_missing,
12
10
  # first it tries to match your method with any of the HTTP parameters
13
11
  # then, in case that fails, it will relay to @request
14
-
15
12
  def method_missing meth, *args
16
13
  key = meth.to_s.upcase
17
14
  return env[key] if env.has_key?(key)
@@ -27,13 +24,14 @@ module Ramaze
27
24
  # @name # => 'manveru'
28
25
  # @lang # => nil
29
26
 
30
- def to_ivs(*args)
27
+ def to_instance_variables(*args)
31
28
  instance = Action.current.instance
32
29
  args.each do |arg|
33
30
  next unless value = self[arg]
34
31
  instance.instance_variable_set("@#{arg}", value)
35
32
  end
36
33
  end
34
+ alias to_ivs to_instance_variables
37
35
 
38
36
  def accept_charset(default = 'UTF-8')
39
37
  return default unless charsets = env['HTTP_ACCEPT_CHARSET']
@@ -4,7 +4,8 @@ module Ramaze
4
4
  # It's almost like Kernel#gem but also installs automatically if a gem is
5
5
  # missing.
6
6
  #
7
- # @usage
7
+ # @example
8
+ #
8
9
  # Ramaze.setup :verbose => true do
9
10
  # # gem and specific version
10
11
  # gem 'makura', '>=2009.01'
@@ -65,14 +66,20 @@ module Ramaze
65
66
 
66
67
  # first try to activate, install and try to activate again if activation
67
68
  # fails the first time
68
- def setup_gem(name, options, try_install = true)
69
+ def setup_gem(name, options)
70
+ version = [options[:version]].compact
71
+ lib_name = options[:lib] || name
72
+
69
73
  log "activating #{name}"
70
- Gem.activate(name, *[options[:version]].compact)
71
- require(options[:lib] || name)
72
- rescue LoadError => exception
73
- puts exception
74
- install_gem(name, options) if try_install
75
- setup_gem(name, options, try_install = false)
74
+
75
+ Gem.activate(name, *version)
76
+ require(lib_name)
77
+
78
+ rescue LoadError
79
+
80
+ install_gem(name, options)
81
+ Gem.activate(name, *version)
82
+ require(lib_name)
76
83
  end
77
84
 
78
85
  # tell rubygems to install a gem
@@ -101,7 +108,13 @@ module Ramaze
101
108
  private
102
109
 
103
110
  def log(msg)
104
- puts(msg) if @verbose
111
+ return unless @verbose
112
+
113
+ if defined?(Log)
114
+ Log.info(msg)
115
+ else
116
+ puts(msg)
117
+ end
105
118
  end
106
119
 
107
120
  def rubyforge; 'http://gems.rubyforge.org/' end
@@ -1,7 +1,4 @@
1
- require 'ramaze'
2
- require 'bacon'
3
-
4
- require 'innate/spec'
1
+ require File.expand_path('../', __FILE__) unless defined?(Ramaze)
5
2
 
6
3
  def spec_requires(*libs)
7
4
  spec_precondition 'require' do
@@ -26,12 +23,11 @@ module Ramaze
26
23
  middleware!(:spec){|m| m.run(AppMap) }
27
24
  end
28
25
 
29
- shared :rack_test do
30
- require 'rack/test'
31
-
32
- extend Rack::Test::Methods
33
-
34
- def app
35
- Ramaze.middleware(:spec)
36
- end
26
+ # FIXME: will remove that in 2009.07, and then we can offer integration with
27
+ # any other test-framework we like and they can share this code.
28
+ # Then Ramaze can be:
29
+ # Any ruby, any ORM, any templating-engine, any test-framework
30
+ unless defined?(Bacon)
31
+ Ramaze.deprecated "require('ramaze/spec')", "require('ramaze/spec/bacon')"
32
+ require 'ramaze/spec/bacon'
37
33
  end
@@ -0,0 +1,34 @@
1
+ begin
2
+ require 'bacon'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ require 'bacon'
6
+ end
7
+
8
+ require File.expand_path('../', __FILE__) unless defined?(Ramaze)
9
+
10
+ require 'innate/spec/bacon'
11
+
12
+ shared :rack_test do
13
+ Ramaze.setup_dependencies
14
+ extend Rack::Test::Methods
15
+
16
+ def app; Ramaze; end
17
+ end
18
+
19
+ shared :webrat do
20
+ behaves_like :rack_test
21
+
22
+ require 'webrat'
23
+
24
+ Webrat.configure{|config| config.mode = :rack_test }
25
+
26
+ extend Webrat::Methods
27
+ extend Webrat::Matchers
28
+ end
29
+
30
+ # Backwards compatibility
31
+ shared(:mock){
32
+ Ramaze.deprecated('behaves_like(:mock)', 'behaves_like(:rack_test)')
33
+ behaves_like :rack_test
34
+ }
@@ -1,28 +1,21 @@
1
- module Ramaze
2
- module Spec
3
- module Examples
4
- module Templates
5
- def self.tests( describe, spec_engine )
1
+ # Copyright (c) 2009 Michael Fellinger m.fellinger@gmail.com
2
+ # All files in this distribution are subject to the terms of the Ruby license.
6
3
 
7
- describe.behaves_like :mock
4
+ shared :template_spec do
5
+ behaves_like :rack_test
8
6
 
9
- describe.it '/' do
10
- get('/').body.strip.should =~
11
- %r{<a href\s*=\s*"/">Home</a>\s+\|\s+<a href\s*=\s*"/internal">internal</a>\s+\|\s+<a href\s*=\s*"/external">external</a>}
12
- end
13
-
14
- %w[/internal /external].each do |url|
15
- describe.it url do
16
- html = get(url).body
17
- html.should.not == nil
18
- html.should =~ %r{<title>Template::#{spec_engine} (internal|external)</title>}
19
- html.should =~ %r{<h1>The (internal|external) Template for #{spec_engine}</h1>}
20
- end
21
-
22
- end
23
-
24
- end
7
+ def spec_template(spec_engine)
8
+ it 'works on /' do
9
+ get('/').body.strip.
10
+ should =~ %r{<a href\s*=\s*"/">Home</a>\s+\|\s+<a href\s*=\s*"/internal">internal</a>\s+\|\s+<a href\s*=\s*"/external">external</a>}
11
+ end
25
12
 
13
+ %w[/internal /external].each do |url|
14
+ it "works on #{url}" do
15
+ html = get(url).body
16
+ html.should.not == nil
17
+ html.should =~ %r{<title>Template::#{spec_engine} (internal|external)</title>}
18
+ html.should =~ %r{<h1>The (internal|external) Template for #{spec_engine}</h1>}
26
19
  end
27
20
  end
28
21
  end
@@ -0,0 +1,340 @@
1
+ #!/usr/bin/env ruby
2
+ ### This module offers the functionality to start, stop, restart, create,
3
+ ### Check status, or run a console of a ramaze application
4
+ ### see ramaze -h for usage
5
+ module Ramaze
6
+ module Tool
7
+ module Bin
8
+ module Helpers # Helper methods {{{
9
+
10
+ def default_pidfile # {{{
11
+ return @default_pidfile if @default_pidfile
12
+ require "pathname"
13
+ @default_pidfile = (Pathname.new(".").expand_path.basename.to_s + ".pid").strip
14
+ end # }}}
15
+
16
+ # We're really only concerned about win32ole, so we focus our check on its
17
+ # ability to load that
18
+ def is_windows? # {{{
19
+ return @is_win if @is_win
20
+ begin
21
+ require "win32ole"
22
+ rescue LoadError
23
+ end
24
+ @is_win ||= Object.const_defined?("WIN32OLE")
25
+ end # }}}
26
+
27
+ # Find the path to rackup, by searching for -R (undocumented cli argument),
28
+ # then checking RUBYLIB for the _first_ rack it can find there, finally
29
+ # falling back to gems and looking for rackup in the gem bindir.
30
+ # If we can't find rackup we're raising; not even #usage is sane without
31
+ # rackup.
32
+ def rackup_path # {{{
33
+ return @rackup_path if @rackup_path
34
+ # Use the supplied path if the user supplied -R
35
+ if path_supplied = ARGV.delete("-R")
36
+ @rackup_path = ARGV.delete(@ourargs[@ourargs.index("-R") + 1])
37
+ if @rackup_path and File.file?(@rackup_path)
38
+ return @rackup_path
39
+ else
40
+ $stderr.puts "rackup does not exist at #{@rackup_path} (given with -R)"
41
+ end
42
+ end
43
+ # Check with 'which' on platforms which support it
44
+ unless is_windows?
45
+ @rackup_path = %x{which rackup}.to_s.chomp
46
+ if @rackup_path.size > 0 and File.file?(@rackup_path)
47
+ return @rackup_path
48
+ end
49
+ end
50
+ # check for rackup in RUBYLIB
51
+ libs = ENV["RUBYLIB"].to_s.split(is_windows? ? ";" : ":")
52
+ if rack_lib = libs.detect { |r| r.match %r<(\\|/)rack\1> }
53
+ require "pathname"
54
+ @rackup_path = Pathname.new(rack_lib).parent.join("bin").join("rackup").expand_path
55
+ return @rackup_path if File.file?(@rackup_path)
56
+ end
57
+ begin
58
+ require "rubygems"
59
+ require "rack"
60
+ require "pathname"
61
+ @rackup_path = Pathname.new(Gem.bindir).join("rackup").to_s
62
+ return @rackup_path if File.file?(@rackup_path)
63
+ rescue LoadError
64
+ nil
65
+ end
66
+ @rackup_path = nil
67
+ raise "Cannot find path to rackup, please supply full path to rackup with -R"
68
+ end # }}}
69
+
70
+ def is_running?(pid) # {{{
71
+ if is_windows?
72
+ wmi = WIN32OLE.connect("winmgmts://")
73
+ processes, ours = wmi.ExecQuery("select * from win32_process where ProcessId = #{pid}"), []
74
+ processes.each { |process| ours << process.Name }
75
+ ours.first.nil?
76
+ else
77
+ begin
78
+ prio = Process.getpriority(Process::PRIO_PROCESS, pid)
79
+ true
80
+ rescue Errno::ESRCH
81
+ false
82
+ end
83
+ end
84
+ end # }}}
85
+
86
+ def check_running?(pid_file) # {{{
87
+ return false unless File.file?(pid_file)
88
+ is_running?(File.read(pid_file).to_i)
89
+ end # }}}
90
+
91
+ def find_pid(pid_file) # {{{
92
+ if pid_file.nil? or not File.file?(pid_file)
93
+ pid_file = default_pidfile
94
+ end
95
+ unless File.file?(pid_file)
96
+ $stderr.puts "Could not find running process id."
97
+ return false
98
+ end
99
+ pid_file
100
+ end # }}}
101
+ end # End helper methods }}}
102
+
103
+ class Cmd # This class contains the command methods {{{
104
+ include Helpers
105
+ attr_accessor :command
106
+
107
+ def initialize(args = nil)
108
+ args ||= ARGV
109
+ raise "arguments must be an array!" unless args.respond_to?(:detect)
110
+ @ourargs = args.dup
111
+ @command = args.detect { |arg| arg.match(/^(?:--?)?(?:start|stop|restart|create|h(?:elp)?|v(?:ersion)?|console|status)/) }
112
+ if command.nil?
113
+ @command = ""
114
+ else
115
+ args.delete(@command)
116
+ end
117
+ ARGV.replace(args)
118
+ end
119
+
120
+ # {{{ #run is called when we're interactive ($0 == __FILE__)
121
+ def self.run(args = nil)
122
+ cmd = new(args)
123
+ case cmd.command
124
+ when /^(?:--?)?status$/
125
+ cmd.status(cmd.command)
126
+ when /^(?:--?)?restart$/
127
+ cmd.stop(cmd.command)
128
+ cmd.start
129
+ when /^(?:--?)?start$/
130
+ cmd.start
131
+ when /^(?:--?)?create$/
132
+ cmd.create(cmd.command)
133
+ when /^(?:--?)?stop$/
134
+ if cmd.stop(cmd.command)
135
+ puts "Ramazement has ended, go in peace."
136
+ $stdout.flush
137
+ else
138
+ puts "Ramaze failed to stop (or was not running)"
139
+ end
140
+ when /^(?:--?)?console$/
141
+ require "ramaze"
142
+ require "irb"
143
+ require "irb/completion"
144
+ Ramaze.options.started = true
145
+ require "start"
146
+ IRB.start
147
+ puts "Ramazement has ended, go in peace."
148
+ when /^(?:--?)?h(elp)?$/
149
+ puts cmd.usage
150
+ when /^(?:--?)?v(ersion)?$/
151
+ cmd.include_ramaze
152
+ puts Ramaze::VERSION
153
+ exit
154
+ when /^$/
155
+ puts "Must supply a valid command"
156
+ puts cmd.usage
157
+ exit 1
158
+ else
159
+ puts "#{command} not implemented"
160
+ puts cmd.usage
161
+ exit 1
162
+ end
163
+ end # }}}
164
+
165
+ def include_ramaze # {{{
166
+ begin
167
+ $:.unshift File.join(File.dirname(__FILE__), '/../lib')
168
+ require 'ramaze'
169
+ rescue LoadError
170
+ $:.shift
171
+
172
+ begin
173
+ require 'rubygems'
174
+ rescue LoadError
175
+ end
176
+ require 'ramaze'
177
+ end
178
+ end # }}}
179
+
180
+ def usage # {{{
181
+ txt = [
182
+ "\n Usage:",
183
+ "ramaze <start [PIDFILE]|stop [PIDFILE]|restart [PIDFILE]|status [PIDFILE]|create PROJECT|console> [ruby/rack options]\n",
184
+ "Commands:\n",
185
+ " * All commands which take an optional PIDFILE (defaults to PROJECT.pid otherwise).",
186
+ " * All commands which start a ramaze instance will default to webrick on port 7000",
187
+ " unless you supply the rack options -p/--port PORT and/or * -s/--server SERVER.\n",
188
+ " start - Starts an instance of this application.\n",
189
+ " stop - Stops a running instance of this application.\n",
190
+ " restart - Stops running instance of this application, then starts it back up. Pidfile",
191
+ " (if supplied) is used for both stop and start.\n",
192
+ " status - Gives status of a running ramaze instance\n",
193
+ " create - Creates a new prototype Ramaze application in a directory named PROJECT in",
194
+ " the current directory. ramaze create foo would make ./foo containing an",
195
+ " application prototype. Rack options are ignored here.\n",
196
+ " console - Starts an irb console with app.rb (and irb completion) loaded. This command",
197
+ " ignores rack options, ARGV is passed on to IRB.\n\n\t"
198
+ ].join("\n\t")
199
+
200
+ if is_windows?
201
+ txt << %x{ruby #{rackup_path} --help}.split("\n").reject { |line| line.match(/^Usage:/) }.join("\n\t")
202
+ else
203
+ txt << %x{#{rackup_path} --help}.split("\n").reject { |line| line.match(/^Usage:/) }.join("\n\t")
204
+ end
205
+
206
+ txt.gsub(/^\t$/, '')
207
+ end # }}}
208
+
209
+ ### Methods for commands {{{
210
+ def start # {{{
211
+ include_ramaze
212
+
213
+ # Find the name of this app
214
+ app_name = default_pidfile.sub(/\.pid$/,'')
215
+ rack_args = []
216
+
217
+ if daemonize = @ourargs.detect { |arg| arg.match(/^(-[dD]|--daemonize)$/) }
218
+ if pid_arg = @ourargs.detect { |arg| arg.match(/^(-P|--pid)/) }
219
+ puts "User supplied pid: #{pid_arg}"
220
+ pid_file = @ourargs[@ourargs.index(pid_arg) + 1]
221
+ puts "Starting daemon with user defined pidfile: #{pid_file}"
222
+ else
223
+ puts "Starting daemon with default pidfile: #{pid_file = default_pidfile}"
224
+ rack_args += ["-P", pid_file]
225
+ end
226
+ if check_running?(pid_file)
227
+ $stderr.puts "Ramaze is already running with pidfile: #{pid_file}"
228
+ exit 127
229
+ end
230
+ end
231
+
232
+ port = Ramaze.options.adapter.port.to_s
233
+ rack_args += ["-p", port ] if @ourargs.grep(/^(-p|--port)/).empty?
234
+
235
+ handler = Ramaze.options.adapter.handler.to_s
236
+ rack_args += ["-s", handler] if @ourargs.grep(/^(-s|--server)/).empty?
237
+
238
+ if is_windows?
239
+ exec("ruby", rackup_path.to_s, "config.ru", *(ARGV + rack_args))
240
+ else
241
+ exec(rackup_path.to_s, "config.ru", *(ARGV + rack_args))
242
+ end
243
+ end # }}}
244
+
245
+ def create(command) # {{{
246
+ opts = {}
247
+ if forced = @ourargs.detect { |arg| arg.match(/^(--force)/) }
248
+ puts "Overwriting any existing files as requested."
249
+ opts[:force] = true
250
+ @ourargs.delete(forced)
251
+ end
252
+ if amended = @ourargs.detect { |arg| arg.match(/^(--amend)/) }
253
+ puts "Only amending missing files as requested."
254
+ opts[:amend] = true
255
+ @ourargs.delete(amended)
256
+ end
257
+ project_name = @ourargs[@ourargs.index(command) + 1]
258
+ if project_name.nil?
259
+ $stderr.puts "Must supply a project name" if project_name.nil?
260
+ puts usage
261
+ exit 1
262
+ end
263
+ include_ramaze
264
+ require 'ramaze/tool/create'
265
+ Ramaze::Tool::Create.create(project_name, opts)
266
+ end # }}}
267
+
268
+ def stop(command) # {{{
269
+ unless pid_file = find_pid(@ourargs[@ourargs.index(command) + 1])
270
+ $stderr.puts "No pid_file found! Cannot stop ramaze (may not be started)."
271
+ return false
272
+ end
273
+ pid = File.read(pid_file).to_i
274
+ puts "Stopping pid #{pid}"
275
+ Process.kill("INT", pid)
276
+ sleep 2
277
+ if is_running?(pid)
278
+ $stderr.puts "Process #{pid} did not die, forcing it with -9"
279
+ Process.kill(9, pid)
280
+ File.unlink(pid_file) if File.file?(pid_file)
281
+ true
282
+ else
283
+ File.unlink(pid_file) if File.file?(pid_file)
284
+ true
285
+ end
286
+ end # }}}
287
+
288
+ def status(command) # {{{
289
+ unless pid_file = find_pid(@ourargs[@ourargs.index(command) + 1])
290
+ $stderr.puts "No pid_file found! Ramaze may not be started."
291
+ exit 1
292
+ end
293
+ puts "Pid file #{pid_file} found, PID is #{pid = File.read(pid_file)}"
294
+ unless is_running?(pid.to_i)
295
+ $stderr.puts "PID #{pid} is not running"
296
+ exit 1
297
+ end
298
+ if is_windows?
299
+ wmi = WIN32OLE.connect("winmgmts://")
300
+ processes, ours = wmi.ExecQuery("select * from win32_process where ProcessId = #{pid}"), []
301
+ processes.each { |p| ours << [p.Name, p.CommandLine, p.VirtualSize, p.CreationDate, p.ExecutablePath, p.Status ] }
302
+ puts "Ramaze is running!\n\tName: %s\n\tCommand Line: %s\n\tVirtual Size: %s\n\tStarted: %s\n\tExec Path: %s\n\tStatus: %s" % ours.first
303
+ else
304
+ require "pathname"
305
+ # Check for /proc
306
+ if File.directory?(proc_dir = Pathname.new("/proc"))
307
+ proc_dir = proc_dir.join(pid)
308
+ # If we have a "stat" file, we'll assume linux and get as much info
309
+ # as we can
310
+ if File.file?(stat_file = proc_dir.join("stat"))
311
+ stats = File.read(stat_file).split
312
+ puts "Ramaze is running!\n\tCommand Line: %s\n\tVirtual Size: %s\n\tStarted: %s\n\tExec Path: %s\n\tStatus: %s" % [
313
+ File.read(proc_dir.join("cmdline")).split("\000").join(" "),
314
+ "%s k" % (stats[22].to_f / 1024),
315
+ File.mtime(proc_dir),
316
+ File.readlink(proc_dir.join("exe")),
317
+ stats[2]
318
+ ]
319
+ exit
320
+ end
321
+ end
322
+ # Fallthrough status, just print a ps
323
+ puts "Ramaze process #{pid} is running!"
324
+ begin
325
+ puts %x{ps l #{pid}}
326
+ rescue
327
+ puts "No further information available"
328
+ end
329
+ end
330
+ end # }}}
331
+
332
+ ### End of command methods }}}
333
+ end # }}}
334
+ end
335
+ end
336
+ end
337
+
338
+ if $0 == __FILE__
339
+ Ramaze::Tool::Bin::Cmd.run(ARGV)
340
+ end