ramaze 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (192) hide show
  1. data/Rakefile +26 -6
  2. data/bin/ramaze +8 -1
  3. data/doc/AUTHORS +13 -11
  4. data/doc/CHANGELOG +472 -13
  5. data/doc/LEGAL +22 -0
  6. data/doc/README +1 -4
  7. data/doc/TODO +7 -2
  8. data/doc/changes.txt +472 -13
  9. data/doc/changes.xml +472 -13
  10. data/doc/meta/announcement.txt +21 -23
  11. data/doc/readme_chunks/appendix.txt +0 -3
  12. data/doc/readme_chunks/features.txt +1 -1
  13. data/examples/auth/auth.rb +49 -0
  14. data/examples/auth/template/layout.haml +20 -0
  15. data/examples/auth/template/login.haml +16 -0
  16. data/examples/blog/spec/blog.rb +1 -0
  17. data/examples/caching.rb +5 -6
  18. data/examples/css.rb +37 -0
  19. data/examples/layout.rb +3 -17
  20. data/examples/simple_auth.rb +23 -0
  21. data/examples/sourceview/public/images/file.gif +0 -0
  22. data/examples/sourceview/public/images/folder.gif +0 -0
  23. data/examples/sourceview/public/images/tv-collapsable-last.gif +0 -0
  24. data/examples/sourceview/public/images/tv-collapsable.gif +0 -0
  25. data/examples/sourceview/public/images/tv-expandable-last.gif +0 -0
  26. data/examples/sourceview/public/images/tv-expandable.gif +0 -0
  27. data/examples/sourceview/public/images/tv-item-last.gif +0 -0
  28. data/examples/sourceview/public/images/tv-item.gif +0 -0
  29. data/examples/sourceview/public/jquery.js +11 -0
  30. data/examples/sourceview/public/jquery.treeview.css +47 -0
  31. data/examples/sourceview/public/jquery.treeview.js +223 -0
  32. data/examples/sourceview/public/sourceview.js +16 -0
  33. data/examples/sourceview/sourceview.rb +74 -0
  34. data/examples/sourceview/template/index.haml +43 -0
  35. data/examples/templates/template/external.nag +28 -0
  36. data/examples/templates/template/external.xsl +57 -0
  37. data/examples/templates/template_amrita2.rb +2 -4
  38. data/examples/templates/template_erubis.rb +1 -1
  39. data/examples/templates/template_haml.rb +1 -1
  40. data/examples/templates/template_liquid.rb +2 -4
  41. data/examples/templates/template_markaby.rb +2 -4
  42. data/examples/templates/template_nagoro.rb +53 -0
  43. data/examples/templates/template_remarkably.rb +2 -4
  44. data/examples/templates/template_xslt.rb +52 -0
  45. data/examples/whywiki/spec/whywiki.rb +63 -0
  46. data/examples/whywiki/start.rb +11 -13
  47. data/examples/whywiki/template/edit.xhtml +3 -3
  48. data/examples/whywiki/template/show.xhtml +5 -8
  49. data/examples/wikore/spec/wikore.rb +115 -0
  50. data/examples/wikore/src/controller.rb +81 -0
  51. data/examples/wikore/src/model.rb +51 -0
  52. data/examples/wikore/start.rb +6 -0
  53. data/examples/wikore/template/index.xhtml +8 -0
  54. data/examples/wiktacular/spec/wiktacular.rb +1 -0
  55. data/examples/wiktacular/src/controller.rb +1 -1
  56. data/lib/ramaze.rb +6 -3
  57. data/lib/ramaze/action.rb +2 -13
  58. data/lib/ramaze/action/render.rb +36 -18
  59. data/lib/ramaze/adapter.rb +1 -1
  60. data/lib/ramaze/adapter/cgi.rb +0 -3
  61. data/lib/ramaze/adapter/evented_mongrel.rb +7 -0
  62. data/lib/ramaze/adapter/mongrel.rb +4 -13
  63. data/lib/ramaze/adapter/swiftiplied_mongrel.rb +7 -0
  64. data/lib/ramaze/cache.rb +12 -7
  65. data/lib/ramaze/contrib.rb +22 -0
  66. data/lib/ramaze/contrib/auto_params.rb +128 -0
  67. data/lib/ramaze/contrib/auto_params/get_args.rb +56 -0
  68. data/lib/ramaze/contrib/gzip_filter.rb +57 -0
  69. data/lib/ramaze/contrib/route.rb +40 -0
  70. data/lib/ramaze/contrib/sequel/fill.rb +12 -0
  71. data/lib/ramaze/controller.rb +17 -6
  72. data/lib/ramaze/controller/resolve.rb +51 -14
  73. data/lib/ramaze/dispatcher.rb +15 -13
  74. data/lib/ramaze/dispatcher/action.rb +4 -3
  75. data/lib/ramaze/dispatcher/directory.rb +3 -3
  76. data/lib/ramaze/dispatcher/error.rb +1 -1
  77. data/lib/ramaze/dispatcher/file.rb +17 -6
  78. data/lib/ramaze/error.rb +3 -0
  79. data/lib/ramaze/gestalt.rb +28 -8
  80. data/lib/ramaze/global.rb +26 -6
  81. data/lib/ramaze/global/globalstruct.rb +31 -6
  82. data/lib/ramaze/helper.rb +2 -1
  83. data/lib/ramaze/helper/aspect.rb +2 -2
  84. data/lib/ramaze/helper/auth.rb +6 -9
  85. data/lib/ramaze/helper/cache.rb +89 -9
  86. data/lib/ramaze/helper/cgi.rb +2 -2
  87. data/lib/ramaze/helper/formatting.rb +44 -0
  88. data/lib/ramaze/helper/link.rb +7 -5
  89. data/lib/ramaze/helper/partial.rb +6 -4
  90. data/lib/ramaze/helper/redirect.rb +24 -9
  91. data/lib/ramaze/helper/stack.rb +6 -1
  92. data/lib/ramaze/inform/growl.rb +1 -1
  93. data/lib/ramaze/inform/informer.rb +2 -1
  94. data/lib/ramaze/inform/informing.rb +6 -0
  95. data/lib/ramaze/inform/syslog.rb +1 -0
  96. data/lib/ramaze/snippets/array/put_within.rb +24 -0
  97. data/lib/ramaze/snippets/dictionary.rb +499 -0
  98. data/lib/ramaze/snippets/numeric/filesize_format.rb +19 -0
  99. data/lib/ramaze/snippets/ordered_set.rb +31 -0
  100. data/lib/ramaze/snippets/string/DIVIDE.rb +1 -1
  101. data/lib/ramaze/snippets/string/snake_case.rb +1 -1
  102. data/lib/ramaze/snippets/struct/values_at.rb +5 -1
  103. data/lib/ramaze/snippets/thread/into.rb +25 -0
  104. data/lib/ramaze/sourcereload.rb +39 -19
  105. data/lib/ramaze/spec/helper.rb +4 -1
  106. data/lib/ramaze/spec/helper/{context.rb → browser.rb} +3 -0
  107. data/lib/ramaze/spec/helper/layout.rb +3 -0
  108. data/lib/ramaze/spec/helper/minimal.rb +3 -0
  109. data/lib/ramaze/spec/helper/mock_http.rb +8 -5
  110. data/lib/ramaze/spec/helper/requester.rb +4 -1
  111. data/lib/ramaze/spec/helper/wrap.rb +15 -7
  112. data/lib/ramaze/template.rb +5 -1
  113. data/lib/ramaze/template/ezamar/engine.rb +2 -3
  114. data/lib/ramaze/template/ezamar/morpher.rb +26 -45
  115. data/lib/ramaze/template/nagoro.rb +53 -0
  116. data/lib/ramaze/template/none.rb +14 -0
  117. data/lib/ramaze/template/xslt.rb +96 -0
  118. data/lib/ramaze/tool.rb +0 -1
  119. data/lib/ramaze/tool/localize.rb +7 -2
  120. data/lib/ramaze/trinity/request.rb +1 -0
  121. data/lib/ramaze/trinity/session.rb +3 -3
  122. data/lib/ramaze/version.rb +2 -2
  123. data/rake_tasks/conf.rake +1 -2
  124. data/rake_tasks/{maintaince.rake → maintenance.rake} +25 -17
  125. data/spec/contrib/auto_params.rb +97 -0
  126. data/spec/contrib/route.rb +60 -0
  127. data/spec/contrib/sequel/fill.rb +46 -0
  128. data/spec/examples/caching.rb +1 -2
  129. data/spec/examples/css.rb +12 -0
  130. data/spec/examples/element.rb +0 -1
  131. data/spec/examples/hello.rb +0 -1
  132. data/spec/examples/simple.rb +0 -1
  133. data/spec/helper.rb +3 -2
  134. data/spec/ramaze/action/cache.rb +24 -7
  135. data/spec/ramaze/action/layout.rb +19 -11
  136. data/spec/ramaze/action/template/sub/sub_wrapper.xhtml +1 -0
  137. data/spec/ramaze/controller.rb +11 -0
  138. data/spec/ramaze/controller/template_resolving.rb +28 -27
  139. data/spec/ramaze/dispatcher.rb +32 -0
  140. data/spec/ramaze/dispatcher/directory.rb +2 -1
  141. data/spec/ramaze/element.rb +1 -1
  142. data/spec/ramaze/gestalt.rb +28 -0
  143. data/spec/ramaze/helper/aspect.rb +14 -3
  144. data/spec/ramaze/helper/cache.rb +78 -13
  145. data/spec/ramaze/helper/formatting.rb +20 -0
  146. data/spec/ramaze/helper/link.rb +2 -0
  147. data/spec/ramaze/helper/partial.rb +12 -1
  148. data/spec/ramaze/helper/redirect.rb +44 -8
  149. data/spec/ramaze/helper/stack.rb +3 -3
  150. data/spec/ramaze/helper/template/loop.xhtml +3 -0
  151. data/spec/ramaze/helper/template/num.xhtml +1 -0
  152. data/spec/ramaze/helper/template/recursive.xhtml +8 -0
  153. data/spec/ramaze/morpher.rb +25 -6
  154. data/spec/ramaze/params.rb +6 -2
  155. data/spec/ramaze/request.rb +5 -2
  156. data/spec/ramaze/session.rb +19 -0
  157. data/spec/ramaze/template.rb +2 -2
  158. data/spec/ramaze/template/amrita2.rb +2 -2
  159. data/spec/ramaze/template/erubis.rb +2 -2
  160. data/spec/ramaze/template/ezamar.rb +6 -3
  161. data/spec/ramaze/template/haml.rb +3 -3
  162. data/spec/ramaze/template/liquid.rb +1 -1
  163. data/spec/ramaze/template/markaby.rb +1 -1
  164. data/spec/ramaze/template/nagoro.rb +65 -0
  165. data/spec/ramaze/template/nagoro/another/long/action.nag +1 -0
  166. data/spec/ramaze/template/nagoro/combined.nag +1 -0
  167. data/spec/ramaze/template/nagoro/file_only.nag +1 -0
  168. data/spec/ramaze/template/nagoro/index.nag +1 -0
  169. data/spec/ramaze/template/nagoro/nested.nag +1 -0
  170. data/spec/ramaze/template/nagoro/some__long__action.nag +1 -0
  171. data/spec/ramaze/template/nagoro/sum.nag +1 -0
  172. data/spec/ramaze/template/remarkably.rb +1 -1
  173. data/spec/ramaze/template/sass.rb +1 -1
  174. data/spec/ramaze/template/xslt.rb +93 -0
  175. data/spec/ramaze/template/xslt/concat_words.xsl +16 -0
  176. data/spec/ramaze/template/xslt/index.xsl +14 -0
  177. data/spec/ramaze/template/xslt/products.xsl +32 -0
  178. data/spec/ramaze/template/xslt/ruby_version.xsl +14 -0
  179. data/spec/snippets/array/put_within.rb +32 -0
  180. data/spec/snippets/numeric/filesize_format.rb +12 -0
  181. data/spec/snippets/ordered_set.rb +56 -0
  182. data/spec/snippets/ramaze/caller_lines.rb +6 -3
  183. data/spec/snippets/string/snake_case.rb +3 -0
  184. metadata +118 -22
  185. data/doc/README.html +0 -737
  186. data/examples/fcgi.rb +0 -13
  187. data/lib/ramaze/snippets/numeric/human_readable_filesize_format.rb +0 -33
  188. data/lib/ramaze/tool/tidy.rb +0 -104
  189. data/spec/ramaze/controller/template/edit.xhtml +0 -1
  190. data/spec/ramaze/controller/template/edit/content.xhtml +0 -1
  191. data/spec/ramaze/tidy.rb +0 -12
  192. data/spec/snippets/numeric/human_readable_filesize_format.rb +0 -11
@@ -0,0 +1,53 @@
1
+ # Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
2
+ # All files in this distribution are subject to the terms of the Ruby license.
3
+
4
+ require 'nagoro'
5
+
6
+ module Ramaze
7
+ module Template
8
+
9
+ # Is responsible for compiling a template using the Nagoro templating engine.
10
+
11
+ class Nagoro < Template
12
+
13
+ ENGINES[self] = %w[ xhtml nag ]
14
+
15
+ LISTENERS = [ :Element, :Morpher, :Include, :Instruction ]
16
+
17
+ TEMPLATE = ::Nagoro::Template[LISTENERS]
18
+
19
+ class << self
20
+
21
+ # Transforms an action into the XHTML code for parsing and returns
22
+ # the result
23
+ def transform action
24
+ nagoro = wrap_compile(action)
25
+ file = action.template || action.method
26
+ nagoro.result(action.binding, file.to_s)
27
+ end
28
+
29
+ def wrap_compile(action, template = nil)
30
+ template ||= file_or_result(action)
31
+ caching_compile(action, template)
32
+ end
33
+
34
+ def file_or_result(action)
35
+ result = render_method(action).to_s
36
+
37
+ if file = action.template
38
+ return File.new(file)
39
+ end
40
+
41
+ result
42
+ end
43
+
44
+ # Compile a template, applying all transformations from the pipeline
45
+ # and returning an instance of ::Nagoro::Template
46
+
47
+ def compile(action, template)
48
+ TEMPLATE.render(template)
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,14 @@
1
+ # Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
2
+ # All files in this distribution are subject to the terms of the Ruby license.
3
+
4
+ module Ramaze
5
+ module Template
6
+
7
+ class None < Template
8
+ def self.transform action
9
+ render_method(action)
10
+ end
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,96 @@
1
+ # Copyright (c) 2007 Stephan Maka stephan@spaceboyz.net
2
+ # All files in this distribution are subject to the terms of the Ruby license.
3
+
4
+ require 'xml/libxml'
5
+ require 'xml/xslt'
6
+ require 'thread'
7
+
8
+ module Ramaze
9
+
10
+ # Use the Gestalt helper to put your controller result
11
+ # into proper XML form
12
+ #
13
+ # TODO:
14
+ # * Error handling
15
+ # * Maybe prevent extFunction to be called by HTTP
16
+ module Template
17
+ class XSLT < Template
18
+ ENGINES[self] = %w[ xsl ]
19
+
20
+ XSLT_EXT_FUNCTIONS_LOCK = Mutex.new
21
+
22
+ class << self
23
+
24
+ # Entry point for Action#render
25
+
26
+ def transform action
27
+
28
+ if options = action.instance.ancestral_trait[:xslt_options] and
29
+ fun_xmlns = options[:fun_xmlns]
30
+ # If a controller uses extFunctions, lock the whole
31
+ # transform action with a Mutex to prevent mixing
32
+ # extFunction binding and callback of two controller
33
+ # instances with one fun_xmlns.
34
+ ext_functions_synchronize do
35
+ register_ext_functions action.instance, fun_xmlns
36
+ do_transform action
37
+ end
38
+
39
+ else
40
+ do_transform action
41
+ end
42
+
43
+ end
44
+
45
+ private
46
+
47
+ def do_transform(action)
48
+ result, file = result_and_file(action)
49
+
50
+ xslt = XML::XSLT.new
51
+ xslt.xsl = action.template
52
+ xslt.xml = result
53
+ xslt.serve
54
+ end
55
+
56
+ def ext_functions_synchronize &block
57
+ XSLT_EXT_FUNCTIONS_LOCK.synchronize &block
58
+ end
59
+
60
+ def register_ext_functions instance, fun_xmlns
61
+
62
+ instance.methods.each do |method|
63
+ if method =~ /^xslt_.+/
64
+ method_name = method[5..-1]
65
+
66
+ proxy_instance = make_functor(method_name.intern) { |*a|
67
+ instance.send method.intern, *a
68
+ }
69
+
70
+ XML::XSLT.extFunction method_name.gsub('_', '-'), fun_xmlns, proxy_instance
71
+ end
72
+ end
73
+
74
+ end
75
+
76
+ # Can be replaced by Ruby Facets' Functor pattern
77
+ def make_functor(m, &block)
78
+ # Create anonymous class and instantiate;
79
+ # anonymous because only this one object with this
80
+ # particular custom method should call &block
81
+ o = Class.new.new
82
+
83
+ class << o
84
+ def create_method(name, &block)
85
+ self.class.send(:define_method, name, &block)
86
+ end
87
+ end
88
+
89
+ o.create_method(m, &block)
90
+ o
91
+ end
92
+
93
+ end
94
+ end
95
+ end
96
+ end
@@ -6,5 +6,4 @@ module Ramaze::Tool
6
6
  autoload :Localize, 'ramaze/tool/localize'
7
7
  autoload :Mime, 'ramaze/tool/mime'
8
8
  autoload :Record, 'ramaze/tool/record'
9
- autoload :Tidy, 'ramaze/tool/tidy'
10
9
  end
@@ -7,6 +7,10 @@ require 'ya2yaml'
7
7
  # Localize helps transforming arbitrary text into localized forms using
8
8
  # a simple regular expression and substituting occurences with predefined
9
9
  # snippets stored in YAML files.
10
+ #
11
+ # == Usage:
12
+ #
13
+ # Ramaze::Dispatcher::Action::FILTER << Ramaze::Tool::Localize
10
14
 
11
15
  class Ramaze::Tool::Localize
12
16
 
@@ -55,7 +59,7 @@ class Ramaze::Tool::Localize
55
59
  # `localize` for more information.
56
60
 
57
61
  def localize_body(body, options)
58
- locale = session[:LOCALE] || set_session_locale
62
+ locale = (session[:LOCALE] || set_session_locale).to_s
59
63
 
60
64
  body.gsub!(trait[:regex]) do
61
65
  localize($1, locale) unless $1.to_s.empty?
@@ -118,6 +122,7 @@ class Ramaze::Tool::Localize
118
122
  # Returns the dictionary used for translation.
119
123
 
120
124
  def dictionary
125
+ trait[:languages].map! {|x| x.to_s }.uniq!
121
126
  trait[:dictionary] || load(*trait[:languages])
122
127
  end
123
128
 
@@ -143,7 +148,7 @@ class Ramaze::Tool::Localize
143
148
 
144
149
  def store(*locales)
145
150
  locales.uniq.compact.each do |locale|
146
- Ramaze::Inform.debug "saving localized to: #{trait[:file] % locale}"
151
+ Ramaze::Inform.dev "saving localized to: #{trait[:file] % locale}"
147
152
  data = dictionary[locale].ya2yaml
148
153
  file = trait[:file] % locale
149
154
  File.open(file, File::CREAT|File::TRUNC|File::WRONLY) do |fd|
@@ -69,6 +69,7 @@ module Ramaze
69
69
  # end
70
70
 
71
71
  def params
72
+ return {} if put?
72
73
  return @ramaze_params if @ramaze_params
73
74
  @rack_params ||= rack_params
74
75
  @ramaze_params = {}
@@ -60,15 +60,15 @@ module Ramaze
60
60
 
61
61
  # the key used for the cookie
62
62
 
63
- SESSION_KEY = '_ramaze_session_id'
63
+ SESSION_KEY = '_ramaze_session_id' unless defined?(SESSION_KEY)
64
64
 
65
65
  # Holds counter for IPs
66
66
 
67
- IP_COUNT = Hash.new{|h,k| h[k] = []}
67
+ IP_COUNT = Hash.new{|h,k| h[k] = OrderedSet.new} unless defined?(IP_COUNT)
68
68
 
69
69
  # Limit the number of sessions one IP is allowed to hold.
70
70
 
71
- IP_COUNT_LIMIT = 1000
71
+ IP_COUNT_LIMIT = 1000 unless defined?(IP_COUNT_LIMIT)
72
72
 
73
73
  class << self
74
74
 
@@ -4,8 +4,8 @@
4
4
  module Ramaze #:nodoc:
5
5
  module Version #:nodoc:
6
6
  MAJOR = 0
7
- MINOR = 1
8
- TINY = 4
7
+ MINOR = 2
8
+ TINY = 0
9
9
 
10
10
  STRING = [MAJOR, MINOR, TINY].join('.')
11
11
  end
@@ -7,8 +7,7 @@ BIN_FILES = %w( ramaze )
7
7
  BASEDIR = File.expand_path(File.join(File.dirname(__FILE__), '..'))
8
8
 
9
9
  NAME = "ramaze"
10
- REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
11
- VERS = ENV['VERSION'] || (Ramaze::VERSION + (REV ? ".#{REV}" : ""))
10
+ VERS = Ramaze::VERSION
12
11
  COPYRIGHT = [
13
12
  "# Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com",
14
13
  "# All files in this distribution are subject to the terms of the Ruby license."
@@ -1,10 +1,16 @@
1
1
  desc "add copyright to all .rb files in the distribution"
2
2
  task 'add-copyright' do
3
+ ignore = File.readlines('doc/LEGAL').
4
+ select{|line| line.strip!; File.exist?(line)}.
5
+ map{|file| File.expand_path(file)}
6
+
3
7
  puts "adding copyright to files that don't have it currently"
4
8
  puts COPYRIGHT
5
9
  puts
10
+
6
11
  Dir['{lib,test}/**/*{.rb}'].each do |file|
7
- next if file =~ /_darcs/
12
+ file = File.expand_path(file)
13
+ next if file =~ /_darcs/ or ignore.include? file
8
14
  lines = File.readlines(file).map{|l| l.chomp}
9
15
  unless lines.first(COPYRIGHT.size) == COPYRIGHT
10
16
  puts "#{file} seems to need attention, first 4 lines:"
@@ -197,11 +203,7 @@ task 'tutorial' => ['tutorial2html'] do
197
203
  end
198
204
  end
199
205
 
200
- desc "Update /doc/AUTORS"
201
- task 'authors' do
202
- changes = `darcs changes`
203
- authors = []
204
- mapping = {}
206
+ def authors
205
207
  author_map = {
206
208
  'm.fellinger@gmail.com' => 'Michael Fellinger',
207
209
  'manveru@weez-int.com' => 'Michael Fellinger',
@@ -210,26 +212,32 @@ task 'authors' do
210
212
  'rff.rff@gmail.com' => 'Gabriele Renzi',
211
213
  'comp.lang.zenix+ramaze@gmail.com' => 'zenix',
212
214
  'jesuswasramazing.10.pistos@geoshell.com' => 'Pistos',
215
+ 'stephan@spaceboyz.net' => 'Stephan Maka',
213
216
  }
214
- changes.split("\n").grep(/^\w/).each do |line|
215
- splat = line.split
216
- author = splat[6..-1]
217
- email = author.pop
218
- email.gsub!(/<(.*?)>/, '\1')
217
+
218
+ mapping = {}
219
+ `darcs changes`.split("\n").grep(/^\w/).each do |line|
220
+ author = line.split[6..-1]
221
+ email = author.pop.gsub(/<(.*?)>/, '\1')
219
222
  name = author.join(' ')
220
223
  name = author_map[email] if name.empty?
221
- mapping[name] = email
224
+ mapping[name] ||= { :email => email, :patches => 0 }
225
+ mapping[name][:patches] += 1
222
226
  end
223
- pp mapping
224
227
 
225
- max = mapping.map{|k,v| k.size}.max
228
+ max = mapping.map{|k,v| k.length}.max
229
+ mapping.inject({}) {|h,(k,v)| h[k.ljust(max)] = v; h}
230
+ end
226
231
 
232
+ desc "Update /doc/AUTHORS"
233
+ task 'authors' do
227
234
  File.open('doc/AUTHORS', 'w+') do |fp|
228
- fp.puts("Following persons (in alphabetical order) have contributed to Ramaze:")
235
+ fp.puts "Following persons (in alphabetical order) have contributed to Ramaze:"
229
236
  fp.puts
230
- mapping.sort_by{|k,v| k}.each do |name, email|
231
- fp.puts("#{name.ljust(max)} - #{email}")
237
+ authors.sort_by{|k,v| k}.each do |name, author|
238
+ fp.puts " #{name} - #{author[:email]}"
232
239
  end
240
+ fp.puts
233
241
  end
234
242
  end
235
243
 
@@ -0,0 +1,97 @@
1
+ require 'spec/helper'
2
+ testcase_requires 'ruby2ruby'
3
+
4
+ require 'ramaze/contrib'
5
+ Ramaze.contrib :auto_params
6
+
7
+ module AnotherController
8
+ def another_page
9
+ 'another page'
10
+ end
11
+ end
12
+
13
+ class MainController < Ramaze::Controller
14
+ include AnotherController
15
+ engine :None
16
+
17
+ def search query
18
+ query.inspect
19
+ end
20
+
21
+ def create name, age = '?', occupation = nil
22
+ [name, age, occupation].compact.join(', ')
23
+ end
24
+
25
+ def show *args
26
+ args.join(', ')
27
+ end
28
+
29
+ def add item, price = 1.0, *args
30
+ [item, price, *args].join(', ')
31
+ end
32
+
33
+ def find width, height, depth
34
+ [width, height, depth].join(', ')
35
+ end
36
+
37
+ define_method('page') do
38
+ 'page'
39
+ end
40
+ end
41
+
42
+ describe 'Parameterized actions' do
43
+ before(:all) { ramaze }
44
+
45
+ it 'should pass in values from request.params' do
46
+ get('/create/Aman/20').body.should == 'Aman, 20'
47
+ get('/create', :name => 'Aman', :age => 20).body.should == 'Aman, 20'
48
+
49
+ get('/create/Aman/20/Unemployed').body.should == 'Aman, 20, Unemployed'
50
+ get('/create', :name => 'Aman', :age => 20, :occupation => 'Unemployed').body.should == 'Aman, 20, Unemployed'
51
+
52
+ get('/create/Aman').body.should == 'Aman, ?'
53
+ get('/create', :name => 'Aman').body.should == 'Aman, ?'
54
+ end
55
+
56
+ it 'should insert nil for arguments not found' do
57
+ get('/find', :width => 10, :depth => 20).body.should == '10, , 20'
58
+ end
59
+
60
+ it 'should work with variable arguments' do
61
+ get('/show/1/2/3').body.should == '1, 2, 3'
62
+
63
+ get('/add/Shoe').body.should == 'Shoe, 1.0'
64
+ get('/add', :item => 'Shoe').body.should == 'Shoe, 1.0'
65
+
66
+ get('/add/Shoe/10.50/1/2/3').body.should == 'Shoe, 10.50, 1, 2, 3'
67
+ get('/add/Shoe/11.00').body.should == 'Shoe, 11.00'
68
+ end
69
+
70
+ it 'should not break existing methods' do
71
+ get('/search/Aman').body.should == '"Aman"'
72
+ get('/search', 'query=Aman').body.should == '"Aman"'
73
+ get('/search/tmm1', 'query=Aman').body.should == ['tmm1','Aman'].inspect
74
+ end
75
+
76
+ it 'should consolidate all values for the same key into an array' do
77
+ get('/add', 'item=Shoe&item=Shirt').body.should == 'Shoe, Shirt, 1.0'
78
+ get('/add/Pants', 'item=Shoe&item=Shirt').body.should == 'Pants, Shoe, Shirt, 1.0'
79
+ get('/add/Shoe', :item => 'Shirt').body.should == 'Shoe, Shirt, 1.0'
80
+ end
81
+ end if method(:puts).respond_to? :get_args
82
+
83
+ describe 'Normal behavior' do
84
+ before(:all) { ramaze }
85
+
86
+ it 'should work with no arguments' do
87
+ get('/page').body.should == 'page'
88
+ end
89
+
90
+ it 'should raise no action' do
91
+ get('/none').body.should =~ /^No Action found/
92
+ end
93
+
94
+ it 'should work with included actions' do
95
+ get('/another_page').body.should == 'another page'
96
+ end
97
+ end
@@ -0,0 +1,60 @@
1
+ require 'spec/helper'
2
+
3
+ require 'ramaze/contrib'
4
+
5
+ class MainController < Ramaze::Controller
6
+ def float(flt)
7
+ "Float: #{flt}"
8
+ end
9
+
10
+ def string(str)
11
+ "String: #{str}"
12
+ end
13
+
14
+ def price(p)
15
+ "Price: \$#{p}"
16
+ end
17
+ end
18
+
19
+ describe 'Route' do
20
+ before :all do
21
+ Ramaze.contrib :route
22
+ ramaze
23
+ @route = Ramaze::Contrib::Route
24
+ end
25
+
26
+ it 'should be possible to define routes' do
27
+ @route[%r!^/(\d+\.\d{2})$!] = "/price/%.2f"
28
+ @route[%r!^/(\d+\.\d{2})$!].should == "/price/%.2f"
29
+
30
+ @route[%r!^/(\d+\.\d+)!] = "/float/%.3f"
31
+ @route[%r!^/(\d+\.\d+)!].should == "/float/%.3f"
32
+
33
+ @route[%r!^/(\w+)!] = "/string/%s"
34
+ @route[%r!^/(\w+)!].should == "/string/%s"
35
+ end
36
+
37
+ it 'should be used - /float' do
38
+ r = get('/123.123')
39
+ r.status.should == 200
40
+ r.body.should == 'Float: 123.123'
41
+ end
42
+
43
+ it 'should be used - /string' do
44
+ r = get('/foo')
45
+ r.status.should == 200
46
+ r.body.should == 'String: foo'
47
+ end
48
+
49
+ it 'should use %.3f' do
50
+ r = get('/123.123456')
51
+ r.status.should == 200
52
+ r.body.should == 'Float: 123.123'
53
+ end
54
+
55
+ it 'should resolve in the order added' do
56
+ r = get('/12.84')
57
+ r.status.should == 200
58
+ r.body.should == 'Price: $12.84'
59
+ end
60
+ end