ramaze 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +14 -29
- data/bin/ramaze +2 -3
- data/doc/AUTHORS +5 -2
- data/doc/CHANGELOG +262 -9
- data/doc/FAQ +6 -6
- data/doc/meta/announcement.txt +5 -19
- data/doc/tutorial/todolist.html +47 -57
- data/doc/tutorial/todolist.mkd +47 -55
- data/examples/memleak_detector.rb +31 -0
- data/examples/todolist/src/controller/main.rb +14 -13
- data/examples/todolist/src/element/page.rb +2 -2
- data/examples/todolist/src/model.rb +2 -2
- data/examples/todolist/todolist.db +0 -4
- data/examples/whywiki/main.rb +2 -2
- data/examples/whywiki/template/edit.xhtml +1 -1
- data/examples/whywiki/template/show.xhtml +3 -3
- data/lib/proto/src/controller/main.rb +18 -1
- data/lib/proto/template/index.xhtml +11 -2
- data/lib/ramaze.rb +1 -1
- data/lib/ramaze/action.rb +104 -5
- data/lib/ramaze/action/render.rb +54 -0
- data/lib/ramaze/adapter.rb +2 -1
- data/lib/ramaze/adapter/mongrel.rb +13 -4
- data/lib/ramaze/cache.rb +17 -8
- data/lib/ramaze/cache/memcached.rb +1 -5
- data/lib/ramaze/controller.rb +51 -18
- data/lib/ramaze/controller/resolve.rb +19 -14
- data/lib/ramaze/dispatcher.rb +13 -16
- data/lib/ramaze/dispatcher/action.rb +2 -3
- data/lib/ramaze/dispatcher/error.rb +8 -3
- data/lib/ramaze/dispatcher/file.rb +1 -4
- data/lib/ramaze/error.rb +5 -5
- data/lib/ramaze/global.rb +7 -1
- data/lib/ramaze/global/globalstruct.rb +1 -3
- data/lib/ramaze/helper/aspect.rb +8 -10
- data/lib/ramaze/helper/cgi.rb +21 -3
- data/lib/ramaze/helper/identity.rb +4 -6
- data/lib/ramaze/helper/link.rb +4 -4
- data/lib/ramaze/helper/pager.rb +316 -0
- data/lib/ramaze/helper/partial.rb +37 -0
- data/lib/ramaze/helper/stack.rb +1 -1
- data/lib/ramaze/inform.rb +9 -0
- data/lib/ramaze/inform/hub.rb +5 -0
- data/lib/ramaze/inform/informer.rb +12 -6
- data/lib/ramaze/inform/informing.rb +32 -7
- data/lib/ramaze/inform/knotify.rb +21 -0
- data/lib/ramaze/inform/xosd.rb +58 -24
- data/lib/ramaze/sourcereload.rb +30 -1
- data/lib/ramaze/template.rb +33 -12
- data/lib/ramaze/template/amrita2.rb +21 -20
- data/lib/ramaze/template/erubis.rb +18 -14
- data/lib/ramaze/template/ezamar.rb +15 -26
- data/lib/ramaze/template/ezamar/element.rb +1 -1
- data/lib/ramaze/template/ezamar/engine.rb +45 -36
- data/lib/ramaze/template/ezamar/morpher.rb +3 -3
- data/lib/ramaze/template/ezamar/render_partial.rb +26 -0
- data/lib/ramaze/template/haml.rb +23 -18
- data/lib/ramaze/template/liquid.rb +5 -3
- data/lib/ramaze/template/markaby.rb +14 -11
- data/lib/ramaze/template/remarkably.rb +11 -5
- data/lib/ramaze/tool/localize.rb +12 -4
- data/lib/ramaze/tool/tidy.rb +26 -23
- data/lib/ramaze/trinity/request.rb +11 -7
- data/lib/ramaze/trinity/session.rb +24 -8
- data/lib/ramaze/version.rb +1 -1
- data/rake_tasks/maintaince.rake +136 -11
- data/spec/examples/templates/template_liquid.rb +6 -3
- data/spec/examples/todolist.rb +1 -2
- data/spec/helper/minimal.rb +7 -7
- data/spec/ramaze/action/basics.rb +19 -0
- data/spec/ramaze/action/render.rb +18 -0
- data/spec/ramaze/controller.rb +1 -1
- data/spec/ramaze/controller/template_resolving.rb +1 -1
- data/spec/ramaze/dispatcher/file.rb +24 -0
- data/spec/ramaze/error.rb +28 -29
- data/spec/ramaze/helper/cgi.rb +43 -0
- data/spec/ramaze/helper/pager.rb +27 -0
- data/spec/ramaze/helper/partial.rb +38 -0
- data/spec/ramaze/helper/template/partial.xhtml +1 -0
- data/spec/ramaze/inform/informer.rb +1 -1
- data/spec/ramaze/localize.rb +1 -1
- data/spec/ramaze/morpher.rb +3 -3
- data/spec/ramaze/request.rb +1 -3
- data/spec/ramaze/template.rb +9 -7
- data/spec/ramaze/template/haml.rb +2 -1
- metadata +21 -7
- data/examples/todolist/public/404.jpg +0 -0
- data/examples/todolist/public/error.xhtml +0 -74
- data/lib/ramaze/controller/render.rb +0 -90
data/doc/tutorial/todolist.html
CHANGED
@@ -70,7 +70,7 @@ RubyForge.</p>
|
|
70
70
|
<p>Additionally, we now have added tests for the resulting application that you
|
71
71
|
can find in spec/examples/todolist.rb</p>
|
72
72
|
|
73
|
-
<p>Date of last update: Thu
|
73
|
+
<p>Date of last update: Thu Jun 14 13:25:45 JST 2007</p>
|
74
74
|
|
75
75
|
<p>Thanks in advance.
|
76
76
|
The author of the tutorial, Michael 'manveru' Fellinger</p>
|
@@ -97,10 +97,10 @@ with your ORM or database-library of choice.</p>
|
|
97
97
|
|
98
98
|
<p>So first, edit the <code>src/model.rb</code> to fit better into our application:</p>
|
99
99
|
|
100
|
-
<pre><code>TodoList = Store::Default.new
|
100
|
+
<pre><code>TodoList = Store::Default.new('todolist.yaml')
|
101
101
|
</code></pre>
|
102
102
|
|
103
|
-
<p>
|
103
|
+
<p>Let's add some items as well to have a base to start from.</p>
|
104
104
|
|
105
105
|
<pre><code>{
|
106
106
|
'Laundry' => {:done => false},
|
@@ -118,6 +118,8 @@ end
|
|
118
118
|
<p>Start with editing <code>template/index.xhtml</code>, it is using the default templating
|
119
119
|
of Ramaze, called Ezamar.</p>
|
120
120
|
|
121
|
+
<p>The index.xhtml currently contains a default welcome page, remove the contents.</p>
|
122
|
+
|
121
123
|
<p>Let's put some things in there, I'll explain the syntax as we go, it's quite
|
122
124
|
simple.</p>
|
123
125
|
|
@@ -139,12 +141,12 @@ simple.</p>
|
|
139
141
|
</html>
|
140
142
|
</code></pre>
|
141
143
|
|
142
|
-
<p>I will assume that you are familiar with basic Ruby already, so
|
144
|
+
<p>I will assume that you are familiar with basic Ruby already, so we will
|
143
145
|
concentrate on the things new here.</p>
|
144
146
|
|
145
|
-
<p><code><?r ?></code> defines an area of ruby-code.
|
146
|
-
pure Ruby it will be evaluated. We iterate over the TodoList model and
|
147
|
-
title and value into a block. In that block we can just get the values
|
147
|
+
<p><code><?r ?></code> defines an area of ruby-code. Later, when the template is transformed
|
148
|
+
into pure Ruby it will be evaluated. We iterate over the TodoList model and
|
149
|
+
pass the title and value into a block. In that block we can just get the values
|
148
150
|
of title and status (which we define based on the value) displayed on the
|
149
151
|
page.</p>
|
150
152
|
|
@@ -193,20 +195,24 @@ edit the file <code>src/controller/main.rb</code>.</p>
|
|
193
195
|
|
194
196
|
<pre><code>class MainController < Controller
|
195
197
|
def index
|
196
|
-
"
|
198
|
+
@welcome = "Welcome to Ramaze!"
|
199
|
+
end
|
200
|
+
|
201
|
+
def notemplate
|
202
|
+
"there is no template associated with this action"
|
197
203
|
end
|
198
204
|
end
|
199
205
|
</code></pre>
|
200
206
|
|
201
|
-
<p>The only
|
202
|
-
|
203
|
-
|
204
|
-
|
207
|
+
<p>The only methods right now are <code>#index</code> and <code>#notemplate</code>.
|
208
|
+
The relationship between the methods on the controller and the templates is
|
209
|
+
1:1, so the method <code>#index</code> is combined with the template <code>index.xhtml</code>. This
|
210
|
+
combination is called an <code>action</code>.</p>
|
205
211
|
|
206
|
-
<p>Let's get back to editing and change the
|
212
|
+
<p>Let's get back to editing and change the method <code>#index</code> to this:</p>
|
207
213
|
|
208
214
|
<pre><code>def index
|
209
|
-
@tasks = TodoList.
|
215
|
+
@tasks = TodoList.original
|
210
216
|
@tasks.each do |title, value|
|
211
217
|
status = value[:done] ? 'done' : 'not done'
|
212
218
|
@tasks[title] = status
|
@@ -246,7 +252,7 @@ Tasks it will say so.</p>
|
|
246
252
|
|
247
253
|
<ul>
|
248
254
|
<li>Instance-variables defined in the Controller are available in the View.</li>
|
249
|
-
<li>The return-value of the Controller does not matter
|
255
|
+
<li>The return-value of the Controller does not matter if a template is present.</li>
|
250
256
|
</ul>
|
251
257
|
|
252
258
|
<a name="Fifth_Step,_getting_dynamic"><h2>Fifth Step, getting dynamic</h2></a>
|
@@ -279,8 +285,7 @@ missing. First off, we want to add new tasks, so let's get that done.</p>
|
|
279
285
|
|
280
286
|
<p>We will not need a method for this on our controller, in fact, actions can
|
281
287
|
consist of either method and template or only one of them. The Controller
|
282
|
-
can act as a View and the View
|
283
|
-
is no template).</p>
|
288
|
+
can act as a View and the View can work like you may know it from PHP.</p>
|
284
289
|
|
285
290
|
<p>If you try to use this form you will notice that we have not yet defined a way
|
286
291
|
to actually create the task.</p>
|
@@ -361,18 +366,7 @@ take a look at the RDoc for LinkHelper.</p>
|
|
361
366
|
which is because we were using an Hash, which are per definition unsorted, so
|
362
367
|
now we use an array to hold our tasks and sort it.</p>
|
363
368
|
|
364
|
-
<p>
|
365
|
-
|
366
|
-
<pre><code><?r @tasks.each do |title, status, toggle| ?>
|
367
|
-
<li>
|
368
|
-
#{title}: #{status} [ #{toggle} ]
|
369
|
-
</li>
|
370
|
-
<?r end ?>
|
371
|
-
</code></pre>
|
372
|
-
|
373
|
-
<p>As usual, the things not changed are omitted for terseness.</p>
|
374
|
-
|
375
|
-
<p>And as usual since the links for open and close don't lead anywhere, add the
|
369
|
+
<p>As usual since the links for open and close don't lead anywhere, add the
|
376
370
|
corresponding methods to the Controller:</p>
|
377
371
|
|
378
372
|
<pre><code>def open title
|
@@ -444,11 +438,10 @@ end
|
|
444
438
|
<?r end ?>
|
445
439
|
</code></pre>
|
446
440
|
|
447
|
-
<p>Voilà, you now have acquired the Certificate of Ramazeness
|
448
|
-
section will contact you within the next few days.</p>
|
441
|
+
<p>Voilà, you now have acquired the Certificate of Ramazeness.</p>
|
449
442
|
|
450
443
|
<p>Just kidding, but that really are the basics, in the next few steps I will
|
451
|
-
explain some more advanced concepts of Ramaze and
|
444
|
+
explain some more advanced concepts of Ramaze and Ezamar.</p>
|
452
445
|
|
453
446
|
<a name="Eighth_Step,_Elements"><h2>Eighth Step, Elements</h2></a>
|
454
447
|
|
@@ -461,7 +454,7 @@ between to that Element.</p>
|
|
461
454
|
|
462
455
|
<p>Sounds weird?</p>
|
463
456
|
|
464
|
-
<p>Let us have a look at our templates, they
|
457
|
+
<p>Let us have a look at our templates, they got some repetitive stuff, like:</p>
|
465
458
|
|
466
459
|
<pre><code><html>
|
467
460
|
<head>
|
@@ -473,7 +466,7 @@ between to that Element.</p>
|
|
473
466
|
</html>
|
474
467
|
</code></pre>
|
475
468
|
|
476
|
-
<p>How about replacing that with something short and
|
469
|
+
<p>How about replacing that with something short and reusable:</p>
|
477
470
|
|
478
471
|
<pre><code><Page title="TodoList">
|
479
472
|
your other content
|
@@ -481,7 +474,7 @@ between to that Element.</p>
|
|
481
474
|
</code></pre>
|
482
475
|
|
483
476
|
<p>Would be nice of course, and when you start having more templates it makes an
|
484
|
-
awful lot of sense to change the enclosing stuff in one place.</p>
|
477
|
+
awful lot of sense being able to change the enclosing stuff in one place.</p>
|
485
478
|
|
486
479
|
<p>So let's apply DRY here as well.</p>
|
487
480
|
|
@@ -565,7 +558,7 @@ the things inside the Element and look at how it behaves.</p>
|
|
565
558
|
|
566
559
|
<a name="Ninth_Step,_Prettify"><h2>Ninth Step, Prettify</h2></a>
|
567
560
|
|
568
|
-
<p>
|
561
|
+
<p>We structure the data inside the list a little bit, in this case into a table,
|
569
562
|
to get it line up properly and look actually structured.</p>
|
570
563
|
|
571
564
|
<p>So, from what we have right now:</p>
|
@@ -594,7 +587,7 @@ to get it line up properly and look actually structured.</p>
|
|
594
587
|
</code></pre>
|
595
588
|
|
596
589
|
<p>And, since we have proper classes to address some style sheets, jump into the
|
597
|
-
Page element and add some style sheet
|
590
|
+
Page element and add some style sheet:</p>
|
598
591
|
|
599
592
|
<pre><code><head>
|
600
593
|
<title>TodoList</title>
|
@@ -610,7 +603,7 @@ Page element and add some style sheet like that:</p>
|
|
610
603
|
</code></pre>
|
611
604
|
|
612
605
|
<p>That looks quite a bit nicer, right? And yes, if you don't like tables (though
|
613
|
-
this is an entirely legit use in my opinion
|
606
|
+
this is an entirely legit use in my opinion) you can just do it like you want,
|
614
607
|
using nested lists or divs/spans, replacing the open/close and delete links with
|
615
608
|
nice images and changing the style according to the status.</p>
|
616
609
|
|
@@ -652,7 +645,7 @@ options, which is either using flags on the ramaze executable, or like this:</p>
|
|
652
645
|
</code></pre>
|
653
646
|
|
654
647
|
<p>We haven't started Ramaze directly as of yet, but this allows you to ignore the
|
655
|
-
ramaze executable and just run your application
|
648
|
+
ramaze executable and just run your application by <code>ruby main.rb</code>.</p>
|
656
649
|
|
657
650
|
<a name="Eleventh_Step,_Refactor_with_AspectHelper"><h2>Eleventh Step, Refactor with AspectHelper</h2></a>
|
658
651
|
|
@@ -707,20 +700,15 @@ def delete title
|
|
707
700
|
end
|
708
701
|
|
709
702
|
helper :aspect
|
710
|
-
after(:create, :open, :close, :delete){
|
711
|
-
|
712
|
-
def redirect_index
|
713
|
-
redirect Rs()
|
714
|
-
end
|
703
|
+
after(:create, :open, :close, :delete){ redirect(Rs()) }
|
715
704
|
</code></pre>
|
716
705
|
|
717
|
-
<p>Alright, that looks a lot nicer already and is definitely easier to maintain
|
718
|
-
Please note that the <code>#redirect_index</code> method should not be private, as it is a
|
719
|
-
usual action that will just run after the others.</p>
|
706
|
+
<p>Alright, that looks a lot nicer already and is definitely easier to maintain.</p>
|
720
707
|
|
721
|
-
<p>There is a symmetrical <code
|
722
|
-
and in case you want to add required authentication for all actions of a
|
723
|
-
Controller you could use <code
|
708
|
+
<p>There is a symmetrical <code>before</code> aspect that you could take advantage of as
|
709
|
+
well, and in case you want to add required authentication for all actions of a
|
710
|
+
Controller you could use <code>before_all</code> and <code>after_all</code> instead of a list of
|
711
|
+
action-names.</p>
|
724
712
|
|
725
713
|
<a name="Twelfth_Step,_Validation_and_Errors"><h2>Twelfth Step, Validation and Errors</h2></a>
|
726
714
|
|
@@ -744,7 +732,7 @@ from your users, so let's apply this advice.</p>
|
|
744
732
|
if title = request['title']
|
745
733
|
title.strip!
|
746
734
|
if title.empty?
|
747
|
-
|
735
|
+
failed("Please enter a title")
|
748
736
|
redirect '/new'
|
749
737
|
end
|
750
738
|
TodoList[title] = {:done => false}
|
@@ -762,16 +750,16 @@ the session for one request, afterwards the hash is thrown away. This is
|
|
762
750
|
specifically useful for giving the user feedback while keeping a stateless
|
763
751
|
approach.</p>
|
764
752
|
|
765
|
-
<p>Let me show you our <code>#
|
753
|
+
<p>Let me show you our <code>#failed</code> method (it goes in the private section to
|
766
754
|
<code>#task_status</code>):</p>
|
767
755
|
|
768
|
-
<pre><code>def
|
756
|
+
<pre><code>def failed(message)
|
769
757
|
flash[:error] = message
|
770
758
|
end
|
771
759
|
</code></pre>
|
772
760
|
|
773
761
|
<p>Duh, you may say, wouldn't that fit in the one line instead of the call to
|
774
|
-
<code>#
|
762
|
+
<code>#failed</code>?
|
775
763
|
Indeed, it would, but let me remind you, we have no checks for changing the
|
776
764
|
status of a task yet. We will need error-handling there as well, so we just keep
|
777
765
|
our code DRY and maintainable by collecting shared behaviour in small pieces.</p>
|
@@ -780,7 +768,7 @@ our code DRY and maintainable by collecting shared behaviour in small pieces.</p
|
|
780
768
|
|
781
769
|
<pre><code>def task_status title, status
|
782
770
|
unless task = TodoList[title]
|
783
|
-
|
771
|
+
failed "No such Task: `#{title}'"
|
784
772
|
redirect_referer
|
785
773
|
end
|
786
774
|
|
@@ -803,7 +791,7 @@ error-message in case it doesn't and redirect to wherever the browser came from.
|
|
803
791
|
|
804
792
|
<p>But what about actually showing the error-messages we so carefully set? Well,
|
805
793
|
where do we change the view? Right, in the templates. But both templates we have
|
806
|
-
so far (index and new) share this behaviour, so
|
794
|
+
so far (index and new) share this behaviour, so we head over to the Element
|
807
795
|
and add in the right place:</p>
|
808
796
|
|
809
797
|
<pre><code><body>
|
@@ -820,7 +808,9 @@ and add in the right place:</p>
|
|
820
808
|
<p>The only thing special about it is the <code>\#{flash[:error]}</code>, we have to escape
|
821
809
|
the <code>#</code> so it won't evaluate this immediately but wait until it is really
|
822
810
|
rendered.
|
823
|
-
|
811
|
+
As a note, If you read this as pure markaby, the double backslash is to output
|
812
|
+
properly to HTML, just use one instead.
|
813
|
+
Again, you can add some nifty style for that.</p>
|
824
814
|
|
825
815
|
<p>To be continued...</p>
|
826
816
|
</body>
|
data/doc/tutorial/todolist.mkd
CHANGED
@@ -25,7 +25,7 @@ RubyForge.
|
|
25
25
|
Additionally, we now have added tests for the resulting application that you
|
26
26
|
can find in spec/examples/todolist.rb
|
27
27
|
|
28
|
-
Date of last update: Thu
|
28
|
+
Date of last update: Thu Jun 14 13:25:45 JST 2007
|
29
29
|
|
30
30
|
Thanks in advance.
|
31
31
|
The author of the tutorial, Michael 'manveru' Fellinger
|
@@ -52,9 +52,9 @@ with your ORM or database-library of choice.
|
|
52
52
|
|
53
53
|
So first, edit the `src/model.rb` to fit better into our application:
|
54
54
|
|
55
|
-
TodoList = Store::Default.new
|
55
|
+
TodoList = Store::Default.new('todolist.yaml')
|
56
56
|
|
57
|
-
|
57
|
+
Let's add some items as well to have a base to start from.
|
58
58
|
|
59
59
|
{
|
60
60
|
'Laundry' => {:done => false},
|
@@ -72,6 +72,8 @@ Now let's get our hands dirty and just edit the templates for our to-do list.
|
|
72
72
|
Start with editing `template/index.xhtml`, it is using the default templating
|
73
73
|
of Ramaze, called Ezamar.
|
74
74
|
|
75
|
+
The index.xhtml currently contains a default welcome page, remove the contents.
|
76
|
+
|
75
77
|
Let's put some things in there, I'll explain the syntax as we go, it's quite
|
76
78
|
simple.
|
77
79
|
|
@@ -92,12 +94,12 @@ simple.
|
|
92
94
|
</body>
|
93
95
|
</html>
|
94
96
|
|
95
|
-
I will assume that you are familiar with basic Ruby already, so
|
97
|
+
I will assume that you are familiar with basic Ruby already, so we will
|
96
98
|
concentrate on the things new here.
|
97
99
|
|
98
|
-
`<?r ?>` defines an area of ruby-code.
|
99
|
-
pure Ruby it will be evaluated. We iterate over the TodoList model and
|
100
|
-
title and value into a block. In that block we can just get the values
|
100
|
+
`<?r ?>` defines an area of ruby-code. Later, when the template is transformed
|
101
|
+
into pure Ruby it will be evaluated. We iterate over the TodoList model and
|
102
|
+
pass the title and value into a block. In that block we can just get the values
|
101
103
|
of title and status (which we define based on the value) displayed on the
|
102
104
|
page.
|
103
105
|
|
@@ -146,19 +148,23 @@ The contents of it are like following:
|
|
146
148
|
|
147
149
|
class MainController < Controller
|
148
150
|
def index
|
149
|
-
"
|
151
|
+
@welcome = "Welcome to Ramaze!"
|
152
|
+
end
|
153
|
+
|
154
|
+
def notemplate
|
155
|
+
"there is no template associated with this action"
|
150
156
|
end
|
151
157
|
end
|
152
158
|
|
153
|
-
The only
|
154
|
-
|
155
|
-
|
156
|
-
|
159
|
+
The only methods right now are `#index` and `#notemplate`.
|
160
|
+
The relationship between the methods on the controller and the templates is
|
161
|
+
1:1, so the method `#index` is combined with the template `index.xhtml`. This
|
162
|
+
combination is called an `action`.
|
157
163
|
|
158
|
-
Let's get back to editing and change the
|
164
|
+
Let's get back to editing and change the method `#index` to this:
|
159
165
|
|
160
166
|
def index
|
161
|
-
@tasks = TodoList.
|
167
|
+
@tasks = TodoList.original
|
162
168
|
@tasks.each do |title, value|
|
163
169
|
status = value[:done] ? 'done' : 'not done'
|
164
170
|
@tasks[title] = status
|
@@ -195,7 +201,7 @@ Tasks it will say so.
|
|
195
201
|
Some things you should know:
|
196
202
|
|
197
203
|
* Instance-variables defined in the Controller are available in the View.
|
198
|
-
* The return-value of the Controller does not matter
|
204
|
+
* The return-value of the Controller does not matter if a template is present.
|
199
205
|
|
200
206
|
## Fifth Step, getting dynamic
|
201
207
|
|
@@ -225,8 +231,7 @@ Open a new file `template/new.xhtml` with a form to add a new task.
|
|
225
231
|
|
226
232
|
We will not need a method for this on our controller, in fact, actions can
|
227
233
|
consist of either method and template or only one of them. The Controller
|
228
|
-
can act as a View and the View
|
229
|
-
is no template).
|
234
|
+
can act as a View and the View can work like you may know it from PHP.
|
230
235
|
|
231
236
|
If you try to use this form you will notice that we have not yet defined a way
|
232
237
|
to actually create the task.
|
@@ -305,17 +310,7 @@ Also, you might have noticed that the tasks were changing order on every reload,
|
|
305
310
|
which is because we were using an Hash, which are per definition unsorted, so
|
306
311
|
now we use an array to hold our tasks and sort it.
|
307
312
|
|
308
|
-
|
309
|
-
|
310
|
-
<?r @tasks.each do |title, status, toggle| ?>
|
311
|
-
<li>
|
312
|
-
#{title}: #{status} [ #{toggle} ]
|
313
|
-
</li>
|
314
|
-
<?r end ?>
|
315
|
-
|
316
|
-
As usual, the things not changed are omitted for terseness.
|
317
|
-
|
318
|
-
And as usual since the links for open and close don't lead anywhere, add the
|
313
|
+
As usual since the links for open and close don't lead anywhere, add the
|
319
314
|
corresponding methods to the Controller:
|
320
315
|
|
321
316
|
def open title
|
@@ -355,6 +350,7 @@ Which in turn will call `task_status('Wash dishes', false)`
|
|
355
350
|
|
356
351
|
That's it, go on and try it :)
|
357
352
|
|
353
|
+
|
358
354
|
## Seventh Step, delete tasks
|
359
355
|
|
360
356
|
Well, creating, opening and closing work now, one of the things you will
|
@@ -381,11 +377,10 @@ Now jumping to `template/index.xhtml` again, change it so it shows the link:
|
|
381
377
|
</li>
|
382
378
|
<?r end ?>
|
383
379
|
|
384
|
-
Voilà, you now have acquired the Certificate of Ramazeness
|
385
|
-
section will contact you within the next few days.
|
380
|
+
Voilà, you now have acquired the Certificate of Ramazeness.
|
386
381
|
|
387
382
|
Just kidding, but that really are the basics, in the next few steps I will
|
388
|
-
explain some more advanced concepts of Ramaze and
|
383
|
+
explain some more advanced concepts of Ramaze and Ezamar.
|
389
384
|
|
390
385
|
|
391
386
|
## Eighth Step, Elements
|
@@ -398,7 +393,7 @@ between to that Element.
|
|
398
393
|
|
399
394
|
Sounds weird?
|
400
395
|
|
401
|
-
Let us have a look at our templates, they
|
396
|
+
Let us have a look at our templates, they got some repetitive stuff, like:
|
402
397
|
|
403
398
|
<html>
|
404
399
|
<head>
|
@@ -409,14 +404,14 @@ Let us have a look at our templates, they all got some repetitive stuff, like:
|
|
409
404
|
</body>
|
410
405
|
</html>
|
411
406
|
|
412
|
-
How about replacing that with something short and
|
407
|
+
How about replacing that with something short and reusable:
|
413
408
|
|
414
409
|
<Page title="TodoList">
|
415
410
|
your other content
|
416
411
|
</Page>
|
417
412
|
|
418
413
|
Would be nice of course, and when you start having more templates it makes an
|
419
|
-
awful lot of sense to change the enclosing stuff in one place.
|
414
|
+
awful lot of sense being able to change the enclosing stuff in one place.
|
420
415
|
|
421
416
|
So let's apply DRY here as well.
|
422
417
|
|
@@ -497,7 +492,7 @@ the things inside the Element and look at how it behaves.
|
|
497
492
|
|
498
493
|
## Ninth Step, Prettify
|
499
494
|
|
500
|
-
|
495
|
+
We structure the data inside the list a little bit, in this case into a table,
|
501
496
|
to get it line up properly and look actually structured.
|
502
497
|
|
503
498
|
So, from what we have right now:
|
@@ -524,7 +519,7 @@ To something like this:
|
|
524
519
|
</table>
|
525
520
|
|
526
521
|
And, since we have proper classes to address some style sheets, jump into the
|
527
|
-
Page element and add some style sheet
|
522
|
+
Page element and add some style sheet:
|
528
523
|
|
529
524
|
<head>
|
530
525
|
<title>TodoList</title>
|
@@ -539,7 +534,7 @@ Page element and add some style sheet like that:
|
|
539
534
|
</head>
|
540
535
|
|
541
536
|
That looks quite a bit nicer, right? And yes, if you don't like tables (though
|
542
|
-
this is an entirely legit use in my opinion
|
537
|
+
this is an entirely legit use in my opinion) you can just do it like you want,
|
543
538
|
using nested lists or divs/spans, replacing the open/close and delete links with
|
544
539
|
nice images and changing the style according to the status.
|
545
540
|
|
@@ -578,7 +573,7 @@ options, which is either using flags on the ramaze executable, or like this:
|
|
578
573
|
Ramaze.start :port => 80, :adapter => :mongrel
|
579
574
|
|
580
575
|
We haven't started Ramaze directly as of yet, but this allows you to ignore the
|
581
|
-
ramaze executable and just run your application.
|
576
|
+
ramaze executable and just run your application by `ruby main.rb`.
|
582
577
|
|
583
578
|
|
584
579
|
## Eleventh Step, Refactor with AspectHelper
|
@@ -633,19 +628,14 @@ In your Controller, replace the previous chunk with following:
|
|
633
628
|
end
|
634
629
|
|
635
630
|
helper :aspect
|
636
|
-
after(:create, :open, :close, :delete){
|
637
|
-
|
638
|
-
def redirect_index
|
639
|
-
redirect Rs()
|
640
|
-
end
|
631
|
+
after(:create, :open, :close, :delete){ redirect(Rs()) }
|
641
632
|
|
642
633
|
Alright, that looks a lot nicer already and is definitely easier to maintain.
|
643
|
-
Please note that the `#redirect_index` method should not be private, as it is a
|
644
|
-
usual action that will just run after the others.
|
645
634
|
|
646
|
-
There is a symmetrical
|
647
|
-
and in case you want to add required authentication for all actions of a
|
648
|
-
Controller you could use
|
635
|
+
There is a symmetrical `before` aspect that you could take advantage of as
|
636
|
+
well, and in case you want to add required authentication for all actions of a
|
637
|
+
Controller you could use `before_all` and `after_all` instead of a list of
|
638
|
+
action-names.
|
649
639
|
|
650
640
|
|
651
641
|
## Twelfth Step, Validation and Errors
|
@@ -669,7 +659,7 @@ from your users, so let's apply this advice.
|
|
669
659
|
if title = request['title']
|
670
660
|
title.strip!
|
671
661
|
if title.empty?
|
672
|
-
|
662
|
+
failed("Please enter a title")
|
673
663
|
redirect '/new'
|
674
664
|
end
|
675
665
|
TodoList[title] = {:done => false}
|
@@ -686,15 +676,15 @@ the session for one request, afterwards the hash is thrown away. This is
|
|
686
676
|
specifically useful for giving the user feedback while keeping a stateless
|
687
677
|
approach.
|
688
678
|
|
689
|
-
Let me show you our `#
|
679
|
+
Let me show you our `#failed` method (it goes in the private section to
|
690
680
|
`#task_status`):
|
691
681
|
|
692
|
-
def
|
682
|
+
def failed(message)
|
693
683
|
flash[:error] = message
|
694
684
|
end
|
695
685
|
|
696
686
|
Duh, you may say, wouldn't that fit in the one line instead of the call to
|
697
|
-
`#
|
687
|
+
`#failed`?
|
698
688
|
Indeed, it would, but let me remind you, we have no checks for changing the
|
699
689
|
status of a task yet. We will need error-handling there as well, so we just keep
|
700
690
|
our code DRY and maintainable by collecting shared behaviour in small pieces.
|
@@ -703,7 +693,7 @@ Now on to the `#task_status`:
|
|
703
693
|
|
704
694
|
def task_status title, status
|
705
695
|
unless task = TodoList[title]
|
706
|
-
|
696
|
+
failed "No such Task: `#{title}'"
|
707
697
|
redirect_referer
|
708
698
|
end
|
709
699
|
|
@@ -724,7 +714,7 @@ error-message in case it doesn't and redirect to wherever the browser came from.
|
|
724
714
|
|
725
715
|
But what about actually showing the error-messages we so carefully set? Well,
|
726
716
|
where do we change the view? Right, in the templates. But both templates we have
|
727
|
-
so far (index and new) share this behaviour, so
|
717
|
+
so far (index and new) share this behaviour, so we head over to the Element
|
728
718
|
and add in the right place:
|
729
719
|
|
730
720
|
<body>
|
@@ -740,6 +730,8 @@ and add in the right place:
|
|
740
730
|
The only thing special about it is the `\\#{flash[:error]}`, we have to escape
|
741
731
|
the `#` so it won't evaluate this immediately but wait until it is really
|
742
732
|
rendered.
|
743
|
-
|
733
|
+
As a note, If you read this as pure markaby, the double backslash is to output
|
734
|
+
properly to HTML, just use one instead.
|
735
|
+
Again, you can add some nifty style for that.
|
744
736
|
|
745
737
|
To be continued...
|