ramaze 2008.06 → 2008.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (184) hide show
  1. data/README.markdown +6 -6
  2. data/Rakefile +33 -3
  3. data/bin/ramaze +18 -0
  4. data/doc/CHANGELOG +960 -0
  5. data/doc/LEGAL +5 -1
  6. data/doc/meta/announcement.txt +20 -36
  7. data/doc/tutorial/todolist.html +421 -313
  8. data/doc/tutorial/todolist.mkd +33 -16
  9. data/examples/app/blog/spec/blog.rb +3 -3
  10. data/examples/app/rapaste/controller/paste.rb +8 -1
  11. data/examples/app/rapaste/model/paste.rb +3 -0
  12. data/examples/app/rapaste/spec/rapaste.rb +3 -1
  13. data/examples/app/rapaste/start.rb +3 -2
  14. data/examples/app/sourceview/public/sourceview.js +2 -2
  15. data/examples/app/todolist/spec/todolist.rb +6 -6
  16. data/examples/app/todolist/template/index.xhtml +1 -1
  17. data/examples/app/whywiki/spec/whywiki.rb +2 -2
  18. data/examples/app/wikore/spec/wikore.rb +2 -2
  19. data/examples/app/wikore/src/model.rb +4 -3
  20. data/examples/app/wiktacular/spec/wiktacular.rb +7 -7
  21. data/examples/basic/simple.rb +2 -2
  22. data/examples/helpers/paginate.rb +71 -0
  23. data/examples/misc/simple_auth.rb +20 -8
  24. data/lib/proto/controller/init.rb +10 -0
  25. data/lib/proto/controller/main.rb +1 -3
  26. data/lib/proto/model/init.rb +4 -0
  27. data/lib/proto/public/dispatch.fcgi +1 -1
  28. data/lib/proto/spec/main.rb +2 -1
  29. data/lib/proto/start.rb +3 -3
  30. data/lib/proto/start.ru +1 -1
  31. data/lib/proto/view/error.xhtml +4 -4
  32. data/lib/ramaze.rb +8 -3
  33. data/lib/ramaze/action.rb +6 -6
  34. data/lib/ramaze/adapter.rb +1 -6
  35. data/lib/ramaze/adapter/base.rb +30 -27
  36. data/lib/ramaze/adapter/cgi.rb +1 -0
  37. data/lib/ramaze/cache.rb +1 -3
  38. data/lib/ramaze/cache/memcached.rb +3 -5
  39. data/lib/ramaze/contrib/auto_params.rb +2 -2
  40. data/lib/ramaze/contrib/auto_params/get_args.rb +2 -1
  41. data/lib/ramaze/contrib/gems.rb +17 -18
  42. data/lib/ramaze/contrib/gzip_filter.rb +22 -9
  43. data/lib/ramaze/contrib/maruku_uv.rb +59 -0
  44. data/lib/ramaze/contrib/profiling.rb +1 -1
  45. data/lib/ramaze/contrib/rest.rb +16 -13
  46. data/lib/ramaze/contrib/sequel/create_join.rb +25 -0
  47. data/lib/ramaze/contrib/sequel/form_field.rb +129 -0
  48. data/lib/ramaze/contrib/sequel/image.rb +198 -0
  49. data/lib/ramaze/contrib/sequel/relation.rb +82 -0
  50. data/lib/ramaze/controller.rb +33 -34
  51. data/lib/ramaze/controller/resolve.rb +29 -9
  52. data/lib/ramaze/current.rb +60 -20
  53. data/lib/ramaze/current/request.rb +8 -7
  54. data/lib/ramaze/current/response.rb +15 -3
  55. data/lib/ramaze/current/session/flash.rb +8 -0
  56. data/lib/ramaze/dispatcher.rb +17 -9
  57. data/lib/ramaze/dispatcher/action.rb +4 -5
  58. data/lib/ramaze/dispatcher/directory.rb +1 -1
  59. data/lib/ramaze/dispatcher/error.rb +4 -4
  60. data/lib/ramaze/dispatcher/file.rb +4 -4
  61. data/lib/ramaze/gestalt.rb +15 -20
  62. data/lib/ramaze/helper/cgi.rb +7 -15
  63. data/lib/ramaze/helper/formatting.rb +41 -1
  64. data/lib/ramaze/helper/httpdigest.rb +20 -7
  65. data/lib/ramaze/helper/link.rb +4 -6
  66. data/lib/ramaze/helper/paginate.rb +233 -0
  67. data/lib/ramaze/helper/redirect.rb +1 -1
  68. data/lib/ramaze/helper/rest.rb +1 -1
  69. data/lib/ramaze/helper/thread.rb +17 -0
  70. data/lib/ramaze/helper/ultraviolet.rb +44 -0
  71. data/lib/ramaze/helper/user.rb +4 -9
  72. data/lib/ramaze/log.rb +2 -2
  73. data/lib/ramaze/log/analogger.rb +21 -23
  74. data/lib/ramaze/log/growl.rb +21 -23
  75. data/lib/ramaze/log/hub.rb +1 -1
  76. data/lib/ramaze/log/informer.rb +97 -99
  77. data/lib/ramaze/log/knotify.rb +14 -16
  78. data/lib/ramaze/log/logger.rb +11 -13
  79. data/lib/ramaze/log/logging.rb +61 -63
  80. data/lib/ramaze/log/rotatinginformer.rb +168 -0
  81. data/lib/ramaze/log/syslog.rb +41 -31
  82. data/lib/ramaze/log/xosd.rb +70 -72
  83. data/lib/ramaze/option.rb +9 -6
  84. data/lib/ramaze/option/holder.rb +5 -27
  85. data/lib/ramaze/reloader.rb +186 -0
  86. data/lib/ramaze/setup.rb +1 -1
  87. data/lib/ramaze/snippets.rb +13 -0
  88. data/lib/ramaze/snippets/array/put_within.rb +31 -24
  89. data/lib/ramaze/snippets/binding/locals.rb +23 -11
  90. data/lib/ramaze/snippets/dictionary.rb +2 -2
  91. data/lib/ramaze/snippets/fiber.rb +63 -0
  92. data/lib/ramaze/snippets/kernel/constant.rb +36 -21
  93. data/lib/ramaze/snippets/kernel/pretty_inspect.rb +12 -6
  94. data/lib/ramaze/snippets/numeric/filesize_format.rb +24 -17
  95. data/lib/ramaze/snippets/numeric/time.rb +63 -0
  96. data/lib/ramaze/snippets/object/__dir__.rb +29 -0
  97. data/lib/ramaze/snippets/object/acquire.rb +40 -0
  98. data/lib/ramaze/snippets/object/instance_variable_defined.rb +16 -5
  99. data/lib/ramaze/snippets/object/pretty.rb +14 -4
  100. data/lib/ramaze/snippets/object/scope.rb +14 -7
  101. data/lib/ramaze/snippets/ordered_set.rb +25 -14
  102. data/lib/ramaze/snippets/proc/locals.rb +17 -9
  103. data/lib/ramaze/snippets/ramaze/deprecated.rb +13 -0
  104. data/lib/ramaze/snippets/ramaze/fiber.rb +24 -0
  105. data/lib/ramaze/snippets/ramaze/state.rb +86 -0
  106. data/lib/ramaze/snippets/ramaze/struct.rb +45 -0
  107. data/lib/ramaze/snippets/string/camel_case.rb +13 -8
  108. data/lib/ramaze/snippets/string/color.rb +24 -20
  109. data/lib/ramaze/snippets/string/each.rb +14 -3
  110. data/lib/ramaze/snippets/string/end_with.rb +20 -0
  111. data/lib/ramaze/snippets/string/esc.rb +26 -21
  112. data/lib/ramaze/snippets/string/ord.rb +12 -6
  113. data/lib/ramaze/snippets/string/snake_case.rb +13 -7
  114. data/lib/ramaze/snippets/string/start_with.rb +16 -5
  115. data/lib/ramaze/snippets/string/unindent.rb +23 -15
  116. data/lib/ramaze/snippets/thread/into.rb +3 -3
  117. data/lib/ramaze/spec/helper/bacon.rb +5 -5
  118. data/lib/ramaze/spec/helper/mock_http.rb +1 -1
  119. data/lib/ramaze/spec/helper/pretty_output.rb +2 -2
  120. data/lib/ramaze/spec/helper/snippets.rb +8 -0
  121. data/lib/ramaze/template.rb +4 -1
  122. data/lib/ramaze/template/ezamar/textpow.syntax +34 -0
  123. data/lib/ramaze/template/maruku.rb +34 -0
  124. data/lib/ramaze/template/tagz.rb +2 -2
  125. data/lib/ramaze/template/xslt.rb +2 -2
  126. data/lib/ramaze/tool/create.rb +27 -53
  127. data/lib/ramaze/tool/localize.rb +8 -4
  128. data/lib/ramaze/tool/mime.rb +11 -1
  129. data/lib/ramaze/tool/project_creator.rb +110 -0
  130. data/lib/ramaze/trinity.rb +4 -1
  131. data/lib/ramaze/version.rb +1 -1
  132. data/lib/vendor/bacon.rb +323 -0
  133. data/rake_tasks/gem.rake +10 -1
  134. data/rake_tasks/maintenance.rake +40 -2
  135. data/rake_tasks/metric.rake +24 -0
  136. data/rake_tasks/release.rake +17 -4
  137. data/rake_tasks/spec.rake +1 -2
  138. data/ramaze.gemspec +549 -495
  139. data/spec/contrib/auto_params.rb +3 -3
  140. data/spec/contrib/profiling.rb +2 -2
  141. data/spec/examples/simple_auth.rb +2 -2
  142. data/spec/examples/templates/template_haml.rb +0 -2
  143. data/spec/ramaze/action/file_cache.rb +22 -0
  144. data/spec/ramaze/adapter.rb +2 -2
  145. data/spec/ramaze/controller/actionless_templates.rb +1 -1
  146. data/spec/ramaze/controller/subclass.rb +15 -0
  147. data/spec/ramaze/controller/template_resolving.rb +1 -1
  148. data/spec/ramaze/controller/view/bar.xhtml +1 -0
  149. data/spec/ramaze/controller/view/base/another.xhtml +1 -0
  150. data/spec/ramaze/current/session.rb +1 -1
  151. data/spec/ramaze/dispatcher/file.rb +2 -2
  152. data/spec/ramaze/helper/aspect.rb +26 -17
  153. data/spec/ramaze/helper/formatting.rb +13 -0
  154. data/spec/ramaze/log/informer.rb +10 -10
  155. data/spec/ramaze/log/syslog.rb +67 -4
  156. data/spec/ramaze/rewrite.rb +1 -1
  157. data/spec/ramaze/route.rb +1 -1
  158. data/spec/ramaze/struct.rb +47 -0
  159. data/spec/ramaze/template/markaby.rb +1 -1
  160. data/spec/ramaze/template/tagz.rb +1 -1
  161. data/spec/snippets/binding/locals.rb +9 -0
  162. data/spec/snippets/numeric/time.rb +12 -0
  163. data/spec/snippets/{kernel → object}/__dir__.rb +0 -0
  164. data/spec/snippets/{kernel → object}/acquire.rb +0 -0
  165. metadata +90 -81
  166. data/cache.yaml +0 -7
  167. data/examples/app/rammit/spec/rammit.rb +0 -31
  168. data/examples/app/rammit/src/controller/main.rb +0 -3
  169. data/examples/app/rammit/src/controller/page.rb +0 -16
  170. data/examples/app/rammit/src/model.rb +0 -33
  171. data/examples/app/rammit/start.rb +0 -8
  172. data/examples/app/rammit/template/index.xhtml +0 -14
  173. data/examples/app/rammit/template/page/view.xhtml +0 -4
  174. data/lib/ramaze/snippets/kernel/__dir__.rb +0 -23
  175. data/lib/ramaze/snippets/kernel/acquire.rb +0 -34
  176. data/lib/ramaze/snippets/object/thread_accessor.rb +0 -5
  177. data/lib/ramaze/snippets/ramaze/thread_accessor.rb +0 -58
  178. data/lib/ramaze/snippets/struct/fill.rb +0 -23
  179. data/lib/ramaze/snippets/struct/values_at.rb +0 -39
  180. data/lib/ramaze/snippets/symbol/to_proc.rb +0 -24
  181. data/lib/ramaze/sourcereload.rb +0 -176
  182. data/spec/snippets/struct/fill.rb +0 -26
  183. data/spec/snippets/struct/values_at.rb +0 -52
  184. data/spec/snippets/symbol/to_proc.rb +0 -13
data/doc/LEGAL CHANGED
@@ -14,9 +14,13 @@ lib/proto/js/jquery.js
14
14
  Author: John Resig
15
15
 
16
16
  lib/ramaze/spec/helper/simple_http.rb
17
- License: GPL
17
+ License: Ruby
18
18
  Author: Tim Becker
19
19
 
20
20
  lib/ramaze/template/xslt.rb
21
21
  License: Ruby
22
22
  Author: Stephan Maka
23
+
24
+ lib/vendor/bacon.rb
25
+ License: MIT
26
+ Author: Christian Neukirchen
@@ -1,4 +1,4 @@
1
- This time we are proud to announce Version 2008.06 of Ramaze, the light and
1
+ This time we are proud to announce Version 2008.07 of Ramaze, the light and
2
2
  modular open source web framework.
3
3
 
4
4
  This release features a lot of work directly from our community and we are
@@ -10,11 +10,11 @@ implementation and usage. Ramaze is under development by a growing community
10
10
  and in production use at companies.
11
11
 
12
12
 
13
- Home page: http://ramaze.net
14
- Screencasts: http://ramaze.net/screencasts
13
+ Home page: http://ramaze.net
14
+ Screencasts: http://ramaze.net/screencasts
15
15
 
16
- View source: http://source.ramaze.net
17
- Github: http://github.com/manveru/ramaze
16
+ Source browser: http://source.ramaze.net
17
+ Repository: http://github.com/manveru/ramaze
18
18
 
19
19
  Nightly gems: http://gems.ramaze.net
20
20
  Git clone: git://github.com/manveru/ramaze
@@ -36,41 +36,25 @@ Simple example:
36
36
  Ramaze.start
37
37
 
38
38
 
39
- This is a special release, and the first of the upcoming new series of monthly releases.
40
- As you may have noticed, Ramaze has changed to a date base versioning system,
41
- although this means that people who have waited for a 1.0 for the past years
42
- may be disappointed it provides much larger flexibility in detecting new
43
- versions and comparing them with nightly builds.
39
+ Some of 52 patches since 2008.06:
44
40
 
45
- Another change is the switch from darcs to git and moving our primary
46
- repository to github. There have been serious performance issues regarding
47
- darcs as Ramaze gathered a longer history, using git allows us to move on at a
48
- faster pace again.
49
-
50
- Please regard this release as a major step from the previous one, over 450
51
- patches have been applied and there were changes in the internal API.
52
-
53
- We are unable to nicely summarize these changes, so this release will not have
54
- a list of the most important ones, if you are concerned about a specific area
55
- feel free to ask on the Mailing list or stop by on IRC.
41
+ - Loggers are now in Ramaze::Logger namespace
42
+ - Global.prefix for nested deployment via webserver in front
43
+ - Binding#locals fixed for Ruby 1.9
44
+ - Redirects now use HTTP status 302 instead of 303
45
+ - Logger::Syslog works again
56
46
 
57
47
  Special (alphabetic) thanks go to:
58
48
 
59
- Aman 'tmm1' Gupta - Tons of patches, support
60
- andy - Cleanup
61
- Ara T. Howard - Tagz templating engine
62
- Clive Crous - Patches, cleanup
63
- evaryont - Patches for identity helper
64
- James Tucker - OSX compatibility, cleanup and fixes
65
- Jonathan 'Kashia' Buch - Patches, support and the first ramaze paper
66
- Keita Yamaguchi - Much work on the benchmark suite
67
- Leo Borisenko - Fix for SourceReload on windows
68
- Pistos - Mathetes, patches and lots of friendly support
69
- Riku Räisäenen - Patches for scaffolding example
70
- Ryan Grove - Various fixes and patches
71
- Sam Carr - Patches and action matching speedup
72
- Thomas Leitner - Patches for identity helper
73
- Wang Jinjing - patches, 1.9/1.8.7 compatibility
49
+ Pistos - The usual Mathetes, patches and lots of friendly support
50
+ Aman 'tmm1' Gupta - Time snippets for numeric
51
+ Clinton R. Nixon - More REST and some fixes
52
+ Jean-Francois Chevrette - Restore --console feature
53
+ raggi - Various fixes
54
+ Rob Lievaart - Fix Logger::Syslog
55
+ Sam Carr - Cleanup of Cache
56
+ Wang Jinjing - 1.9 compatibility
57
+ Yasushi Abe - First patch!
74
58
 
75
59
  A complete Changelog is available at
76
60
  http://github.com/manveru/ramaze/tree/master/doc/CHANGELOG?raw=true
@@ -2,26 +2,89 @@
2
2
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">
3
3
  <html xml:lang="en" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/1999/xhtml">
4
4
  <head><meta content="application/xhtml+xml;charset=utf-8" http-equiv="Content-type" /><title>The official Ramaze todolist tutorial</title><style type="text/css">
5
- .ruby .normal {}
6
- .ruby .comment { color: #005; font-style: italic; }
7
- .ruby .keyword { color: #A00; font-weight: bold; }
8
- .ruby .method { color: #077; }
9
- .ruby .class { color: #074; }
10
- .ruby .module { color: #050; }
11
- .ruby .punct { color: #447; font-weight: bold; }
12
- .ruby .symbol { color: #099; }
13
- .ruby .string { color: #944; background: #FFE; }
14
- .ruby .char { color: #F07; }
15
- .ruby .ident { color: #004; }
16
- .ruby .constant { color: #07F; }
17
- .ruby .regex { color: #B66; background: #FEF; }
18
- .ruby .number { color: #F99; }
19
- .ruby .attribute { color: #7BB; }
20
- .ruby .global { color: #7FB; }
21
- .ruby .expr { color: #227; }
22
- .ruby .escape { color: #277; }
23
-
24
- </style></head>
5
+ pre { margin: 1em; padding: 1em; }
6
+ pre.iplastic .Constant {
7
+ color: #6782D3;
8
+ }
9
+ pre.iplastic .Support {
10
+ font-weight: bold;
11
+ color: #3333FF;
12
+ }
13
+ pre.iplastic .EmbeddedSource {
14
+ background-color: #F9F9F9;
15
+ color: #000000;
16
+ }
17
+ pre.iplastic .Arguments {
18
+ font-style: italic;
19
+ }
20
+ pre.iplastic .TypeName {
21
+ font-weight: bold;
22
+ }
23
+ pre.iplastic .Identifier {
24
+ color: #9700CC;
25
+ }
26
+ pre.iplastic .Number {
27
+ color: #0066FF;
28
+ }
29
+ pre.iplastic .SectionName {
30
+ font-weight: bold;
31
+ }
32
+ pre.iplastic .Storage {
33
+ font-weight: bold;
34
+ }
35
+ pre.iplastic .line-numbers {
36
+ background-color: #BAD6FD;
37
+ color: #000000;
38
+ }
39
+ pre.iplastic {
40
+ background-color: #EEEEEE;
41
+ color: #000000;
42
+ }
43
+ pre.iplastic .FrameTitle {
44
+ font-weight: bold;
45
+ color: #000000;
46
+ }
47
+ pre.iplastic .TagName {
48
+ font-weight: bold;
49
+ }
50
+ pre.iplastic .Tag {
51
+ color: #0033CC;
52
+ }
53
+ pre.iplastic .Exception {
54
+ color: #990000;
55
+ }
56
+ pre.iplastic .XmlDeclaration {
57
+ color: #333333;
58
+ }
59
+ pre.iplastic .TrailingWhitespace {
60
+ background-color: #EEEEEE;
61
+ }
62
+ pre.iplastic .TagAttribute {
63
+ color: #3366CC;
64
+ font-style: italic;
65
+ }
66
+ pre.iplastic .Invalid {
67
+ background-color: #E7342D;
68
+ color: #FF0000;
69
+ }
70
+ pre.iplastic .Keyword {
71
+ color: #0000FF;
72
+ }
73
+ pre.iplastic .String {
74
+ color: #009933;
75
+ }
76
+ pre.iplastic .Comment {
77
+ color: #0066FF;
78
+ font-style: italic;
79
+ }
80
+ pre.iplastic .FunctionName {
81
+ color: #FF8000;
82
+ }
83
+ pre.iplastic .RegularExpression {
84
+ color: #FF0080;
85
+ }
86
+
87
+ </style></head>
25
88
  <body>
26
89
  <h1 id="todo_list_tutorial">To-do List Tutorial</h1>
27
90
  <div class="maruku_toc"><ul style="list-style: none;"><li><a href="#step_zero_introduction">Step Zero, Introduction</a></li><li><a href="#first_step_create">First Step, Create</a></li><li><a href="#second_step_m_like_model">Second Step, M, like Model</a></li><li><a href="#third_step_v_like_view">Third Step, V, like View</a></li><li><a href="#fourth_step_c_like_controller">Fourth Step, C, like Controller</a></li><li><a href="#fifth_step_getting_dynamic">Fifth Step, getting dynamic</a></li><li><a href="#sixth_step_open_and_close_tasks">Sixth Step, open and close tasks</a></li><li><a href="#seventh_step_delete_tasks">Seventh Step, delete tasks</a></li><li><a href="#eighth_step_elements">Eighth Step, Elements</a></li><li><a href="#ninth_step_prettify">Ninth Step, Prettify</a></li><li><a href="#tenth_step_configuration">Tenth Step, Configuration</a></li><li><a href="#eleventh_step_refactor_with_aspecthelper">Eleventh Step, Refactor with AspectHelper</a></li><li><a href="#twelfth_step_validation_and_errors">Twelfth Step, Validation and Errors</a></li></ul></div>
@@ -49,7 +112,8 @@
49
112
 
50
113
  <p>So run:</p>
51
114
 
52
- <pre><code>$ ramaze --create todolist</code></pre>
115
+ <pre class="iplastic"><code class="shell-unix-generic" lang="shell-unix-generic">ramaze --create todolist
116
+ </code></pre>
53
117
 
54
118
  <p>done.</p>
55
119
 
@@ -59,16 +123,18 @@
59
123
 
60
124
  <p>So first, create a <code>model/todolist.rb</code> for our application:</p>
61
125
 
62
- <pre><code class="ruby" lang="ruby"><span class="ident">require</span> <span class="punct">&#39;</span><span class="string">ramaze/store/default</span><span class="punct">&#39;</span>
63
- <span class="constant">TodoList</span> <span class="punct">=</span> <span class="constant">Ramaze</span><span class="punct">::</span><span class="constant">Store</span><span class="punct">::</span><span class="constant">Default</span><span class="punct">.</span><span class="ident">new</span><span class="punct">(&#39;</span><span class="string">todolist.yaml</span><span class="punct">&#39;)</span></code></pre>
126
+ <pre class="iplastic"><code class="ruby" lang="ruby"><span class="Keyword">require</span> <span class="String"><span class="String">'</span>ramaze/store/default<span class="String">'</span></span>
127
+ TodoList <span class="Keyword">=</span> <span class="Support">Ramaze</span>::<span class="FunctionName">Store</span>::<span class="FunctionName">Default</span>.<span class="FunctionName">new</span>(<span class="String"><span class="String">'</span>todolist.yaml<span class="String">'</span></span>)
128
+ </code></pre>
64
129
 
65
130
  <p>Let&#8217;s add some items as well to have a base to start from.</p>
66
131
 
67
- <pre><code class="ruby" lang="ruby"><span class="punct">{</span> <span class="punct">&#39;</span><span class="string">Laundry</span><span class="punct">&#39;</span> <span class="punct">=&gt;</span> <span class="punct">{</span><span class="symbol">:done</span> <span class="punct">=&gt;</span> <span class="constant">false</span><span class="punct">},</span>
68
- <span class="punct">&#39;</span><span class="string">Wash dishes</span><span class="punct">&#39;</span> <span class="punct">=&gt;</span> <span class="punct">{</span><span class="symbol">:done</span> <span class="punct">=&gt;</span> <span class="constant">false</span><span class="punct">},</span>
69
- <span class="punct">}.</span><span class="ident">each</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">title</span><span class="punct">,</span> <span class="ident">value</span><span class="punct">|</span>
70
- <span class="constant">TodoList</span><span class="punct">[</span><span class="ident">title</span><span class="punct">]</span> <span class="punct">=</span> <span class="ident">value</span>
71
- <span class="keyword">end</span></code></pre>
132
+ <pre class="iplastic"><code class="ruby" lang="ruby">{ <span class="String"><span class="String">'</span>Laundry<span class="String">'</span></span> =&gt; {<span class="Constant"><span class="Constant">:</span>done</span> =&gt; <span class="Identifier">false</span>},
133
+ <span class="String"><span class="String">'</span>Wash dishes<span class="String">'</span></span> =&gt; {<span class="Constant"><span class="Constant">:</span>done</span> =&gt; <span class="Identifier">false</span>},
134
+ }.<span class="FunctionName">each</span> <span class="Keyword">do </span>|title, value|
135
+ <span class="Support">TodoList</span>[title] <span class="Keyword">=</span> value
136
+ <span class="Keyword">end</span>
137
+ </code></pre>
72
138
 
73
139
  <h2 id="third_step_v_like_view">Third Step, V, like View</h2>
74
140
 
@@ -80,22 +146,23 @@
80
146
 
81
147
  <p>Let&#8217;s put some things in there, I&#8217;ll explain the syntax as we go, it&#8217;s quite simple.</p>
82
148
 
83
- <pre><code class="nagoro" lang="nagoro">&lt;html&gt;
84
- &lt;head&gt;
85
- &lt;title&gt;TodoList&lt;/title&gt;
86
- &lt;/head&gt;
87
- &lt;body&gt;
88
- &lt;h1&gt;TodoList&lt;/h1&gt;
89
- &lt;ul&gt;
90
- &lt;?r
91
- TodoList.each do |title, value|
92
- status = value[:done] ? &#39;done&#39; : &#39;not done&#39;
93
- ?&gt;
94
- &lt;li&gt;#{c title}: #{status}&lt;/li&gt;
95
- &lt;?r end ?&gt;
96
- &lt;/ul&gt;
97
- &lt;/body&gt;
98
- &lt;/html&gt;</code></pre>
149
+ <pre class="iplastic"><code class="html" lang="html"><span class="Tag"><span class="Tag">&lt;</span><span class="TagName">html</span><span class="Tag">&gt;</span></span>
150
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">head</span><span class="Tag">&gt;</span></span>
151
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">title</span><span class="Tag">&gt;</span></span>TodoList<span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">title</span><span class="Tag">&gt;</span></span>
152
+ <span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">head</span><span class="Tag">&gt;</span></span>
153
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">body</span><span class="Tag">&gt;</span></span>
154
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">h1</span><span class="Tag">&gt;</span></span>TodoList<span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">h1</span><span class="Tag">&gt;</span></span>
155
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">ul</span><span class="Tag">&gt;</span></span>
156
+ <span class="EmbeddedSource"> <span class="EmbeddedSource"><span class="EmbeddedSource">&lt;?</span><span class="Constant">r</span></span></span>
157
+ <span class="EmbeddedSource"><span class="EmbeddedSource"> <span class="Constant">TodoList</span><span class="Keyword">.</span><span class="Constant">each</span> <span class="Keyword">do</span> <span class="Keyword">|</span><span class="Constant">title</span>, <span class="Constant">value</span><span class="Keyword">|</span></span></span>
158
+ <span class="EmbeddedSource"><span class="EmbeddedSource"> <span class="Constant">status</span> <span class="Keyword">=</span> <span class="Constant">value</span>[:<span class="Constant">done</span>] ? <span class="String"><span class="String">'</span><span class="String">done</span><span class="String">'</span></span> : <span class="String"><span class="String">'</span><span class="String">not done</span><span class="String">'</span></span></span></span>
159
+ <span class="EmbeddedSource"><span class="EmbeddedSource"> <span class="EmbeddedSource"><span class="EmbeddedSource">?</span>&gt;</span></span></span>
160
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">li</span><span class="Tag">&gt;</span></span>#<span class="EmbeddedSource">{h title}</span>: #<span class="EmbeddedSource">{status}</span><span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">li</span><span class="Tag">&gt;</span></span>
161
+ <span class="EmbeddedSource"><span class="EmbeddedSource">&lt;?r</span> <span class="Keyword">end</span> <span class="EmbeddedSource">?&gt;</span></span>
162
+ <span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">ul</span><span class="Tag">&gt;</span></span>
163
+ <span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">body</span><span class="Tag">&gt;</span></span>
164
+ <span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">html</span><span class="Tag">&gt;</span></span>
165
+ </code></pre>
99
166
 
100
167
  <p>I will assume that you are familiar with basic Ruby already, so we will concentrate on the things new here.</p>
101
168
 
@@ -103,10 +170,11 @@
103
170
 
104
171
  <p>The whole Template would expand to something like this (only showing the interesting part)</p>
105
172
 
106
- <pre><code class="nagoro" lang="nagoro">&lt;ul&gt;
107
- &lt;li&gt;Laundry: not done&lt;/li&gt;
108
- &lt;li&gt;Wash dishes: not done&lt;/li&gt;
109
- &lt;/ul&gt;</code></pre>
173
+ <pre class="iplastic"><code class="html" lang="html"><span class="Tag"><span class="Tag">&lt;</span><span class="TagName">ul</span><span class="Tag">&gt;</span></span>
174
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">li</span><span class="Tag">&gt;</span></span>Laundry: not done<span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">li</span><span class="Tag">&gt;</span></span>
175
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">li</span><span class="Tag">&gt;</span></span>Wash dishes: not done<span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">li</span><span class="Tag">&gt;</span></span>
176
+ <span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">ul</span><span class="Tag">&gt;</span></span>
177
+ </code></pre>
110
178
 
111
179
  <p>That wasn&#8217;t too bad, huh?</p>
112
180
 
@@ -132,47 +200,50 @@
132
200
 
133
201
  <p>The contents of it are like following:</p>
134
202
 
135
- <pre><code class="ruby" lang="ruby"><span class="keyword">class </span><span class="class">MainController</span> <span class="punct">&lt;</span> <span class="constant">Controller</span>
136
- <span class="keyword">def </span><span class="method">index</span>
137
- <span class="attribute">@welcome</span> <span class="punct">=</span> <span class="punct">&quot;</span><span class="string">Welcome to Ramaze!</span><span class="punct">&quot;</span>
138
- <span class="keyword">end</span>
203
+ <pre class="iplastic"><code class="ruby" lang="ruby"><span class="Keyword">class</span> <span class="TypeName">MainController<span class="TypeName"> <span class="TypeName">&lt;</span> Controller</span></span>
204
+ <span class="Keyword">def</span> <span class="FunctionName">index</span>
205
+ @welcome <span class="Keyword">=</span> <span class="String"><span class="String">&quot;</span>Welcome to Ramaze!<span class="String">&quot;</span></span>
206
+ <span class="Keyword">end</span>
139
207
 
140
- <span class="keyword">def </span><span class="method">notemplate</span>
141
- <span class="punct">&quot;</span><span class="string">there is no template associated with this action</span><span class="punct">&quot;</span>
142
- <span class="keyword">end</span>
143
- <span class="keyword">end</span></code></pre>
208
+ <span class="Keyword">def</span> <span class="FunctionName">notemplate</span>
209
+ <span class="String"><span class="String">&quot;</span>there is no template associated with this action<span class="String">&quot;</span></span>
210
+ <span class="Keyword">end</span>
211
+ <span class="Keyword">end</span>
212
+ </code></pre>
144
213
 
145
214
  <p>The only methods right now are <code>#index</code> and <code>#notemplate</code>. The relationship between the methods on the controller and the templates is 1:1, so the method <code>#index</code> is combined with the template <code>index.xhtml</code>. This combination is called an <code>action</code>.</p>
146
215
 
147
216
  <p>Let&#8217;s get back to editing and change the method <code>#index</code> to this:</p>
148
217
 
149
- <pre><code class="ruby" lang="ruby"><span class="keyword">def </span><span class="method">index</span>
150
- <span class="attribute">@tasks</span> <span class="punct">=</span> <span class="constant">TodoList</span><span class="punct">.</span><span class="ident">original</span>
151
- <span class="attribute">@tasks</span><span class="punct">.</span><span class="ident">each</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">title</span><span class="punct">,</span> <span class="ident">value</span><span class="punct">|</span>
152
- <span class="ident">status</span> <span class="punct">=</span> <span class="ident">value</span><span class="punct">[</span><span class="symbol">:done</span><span class="punct">]</span> <span class="punct">?</span> <span class="punct">&#39;</span><span class="string">done</span><span class="punct">&#39;</span> <span class="punct">:</span> <span class="punct">&#39;</span><span class="string">not done</span><span class="punct">&#39;</span>
153
- <span class="attribute">@tasks</span><span class="punct">[</span><span class="ident">title</span><span class="punct">]</span> <span class="punct">=</span> <span class="ident">status</span>
154
- <span class="keyword">end</span>
155
- <span class="keyword">end</span></code></pre>
218
+ <pre class="iplastic"><code class="ruby" lang="ruby"><span class="Keyword">def</span> <span class="FunctionName">index</span>
219
+ @tasks <span class="Keyword">=</span> <span class="Support">TodoList</span>.<span class="FunctionName">original</span>
220
+ @tasks.<span class="FunctionName">each</span> <span class="Keyword">do </span>|title, value|
221
+ status <span class="Keyword">=</span> value[<span class="Constant"><span class="Constant">:</span>done</span>] <span class="Keyword">?</span> <span class="String"><span class="String">'</span>done<span class="String">'</span></span> : <span class="String"><span class="String">'</span>not done<span class="String">'</span></span>
222
+ @tasks[title] <span class="Keyword">=</span> status
223
+ <span class="Keyword">end</span>
224
+ <span class="Keyword">end</span>
225
+ </code></pre>
156
226
 
157
227
  <p>This will take care of the logic inside the template, which now should be changed to do following:</p>
158
228
 
159
- <pre><code class="ruby" lang="ruby"><span class="punct">&lt;</span><span class="ident">html</span><span class="punct">&gt;</span>
160
- <span class="punct">&lt;</span><span class="ident">head</span><span class="punct">&gt;</span>
161
- <span class="punct">&lt;</span><span class="ident">title</span><span class="punct">&gt;</span><span class="constant">TodoList</span><span class="punct">&lt;/</span><span class="regex">title&gt;
162
- &lt;</span><span class="punct">/</span><span class="ident">head</span><span class="punct">&gt;</span>
163
- <span class="punct">&lt;</span><span class="ident">body</span><span class="punct">&gt;</span>
164
- <span class="punct">&lt;</span><span class="ident">h1</span><span class="punct">&gt;</span><span class="constant">TodoList</span><span class="punct">&lt;/</span><span class="regex">h1&gt;
165
- &lt;?r if @tasks.empty? ?&gt;
229
+ <pre class="iplastic"><code class="ezamar" lang="ezamar"><span class="Tag"><span class="Tag">&lt;</span><span class="TagName">html</span><span class="Tag">&gt;</span></span>
230
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">head</span><span class="Tag">&gt;</span></span>
231
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">title</span><span class="Tag">&gt;</span></span>TodoList<span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">title</span><span class="Tag">&gt;</span></span>
232
+ <span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">head</span><span class="Tag">&gt;</span></span>
233
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">body</span><span class="Tag">&gt;</span></span>
234
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">h1</span><span class="Tag">&gt;</span></span>TodoList<span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">h1</span><span class="Tag">&gt;</span></span>
235
+ <span class="EmbeddedSource"><span class="EmbeddedSource">&lt;?r</span> <span class="Keyword">if</span> <span class="EmbeddedSource"><span class="EmbeddedSource">@</span>tasks</span><span class="EmbeddedSource"><span class="EmbeddedSource">.</span><span class="FunctionName">empty?</span></span> <span class="EmbeddedSource">?&gt;</span></span>
166
236
  No Tasks
167
- &lt;?r else ?&gt;
168
- &lt;ul&gt;
169
- &lt;?r @tasks.each do |title, status| ?&gt;
170
- &lt;li&gt;<span class="expr">#{c title}</span>: <span class="expr">#{status}</span>&lt;</span><span class="punct">/</span><span class="ident">li</span><span class="punct">&gt;</span>
171
- <span class="punct">&lt;</span><span class="char">?r</span> <span class="keyword">end</span> <span class="char">?&gt;</span>
172
- <span class="punct">&lt;/</span><span class="regex">ul&gt;
173
- &lt;?r end ?&gt;
174
- &lt;</span><span class="punct">/</span><span class="ident">body</span><span class="punct">&gt;</span>
175
- <span class="punct">&lt;/</span><span class="regex">html&gt;</span></code></pre>
237
+ <span class="EmbeddedSource"><span class="EmbeddedSource">&lt;?r</span> <span class="Keyword">else</span> <span class="EmbeddedSource">?&gt;</span></span>
238
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">ul</span><span class="Tag">&gt;</span></span>
239
+ <span class="EmbeddedSource"><span class="EmbeddedSource">&lt;?r</span> <span class="EmbeddedSource"><span class="EmbeddedSource">@</span>tasks</span><span class="EmbeddedSource"><span class="EmbeddedSource">.</span><span class="FunctionName">each</span></span> <span class="Keyword">do </span><span class="EmbeddedSource">|</span><span class="EmbeddedSource">title</span><span class="EmbeddedSource">,</span> <span class="EmbeddedSource">status</span><span class="EmbeddedSource">|</span> <span class="EmbeddedSource">?&gt;</span></span>
240
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">li</span><span class="Tag">&gt;</span></span>#<span class="EmbeddedSource">{h title}</span>: #<span class="EmbeddedSource">{status}</span><span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">li</span><span class="Tag">&gt;</span></span>
241
+ <span class="EmbeddedSource"><span class="EmbeddedSource">&lt;?r</span> <span class="Keyword">end</span> <span class="EmbeddedSource">?&gt;</span></span>
242
+ <span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">ul</span><span class="Tag">&gt;</span></span>
243
+ <span class="EmbeddedSource"><span class="EmbeddedSource">&lt;?r</span> <span class="Keyword">end</span> <span class="EmbeddedSource">?&gt;</span></span>
244
+ <span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">body</span><span class="Tag">&gt;</span></span>
245
+ <span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">html</span><span class="Tag">&gt;</span></span>
246
+ </code></pre>
176
247
 
177
248
  <p>The rest of the template can stay the same.</p>
178
249
 
@@ -192,24 +263,26 @@
192
263
 
193
264
  <p>Add a link on the <code>view/index.xhtml</code> like this:</p>
194
265
 
195
- <pre><code>&lt;h1&gt;TodoList&lt;/h1&gt;
196
- &lt;a href=&quot;/new&quot;&gt;New Task&lt;/a&gt;</code></pre>
266
+ <pre class="iplastic"><code class="ezamar" lang="ezamar"><span class="Tag"><span class="Tag">&lt;</span><span class="TagName">h1</span><span class="Tag">&gt;</span></span>TodoList<span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">h1</span><span class="Tag">&gt;</span></span>
267
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">a</span> <span class="TagAttribute">href</span>=<span class="String"><span class="String">&quot;</span>/new<span class="String">&quot;</span></span><span class="Tag">&gt;</span></span>New Task<span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">a</span><span class="Tag">&gt;</span></span>
268
+ </code></pre>
197
269
 
198
270
  <p>Open a new file <code>view/new.xhtml</code> with a form to add a new task.</p>
199
271
 
200
- <pre><code>&lt;html&gt;
201
- &lt;head&gt;
202
- &lt;title&gt;TodoList&lt;/title&gt;
203
- &lt;/head&gt;
204
- &lt;body&gt;
205
- &lt;h1&gt;New Task&lt;/h1&gt;
206
- &lt;a href=&quot;/&quot;&gt;Back to TodoList&lt;/a&gt;
207
- &lt;form method=&quot;POST&quot; action=&quot;create&quot;&gt;
208
- Task: &lt;input type=&quot;text&quot; name=&quot;title&quot; /&gt;&lt;br /&gt;
209
- &lt;input type=&quot;submit&quot; /&gt;
210
- &lt;/form&gt;
211
- &lt;/body&gt;
212
- &lt;/html&gt;</code></pre>
272
+ <pre class="iplastic"><code class="ezamar" lang="ezamar"><span class="Tag"><span class="Tag">&lt;</span><span class="TagName">html</span><span class="Tag">&gt;</span></span>
273
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">head</span><span class="Tag">&gt;</span></span>
274
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">title</span><span class="Tag">&gt;</span></span>TodoList<span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">title</span><span class="Tag">&gt;</span></span>
275
+ <span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">head</span><span class="Tag">&gt;</span></span>
276
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">body</span><span class="Tag">&gt;</span></span>
277
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">h1</span><span class="Tag">&gt;</span></span>New Task<span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">h1</span><span class="Tag">&gt;</span></span>
278
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">a</span> <span class="TagAttribute">href</span>=<span class="String"><span class="String">&quot;</span>/<span class="String">&quot;</span></span><span class="Tag">&gt;</span></span>Back to TodoList<span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">a</span><span class="Tag">&gt;</span></span>
279
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">form</span> <span class="TagAttribute">method</span>=<span class="String"><span class="String">&quot;</span>POST<span class="String">&quot;</span></span> <span class="TagAttribute">action</span>=<span class="String"><span class="String">&quot;</span>create<span class="String">&quot;</span></span><span class="Tag">&gt;</span></span>
280
+ Task: <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">input</span> <span class="TagAttribute">type</span>=<span class="String"><span class="String">&quot;</span>text<span class="String">&quot;</span></span> <span class="TagAttribute">name</span>=<span class="String"><span class="String">&quot;</span>title<span class="String">&quot;</span></span> /<span class="Tag">&gt;</span></span><span class="Tag"><span class="Tag">&lt;</span><span class="TagName">br</span> /<span class="Tag">&gt;</span></span>
281
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">input</span> <span class="TagAttribute">type</span>=<span class="String"><span class="String">&quot;</span>submit<span class="String">&quot;</span></span> /<span class="Tag">&gt;</span></span>
282
+ <span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">form</span><span class="Tag">&gt;</span></span>
283
+ <span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">body</span><span class="Tag">&gt;</span></span>
284
+ <span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">html</span><span class="Tag">&gt;</span></span>
285
+ </code></pre>
213
286
 
214
287
  <p>We will not need a method for this on our controller, in fact, actions can consist of either method and template or only one of them. The Controller can act as a View and the View can work like you may know it from PHP.</p>
215
288
 
@@ -221,11 +294,12 @@
221
294
 
222
295
  <p>OK, let&#8217;s implement the action for <code>#create</code>, all we want to do is take the requests parameters and create a new task for it, this looks like following on your MainController.</p>
223
296
 
224
- <pre><code class="ruby" lang="ruby"><span class="keyword">def </span><span class="method">create</span>
225
- <span class="ident">title</span> <span class="punct">=</span> <span class="ident">request</span><span class="punct">[&#39;</span><span class="string">title</span><span class="punct">&#39;]</span>
226
- <span class="constant">TodoList</span><span class="punct">[</span><span class="ident">title</span><span class="punct">]</span> <span class="punct">=</span> <span class="punct">{</span><span class="symbol">:done</span> <span class="punct">=&gt;</span> <span class="constant">false</span><span class="punct">}</span>
227
- <span class="ident">redirect</span> <span class="constant">Rs</span><span class="punct">()</span>
228
- <span class="keyword">end</span></code></pre>
297
+ <pre class="iplastic"><code class="ruby" lang="ruby"><span class="Keyword">def</span> <span class="FunctionName">create</span>
298
+ title <span class="Keyword">=</span> request[<span class="String"><span class="String">'</span>title<span class="String">'</span></span>]
299
+ <span class="Support">TodoList</span>[title] <span class="Keyword">=</span> {<span class="Constant"><span class="Constant">:</span>done</span> =&gt; <span class="Identifier">false</span>}
300
+ redirect Rs()
301
+ <span class="Keyword">end</span>
302
+ </code></pre>
229
303
 
230
304
  <p>That&#8217;s all folks!</p>
231
305
 
@@ -239,34 +313,37 @@
239
313
 
240
314
  <p>Jump into <code>view/index.xhtml</code> and do the following:</p>
241
315
 
242
- <pre><code class="ruby" lang="ruby"><span class="punct">&lt;</span><span class="char">?r</span> <span class="attribute">@tasks</span><span class="punct">.</span><span class="ident">each</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">title</span><span class="punct">,</span> <span class="ident">status</span><span class="punct">,</span> <span class="ident">toggle</span><span class="punct">|</span> <span class="char">?&gt;</span>
243
- <span class="punct">&lt;</span><span class="ident">li</span><span class="punct">&gt;</span>
244
- <span class="comment">#{c title}: #{status} - [ #{toggle} ]</span>
245
- <span class="punct">&lt;/</span><span class="regex">li&gt;
246
- &lt;?r end</span></code></pre>
316
+ <pre class="iplastic"><code class="ezamar" lang="ezamar"><span class="EmbeddedSource"><span class="EmbeddedSource">&lt;?r</span> <span class="EmbeddedSource"><span class="EmbeddedSource">@</span>tasks</span><span class="EmbeddedSource"><span class="EmbeddedSource">.</span><span class="FunctionName">each</span></span> <span class="Keyword">do </span><span class="EmbeddedSource">|</span><span class="EmbeddedSource">title</span><span class="EmbeddedSource">,</span> <span class="EmbeddedSource">status</span><span class="EmbeddedSource">,</span> <span class="EmbeddedSource">toggle</span><span class="EmbeddedSource">|</span> <span class="EmbeddedSource">?&gt;</span></span>
317
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">li</span><span class="Tag">&gt;</span></span>
318
+ #<span class="EmbeddedSource">{h title}</span>: #<span class="EmbeddedSource">{status}</span> - [ #<span class="EmbeddedSource">{toggle}</span> ]
319
+ <span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">li</span><span class="Tag">&gt;</span></span>
320
+ <span class="EmbeddedSource"><span class="EmbeddedSource">&lt;?r</span> <span class="Keyword">end</span></span>
321
+ </code></pre>
247
322
 
248
323
  <p>We added a new element here, <code>toggle</code>, the Controller should give us a link to change the status corresponding to the status of the task, so off we go and change the index method on the controller once again:</p>
249
324
 
250
- <pre><code class="ruby" lang="ruby"><span class="keyword">def </span><span class="method">index</span>
251
- <span class="attribute">@tasks</span> <span class="punct">=</span> <span class="punct">[]</span>
252
- <span class="constant">TodoList</span><span class="punct">.</span><span class="ident">original</span><span class="punct">.</span><span class="ident">each</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">title</span><span class="punct">,</span> <span class="ident">value</span><span class="punct">|</span>
253
- <span class="keyword">if</span> <span class="ident">value</span><span class="punct">[</span><span class="symbol">:done</span><span class="punct">]</span>
254
- <span class="ident">status</span> <span class="punct">=</span> <span class="punct">&#39;</span><span class="string">done</span><span class="punct">&#39;</span>
255
- <span class="ident">toggle</span> <span class="punct">=</span> <span class="constant">A</span><span class="punct">(&#39;</span><span class="string">Open Task</span><span class="punct">&#39;,</span> <span class="symbol">:href</span> <span class="punct">=&gt;</span> <span class="constant">Rs</span><span class="punct">(</span><span class="symbol">:open</span><span class="punct">,</span> <span class="ident">title</span><span class="punct">))</span>
256
- <span class="keyword">else</span>
257
- <span class="ident">status</span> <span class="punct">=</span> <span class="punct">&#39;</span><span class="string">not done</span><span class="punct">&#39;</span>
258
- <span class="ident">toggle</span> <span class="punct">=</span> <span class="constant">A</span><span class="punct">(&#39;</span><span class="string">Close Task</span><span class="punct">&#39;,</span> <span class="symbol">:href</span> <span class="punct">=&gt;</span> <span class="constant">Rs</span><span class="punct">(</span><span class="symbol">:close</span><span class="punct">,</span> <span class="ident">title</span><span class="punct">))</span>
259
- <span class="keyword">end</span>
260
- <span class="attribute">@tasks</span> <span class="punct">&lt;&lt;</span> <span class="punct">[</span><span class="ident">title</span><span class="punct">,</span> <span class="ident">status</span><span class="punct">,</span> <span class="ident">toggle</span><span class="punct">]</span>
261
- <span class="keyword">end</span>
262
- <span class="attribute">@tasks</span><span class="punct">.</span><span class="ident">sort!</span>
263
- <span class="keyword">end</span></code></pre>
325
+ <pre class="iplastic"><code class="ruby" lang="ruby"><span class="Keyword">def</span> <span class="FunctionName">index</span>
326
+ @tasks <span class="Keyword">=</span> []
327
+ <span class="Support">TodoList</span>.<span class="FunctionName">original</span>.<span class="FunctionName">each</span> <span class="Keyword">do </span>|title, value|
328
+ <span class="Keyword">if</span> value[<span class="Constant"><span class="Constant">:</span>done</span>]
329
+ status <span class="Keyword">=</span> <span class="String"><span class="String">'</span>done<span class="String">'</span></span>
330
+ toggle <span class="Keyword">=</span> A(<span class="String"><span class="String">'</span>Open Task<span class="String">'</span></span>, <span class="Constant"><span class="Constant">:</span>href</span> =&gt; Rs(<span class="Constant"><span class="Constant">:</span>open</span>, title))
331
+ <span class="Keyword">else</span>
332
+ status <span class="Keyword">=</span> <span class="String"><span class="String">'</span>not done<span class="String">'</span></span>
333
+ toggle <span class="Keyword">=</span> A(<span class="String"><span class="String">'</span>Close Task<span class="String">'</span></span>, <span class="Constant"><span class="Constant">:</span>href</span> =&gt; Rs(<span class="Constant"><span class="Constant">:</span>close</span>, title))
334
+ <span class="Keyword">end</span>
335
+ @tasks <span class="Keyword">&lt;&lt;</span> [title, status, toggle]
336
+ <span class="Keyword">end</span>
337
+ @tasks.<span class="FunctionName">sort!</span>
338
+ <span class="Keyword">end</span>
339
+ </code></pre>
264
340
 
265
341
  <p>Wow, quite some new stuff here. Let me explain that in detail.</p>
266
342
 
267
343
  <p>We first decide whether a task is done or not, then go on and provide a link to toggle the status, A and Rs are both methods that help you do that. The result will be something like:</p>
268
344
 
269
- <pre><code>&lt;a href=&quot;/open/Wash+dishes&quot;&gt;Close Task&lt;/a&gt;</code></pre>
345
+ <pre class="iplastic"><code class="ezamar" lang="ezamar"><span class="Tag"><span class="Tag">&lt;</span><span class="TagName">a</span> <span class="TagAttribute">href</span>=<span class="String"><span class="String">&quot;</span>/open/Wash+dishes<span class="String">&quot;</span></span><span class="Tag">&gt;</span></span>Close Task<span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">a</span><span class="Tag">&gt;</span></span>
346
+ </code></pre>
270
347
 
271
348
  <p>Rs actually is responsible to build the links href, for more information please take a look at the RDoc for LinkHelper.</p>
272
349
 
@@ -274,35 +351,41 @@
274
351
 
275
352
  <p>As usual since the links for open and close don&#8217;t lead anywhere, add the corresponding methods to the Controller:</p>
276
353
 
277
- <pre><code class="ruby" lang="ruby"><span class="keyword">def </span><span class="method">open</span> <span class="ident">title</span>
278
- <span class="ident">task_status</span> <span class="ident">title</span><span class="punct">,</span> <span class="constant">false</span>
279
- <span class="ident">redirect</span> <span class="constant">Rs</span><span class="punct">()</span>
280
- <span class="keyword">end</span>
354
+ <pre class="iplastic"><code class="ruby" lang="ruby"><span class="Keyword">def</span> <span class="FunctionName">open</span> title
355
+ task_status title, <span class="Identifier">false</span>
356
+ redirect Rs()
357
+ <span class="Keyword">end</span>
281
358
 
282
- <span class="keyword">def </span><span class="method">close</span> <span class="ident">title</span>
283
- <span class="ident">task_status</span> <span class="ident">title</span><span class="punct">,</span> <span class="constant">true</span>
284
- <span class="ident">redirect</span> <span class="constant">Rs</span><span class="punct">()</span>
285
- <span class="keyword">end</span>
359
+ <span class="Keyword">def</span> <span class="FunctionName">close</span> title
360
+ task_status title, <span class="Identifier">true</span>
361
+ redirect Rs()
362
+ <span class="Keyword">end</span>
286
363
 
287
- <span class="ident">private</span>
364
+ <span class="Keyword">private</span>
288
365
 
289
- <span class="keyword">def </span><span class="method">task_status</span> <span class="ident">title</span><span class="punct">,</span> <span class="ident">status</span>
290
- <span class="ident">task</span> <span class="punct">=</span> <span class="constant">TodoList</span><span class="punct">[</span><span class="ident">title</span><span class="punct">]</span>
291
- <span class="ident">task</span><span class="punct">[</span><span class="symbol">:done</span><span class="punct">]</span> <span class="punct">=</span> <span class="ident">status</span>
292
- <span class="constant">TodoList</span><span class="punct">[</span><span class="ident">title</span><span class="punct">]</span> <span class="punct">=</span> <span class="ident">task</span>
293
- <span class="keyword">end</span></code></pre>
366
+ <span class="Keyword">def</span> <span class="FunctionName">task_status</span> title, status
367
+ task <span class="Keyword">=</span> <span class="Support">TodoList</span>[title]
368
+ task[<span class="Constant"><span class="Constant">:</span>done</span>] <span class="Keyword">=</span> status
369
+ <span class="Support">TodoList</span>[title] <span class="Keyword">=</span> task
370
+ <span class="Keyword">end</span>
371
+ </code></pre>
294
372
 
295
373
  <p>Oh, now what have we got here? <code>private</code> declares that methods from here on are only to be used within the Controller itself, we define an <code>#task_status</code> method that takes the title and status to be set so we don&#8217;t have to repeat that code in <code>#open</code> and <code>#close</code> and follow the DRY (Don&#8217;t repeat yourself) paradigm.</p>
296
374
 
297
375
  <p>Another thing we have not encountered so far is that you can define your public methods to take parameters on their own, they will be calculated from requests.</p>
298
376
 
299
- <pre><code class="ruby" lang="ruby"><span class="punct">&#39;</span><span class="string">/open/Wash+dishes</span><span class="punct">&#39;</span></code></pre>
377
+ <pre class="iplastic"><code class="ruby" lang="ruby"><span class="String"><span class="String">'</span>/open/Wash+dishes<span class="String">'</span></span>
378
+ </code></pre>
300
379
 
301
380
  <p>will translate into:</p>
302
381
 
303
- <pre><code class="ruby" lang="ruby"><span class="ident">open</span><span class="punct">(&#39;</span><span class="string">Wash dishes</span><span class="punct">&#39;)</span></code></pre>
382
+ <pre class="iplastic"><code class="ruby" lang="ruby"><span class="FunctionName">open</span>(<span class="String"><span class="String">'</span>Wash dishes<span class="String">'</span></span>)
383
+ </code></pre>
304
384
 
305
- <p>Which in turn will call <code>task_status(&#39;Wash dishes&#39;, false)</code></p>
385
+ <p>Which in turn will call</p>
386
+
387
+ <pre class="iplastic"><code class="ruby" lang="ruby"><span class="FunctionName">task_status</span>(<span class="String"><span class="String">'</span>Wash dishes<span class="String">'</span></span>, <span class="Identifier">false</span>)
388
+ </code></pre>
306
389
 
307
390
  <p>That&#8217;s it, go on and try it :)</p>
308
391
 
@@ -312,23 +395,26 @@
312
395
 
313
396
  <p>This is just two little changes away, so let&#8217;s add the link for deletion in our Controller:</p>
314
397
 
315
- <pre><code class="ruby" lang="ruby"><span class="ident">delete</span> <span class="punct">=</span> <span class="constant">A</span><span class="punct">(&#39;</span><span class="string">Delete</span><span class="punct">&#39;,</span> <span class="symbol">:href</span> <span class="punct">=&gt;</span> <span class="constant">Rs</span><span class="punct">(</span><span class="symbol">:delete</span><span class="punct">,</span> <span class="ident">title</span><span class="punct">))</span>
316
- <span class="attribute">@tasks</span> <span class="punct">&lt;&lt;</span> <span class="punct">[</span><span class="ident">title</span><span class="punct">,</span> <span class="ident">status</span><span class="punct">,</span> <span class="ident">toggle</span><span class="punct">,</span> <span class="ident">delete</span><span class="punct">]</span></code></pre>
398
+ <pre class="iplastic"><code class="ruby" lang="ruby">delete <span class="Keyword">=</span> A(<span class="String"><span class="String">'</span>Delete<span class="String">'</span></span>, <span class="Constant"><span class="Constant">:</span>href</span> =&gt; Rs(<span class="Constant"><span class="Constant">:</span>delete</span>, title))
399
+ @tasks <span class="Keyword">&lt;&lt;</span> [title, status, toggle, delete]
400
+ </code></pre>
317
401
 
318
402
  <p>and an corresponding method while we&#8217;re at it:</p>
319
403
 
320
- <pre><code class="ruby" lang="ruby"><span class="keyword">def </span><span class="method">delete</span> <span class="ident">title</span>
321
- <span class="constant">TodoList</span><span class="punct">.</span><span class="ident">delete</span> <span class="ident">title</span>
322
- <span class="ident">redirect</span> <span class="constant">Rs</span><span class="punct">()</span>
323
- <span class="keyword">end</span></code></pre>
404
+ <pre class="iplastic"><code class="ruby" lang="ruby"><span class="Keyword">def</span> <span class="FunctionName">delete</span> title
405
+ <span class="Support">TodoList</span>.<span class="FunctionName">delete</span> title
406
+ redirect Rs()
407
+ <span class="Keyword">end</span>
408
+ </code></pre>
324
409
 
325
410
  <p>Now jumping to <code>view/index.xhtml</code> again, change it so it shows the link:</p>
326
411
 
327
- <pre><code>&lt;?r @tasks.each do |title, status, toggle, delete| ?&gt;
328
- &lt;li&gt;
329
- #{c title}: #{status} [ #{toggle} | #{delete} ]
330
- &lt;/li&gt;
331
- &lt;?r end ?&gt;</code></pre>
412
+ <pre class="iplastic"><code class="ezamar" lang="ezamar"><span class="EmbeddedSource"><span class="EmbeddedSource">&lt;?r</span> <span class="EmbeddedSource"><span class="EmbeddedSource">@</span>tasks</span><span class="EmbeddedSource"><span class="EmbeddedSource">.</span><span class="FunctionName">each</span></span> <span class="Keyword">do </span><span class="EmbeddedSource">|</span><span class="EmbeddedSource">title</span><span class="EmbeddedSource">,</span> <span class="EmbeddedSource">status</span><span class="EmbeddedSource">,</span> <span class="EmbeddedSource">toggle</span><span class="EmbeddedSource">,</span> <span class="EmbeddedSource">delete</span><span class="EmbeddedSource">|</span> <span class="EmbeddedSource">?&gt;</span></span>
413
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">li</span><span class="Tag">&gt;</span></span>
414
+ #<span class="EmbeddedSource">{h title}</span>: #<span class="EmbeddedSource">{status}</span> [ #<span class="EmbeddedSource">{toggle}</span> | #<span class="EmbeddedSource">{delete}</span> ]
415
+ <span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">li</span><span class="Tag">&gt;</span></span>
416
+ <span class="EmbeddedSource"><span class="EmbeddedSource">&lt;?r</span> <span class="Keyword">end</span> <span class="EmbeddedSource">?&gt;</span></span>
417
+ </code></pre>
332
418
 
333
419
  <p>Voilà, you now have acquired the Certificate of Ramazeness.</p>
334
420
 
@@ -336,7 +422,8 @@
336
422
 
337
423
  <h2 id="eighth_step_elements">Eighth Step, Elements</h2>
338
424
 
339
- <pre><code>&lt;Page&gt;&lt;/Page&gt;</code></pre>
425
+ <pre class="iplastic"><code class="ezamar" lang="ezamar"><span class="Tag"><span class="Tag">&lt;</span><span class="TagName">Page</span><span class="Tag">&gt;<span class="Tag">&lt;</span>/</span><span class="TagName">Page</span><span class="Tag">&gt;</span></span>
426
+ </code></pre>
340
427
 
341
428
  <p>This is called an Element, Ramaze will go and search for a class that matches the name Page and responds to <code>#render</code>. Then it will go and hand the content in between to that Element.</p>
342
429
 
@@ -344,20 +431,22 @@
344
431
 
345
432
  <p>Let us have a look at our templates, they got some repetitive stuff, like:</p>
346
433
 
347
- <pre><code>&lt;html&gt;
348
- &lt;head&gt;
349
- &lt;title&gt;TodoList&lt;/title&gt;
350
- &lt;/head&gt;
351
- &lt;body&gt;
352
- &lt;h1&gt;some title&lt;/h1&gt;
353
- &lt;/body&gt;
354
- &lt;/html&gt;</code></pre>
434
+ <pre class="iplastic"><code class="ezamar" lang="ezamar"><span class="Tag"><span class="Tag">&lt;</span><span class="TagName">html</span><span class="Tag">&gt;</span></span>
435
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">head</span><span class="Tag">&gt;</span></span>
436
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">title</span><span class="Tag">&gt;</span></span>TodoList<span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">title</span><span class="Tag">&gt;</span></span>
437
+ <span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">head</span><span class="Tag">&gt;</span></span>
438
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">body</span><span class="Tag">&gt;</span></span>
439
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">h1</span><span class="Tag">&gt;</span></span>some title<span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">h1</span><span class="Tag">&gt;</span></span>
440
+ <span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">body</span><span class="Tag">&gt;</span></span>
441
+ <span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">html</span><span class="Tag">&gt;</span></span>
442
+ </code></pre>
355
443
 
356
444
  <p>How about replacing that with something short and reusable:</p>
357
445
 
358
- <pre><code>&lt;Page title=&quot;TodoList&quot;&gt;
446
+ <pre class="iplastic"><code class="html" lang="html"><span class="Tag"><span class="Tag">&lt;</span><span class="TagName">Page</span> <span class="TagAttribute">title</span>=<span class="String"><span class="String">&quot;</span>TodoList<span class="String">&quot;</span></span><span class="Tag">&gt;</span></span>
359
447
  your other content
360
- &lt;/Page&gt;</code></pre>
448
+ <span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">Page</span><span class="Tag">&gt;</span></span>
449
+ </code></pre>
361
450
 
362
451
  <p>Would be nice of course, and when you start having more templates it makes an awful lot of sense being able to change the enclosing stuff in one place.</p>
363
452
 
@@ -365,40 +454,42 @@
365
454
 
366
455
  <p>Take a look at the <code>src/element/page.rb</code></p>
367
456
 
368
- <pre><code class="ruby" lang="ruby"><span class="keyword">class </span><span class="class">Page</span> <span class="punct">&lt;</span> <span class="constant">Ezamar</span><span class="punct">::</span><span class="constant">Element</span>
369
- <span class="keyword">def </span><span class="method">render</span>
370
- <span class="punct">%{</span><span class="string">
371
- &lt;html&gt;
372
- &lt;head&gt;
373
- &lt;title&gt;Welcome to Ramaze&lt;/title&gt;
374
- &lt;/head&gt;
375
- &lt;body&gt;
376
- <span class="expr">#{content}</span>
377
- &lt;/body&gt;
378
- &lt;/html&gt;
379
- </span><span class="punct">}</span>
380
- <span class="keyword">end</span>
381
- <span class="keyword">end</span></code></pre>
457
+ <pre class="iplastic"><code class="ruby" lang="ruby"><span class="Keyword">class</span> <span class="TypeName">Page<span class="TypeName"> <span class="TypeName">&lt;</span> Ezamar::Element</span></span>
458
+ <span class="Keyword">def</span> <span class="FunctionName">render</span>
459
+ <span class="String"><span class="String">%{</span></span>
460
+ <span class="String"> &lt;html&gt;</span>
461
+ <span class="String"> &lt;head&gt;</span>
462
+ <span class="String"> &lt;title&gt;Welcome to Ramaze&lt;/title&gt;</span>
463
+ <span class="String"> &lt;/head&gt;</span>
464
+ <span class="String"> &lt;body&gt;</span>
465
+ <span class="String"> <span class="String"><span class="String">#{</span>content<span class="String">}</span></span></span>
466
+ <span class="String"> &lt;/body&gt;</span>
467
+ <span class="String"> &lt;/html&gt;</span>
468
+ <span class="String"> <span class="String">}</span></span>
469
+ <span class="Keyword">end</span>
470
+ <span class="Keyword">end</span>
471
+ </code></pre>
382
472
 
383
473
  <p>Alright, most things we need are in place already, the most important thing is the <code>#content</code> method that we call with <code>#{content}</code> inside the string in <code>#render</code>.</p>
384
474
 
385
475
  <p>Just adopt it to your liking, I&#8217;ll just use the things we had in our templates so far:</p>
386
476
 
387
- <pre><code class="ruby" lang="ruby"><span class="keyword">class </span><span class="class">Page</span> <span class="punct">&lt;</span> <span class="constant">Ezamar</span><span class="punct">::</span><span class="constant">Element</span>
388
- <span class="keyword">def </span><span class="method">render</span>
389
- <span class="punct">%{</span><span class="string">
390
- &lt;html&gt;
391
- &lt;head&gt;
392
- &lt;title&gt;TodoList&lt;/title&gt;
393
- &lt;/head&gt;
394
- &lt;body&gt;
395
- &lt;h1&gt;<span class="expr">#{@title}</span>&lt;/h1&gt;
396
- <span class="expr">#{content}</span>
397
- &lt;/body&gt;
398
- &lt;/html&gt;
399
- </span><span class="punct">}</span>
400
- <span class="keyword">end</span>
401
- <span class="keyword">end</span></code></pre>
477
+ <pre class="iplastic"><code class="ruby" lang="ruby"><span class="Keyword">class</span> <span class="TypeName">Page<span class="TypeName"> <span class="TypeName">&lt;</span> Ezamar::Element</span></span>
478
+ <span class="Keyword">def</span> <span class="FunctionName">render</span>
479
+ <span class="String"><span class="String">%{</span></span>
480
+ <span class="String"> &lt;html&gt;</span>
481
+ <span class="String"> &lt;head&gt;</span>
482
+ <span class="String"> &lt;title&gt;TodoList&lt;/title&gt;</span>
483
+ <span class="String"> &lt;/head&gt;</span>
484
+ <span class="String"> &lt;body&gt;</span>
485
+ <span class="String"> &lt;h1&gt;<span class="String"><span class="String">#{</span><span class="String"><span class="String">@</span>title</span><span class="String">}</span></span>&lt;/h1&gt;</span>
486
+ <span class="String"> <span class="String"><span class="String">#{</span>content<span class="String">}</span></span></span>
487
+ <span class="String"> &lt;/body&gt;</span>
488
+ <span class="String"> &lt;/html&gt;</span>
489
+ <span class="String"> <span class="String">}</span></span>
490
+ <span class="Keyword">end</span>
491
+ <span class="Keyword">end</span>
492
+ </code></pre>
402
493
 
403
494
  <p>Please note that instance variables reflecting the parameters are set.</p>
404
495
 
@@ -406,30 +497,32 @@
406
497
 
407
498
  <p>First the <code>view/index.xhtml</code></p>
408
499
 
409
- <pre><code>&lt;Page title=&quot;TodoList&quot;&gt;
410
- &lt;a href=&quot;/new&quot;&gt;New Task&lt;/a&gt;
411
- &lt;?r if @tasks.empty? ?&gt;
500
+ <pre class="iplastic"><code class="ezamar" lang="ezamar"><span class="Tag"><span class="Tag">&lt;</span><span class="TagName">Page</span> <span class="TagAttribute">title</span>=<span class="String"><span class="String">&quot;</span>TodoList<span class="String">&quot;</span></span><span class="Tag">&gt;</span></span>
501
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">a</span> <span class="TagAttribute">href</span>=<span class="String"><span class="String">&quot;</span>/new<span class="String">&quot;</span></span><span class="Tag">&gt;</span></span>New Task<span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">a</span><span class="Tag">&gt;</span></span>
502
+ <span class="EmbeddedSource"><span class="EmbeddedSource">&lt;?r</span> <span class="Keyword">if</span> <span class="EmbeddedSource"><span class="EmbeddedSource">@</span>tasks</span><span class="EmbeddedSource"><span class="EmbeddedSource">.</span><span class="FunctionName">empty?</span></span> <span class="EmbeddedSource">?&gt;</span></span>
412
503
  No Tasks
413
- &lt;?r else ?&gt;
414
- &lt;ul&gt;
415
- &lt;?r @tasks.each do |title, status, toggle, delete| ?&gt;
416
- &lt;li&gt;
417
- #{c title}: #{status} [ #{toggle} | #{delete} ]
418
- &lt;/li&gt;
419
- &lt;?r end ?&gt;
420
- &lt;/ul&gt;
421
- &lt;?r end ?&gt;
422
- &lt;/Page&gt;</code></pre>
504
+ <span class="EmbeddedSource"><span class="EmbeddedSource">&lt;?r</span> <span class="Keyword">else</span> <span class="EmbeddedSource">?&gt;</span></span>
505
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">ul</span><span class="Tag">&gt;</span></span>
506
+ <span class="EmbeddedSource"><span class="EmbeddedSource">&lt;?r</span> <span class="EmbeddedSource"><span class="EmbeddedSource">@</span>tasks</span><span class="EmbeddedSource"><span class="EmbeddedSource">.</span><span class="FunctionName">each</span></span> <span class="Keyword">do </span><span class="EmbeddedSource">|</span><span class="EmbeddedSource">title</span><span class="EmbeddedSource">,</span> <span class="EmbeddedSource">status</span><span class="EmbeddedSource">,</span> <span class="EmbeddedSource">toggle</span><span class="EmbeddedSource">,</span> <span class="EmbeddedSource">delete</span><span class="EmbeddedSource">|</span> <span class="EmbeddedSource">?&gt;</span></span>
507
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">li</span><span class="Tag">&gt;</span></span>
508
+ #<span class="EmbeddedSource">{h title}</span>: #<span class="EmbeddedSource">{status}</span> [ #<span class="EmbeddedSource">{toggle}</span> | #<span class="EmbeddedSource">{delete}</span> ]
509
+ <span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">li</span><span class="Tag">&gt;</span></span>
510
+ <span class="EmbeddedSource"><span class="EmbeddedSource">&lt;?r</span> <span class="Keyword">end</span> <span class="EmbeddedSource">?&gt;</span></span>
511
+ <span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">ul</span><span class="Tag">&gt;</span></span>
512
+ <span class="EmbeddedSource"><span class="EmbeddedSource">&lt;?r</span> <span class="Keyword">end</span> <span class="EmbeddedSource">?&gt;</span></span>
513
+ <span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">Page</span><span class="Tag">&gt;</span></span>
514
+ </code></pre>
423
515
 
424
516
  <p>and the <code>view/new.xhtml</code></p>
425
517
 
426
- <pre><code>&lt;Page title=&quot;New Task&quot;&gt;
427
- &lt;a href=&quot;/&quot;&gt;Back to TodoList&lt;/a&gt;
428
- &lt;form method=&quot;POST&quot; action=&quot;create&quot;&gt;
429
- Task: &lt;input type=&quot;text&quot; name=&quot;title&quot; /&gt;&lt;br /&gt;
430
- &lt;input type=&quot;submit&quot; /&gt;
431
- &lt;/form&gt;
432
- &lt;/Page&gt;</code></pre>
518
+ <pre class="iplastic"><code class="ezamar" lang="ezamar"><span class="Tag"><span class="Tag">&lt;</span><span class="TagName">Page</span> <span class="TagAttribute">title</span>=<span class="String"><span class="String">&quot;</span>New Task<span class="String">&quot;</span></span><span class="Tag">&gt;</span></span>
519
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">a</span> <span class="TagAttribute">href</span>=<span class="String"><span class="String">&quot;</span>/<span class="String">&quot;</span></span><span class="Tag">&gt;</span></span>Back to TodoList<span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">a</span><span class="Tag">&gt;</span></span>
520
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">form</span> <span class="TagAttribute">method</span>=<span class="String"><span class="String">&quot;</span>POST<span class="String">&quot;</span></span> <span class="TagAttribute">action</span>=<span class="String"><span class="String">&quot;</span>create<span class="String">&quot;</span></span><span class="Tag">&gt;</span></span>
521
+ Task: <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">input</span> <span class="TagAttribute">type</span>=<span class="String"><span class="String">&quot;</span>text<span class="String">&quot;</span></span> <span class="TagAttribute">name</span>=<span class="String"><span class="String">&quot;</span>title<span class="String">&quot;</span></span> /<span class="Tag">&gt;</span></span><span class="Tag"><span class="Tag">&lt;</span><span class="TagName">br</span> /<span class="Tag">&gt;</span></span>
522
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">input</span> <span class="TagAttribute">type</span>=<span class="String"><span class="String">&quot;</span>submit<span class="String">&quot;</span></span> /<span class="Tag">&gt;</span></span>
523
+ <span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">form</span><span class="Tag">&gt;</span></span>
524
+ <span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">Page</span><span class="Tag">&gt;</span></span>
525
+ </code></pre>
433
526
 
434
527
  <p>Alright, now just go and look at the result in the browser, try changing the things inside the Element and look at how it behaves.</p>
435
528
 
@@ -439,40 +532,43 @@
439
532
 
440
533
  <p>So, from what we have right now:</p>
441
534
 
442
- <pre><code>&lt;ul&gt;
443
- &lt;?r @tasks.each do |title, status, toggle, delete| ?&gt;
444
- &lt;li&gt;
445
- #{c title}: #{status} [ #{toggle} | #{delete} ]
446
- &lt;/li&gt;
447
- &lt;?r end ?&gt;
448
- &lt;/ul&gt;</code></pre>
535
+ <pre class="iplastic"><code class="ezamar" lang="ezamar"><span class="Tag"><span class="Tag">&lt;</span><span class="TagName">ul</span><span class="Tag">&gt;</span></span>
536
+ <span class="EmbeddedSource"><span class="EmbeddedSource">&lt;?r</span> <span class="EmbeddedSource"><span class="EmbeddedSource">@</span>tasks</span><span class="EmbeddedSource"><span class="EmbeddedSource">.</span><span class="FunctionName">each</span></span> <span class="Keyword">do </span><span class="EmbeddedSource">|</span><span class="EmbeddedSource">title</span><span class="EmbeddedSource">,</span> <span class="EmbeddedSource">status</span><span class="EmbeddedSource">,</span> <span class="EmbeddedSource">toggle</span><span class="EmbeddedSource">,</span> <span class="EmbeddedSource">delete</span><span class="EmbeddedSource">|</span> <span class="EmbeddedSource">?&gt;</span></span>
537
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">li</span><span class="Tag">&gt;</span></span>
538
+ #<span class="EmbeddedSource">{h title}</span>: #<span class="EmbeddedSource">{status}</span> [ #<span class="EmbeddedSource">{toggle}</span> | #<span class="EmbeddedSource">{delete}</span> ]
539
+ <span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">li</span><span class="Tag">&gt;</span></span>
540
+ <span class="EmbeddedSource"><span class="EmbeddedSource">&lt;?r</span> <span class="Keyword">end</span> <span class="EmbeddedSource">?&gt;</span></span>
541
+ <span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">ul</span><span class="Tag">&gt;</span></span>
542
+ </code></pre>
449
543
 
450
544
  <p>To something like this:</p>
451
545
 
452
- <pre><code>&lt;table&gt;
453
- &lt;?r @tasks.each do |title, status, toggle, delete| ?&gt;
454
- &lt;tr&gt;
455
- &lt;td class=&quot;title&quot;&gt; #{c title} &lt;/td&gt;
456
- &lt;td class=&quot;status&quot;&gt; #{status} &lt;/td&gt;
457
- &lt;td class=&quot;toggle&quot;&gt; #{toggle} &lt;/td&gt;
458
- &lt;td class=&quot;delete&quot;&gt; #{delete} &lt;/td&gt;
459
- &lt;/tr&gt;
460
- &lt;?r end ?&gt;
461
- &lt;/table&gt;</code></pre>
546
+ <pre class="iplastic"><code class="ezamar" lang="ezamar"><span class="Tag"><span class="Tag">&lt;</span><span class="TagName">table</span><span class="Tag">&gt;</span></span>
547
+ <span class="EmbeddedSource"><span class="EmbeddedSource">&lt;?r</span> <span class="EmbeddedSource"><span class="EmbeddedSource">@</span>tasks</span><span class="EmbeddedSource"><span class="EmbeddedSource">.</span><span class="FunctionName">each</span></span> <span class="Keyword">do </span><span class="EmbeddedSource">|</span><span class="EmbeddedSource">title</span><span class="EmbeddedSource">,</span> <span class="EmbeddedSource">status</span><span class="EmbeddedSource">,</span> <span class="EmbeddedSource">toggle</span><span class="EmbeddedSource">,</span> <span class="EmbeddedSource">delete</span><span class="EmbeddedSource">|</span> <span class="EmbeddedSource">?&gt;</span></span>
548
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">tr</span><span class="Tag">&gt;</span></span>
549
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">td</span> <span class="TagAttribute">class</span>=<span class="String"><span class="String">&quot;</span>title<span class="String">&quot;</span></span><span class="Tag">&gt;</span></span> #<span class="EmbeddedSource">{h title}</span> <span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">td</span><span class="Tag">&gt;</span></span>
550
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">td</span> <span class="TagAttribute">class</span>=<span class="String"><span class="String">&quot;</span>status<span class="String">&quot;</span></span><span class="Tag">&gt;</span></span> #<span class="EmbeddedSource">{status}</span> <span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">td</span><span class="Tag">&gt;</span></span>
551
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">td</span> <span class="TagAttribute">class</span>=<span class="String"><span class="String">&quot;</span>toggle<span class="String">&quot;</span></span><span class="Tag">&gt;</span></span> #<span class="EmbeddedSource">{toggle}</span> <span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">td</span><span class="Tag">&gt;</span></span>
552
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">td</span> <span class="TagAttribute">class</span>=<span class="String"><span class="String">&quot;</span>delete<span class="String">&quot;</span></span><span class="Tag">&gt;</span></span> #<span class="EmbeddedSource">{delete}</span> <span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">td</span><span class="Tag">&gt;</span></span>
553
+ <span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">tr</span><span class="Tag">&gt;</span></span>
554
+ <span class="EmbeddedSource"><span class="EmbeddedSource">&lt;?r</span> <span class="Keyword">end</span> <span class="EmbeddedSource">?&gt;</span></span>
555
+ <span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">table</span><span class="Tag">&gt;</span></span>
556
+ </code></pre>
462
557
 
463
558
  <p>And, since we have proper classes to address some style sheets, jump into the Page element and add some style sheet:</p>
464
559
 
465
- <pre><code>&lt;head&gt;
466
- &lt;title&gt;TodoList&lt;/title&gt;
467
- &lt;style&gt;
468
- table { width: 100%; }
469
- tr { background: #efe; width: 100%; }
470
- tr:hover { background: #dfd; }
471
- td.title { font-weight: bold; width: 60%; }
472
- td.status { margin: 1em; }
473
- a { color: #3a3; }
474
- &lt;/style&gt;
475
- &lt;/head&gt;</code></pre>
560
+ <pre class="iplastic"><code class="ezamar" lang="ezamar"><span class="Tag"><span class="Tag">&lt;</span><span class="TagName">head</span><span class="Tag">&gt;</span></span>
561
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">title</span><span class="Tag">&gt;</span></span>TodoList<span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">title</span><span class="Tag">&gt;</span></span>
562
+ <span class="EmbeddedSource"> <span class="EmbeddedSource">&lt;</span><span class="TagName">style</span><span class="EmbeddedSource">&gt;</span></span>
563
+ <span class="EmbeddedSource"><span class="EmbeddedSource"> <span class="TagName">table</span> </span><span class="EmbeddedSource">{ width: 100%; }</span></span>
564
+ <span class="EmbeddedSource"><span class="EmbeddedSource"> <span class="TagName">tr</span> </span><span class="EmbeddedSource">{ background: #efe; width: 100%; }</span></span>
565
+ <span class="EmbeddedSource"><span class="EmbeddedSource"> <span class="TagName">tr</span><span class="TagAttribute"><span class="TagAttribute">:</span>hover</span> </span><span class="EmbeddedSource">{ background: #dfd; }</span></span>
566
+ <span class="EmbeddedSource"><span class="EmbeddedSource"> <span class="TagName">td</span><span class="TagAttribute"><span class="TagAttribute">.</span>title</span> </span><span class="EmbeddedSource">{ font-weight: bold; width: 60%; }</span></span>
567
+ <span class="EmbeddedSource"><span class="EmbeddedSource"> <span class="TagName">td</span><span class="TagAttribute"><span class="TagAttribute">.</span>status</span> </span><span class="EmbeddedSource">{ margin: 1em; }</span></span>
568
+ <span class="EmbeddedSource"><span class="EmbeddedSource"> <span class="TagName">a</span> </span><span class="EmbeddedSource">{ color: #3a3; }</span></span>
569
+ <span class="EmbeddedSource"> <span class="EmbeddedSource">&lt;/</span><span class="TagName">style</span><span class="EmbeddedSource">&gt;</span></span>
570
+ <span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">head</span><span class="Tag">&gt;</span></span>
571
+ </code></pre>
476
572
 
477
573
  <p>That looks quite a bit nicer, right? And yes, if you don&#8217;t like tables (though this is an entirely legit use in my opinion) you can just do it like you want, using nested lists or divs/spans, replacing the open/close and delete links with nice images and changing the style according to the status.</p>
478
574
 
@@ -484,22 +580,26 @@
484
580
 
485
581
  <p>First of all, the default port Ramaze runs on is 7000, but to make it a usual webserver it has to run on port 80. So, let&#8217;s add following line in your start.rb right after the lines of require you added before:</p>
486
582
 
487
- <pre><code class="ruby" lang="ruby"><span class="constant">Ramaze</span><span class="punct">::</span><span class="constant">Global</span><span class="punct">.</span><span class="ident">port</span> <span class="punct">=</span> <span class="number">80</span></code></pre>
583
+ <pre class="iplastic"><code class="ruby" lang="ruby"><span class="Support">Ramaze</span>::<span class="FunctionName">Global</span>.<span class="FunctionName">port</span> <span class="Keyword">=</span> <span class="Number">80</span>
584
+ </code></pre>
488
585
 
489
586
  <p>Alright, that wasn&#8217;t that hard. Let&#8217;s say now you also want to run Mongrel instead of WEBrick, to get nice a bit of performance:</p>
490
587
 
491
- <pre><code class="ruby" lang="ruby"><span class="constant">Ramaze</span><span class="punct">::</span><span class="constant">Global</span><span class="punct">.</span><span class="ident">adapter</span> <span class="punct">=</span> <span class="symbol">:mongrel</span></code></pre>
588
+ <pre class="iplastic"><code class="ruby" lang="ruby"><span class="Support">Ramaze</span>::<span class="FunctionName">Global</span>.<span class="FunctionName">adapter</span> <span class="Keyword">=</span> <span class="Constant"><span class="Constant">:</span>mongrel</span>
589
+ </code></pre>
492
590
 
493
591
  <p>To do this in a DRY way you could also do following:</p>
494
592
 
495
- <pre><code class="ruby" lang="ruby"><span class="constant">Ramaze</span><span class="punct">::</span><span class="constant">Global</span><span class="punct">.</span><span class="ident">setup</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">g</span><span class="punct">|</span>
496
- <span class="ident">g</span><span class="punct">.</span><span class="ident">port</span> <span class="punct">=</span> <span class="number">80</span>
497
- <span class="ident">g</span><span class="punct">.</span><span class="ident">adapter</span> <span class="punct">=</span> <span class="symbol">:mongrel</span>
498
- <span class="keyword">end</span></code></pre>
593
+ <pre class="iplastic"><code class="ruby" lang="ruby"><span class="Support">Ramaze</span>::<span class="FunctionName">Global</span>.<span class="FunctionName">setup</span> <span class="Keyword">do </span>|g|
594
+ g.<span class="FunctionName">port</span> <span class="Keyword">=</span> <span class="Number">80</span>
595
+ g.<span class="FunctionName">adapter</span> <span class="Keyword">=</span> <span class="Constant"><span class="Constant">:</span>mongrel</span>
596
+ <span class="Keyword">end</span>
597
+ </code></pre>
499
598
 
500
599
  <p>It seems to be quite common to put this configuration into separate files so you can just require it on demand. There are other, slightly stronger way to set options, which is either using flags on the ramaze executable, or like this:</p>
501
600
 
502
- <pre><code class="ruby" lang="ruby"><span class="constant">Ramaze</span><span class="punct">.</span><span class="ident">start</span> <span class="symbol">:port</span> <span class="punct">=&gt;</span> <span class="number">80</span><span class="punct">,</span> <span class="symbol">:adapter</span> <span class="punct">=&gt;</span> <span class="symbol">:mongrel</span></code></pre>
601
+ <pre class="iplastic"><code class="ruby" lang="ruby"><span class="Support">Ramaze</span>.<span class="FunctionName">start</span> <span class="Constant"><span class="Constant">:</span>port</span> =&gt; <span class="Number">80</span>, <span class="Constant"><span class="Constant">:</span>adapter</span> =&gt; <span class="Constant"><span class="Constant">:</span>mongrel</span>
602
+ </code></pre>
503
603
 
504
604
  <p>We haven&#8217;t started Ramaze directly as of yet, but this allows you to ignore the ramaze executable and just run your application by <code>ruby start.rb</code>.</p>
505
605
 
@@ -507,26 +607,27 @@
507
607
 
508
608
  <p>Now, if you take a closer look at the Controller you will see:</p>
509
609
 
510
- <pre><code class="ruby" lang="ruby"><span class="keyword">def </span><span class="method">create</span>
511
- <span class="ident">title</span> <span class="punct">=</span> <span class="ident">request</span><span class="punct">[&#39;</span><span class="string">title</span><span class="punct">&#39;]</span>
512
- <span class="constant">TodoList</span><span class="punct">[</span><span class="ident">title</span><span class="punct">]</span> <span class="punct">=</span> <span class="punct">{</span><span class="symbol">:done</span> <span class="punct">=&gt;</span> <span class="constant">false</span><span class="punct">}</span>
513
- <span class="ident">redirect</span> <span class="constant">R</span><span class="punct">(</span><span class="constant">self</span><span class="punct">)</span>
514
- <span class="keyword">end</span>
610
+ <pre class="iplastic"><code class="ruby" lang="ruby"><span class="Keyword">def</span> <span class="FunctionName">create</span>
611
+ title <span class="Keyword">=</span> request[<span class="String"><span class="String">'</span>title<span class="String">'</span></span>]
612
+ <span class="Support">TodoList</span>[title] <span class="Keyword">=</span> {<span class="Constant"><span class="Constant">:</span>done</span> =&gt; <span class="Identifier">false</span>}
613
+ redirect R(self)
614
+ <span class="Keyword">end</span>
515
615
 
516
- <span class="keyword">def </span><span class="method">open</span> <span class="ident">title</span>
517
- <span class="ident">task_status</span> <span class="ident">title</span><span class="punct">,</span> <span class="constant">false</span>
518
- <span class="ident">redirect</span> <span class="constant">R</span><span class="punct">(</span><span class="constant">self</span><span class="punct">)</span>
519
- <span class="keyword">end</span>
616
+ <span class="Keyword">def</span> <span class="FunctionName">open</span> title
617
+ task_status title, <span class="Identifier">false</span>
618
+ redirect R(self)
619
+ <span class="Keyword">end</span>
520
620
 
521
- <span class="keyword">def </span><span class="method">close</span> <span class="ident">title</span>
522
- <span class="ident">task_status</span> <span class="ident">title</span><span class="punct">,</span> <span class="constant">true</span>
523
- <span class="ident">redirect</span> <span class="constant">R</span><span class="punct">(</span><span class="constant">self</span><span class="punct">)</span>
524
- <span class="keyword">end</span>
621
+ <span class="Keyword">def</span> <span class="FunctionName">close</span> title
622
+ task_status title, <span class="Identifier">true</span>
623
+ redirect R(self)
624
+ <span class="Keyword">end</span>
525
625
 
526
- <span class="keyword">def </span><span class="method">delete</span> <span class="ident">title</span>
527
- <span class="constant">TodoList</span><span class="punct">.</span><span class="ident">delete</span> <span class="ident">title</span>
528
- <span class="ident">redirect</span> <span class="constant">R</span><span class="punct">(</span><span class="constant">self</span><span class="punct">)</span>
529
- <span class="keyword">end</span></code></pre>
626
+ <span class="Keyword">def</span> <span class="FunctionName">delete</span> title
627
+ <span class="Support">TodoList</span>.<span class="FunctionName">delete</span> title
628
+ redirect R(self)
629
+ <span class="Keyword">end</span>
630
+ </code></pre>
530
631
 
531
632
  <p>We did some refactoring before, by introducing <code>#task_status</code>, but here we have repetition again: <code>redirect Rs()</code> <em>after</em> each method did its job.</p>
532
633
 
@@ -534,25 +635,26 @@
534
635
 
535
636
  <p>In your Controller, replace the previous chunk with following:</p>
536
637
 
537
- <pre><code class="ruby" lang="ruby"><span class="keyword">def </span><span class="method">create</span>
538
- <span class="ident">title</span> <span class="punct">=</span> <span class="ident">request</span><span class="punct">[&#39;</span><span class="string">title</span><span class="punct">&#39;]</span>
539
- <span class="constant">TodoList</span><span class="punct">[</span><span class="ident">title</span><span class="punct">]</span> <span class="punct">=</span> <span class="punct">{</span><span class="symbol">:done</span> <span class="punct">=&gt;</span> <span class="constant">false</span><span class="punct">}</span>
540
- <span class="keyword">end</span>
638
+ <pre class="iplastic"><code class="ruby" lang="ruby"><span class="Keyword">def</span> <span class="FunctionName">create</span>
639
+ title <span class="Keyword">=</span> request[<span class="String"><span class="String">'</span>title<span class="String">'</span></span>]
640
+ <span class="Support">TodoList</span>[title] <span class="Keyword">=</span> {<span class="Constant"><span class="Constant">:</span>done</span> =&gt; <span class="Identifier">false</span>}
641
+ <span class="Keyword">end</span>
541
642
 
542
- <span class="keyword">def </span><span class="method">open</span> <span class="ident">title</span>
543
- <span class="ident">task_status</span> <span class="ident">title</span><span class="punct">,</span> <span class="constant">false</span>
544
- <span class="keyword">end</span>
643
+ <span class="Keyword">def</span> <span class="FunctionName">open</span> title
644
+ task_status title, <span class="Identifier">false</span>
645
+ <span class="Keyword">end</span>
545
646
 
546
- <span class="keyword">def </span><span class="method">close</span> <span class="ident">title</span>
547
- <span class="ident">task_status</span> <span class="ident">title</span><span class="punct">,</span> <span class="constant">true</span>
548
- <span class="keyword">end</span>
647
+ <span class="Keyword">def</span> <span class="FunctionName">close</span> title
648
+ task_status title, <span class="Identifier">true</span>
649
+ <span class="Keyword">end</span>
549
650
 
550
- <span class="keyword">def </span><span class="method">delete</span> <span class="ident">title</span>
551
- <span class="constant">TodoList</span><span class="punct">.</span><span class="ident">delete</span> <span class="ident">title</span>
552
- <span class="keyword">end</span>
651
+ <span class="Keyword">def</span> <span class="FunctionName">delete</span> title
652
+ <span class="Support">TodoList</span>.<span class="FunctionName">delete</span> title
653
+ <span class="Keyword">end</span>
553
654
 
554
- <span class="ident">helper</span> <span class="symbol">:aspect</span>
555
- <span class="ident">after</span><span class="punct">(</span><span class="symbol">:create</span><span class="punct">,</span> <span class="symbol">:open</span><span class="punct">,</span> <span class="symbol">:close</span><span class="punct">,</span> <span class="symbol">:delete</span><span class="punct">){</span> <span class="ident">redirect</span><span class="punct">(</span><span class="constant">Rs</span><span class="punct">())</span> <span class="punct">}</span></code></pre>
655
+ helper <span class="Constant"><span class="Constant">:</span>aspect</span>
656
+ <span class="FunctionName">after</span>(<span class="Constant"><span class="Constant">:</span>create</span>, <span class="Constant"><span class="Constant">:</span>open</span>, <span class="Constant"><span class="Constant">:</span>close</span>, <span class="Constant"><span class="Constant">:</span>delete</span>){ <span class="FunctionName">redirect</span>(Rs()) }
657
+ </code></pre>
556
658
 
557
659
  <p>Alright, that looks a lot nicer already and is definitely easier to maintain.</p>
558
660
 
@@ -564,23 +666,25 @@
564
666
 
565
667
  <p>First we head over to the Controller again and take a look at <code>#create</code>:</p>
566
668
 
567
- <pre><code class="ruby" lang="ruby"><span class="keyword">def </span><span class="method">create</span>
568
- <span class="ident">title</span> <span class="punct">=</span> <span class="ident">request</span><span class="punct">[&#39;</span><span class="string">title</span><span class="punct">&#39;]</span>
569
- <span class="constant">TodoList</span><span class="punct">[</span><span class="ident">title</span><span class="punct">]</span> <span class="punct">=</span> <span class="punct">{</span><span class="symbol">:done</span> <span class="punct">=&gt;</span> <span class="constant">false</span><span class="punct">}</span>
570
- <span class="keyword">end</span></code></pre>
669
+ <pre class="iplastic"><code class="ruby" lang="ruby"><span class="Keyword">def</span> <span class="FunctionName">create</span>
670
+ title <span class="Keyword">=</span> request[<span class="String"><span class="String">'</span>title<span class="String">'</span></span>]
671
+ <span class="Support">TodoList</span>[title] <span class="Keyword">=</span> {<span class="Constant"><span class="Constant">:</span>done</span> =&gt; <span class="Identifier">false</span>}
672
+ <span class="Keyword">end</span>
673
+ </code></pre>
571
674
 
572
675
  <p>Here we just create a new task, no matter what we get. Every seasoned web-developer would advise you to be suspicious about all the input you receive from your users, so let&#8217;s apply this advice.</p>
573
676
 
574
- <pre><code class="ruby" lang="ruby"><span class="keyword">def </span><span class="method">create</span>
575
- <span class="keyword">if</span> <span class="ident">title</span> <span class="punct">=</span> <span class="ident">request</span><span class="punct">[&#39;</span><span class="string">title</span><span class="punct">&#39;]</span>
576
- <span class="ident">title</span><span class="punct">.</span><span class="ident">strip!</span>
577
- <span class="keyword">if</span> <span class="ident">title</span><span class="punct">.</span><span class="ident">empty?</span>
578
- <span class="ident">failed</span><span class="punct">(&quot;</span><span class="string">Please enter a title</span><span class="punct">&quot;)</span>
579
- <span class="ident">redirect</span> <span class="punct">&#39;</span><span class="string">/new</span><span class="punct">&#39;</span>
580
- <span class="keyword">end</span>
581
- <span class="constant">TodoList</span><span class="punct">[</span><span class="ident">title</span><span class="punct">]</span> <span class="punct">=</span> <span class="punct">{</span><span class="symbol">:done</span> <span class="punct">=&gt;</span> <span class="constant">false</span><span class="punct">}</span>
582
- <span class="keyword">end</span>
583
- <span class="keyword">end</span></code></pre>
677
+ <pre class="iplastic"><code class="ruby" lang="ruby"><span class="Keyword">def</span> <span class="FunctionName">create</span>
678
+ <span class="Keyword">if</span> title <span class="Keyword">=</span> request[<span class="String"><span class="String">'</span>title<span class="String">'</span></span>]
679
+ title.<span class="FunctionName">strip!</span>
680
+ <span class="Keyword">if</span> title.<span class="FunctionName">empty?</span>
681
+ <span class="FunctionName">failed</span>(<span class="String"><span class="String">&quot;</span>Please enter a title<span class="String">&quot;</span></span>)
682
+ redirect <span class="String"><span class="String">'</span>/new<span class="String">'</span></span>
683
+ <span class="Keyword">end</span>
684
+ <span class="Support">TodoList</span>[title] <span class="Keyword">=</span> {<span class="Constant"><span class="Constant">:</span>done</span> =&gt; <span class="Identifier">false</span>}
685
+ <span class="Keyword">end</span>
686
+ <span class="Keyword">end</span>
687
+ </code></pre>
584
688
 
585
689
  <p>First of all we check if we got a request with a value for &#8216;title&#8217;, if we get none we just let the aspect kick in that will redirect the browser to the index. Next we strip the title of all spaces around it so we can check if it is empty. We will talk about the specifics of our error-handling now.</p>
586
690
 
@@ -588,45 +692,49 @@
588
692
 
589
693
  <p>Let me show you our <code>#failed</code> method (it goes in the private section to <code>#task_status</code>):</p>
590
694
 
591
- <pre><code class="ruby" lang="ruby"><span class="keyword">def </span><span class="method">failed</span><span class="punct">(</span><span class="ident">message</span><span class="punct">)</span>
592
- <span class="ident">flash</span><span class="punct">[</span><span class="symbol">:error</span><span class="punct">]</span> <span class="punct">=</span> <span class="ident">message</span>
593
- <span class="keyword">end</span></code></pre>
695
+ <pre class="iplastic"><code class="ruby" lang="ruby"><span class="Keyword">def</span> <span class="FunctionName">failed</span>(<span class="Arguments">message</span>)
696
+ flash[<span class="Constant"><span class="Constant">:</span>error</span>] <span class="Keyword">=</span> message
697
+ <span class="Keyword">end</span>
698
+ </code></pre>
594
699
 
595
700
  <p>Duh, you may say, wouldn&#8217;t that fit in the one line instead of the call to <code>#failed</code>? Indeed, it would, but let me remind you, we have no checks for changing the status of a task yet. We will need error-handling there as well, so we just keep our code DRY and maintainable by collecting shared behaviour in small pieces.</p>
596
701
 
597
702
  <p>Now on to the <code>#task_status</code>:</p>
598
703
 
599
- <pre><code class="ruby" lang="ruby"><span class="keyword">def </span><span class="method">task_status</span> <span class="ident">title</span><span class="punct">,</span> <span class="ident">status</span>
600
- <span class="keyword">unless</span> <span class="ident">task</span> <span class="punct">=</span> <span class="constant">TodoList</span><span class="punct">[</span><span class="ident">title</span><span class="punct">]</span>
601
- <span class="ident">failed</span> <span class="punct">&quot;</span><span class="string">No such Task: `<span class="expr">#{title}</span>&#39;</span><span class="punct">&quot;</span>
602
- <span class="ident">redirect_referer</span>
603
- <span class="keyword">end</span>
704
+ <pre class="iplastic"><code class="ruby" lang="ruby"><span class="Keyword">def</span> <span class="FunctionName">task_status</span> title, status
705
+ <span class="Keyword">unless</span> task <span class="Keyword">=</span> <span class="Support">TodoList</span>[title]
706
+ failed <span class="String"><span class="String">&quot;</span>No such Task: `<span class="String"><span class="String">#{</span>title<span class="String">}</span></span>'<span class="String">&quot;</span></span>
707
+ redirect_referer
708
+ <span class="Keyword">end</span>
604
709
 
605
- <span class="ident">task</span><span class="punct">[</span><span class="symbol">:done</span><span class="punct">]</span> <span class="punct">=</span> <span class="ident">status</span>
606
- <span class="constant">TodoList</span><span class="punct">[</span><span class="ident">title</span><span class="punct">]</span> <span class="punct">=</span> <span class="ident">task</span>
607
- <span class="keyword">end</span></code></pre>
710
+ task[<span class="Constant"><span class="Constant">:</span>done</span>] <span class="Keyword">=</span> status
711
+ <span class="Support">TodoList</span>[title] <span class="Keyword">=</span> task
712
+ <span class="Keyword">end</span>
713
+ </code></pre>
608
714
 
609
715
  <p>That used to look like this:</p>
610
716
 
611
- <pre><code class="ruby" lang="ruby"><span class="keyword">def </span><span class="method">task_status</span> <span class="ident">title</span><span class="punct">,</span> <span class="ident">status</span>
612
- <span class="ident">task</span> <span class="punct">=</span> <span class="constant">TodoList</span><span class="punct">[</span><span class="ident">title</span><span class="punct">]</span>
613
- <span class="ident">task</span><span class="punct">[</span><span class="symbol">:done</span><span class="punct">]</span> <span class="punct">=</span> <span class="ident">status</span>
614
- <span class="constant">TodoList</span><span class="punct">[</span><span class="ident">title</span><span class="punct">]</span> <span class="punct">=</span> <span class="ident">task</span>
615
- <span class="keyword">end</span></code></pre>
717
+ <pre class="iplastic"><code class="ruby" lang="ruby"><span class="Keyword">def</span> <span class="FunctionName">task_status</span> title, status
718
+ task <span class="Keyword">=</span> <span class="Support">TodoList</span>[title]
719
+ task[<span class="Constant"><span class="Constant">:</span>done</span>] <span class="Keyword">=</span> status
720
+ <span class="Support">TodoList</span>[title] <span class="Keyword">=</span> task
721
+ <span class="Keyword">end</span>
722
+ </code></pre>
616
723
 
617
724
  <p>So in fact all we added is a check whether a task already exists, set an error-message in case it doesn&#8217;t and redirect to wherever the browser came from.</p>
618
725
 
619
726
  <p>But what about actually showing the error-messages we so carefully set? Well, where do we change the view? Right, in the templates. But both templates we have so far (index and new) share this behaviour, so we head over to the Element and add in the right place:</p>
620
727
 
621
- <pre><code>&lt;body&gt;
622
- &lt;h1&gt;#{@title}&lt;/h1&gt;
623
- &lt;?r if flash[:error] ?&gt;
624
- &lt;div class=&quot;error&quot;&gt;
625
- \\#{flash[:error]}
626
- &lt;/div&gt;
627
- &lt;?r end ?&gt;
628
- #{content}
629
- &lt;/body&gt;</code></pre>
728
+ <pre class="iplastic"><code class="ezamar" lang="ezamar"><span class="Tag"><span class="Tag">&lt;</span><span class="TagName">body</span><span class="Tag">&gt;</span></span>
729
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">h1</span><span class="Tag">&gt;</span></span>#<span class="EmbeddedSource">{@title}</span><span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">h1</span><span class="Tag">&gt;</span></span>
730
+ <span class="EmbeddedSource"><span class="EmbeddedSource">&lt;?r</span> <span class="Keyword">if</span> flash<span class="EmbeddedSource">[</span><span class="Constant"><span class="Constant">:</span>error</span><span class="EmbeddedSource">]</span> <span class="EmbeddedSource">?&gt;</span></span>
731
+ <span class="Tag"><span class="Tag">&lt;</span><span class="TagName">div</span> <span class="TagAttribute">class</span>=<span class="String"><span class="String">&quot;</span>error<span class="String">&quot;</span></span><span class="Tag">&gt;</span></span>
732
+ \\#<span class="EmbeddedSource">{flash[:error]}</span>
733
+ <span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">div</span><span class="Tag">&gt;</span></span>
734
+ <span class="EmbeddedSource"><span class="EmbeddedSource">&lt;?r</span> <span class="Keyword">end</span> <span class="EmbeddedSource">?&gt;</span></span>
735
+ #<span class="EmbeddedSource">{content}</span>
736
+ <span class="Tag"><span class="Tag">&lt;/</span><span class="TagName">body</span><span class="Tag">&gt;</span></span>
737
+ </code></pre>
630
738
 
631
739
  <p>The only thing special about it is the <code>\\#{flash[:error]}</code>, we have to escape the <code>#</code> so it won&#8217;t evaluate this immediately but wait until it is really rendered. As a note, If you read this as pure markaby, the double backslash is to output properly to HTML, just use one instead. Again, you can add some nifty style for that.</p>
632
740