manveru-ramaze 2008.08 → 2008.09

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. data/Rakefile +1 -1
  2. data/bin/ramaze +1 -0
  3. data/doc/CHANGELOG +966 -0
  4. data/doc/tutorial/todolist.html +421 -313
  5. data/doc/tutorial/todolist.mkd +26 -9
  6. data/examples/helpers/paginate.rb +71 -0
  7. data/examples/misc/simple_auth.rb +20 -8
  8. data/lib/proto/controller/init.rb +10 -0
  9. data/lib/proto/controller/main.rb +1 -3
  10. data/lib/proto/model/init.rb +4 -0
  11. data/lib/proto/spec/main.rb +2 -1
  12. data/lib/proto/start.rb +3 -3
  13. data/lib/ramaze.rb +6 -1
  14. data/lib/ramaze/action.rb +2 -2
  15. data/lib/ramaze/adapter.rb +0 -5
  16. data/lib/ramaze/adapter/base.rb +24 -7
  17. data/lib/ramaze/contrib/gzip_filter.rb +22 -9
  18. data/lib/ramaze/contrib/maruku_uv.rb +59 -0
  19. data/lib/ramaze/contrib/profiling.rb +1 -1
  20. data/lib/ramaze/contrib/sequel/create_join.rb +25 -0
  21. data/lib/ramaze/contrib/sequel/form_field.rb +129 -0
  22. data/lib/ramaze/contrib/sequel/image.rb +198 -0
  23. data/lib/ramaze/contrib/sequel/relation.rb +82 -0
  24. data/lib/ramaze/controller/resolve.rb +1 -1
  25. data/lib/ramaze/current.rb +60 -20
  26. data/lib/ramaze/current/response.rb +15 -3
  27. data/lib/ramaze/dispatcher.rb +9 -3
  28. data/lib/ramaze/dispatcher/action.rb +2 -3
  29. data/lib/ramaze/dispatcher/directory.rb +1 -1
  30. data/lib/ramaze/dispatcher/error.rb +1 -1
  31. data/lib/ramaze/dispatcher/file.rb +1 -1
  32. data/lib/ramaze/helper/formatting.rb +33 -0
  33. data/lib/ramaze/helper/paginate.rb +234 -0
  34. data/lib/ramaze/option.rb +2 -2
  35. data/lib/ramaze/reloader.rb +2 -2
  36. data/lib/ramaze/snippets.rb +13 -0
  37. data/lib/ramaze/snippets/array/put_within.rb +31 -24
  38. data/lib/ramaze/snippets/binding/locals.rb +23 -11
  39. data/lib/ramaze/snippets/kernel/constant.rb +36 -21
  40. data/lib/ramaze/snippets/kernel/pretty_inspect.rb +12 -6
  41. data/lib/ramaze/snippets/numeric/filesize_format.rb +24 -17
  42. data/lib/ramaze/snippets/numeric/time.rb +63 -56
  43. data/lib/ramaze/snippets/object/__dir__.rb +29 -0
  44. data/lib/ramaze/snippets/object/acquire.rb +40 -0
  45. data/lib/ramaze/snippets/object/instance_variable_defined.rb +16 -5
  46. data/lib/ramaze/snippets/object/pretty.rb +14 -4
  47. data/lib/ramaze/snippets/object/scope.rb +14 -7
  48. data/lib/ramaze/snippets/ordered_set.rb +4 -0
  49. data/lib/ramaze/snippets/proc/locals.rb +17 -9
  50. data/lib/ramaze/snippets/ramaze/struct.rb +45 -0
  51. data/lib/ramaze/snippets/string/camel_case.rb +13 -8
  52. data/lib/ramaze/snippets/string/color.rb +24 -20
  53. data/lib/ramaze/snippets/string/each.rb +14 -3
  54. data/lib/ramaze/snippets/string/end_with.rb +17 -6
  55. data/lib/ramaze/snippets/string/esc.rb +26 -18
  56. data/lib/ramaze/snippets/string/ord.rb +12 -6
  57. data/lib/ramaze/snippets/string/snake_case.rb +13 -7
  58. data/lib/ramaze/snippets/string/start_with.rb +16 -6
  59. data/lib/ramaze/snippets/string/unindent.rb +23 -15
  60. data/lib/ramaze/snippets/thread/into.rb +3 -3
  61. data/lib/ramaze/spec/helper/snippets.rb +8 -0
  62. data/lib/ramaze/template/ezamar/textpow.syntax +34 -0
  63. data/lib/ramaze/tool/create.rb +27 -53
  64. data/lib/ramaze/tool/project_creator.rb +110 -0
  65. data/lib/ramaze/version.rb +1 -1
  66. data/rake_tasks/gem.rake +2 -1
  67. data/rake_tasks/maintenance.rake +38 -0
  68. data/rake_tasks/release.rake +6 -2
  69. data/rake_tasks/spec.rake +1 -2
  70. data/ramaze.gemspec +69 -78
  71. data/spec/examples/simple_auth.rb +2 -2
  72. data/spec/examples/templates/template_haml.rb +0 -2
  73. data/spec/ramaze/current/session.rb +1 -1
  74. data/spec/ramaze/dispatcher/file.rb +2 -2
  75. data/spec/ramaze/helper/formatting.rb +13 -0
  76. data/spec/ramaze/rewrite.rb +1 -1
  77. data/spec/ramaze/struct.rb +47 -0
  78. data/spec/ramaze/template/markaby.rb +1 -1
  79. data/spec/snippets/{kernel → object}/__dir__.rb +0 -0
  80. data/spec/snippets/{kernel → object}/acquire.rb +0 -0
  81. metadata +69 -78
  82. data/examples/app/rammit/spec/rammit.rb +0 -31
  83. data/examples/app/rammit/src/controller/main.rb +0 -3
  84. data/examples/app/rammit/src/controller/page.rb +0 -16
  85. data/examples/app/rammit/src/model.rb +0 -33
  86. data/examples/app/rammit/start.rb +0 -8
  87. data/examples/app/rammit/template/index.xhtml +0 -14
  88. data/examples/app/rammit/template/page/view.xhtml +0 -4
  89. data/lib/ramaze/snippets/kernel/__dir__.rb +0 -23
  90. data/lib/ramaze/snippets/kernel/acquire.rb +0 -34
  91. data/lib/ramaze/snippets/struct/fill.rb +0 -23
  92. data/lib/ramaze/snippets/struct/values_at.rb +0 -39
  93. data/lib/ramaze/snippets/symbol/to_proc.rb +0 -24
  94. data/lib/ramaze/sourcereload.rb +0 -183
  95. data/spec/snippets/struct/fill.rb +0 -26
  96. data/spec/snippets/struct/values_at.rb +0 -52
  97. data/spec/snippets/symbol/to_proc.rb +0 -13
@@ -1,6 +1,6 @@
1
1
  Title: The official Ramaze todolist tutorial
2
- HTML use syntax: true
3
-
2
+ html_use_syntax: true
3
+ uv_style: iplastic
4
4
 
5
5
  # To-do List Tutorial
6
6
 
@@ -46,7 +46,8 @@ to-do list.
46
46
 
47
47
  So run:
48
48
 
49
- $ ramaze --create todolist
49
+ ramaze --create todolist
50
+ {:lang=shell-unix-generic}
50
51
 
51
52
  done.
52
53
 
@@ -59,7 +60,7 @@ with your ORM or database-library of choice.
59
60
 
60
61
  So first, create a `model/todolist.rb` for our application:
61
62
 
62
- require 'ramaze/store/default'
63
+ require 'ramaze/store/default'
63
64
  TodoList = Ramaze::Store::Default.new('todolist.yaml')
64
65
  {:lang=ruby}
65
66
 
@@ -100,7 +101,7 @@ simple.
100
101
  </ul>
101
102
  </body>
102
103
  </html>
103
- {:lang=nagoro}
104
+ {:lang=html}
104
105
 
105
106
  I will assume that you are familiar with basic Ruby already, so we will
106
107
  concentrate on the things new here.
@@ -118,7 +119,7 @@ interesting part)
118
119
  <li>Laundry: not done</li>
119
120
  <li>Wash dishes: not done</li>
120
121
  </ul>
121
- {:lang=nagoro}
122
+ {:lang=html}
122
123
 
123
124
  That wasn't too bad, huh?
124
125
 
@@ -202,7 +203,7 @@ changed to do following:
202
203
  <?r end ?>
203
204
  </body>
204
205
  </html>
205
- {:lang=ruby}
206
+ {:lang=ezamar}
206
207
 
207
208
  The rest of the template can stay the same.
208
209
 
@@ -224,6 +225,7 @@ Add a link on the `view/index.xhtml` like this:
224
225
 
225
226
  <h1>TodoList</h1>
226
227
  <a href="/new">New Task</a>
228
+ {:lang=ezamar}
227
229
 
228
230
  Open a new file `view/new.xhtml` with a form to add a new task.
229
231
 
@@ -240,6 +242,7 @@ Open a new file `view/new.xhtml` with a form to add a new task.
240
242
  </form>
241
243
  </body>
242
244
  </html>
245
+ {:lang=ezamar}
243
246
 
244
247
  We will not need a method for this on our controller, in fact, actions can
245
248
  consist of either method and template or only one of them. The Controller
@@ -288,7 +291,7 @@ Jump into `view/index.xhtml` and do the following:
288
291
  #{h title}: #{status} - [ #{toggle} ]
289
292
  </li>
290
293
  <?r end
291
- {:lang=ruby}
294
+ {:lang=ezamar}
292
295
 
293
296
  We added a new element here, `toggle`, the Controller should give us
294
297
  a link to change the status corresponding to the status of the task, so off
@@ -317,6 +320,7 @@ toggle the status, A and Rs are both methods that help you do that.
317
320
  The result will be something like:
318
321
 
319
322
  <a href="/open/Wash+dishes">Close Task</a>
323
+ {:lang=ezamar}
320
324
 
321
325
  Rs actually is responsible to build the links href, for more information please
322
326
  take a look at the RDoc for LinkHelper.
@@ -364,7 +368,10 @@ will translate into:
364
368
  open('Wash dishes')
365
369
  {:lang=ruby}
366
370
 
367
- Which in turn will call `task_status('Wash dishes', false)`
371
+ Which in turn will call
372
+
373
+ task_status('Wash dishes', false)
374
+ {:lang=ruby}
368
375
 
369
376
  That's it, go on and try it :)
370
377
 
@@ -396,6 +403,7 @@ Now jumping to `view/index.xhtml` again, change it so it shows the link:
396
403
  #{h title}: #{status} [ #{toggle} | #{delete} ]
397
404
  </li>
398
405
  <?r end ?>
406
+ {:lang=ezamar}
399
407
 
400
408
  Voilà, you now have acquired the Certificate of Ramazeness.
401
409
 
@@ -406,6 +414,7 @@ explain some more advanced concepts of Ramaze and Ezamar.
406
414
  ## Eighth Step, Elements
407
415
 
408
416
  <Page></Page>
417
+ {:lang=ezamar}
409
418
 
410
419
  This is called an Element, Ramaze will go and search for a class that matches
411
420
  the name Page and responds to `#render`. Then it will go and hand the content in
@@ -423,12 +432,14 @@ Let us have a look at our templates, they got some repetitive stuff, like:
423
432
  <h1>some title</h1>
424
433
  </body>
425
434
  </html>
435
+ {:lang=ezamar}
426
436
 
427
437
  How about replacing that with something short and reusable:
428
438
 
429
439
  <Page title="TodoList">
430
440
  your other content
431
441
  </Page>
442
+ {:lang=html}
432
443
 
433
444
  Would be nice of course, and when you start having more templates it makes an
434
445
  awful lot of sense being able to change the enclosing stuff in one place.
@@ -497,6 +508,7 @@ First the `view/index.xhtml`
497
508
  </ul>
498
509
  <?r end ?>
499
510
  </Page>
511
+ {:lang=ezamar}
500
512
 
501
513
  and the `view/new.xhtml`
502
514
 
@@ -507,6 +519,7 @@ and the `view/new.xhtml`
507
519
  <input type="submit" />
508
520
  </form>
509
521
  </Page>
522
+ {:lang=ezamar}
510
523
 
511
524
  Alright, now just go and look at the result in the browser, try changing
512
525
  the things inside the Element and look at how it behaves.
@@ -526,6 +539,7 @@ So, from what we have right now:
526
539
  </li>
527
540
  <?r end ?>
528
541
  </ul>
542
+ {:lang=ezamar}
529
543
 
530
544
  To something like this:
531
545
 
@@ -539,6 +553,7 @@ To something like this:
539
553
  </tr>
540
554
  <?r end ?>
541
555
  </table>
556
+ {:lang=ezamar}
542
557
 
543
558
  And, since we have proper classes to address some style sheets, jump into the
544
559
  Page element and add some style sheet:
@@ -554,6 +569,7 @@ Page element and add some style sheet:
554
569
  a { color: #3a3; }
555
570
  </style>
556
571
  </head>
572
+ {:lang=ezamar}
557
573
 
558
574
  That looks quite a bit nicer, right? And yes, if you don't like tables (though
559
575
  this is an entirely legit use in my opinion) you can just do it like you want,
@@ -759,6 +775,7 @@ and add in the right place:
759
775
  <?r end ?>
760
776
  #{content}
761
777
  </body>
778
+ {:lang=ezamar}
762
779
 
763
780
  The only thing special about it is the `\\#{flash[:error]}`, we have to escape
764
781
  the `#` so it won't evaluate this immediately but wait until it is really
@@ -0,0 +1,71 @@
1
+ require 'rubygems'
2
+ require 'ramaze'
3
+
4
+ USERS = DATA.read.split("\n")
5
+
6
+ class MainController < Ramaze::Controller
7
+ helper :paginate
8
+
9
+ trait :paginate => {
10
+ :limit => 6,
11
+ :var => 'user_page',
12
+ }
13
+
14
+ def index
15
+ @pager = paginate(USERS)
16
+ %q~
17
+ <html>
18
+
19
+ <head><title>Users</title></head>
20
+ <body>
21
+ #{@pager.navigation if @pager.needed?}
22
+ <pre>
23
+ <?r @pager.each do |user| ?>
24
+ #{user}
25
+ <?r end ?>
26
+ </pre>
27
+ #{@pager.navigation if @pager.needed?}
28
+ </body>
29
+ </html>
30
+ ~
31
+ end
32
+ end
33
+
34
+ Ramaze.start
35
+
36
+ __END__
37
+ Michael Fellinger 1868 [ 77.13% ]
38
+ Aman Gupta 211 [ 8.71% ]
39
+ Jonathan Buch 89 [ 3.67% ]
40
+ Gabriele Renzi 49 [ 2.02% ]
41
+ Ara T. Howard 44 [ 1.82% ]
42
+ Clive Crous 37 [ 1.53% ]
43
+ Keita Yamaguchi 27 [ 1.11% ]
44
+ Ryan Grove 17 [ 0.70% ]
45
+ Pistos 16 [ 0.66% ]
46
+ Wang, Jinjing 11 [ 0.45% ]
47
+ Colin Shea 9 [ 0.37% ]
48
+ Sam Carr 6 [ 0.25% ]
49
+ Stephan Maka 5 [ 0.21% ]
50
+ samcarr 4 [ 0.17% ]
51
+ raggi 3 [ 0.12% ]
52
+ Clinton R. Nixon 3 [ 0.12% ]
53
+ Chris Duncan 3 [ 0.12% ]
54
+ Richard Outten 2 [ 0.08% ]
55
+ Andy Smith 2 [ 0.08% ]
56
+ skaar 1 [ 0.04% ]
57
+ Yasushi Abe 1 [ 0.04% ]
58
+ Thomas Leitner 1 [ 0.04% ]
59
+ Rob Lievaart 1 [ 0.04% ]
60
+ Riku Raisaenen 1 [ 0.04% ]
61
+ Matt Rubens 1 [ 0.04% ]
62
+ Martin Hilbig 1 [ 0.04% ]
63
+ Leo Borisenko 1 [ 0.04% ]
64
+ Lars Olsson 1 [ 0.04% ]
65
+ Jeremy Evans 1 [ 0.04% ]
66
+ Jean-Francois Chevrette 1 [ 0.04% ]
67
+ James Tucker 1 [ 0.04% ]
68
+ Fabian Buch 1 [ 0.04% ]
69
+ Christian Neukirchen 1 [ 0.04% ]
70
+ Carlo Zottmann 1 [ 0.04% ]
71
+ Andrew Farmer 1 [ 0.04% ]
@@ -2,22 +2,34 @@ require 'rubygems'
2
2
  require 'ramaze'
3
3
 
4
4
  class MainController < Ramaze::Controller
5
- LOGINS = {
6
- :username => 'password',
7
- :admin => 'secret'
8
- }.map{|k,v| ["#{k}:#{v}"].pack('m').strip} unless defined? LOGINS
5
+ trait :logins => {
6
+ 'jill' => 'password1',
7
+ 'jack' => 'password2',
8
+ }.map{|k,v| ["#{k}:#{v}"].pack('m').strip }
9
9
 
10
10
  helper :aspect
11
11
 
12
12
  before_all do
13
- response['WWW-Authenticate'] = %(Basic realm="Login Required")
14
- respond 'Unauthorized', 401 unless auth = request.env['HTTP_AUTHORIZATION'] and
15
- LOGINS.include? auth.split.last
13
+ check_auth
16
14
  end
17
15
 
18
16
  def index
19
17
  'Secret Info'
20
18
  end
19
+
20
+ private
21
+
22
+ def check_auth
23
+ response['WWW-Authenticate'] = 'Basic realm="Login Required"'
24
+
25
+ if auth = request.env['HTTP_AUTHORIZATION']
26
+ if class_trait[:logins].include?(auth.split.last)
27
+ return true
28
+ end
29
+ end
30
+
31
+ respond 'Unauthorized', 401
32
+ end
21
33
  end
22
34
 
23
- Ramaze.start :adapter => :mongrel
35
+ Ramaze.start :adapter => :mongrel
@@ -0,0 +1,10 @@
1
+ # Define a subclass of Ramaze::Controller holding your defaults for all
2
+ # controllers
3
+
4
+ class Controller < Ramaze::Controller
5
+ layout '/page'
6
+ helper :xhtml
7
+ engine :Ezamar
8
+ end
9
+
10
+ acquire __DIR__/"*.rb"
@@ -5,9 +5,7 @@
5
5
  # map '/otherurl'
6
6
  # this will force the controller to be mounted on: /otherurl
7
7
 
8
- class MainController < Ramaze::Controller
9
- layout '/page'
10
-
8
+ class MainController < Controller
11
9
  # the index action is called automatically when no other action is specified
12
10
  def index
13
11
  @title = "Welcome to Ramaze!"
@@ -0,0 +1,4 @@
1
+ # Here goes your database connection and options
2
+
3
+ # Require all models in '/model/*.rb'
4
+ acquire __DIR__/"*.rb"
@@ -1,7 +1,7 @@
1
1
  require 'ramaze'
2
2
  require 'ramaze/spec/helper'
3
3
 
4
- require __DIR__/'..'/'start'
4
+ require __DIR__/'../start'
5
5
 
6
6
  describe MainController do
7
7
  behaves_like 'http', 'xpath'
@@ -11,6 +11,7 @@ describe MainController do
11
11
  it 'should show start page' do
12
12
  got = get('/')
13
13
  got.status.should == 200
14
+ puts got.body
14
15
  got.at('//title').text.strip.should ==
15
16
  MainController.new.index
16
17
  end
data/lib/proto/start.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  require 'rubygems'
2
2
  require 'ramaze'
3
3
 
4
- # require all controllers and models
5
- acquire __DIR__/:controller/'*'
6
- acquire __DIR__/:model/'*'
4
+ # Initialize controllers and models
5
+ require 'controller/init'
6
+ require 'model/init'
7
7
 
8
8
  Ramaze.start :adapter => :webrick, :port => 7000
data/lib/ramaze.rb CHANGED
@@ -33,6 +33,11 @@ module Ramaze
33
33
  BASEDIR = File.dirname(File.expand_path(__FILE__))
34
34
  $LOAD_PATH.unshift BASEDIR
35
35
  $LOAD_PATH.uniq!
36
+
37
+ # Shortcut to the HTTP_STATUS_CODES of Rack::Utils
38
+ # inverted for easier access
39
+
40
+ STATUS_CODE = Rack::Utils::HTTP_STATUS_CODES.invert
36
41
  end
37
42
 
38
43
  Thread.abort_on_exception = true
@@ -43,6 +48,7 @@ require 'ramaze/reloader'
43
48
  require 'ramaze/snippets'
44
49
  require 'ramaze/log'
45
50
  require 'ramaze/trinity'
51
+ require 'ramaze/dispatcher'
46
52
  require 'ramaze/current'
47
53
  require 'ramaze/adapter'
48
54
  require 'ramaze/option'
@@ -53,7 +59,6 @@ require 'ramaze/tool'
53
59
  require 'ramaze/controller'
54
60
 
55
61
  # Complete
56
- require 'ramaze/dispatcher'
57
62
  require 'ramaze/template/ezamar'
58
63
  require 'ramaze/contrib'
59
64
  require 'ramaze/route'
data/lib/ramaze/action.rb CHANGED
@@ -10,7 +10,7 @@ module Ramaze
10
10
  # The Action holds information that is essential to render the action for a
11
11
  # request.
12
12
 
13
- class Action < Struct.new('Action', *members)
13
+ class Action < Ramaze::Struct.new('Action', *members)
14
14
  end
15
15
  end
16
16
 
@@ -145,7 +145,7 @@ module Ramaze
145
145
  end
146
146
  end
147
147
 
148
- # Shortcut to create new instances of Action via Action::fill
148
+ # Shortcut to create new instances of Action
149
149
 
150
150
  def self.Action(hash = {})
151
151
  Action.create(hash)
@@ -11,11 +11,6 @@ Socket.do_not_reverse_lookup = true
11
11
 
12
12
  module Ramaze
13
13
 
14
- # Shortcut to the HTTP_STATUS_CODES of Rack::Utils
15
- # inverted for easier access
16
-
17
- STATUS_CODE = Rack::Utils::HTTP_STATUS_CODES.invert
18
-
19
14
  # This module holds all classes and methods related to the adapters like
20
15
  # webrick or mongrel.
21
16
  # It's responsible for starting and stopping them.
@@ -5,14 +5,29 @@ module Ramaze
5
5
  module Adapter
6
6
 
7
7
  # (Rack) middleware injected around Adapter::Base::call
8
- MIDDLEWARE = OrderedSet.new(
9
- Ramaze::Current,
10
- Ramaze::Reloader,
8
+ MIDDLEWARE = OrderedSet[
9
+ Rack::ShowExceptions,
11
10
  Rack::ShowStatus,
12
- Rack::ShowExceptions
13
- )
11
+ # Rack::Deflater,
12
+ Ramaze::Reloader,
13
+ Ramaze::Current,
14
+ Ramaze::Dispatcher,
15
+ ]
16
+
17
+ def self.middleware(mws = MIDDLEWARE)
18
+ if @middleware and trait[:previous] == mws
19
+ @middleware
20
+ else
21
+ trait :previous => mws.dup
22
+ inner_app = mws.last
23
+ cascade = mws[0...-1].reverse
24
+
25
+ @middleware = cascade.inject(inner_app){|app, mw| mw.new(app) }
26
+ end
27
+ end
14
28
 
15
- trait :middleware => MIDDLEWARE.inject{|app, middleware| middleware.new(app) }
29
+ @middleware = nil
30
+ @middleware = middleware
16
31
 
17
32
  # Helper to assign a new block to before_call
18
33
  # Usage:
@@ -31,6 +46,7 @@ module Ramaze
31
46
 
32
47
  class Base
33
48
  class << self
49
+
34
50
  attr_reader :thread
35
51
 
36
52
  # Call ::startup with the given host and port.
@@ -102,9 +118,10 @@ module Ramaze
102
118
 
103
119
  def respond(env)
104
120
  Ramaze::STATE.wrap do
105
- Adapter.trait[:middleware].call(env)
121
+ Adapter::middleware.call(env)
106
122
  end
107
123
  end
124
+
108
125
  end
109
126
  end
110
127
  end