ramaze 0.3.9.1 → 2008.06
Sign up to get free protection for your applications and to get access to all the features.
- data/{doc/README → README.markdown} +78 -32
- data/Rakefile +53 -50
- data/benchmark/results.txt +131 -0
- data/benchmark/run.rb +362 -0
- data/benchmark/suite/minimal.rb +13 -0
- data/benchmark/suite/no_informer.rb +9 -0
- data/benchmark/suite/no_sessions.rb +10 -0
- data/benchmark/suite/no_template.rb +9 -0
- data/benchmark/suite/simple.rb +7 -0
- data/benchmark/suite/template_amrita2.rb +17 -0
- data/benchmark/suite/template_builder.rb +12 -0
- data/benchmark/suite/template_erubis.rb +10 -0
- data/benchmark/suite/template_ezamar.rb +10 -0
- data/benchmark/suite/template_haml.rb +15 -0
- data/benchmark/suite/template_liquid.rb +13 -0
- data/benchmark/suite/template_markaby.rb +11 -0
- data/benchmark/suite/template_nagoro.rb +10 -0
- data/benchmark/suite/template_redcloth.rb +15 -0
- data/benchmark/suite/template_tenjin.rb +10 -0
- data/benchmark/test.rb +35 -0
- data/bin/ramaze +32 -122
- data/cache.yaml +7 -0
- data/doc/AUTHORS +26 -22
- data/doc/CHANGELOG +16720 -3907
- data/doc/INSTALL +77 -19
- data/doc/LEGAL +0 -4
- data/doc/meta/announcement.txt +43 -54
- data/doc/meta/configuration.txt +3 -2
- data/doc/readme_chunks/examples.txt +2 -2
- data/doc/readme_chunks/installing.txt +66 -20
- data/doc/tutorial/todolist.html +338 -520
- data/doc/tutorial/todolist.mkd +36 -2
- data/examples/{auth → app/auth}/auth.rb +0 -0
- data/examples/{auth → app/auth}/template/layout.haml +0 -0
- data/examples/{auth → app/auth}/template/login.haml +0 -0
- data/examples/{blog → app/blog}/README +0 -0
- data/examples/{blog → app/blog}/controller/main.rb +1 -1
- data/examples/{blog → app/blog}/model/entry.rb +1 -1
- data/examples/{blog → app/blog}/public/styles/blog.css +0 -0
- data/examples/{blog → app/blog}/spec/blog.rb +2 -2
- data/examples/{blog → app/blog}/start.rb +0 -0
- data/examples/{blog → app/blog}/view/edit.xhtml +0 -0
- data/examples/{blog → app/blog}/view/index.xhtml +0 -0
- data/examples/{blog → app/blog}/view/layout.xhtml +0 -0
- data/examples/{blog → app/blog}/view/new.xhtml +0 -0
- data/examples/app/chat/model/history.rb +36 -0
- data/examples/app/chat/model/message.rb +7 -0
- data/examples/app/chat/public/css/chat.css +13 -0
- data/examples/app/chat/public/js/chat.js +22 -0
- data/examples/app/chat/public/js/jquery.js +3436 -0
- data/examples/app/chat/start.rb +40 -0
- data/examples/app/chat/view/chat.xhtml +9 -0
- data/examples/app/chat/view/index.xhtml +7 -0
- data/examples/app/chat/view/layout.xhtml +13 -0
- data/examples/app/localization/start.rb +35 -0
- data/examples/{rammit → app/rammit}/spec/rammit.rb +2 -1
- data/examples/{rammit → app/rammit}/src/controller/main.rb +0 -0
- data/examples/{rammit → app/rammit}/src/controller/page.rb +0 -0
- data/examples/{rammit → app/rammit}/src/model.rb +0 -0
- data/examples/{rammit → app/rammit}/start.rb +0 -0
- data/examples/{rammit → app/rammit}/template/index.xhtml +0 -0
- data/examples/{rammit → app/rammit}/template/page/view.xhtml +0 -0
- data/examples/{rapaste → app/rapaste}/Rakefile +0 -1
- data/examples/{rapaste → app/rapaste}/controller/paste.rb +3 -3
- data/examples/{rapaste → app/rapaste}/model/paste.rb +0 -0
- data/examples/{rapaste → app/rapaste}/public/css/active4d.css +0 -0
- data/examples/{rapaste → app/rapaste}/public/css/all_hallows_eve.css +0 -0
- data/examples/{rapaste → app/rapaste}/public/css/amy.css +0 -0
- data/examples/{rapaste → app/rapaste}/public/css/blackboard.css +0 -0
- data/examples/{rapaste → app/rapaste}/public/css/brilliance_black.css +0 -0
- data/examples/{rapaste → app/rapaste}/public/css/brilliance_dull.css +0 -0
- data/examples/{rapaste → app/rapaste}/public/css/cobalt.css +0 -0
- data/examples/{rapaste → app/rapaste}/public/css/dawn.css +0 -0
- data/examples/{rapaste → app/rapaste}/public/css/display.css +0 -0
- data/examples/{rapaste → app/rapaste}/public/css/eiffel.css +0 -0
- data/examples/{rapaste → app/rapaste}/public/css/espresso_libre.css +0 -0
- data/examples/{rapaste → app/rapaste}/public/css/idle.css +0 -0
- data/examples/{rapaste → app/rapaste}/public/css/iplastic.css +0 -0
- data/examples/{rapaste → app/rapaste}/public/css/lazy.css +0 -0
- data/examples/{rapaste → app/rapaste}/public/css/mac_classic.css +0 -0
- data/examples/{rapaste → app/rapaste}/public/css/magicwb_amiga.css +0 -0
- data/examples/{rapaste → app/rapaste}/public/css/pastels_on_dark.css +0 -0
- data/examples/{rapaste → app/rapaste}/public/css/slush_poppies.css +0 -0
- data/examples/{rapaste → app/rapaste}/public/css/spacecadet.css +0 -0
- data/examples/{rapaste → app/rapaste}/public/css/sunburst.css +0 -0
- data/examples/{rapaste → app/rapaste}/public/css/twilight.css +0 -0
- data/examples/{rapaste → app/rapaste}/public/css/zenburnesque.css +0 -0
- data/examples/{rapaste → app/rapaste}/public/js/jquery.js +0 -0
- data/examples/{rapaste → app/rapaste}/spec/rapaste.rb +2 -2
- data/examples/{rapaste → app/rapaste}/start.rb +0 -0
- data/examples/{rapaste → app/rapaste}/view/copy.xhtml +0 -0
- data/examples/{rapaste → app/rapaste}/view/index.xhtml +0 -0
- data/examples/{rapaste → app/rapaste}/view/layout.xhtml +0 -0
- data/examples/{rapaste → app/rapaste}/view/list.xhtml +0 -0
- data/examples/{rapaste → app/rapaste}/view/search.xhtml +0 -0
- data/examples/{rapaste → app/rapaste}/view/view.xhtml +0 -0
- data/examples/{sourceview → app/sourceview}/public/coderay.css +0 -0
- data/examples/{sourceview → app/sourceview}/public/images/file.gif +0 -0
- data/examples/{sourceview → app/sourceview}/public/images/folder.gif +0 -0
- data/examples/{sourceview → app/sourceview}/public/images/tv-collapsable-last.gif +0 -0
- data/examples/{sourceview → app/sourceview}/public/images/tv-collapsable.gif +0 -0
- data/examples/{sourceview → app/sourceview}/public/images/tv-expandable-last.gif +0 -0
- data/examples/{sourceview → app/sourceview}/public/images/tv-expandable.gif +0 -0
- data/examples/{sourceview → app/sourceview}/public/images/tv-item-last.gif +0 -0
- data/examples/{sourceview → app/sourceview}/public/images/tv-item.gif +0 -0
- data/examples/{sourceview → app/sourceview}/public/jquery.js +0 -0
- data/examples/{sourceview → app/sourceview}/public/jquery.treeview.css +0 -0
- data/examples/{sourceview → app/sourceview}/public/jquery.treeview.js +0 -0
- data/examples/{sourceview → app/sourceview}/public/sourceview.js +0 -0
- data/examples/{sourceview → app/sourceview}/sourceview.rb +1 -1
- data/examples/{sourceview → app/sourceview}/template/index.haml +0 -0
- data/examples/{todolist → app/todolist}/README +0 -0
- data/examples/{todolist → app/todolist}/public/favicon.ico +0 -0
- data/examples/{todolist → app/todolist}/public/js/jquery.js +0 -0
- data/examples/{todolist → app/todolist}/public/ramaze.png +0 -0
- data/examples/{todolist → app/todolist}/spec/todolist.rb +2 -2
- data/examples/{todolist → app/todolist}/src/controller/main.rb +0 -0
- data/examples/{todolist → app/todolist}/src/element/page.rb +0 -0
- data/examples/{todolist → app/todolist}/src/model.rb +0 -0
- data/examples/{todolist → app/todolist}/start.rb +0 -0
- data/examples/{todolist → app/todolist}/template/index.xhtml +0 -0
- data/examples/{todolist → app/todolist}/template/new.xhtml +0 -0
- data/examples/{upload → app/upload}/start.rb +0 -0
- data/examples/{upload → app/upload}/view/index.xhtml +0 -0
- data/examples/{whywiki → app/whywiki}/spec/whywiki.rb +3 -3
- data/examples/{whywiki → app/whywiki}/start.rb +0 -0
- data/examples/{whywiki → app/whywiki}/template/edit.xhtml +0 -0
- data/examples/{whywiki → app/whywiki}/template/show.xhtml +0 -0
- data/examples/{wikore → app/wikore}/spec/wikore.rb +2 -2
- data/examples/{wikore → app/wikore}/src/controller.rb +0 -0
- data/examples/{wikore → app/wikore}/src/model.rb +0 -0
- data/examples/{wikore → app/wikore}/start.rb +0 -0
- data/examples/{wikore → app/wikore}/template/index.xhtml +0 -0
- data/examples/{wiktacular → app/wiktacular}/README +0 -0
- data/examples/{wiktacular → app/wiktacular}/mkd/link/2007-07-20_19-45-51.mkd +0 -0
- data/examples/{wiktacular → app/wiktacular}/mkd/link/current.mkd +0 -0
- data/examples/{wiktacular → app/wiktacular}/mkd/main/2007-07-20_16-31-33.mkd +0 -0
- data/examples/{wiktacular → app/wiktacular}/mkd/main/2007-07-20_19-21-12.mkd +0 -0
- data/examples/{wiktacular → app/wiktacular}/mkd/main/2007-07-20_19-23-10.mkd +0 -0
- data/examples/{wiktacular → app/wiktacular}/mkd/main/2007-07-20_19-45-07.mkd +0 -0
- data/examples/{wiktacular → app/wiktacular}/mkd/main/current.mkd +0 -0
- data/examples/{wiktacular → app/wiktacular}/mkd/markdown/current.mkd +0 -0
- data/examples/{wiktacular → app/wiktacular}/mkd/testing/2007-07-20_16-43-46.mkd +0 -0
- data/examples/{wiktacular → app/wiktacular}/mkd/testing/2007-07-20_19-43-50.mkd +0 -0
- data/examples/{wiktacular → app/wiktacular}/mkd/testing/2007-07-21_18-46-01.mkd +0 -0
- data/examples/{wiktacular → app/wiktacular}/mkd/testing/2007-07-21_18-46-32.mkd +0 -0
- data/examples/{wiktacular → app/wiktacular}/mkd/testing/2007-07-21_18-47-08.mkd +0 -0
- data/examples/{wiktacular → app/wiktacular}/mkd/testing/2007-07-21_18-47-54.mkd +0 -0
- data/examples/{wiktacular → app/wiktacular}/mkd/testing/current.mkd +0 -0
- data/examples/{wiktacular → app/wiktacular}/public/favicon.ico +0 -0
- data/examples/{wiktacular → app/wiktacular}/public/screen.css +0 -0
- data/examples/{wiktacular → app/wiktacular}/spec/wiktacular.rb +4 -5
- data/examples/{wiktacular → app/wiktacular}/src/controller.rb +0 -0
- data/examples/{wiktacular → app/wiktacular}/src/model.rb +0 -0
- data/examples/{wiktacular → app/wiktacular}/start.rb +0 -0
- data/examples/{wiktacular → app/wiktacular}/template/edit.xhtml +0 -0
- data/examples/{wiktacular → app/wiktacular}/template/html_layout.xhtml +0 -0
- data/examples/{wiktacular → app/wiktacular}/template/index.xhtml +0 -0
- data/examples/{wiktacular → app/wiktacular}/template/new.xhtml +0 -0
- data/examples/{element.rb → basic/element.rb} +0 -0
- data/examples/basic/gestalt.rb +27 -0
- data/examples/{hello.rb → basic/hello.rb} +0 -0
- data/examples/{layout.rb → basic/layout.rb} +0 -0
- data/examples/{linking.rb → basic/linking.rb} +0 -0
- data/examples/{simple.rb → basic/simple.rb} +3 -3
- data/examples/{caching.rb → helpers/cache.rb} +0 -0
- data/examples/helpers/form_with_sequel.rb +24 -0
- data/examples/helpers/httpdigest.rb +50 -0
- data/examples/{identity.rb → helpers/identity.rb} +0 -0
- data/examples/{nitro_form.rb → helpers/nitro_form.rb} +0 -0
- data/examples/helpers/provide.rb +23 -0
- data/examples/helpers/rest.rb +28 -0
- data/examples/helpers/simple_captcha.rb +29 -0
- data/examples/{css.rb → misc/css.rb} +0 -0
- data/examples/{facebook.rb → misc/facebook.rb} +0 -0
- data/examples/{memleak_detector.rb → misc/memleak_detector.rb} +0 -0
- data/examples/misc/nagoro_element.rb +43 -0
- data/examples/{ramaise.rb → misc/ramaise.rb} +0 -0
- data/examples/misc/rapp.rb +45 -0
- data/examples/misc/sequel_scaffolding.rb +34 -0
- data/examples/{simple_auth.rb → misc/simple_auth.rb} +0 -0
- data/examples/templates/template_amrita2.rb +1 -1
- data/examples/templates/template_erubis.rb +2 -2
- data/examples/templates/template_ezamar.rb +1 -1
- data/examples/templates/template_haml.rb +2 -2
- data/examples/templates/template_liquid.rb +2 -2
- data/examples/templates/template_markaby.rb +1 -1
- data/examples/templates/template_nagoro.rb +1 -1
- data/examples/templates/template_redcloth.rb +2 -2
- data/examples/templates/template_remarkably.rb +1 -1
- data/examples/templates/template_tenjin.rb +5 -9
- data/examples/templates/template_xslt.rb +1 -1
- data/lib/proto/public/dispatch.fcgi +0 -0
- data/lib/proto/public/js/jquery.js +750 -577
- data/lib/proto/spec/main.rb +1 -1
- data/lib/proto/start.ru +8 -0
- data/lib/proto/view/page.xhtml +13 -1
- data/lib/ramaze.rb +32 -15
- data/lib/ramaze/action.rb +18 -1
- data/lib/ramaze/action/render.rb +45 -17
- data/lib/ramaze/adapter.rb +8 -7
- data/lib/ramaze/adapter/base.rb +79 -13
- data/lib/ramaze/adapter/cgi.rb +5 -10
- data/lib/ramaze/adapter/ebb.rb +6 -20
- data/lib/ramaze/adapter/fake.rb +12 -0
- data/lib/ramaze/adapter/fcgi.rb +5 -11
- data/lib/ramaze/adapter/lsws.rb +5 -9
- data/lib/ramaze/adapter/mongrel.rb +5 -9
- data/lib/ramaze/adapter/scgi.rb +4 -8
- data/lib/ramaze/adapter/thin.rb +6 -11
- data/lib/ramaze/adapter/webrick.rb +13 -22
- data/lib/ramaze/cache.rb +36 -10
- data/lib/ramaze/cache/memcached.rb +3 -2
- data/lib/ramaze/contrib.rb +1 -1
- data/lib/ramaze/contrib/email.rb +1 -1
- data/lib/ramaze/contrib/file_cache.rb +1 -1
- data/lib/ramaze/contrib/gems.rb +79 -0
- data/lib/ramaze/contrib/gettext/po.rb +0 -0
- data/lib/ramaze/contrib/profiling.rb +1 -1
- data/lib/ramaze/contrib/rest.rb +14 -0
- data/lib/ramaze/controller.rb +45 -12
- data/lib/ramaze/controller/error.rb +4 -4
- data/lib/ramaze/controller/resolve.rb +61 -42
- data/lib/ramaze/current.rb +2 -2
- data/lib/ramaze/current/request.rb +25 -2
- data/lib/ramaze/current/response.rb +8 -0
- data/lib/ramaze/current/session.rb +64 -36
- data/lib/ramaze/current/session/flash.rb +14 -2
- data/lib/ramaze/current/session/hash.rb +3 -2
- data/lib/ramaze/dispatcher.rb +25 -12
- data/lib/ramaze/dispatcher/action.rb +12 -3
- data/lib/ramaze/dispatcher/directory.rb +4 -1
- data/lib/ramaze/dispatcher/error.rb +3 -3
- data/lib/ramaze/dispatcher/file.rb +11 -3
- data/lib/ramaze/gestalt.rb +1 -1
- data/lib/ramaze/helper.rb +17 -21
- data/lib/ramaze/helper/aspect.rb +20 -14
- data/lib/ramaze/helper/auth.rb +1 -1
- data/lib/ramaze/helper/cache.rb +3 -6
- data/lib/ramaze/helper/cgi.rb +6 -2
- data/lib/ramaze/helper/flash.rb +7 -7
- data/lib/ramaze/helper/form.rb +281 -0
- data/lib/ramaze/helper/formatting.rb +76 -0
- data/lib/ramaze/helper/gestalt.rb +15 -0
- data/lib/ramaze/helper/gravatar.rb +15 -0
- data/lib/ramaze/helper/httpdigest.rb +48 -0
- data/lib/ramaze/helper/identity.rb +87 -62
- data/lib/ramaze/helper/partial.rb +11 -2
- data/lib/ramaze/helper/redirect.rb +12 -3
- data/lib/ramaze/helper/rest.rb +43 -0
- data/lib/ramaze/helper/sendfile.rb +1 -3
- data/lib/ramaze/helper/sequel.rb +3 -0
- data/lib/ramaze/helper/simple_captcha.rb +31 -0
- data/lib/ramaze/helper/stack.rb +14 -5
- data/lib/ramaze/helper/user.rb +86 -34
- data/lib/ramaze/helper/xhtml.rb +23 -0
- data/lib/ramaze/log.rb +1 -2
- data/lib/ramaze/log/analogger.rb +24 -19
- data/lib/ramaze/log/growl.rb +24 -19
- data/lib/ramaze/log/hub.rb +25 -22
- data/lib/ramaze/log/informer.rb +104 -99
- data/lib/ramaze/log/knotify.rb +17 -12
- data/lib/ramaze/log/logger.rb +14 -8
- data/lib/ramaze/log/logging.rb +63 -60
- data/lib/ramaze/log/syslog.rb +24 -19
- data/lib/ramaze/log/xosd.rb +77 -71
- data/lib/ramaze/option.rb +153 -0
- data/lib/ramaze/option/dsl.rb +45 -0
- data/lib/ramaze/option/holder.rb +153 -0
- data/lib/ramaze/option/merger.rb +108 -0
- data/lib/ramaze/route.rb +15 -2
- data/lib/ramaze/setup.rb +50 -0
- data/lib/ramaze/snippets/binding/locals.rb +1 -1
- data/lib/ramaze/snippets/dictionary.rb +3 -3
- data/lib/ramaze/snippets/divide.rb +7 -7
- data/lib/ramaze/snippets/kernel/__dir__.rb +1 -1
- data/lib/ramaze/snippets/kernel/acquire.rb +0 -5
- data/lib/ramaze/snippets/metaid.rb +1 -1
- data/lib/ramaze/snippets/numeric/filesize_format.rb +11 -5
- data/lib/ramaze/snippets/object/instance_variable_defined.rb +8 -0
- data/lib/ramaze/snippets/object/scope.rb +1 -1
- data/lib/ramaze/snippets/object/thread_accessor.rb +1 -1
- data/lib/ramaze/snippets/ordered_set.rb +5 -1
- data/lib/ramaze/snippets/ramaze/deprecated.rb +7 -0
- data/lib/ramaze/snippets/ramaze/thread_accessor.rb +15 -1
- data/lib/ramaze/snippets/string/esc.rb +2 -2
- data/lib/ramaze/snippets/string/start_with.rb +1 -0
- data/lib/ramaze/snippets/string/unindent.rb +9 -1
- data/lib/ramaze/snippets/struct/values_at.rb +17 -1
- data/lib/ramaze/snippets/thread/into.rb +1 -1
- data/lib/ramaze/sourcereload.rb +83 -76
- data/lib/ramaze/spec/helper.rb +39 -26
- data/lib/ramaze/spec/helper/bacon.rb +5 -5
- data/lib/ramaze/spec/helper/mock_http.rb +1 -7
- data/lib/ramaze/spec/helper/pretty_output.rb +10 -2
- data/lib/ramaze/spec/helper/requester.rb +14 -0
- data/lib/ramaze/template.rb +6 -3
- data/lib/ramaze/template/amrita2.rb +1 -0
- data/lib/ramaze/template/erubis.rb +7 -1
- data/lib/ramaze/template/ezamar/render_partial.rb +1 -1
- data/lib/ramaze/template/nagoro.rb +1 -0
- data/lib/ramaze/template/redcloth.rb +1 -0
- data/lib/ramaze/template/tagz.rb +8 -8
- data/lib/ramaze/template/tenjin.rb +42 -2
- data/lib/ramaze/template/xslt.rb +4 -0
- data/lib/ramaze/tool/daemonize.rb +37 -0
- data/lib/ramaze/tool/localize.rb +142 -106
- data/lib/ramaze/version.rb +2 -10
- data/rake_tasks/conf.rake +11 -13
- data/rake_tasks/gem.rake +59 -37
- data/rake_tasks/git.rake +41 -0
- data/rake_tasks/maintenance.rake +263 -299
- data/rake_tasks/release.rake +63 -0
- data/rake_tasks/spec.rake +1 -1
- data/ramaze.gemspec +731 -0
- data/spec/contrib/profiling.rb +5 -2
- data/spec/examples/caching.rb +1 -1
- data/spec/examples/css.rb +1 -1
- data/spec/examples/element.rb +1 -1
- data/spec/examples/hello.rb +1 -1
- data/spec/examples/linking.rb +1 -1
- data/spec/examples/simple.rb +1 -1
- data/spec/examples/simple_auth.rb +1 -1
- data/spec/ramaze/action/cache.rb +58 -14
- data/spec/ramaze/action/file_cache.rb +48 -0
- data/spec/ramaze/action/layout.rb +2 -2
- data/spec/ramaze/action/render.rb +1 -2
- data/spec/ramaze/action/{template → view}/bar.xhtml +0 -0
- data/spec/ramaze/action/{template → view}/instancevars/layout.xhtml +0 -0
- data/spec/ramaze/action/{template → view}/other_wrapper.xhtml +0 -0
- data/spec/ramaze/action/{template → view}/single_wrapper.xhtml +0 -0
- data/spec/ramaze/action/{template → view}/sub/sub_wrapper.xhtml +0 -0
- data/spec/ramaze/adapter.rb +29 -2
- data/spec/ramaze/adapter/ebb.rb +12 -0
- data/spec/ramaze/cache.rb +82 -15
- data/spec/ramaze/controller.rb +6 -3
- data/spec/ramaze/controller/actionless_templates.rb +2 -2
- data/spec/ramaze/controller/resolve.rb +1 -1
- data/spec/ramaze/controller/template_resolving.rb +4 -6
- data/spec/ramaze/controller/{template → view}/greet.xhtml +0 -0
- data/spec/ramaze/controller/{template → view}/list.xhtml +0 -0
- data/spec/ramaze/controller/{template → view}/other/greet/other.xhtml +0 -0
- data/spec/ramaze/controller/{template → view}/other_wrapper.xhtml +0 -0
- data/spec/ramaze/error.rb +1 -1
- data/spec/ramaze/helper/aspect.rb +4 -4
- data/spec/ramaze/helper/cache.rb +56 -39
- data/spec/ramaze/helper/flash.rb +14 -1
- data/spec/ramaze/helper/form.rb +118 -0
- data/spec/ramaze/helper/formatting.rb +21 -0
- data/spec/ramaze/helper/link.rb +2 -2
- data/spec/ramaze/helper/pager.rb +2 -2
- data/spec/ramaze/helper/partial.rb +13 -1
- data/spec/ramaze/helper/simple_captcha.rb +22 -0
- data/spec/ramaze/helper/user.rb +7 -10
- data/spec/ramaze/helper/{template → view}/locals.xhtml +0 -0
- data/spec/ramaze/helper/{template → view}/loop.xhtml +0 -0
- data/spec/ramaze/helper/{template → view}/num.xhtml +0 -0
- data/spec/ramaze/helper/{template → view}/partial.xhtml +0 -0
- data/spec/ramaze/helper/{template → view}/recursive.xhtml +0 -0
- data/spec/ramaze/helper/{template → view}/recursive_local_ivars.xhtml +0 -0
- data/spec/ramaze/helper/{template → view}/recursive_locals.xhtml +0 -0
- data/spec/ramaze/helper/{template → view}/test_template.xhtml +0 -0
- data/spec/ramaze/localize.rb +22 -0
- data/spec/ramaze/log/informer.rb +10 -10
- data/spec/ramaze/log/syslog.rb +1 -1
- data/spec/ramaze/request.rb +13 -1
- data/spec/ramaze/request/ebb.rb +9 -0
- data/spec/ramaze/rewrite.rb +36 -0
- data/spec/ramaze/rewrite/file.css +1 -0
- data/spec/ramaze/route.rb +1 -0
- data/spec/ramaze/template.rb +5 -5
- data/spec/ramaze/template/amrita2.rb +1 -1
- data/spec/ramaze/template/builder.rb +18 -22
- data/spec/ramaze/template/erubis.rb +1 -1
- data/spec/ramaze/template/ezamar.rb +1 -1
- data/spec/ramaze/template/haml.rb +2 -2
- data/spec/ramaze/template/liquid.rb +1 -1
- data/spec/ramaze/template/markaby.rb +1 -1
- data/spec/ramaze/template/nagoro.rb +1 -1
- data/spec/ramaze/template/redcloth.rb +1 -1
- data/spec/ramaze/template/remarkably.rb +1 -1
- data/spec/ramaze/template/sass.rb +1 -1
- data/spec/ramaze/template/tagz.rb +1 -1
- data/spec/ramaze/template/tenjin.rb +4 -6
- data/spec/ramaze/template/xslt.rb +1 -1
- data/spec/snippets/string/unindent.rb +6 -0
- data/spec/snippets/struct/values_at.rb +8 -0
- metadata +522 -487
- data/doc/ProjectInfo +0 -53
- data/doc/migrate/1110_to_1111.txt +0 -131
- data/lib/ramaze/contrib/route.rb +0 -22
- data/lib/ramaze/global.rb +0 -116
- data/lib/ramaze/global/dsl.rb +0 -39
- data/lib/ramaze/global/globalstruct.rb +0 -147
- data/lib/ramaze/helper/inform.rb +0 -40
- data/lib/ramaze/inform.rb +0 -4
- data/lib/ramaze/snippets/kernel/aquire.rb +0 -1
- data/lib/vendor/bacon.rb +0 -323
- data/rake_tasks/darcs.rake +0 -5
- data/spec/contrib/route.rb +0 -36
data/doc/INSTALL
CHANGED
@@ -1,34 +1,92 @@
|
|
1
|
-
= Installating Ramaze
|
2
|
-
|
3
1
|
* via RubyGems
|
4
2
|
|
5
|
-
The simplest way of installing Ramaze is via
|
3
|
+
The simplest way of installing Ramaze is via the gem.
|
4
|
+
|
5
|
+
[Rubygems](http://rubygems.org) is the package manager for ruby apps and
|
6
|
+
libraries and provides you with the last tagged version of Ramaze.
|
6
7
|
|
7
|
-
|
8
|
+
$ gem install ramaze
|
8
9
|
|
9
|
-
|
10
|
-
|
10
|
+
Versions are made as we see fit and get an announcment out (usually that's
|
11
|
+
the major obstacle as there is a lot to announce).
|
11
12
|
|
12
|
-
|
13
|
+
If you want to install the nightly gem of Ramaze you can do this with:
|
13
14
|
|
14
|
-
|
15
|
-
you can use it like
|
15
|
+
$ gem install ramaze --source=http://gem.ramaze.net/
|
16
16
|
|
17
|
-
|
17
|
+
We also use the gem building process on github, which locates gems at
|
18
|
+
http://gems.github.com - so you can get a version from there as well:
|
18
19
|
|
19
|
-
|
20
|
-
that, depending on what options you provide.
|
21
|
-
(please note that I haven't tested the install.rb extensively yet, so if you
|
22
|
-
find some quirks, please send me patches or a simple note)
|
20
|
+
$ gem install manveru-ramaze --source=http://gems.github.com/
|
23
21
|
|
24
|
-
* via
|
22
|
+
* via git
|
25
23
|
|
26
24
|
To get the latest and sweetest, you can just pull from the repository and run
|
27
25
|
Ramaze that way.
|
28
26
|
|
29
|
-
|
27
|
+
$ git clone git://github.com/manveru/ramaze.git
|
30
28
|
|
31
|
-
Please read the man
|
29
|
+
Please read the `man git` or `git help` for more information about updating
|
32
30
|
and creating your own patches.
|
33
|
-
This is at the moment the premier way to use Ramaze, since it is the way I
|
34
|
-
it.
|
31
|
+
This is at the moment the premier way to use Ramaze, since it is the way I
|
32
|
+
use it.
|
33
|
+
|
34
|
+
Some hints for the usage of Git.
|
35
|
+
|
36
|
+
* use `require 'ramaze'` from everywhere
|
37
|
+
|
38
|
+
Simply add the path to your repository to the RUBYLIB environment variable.
|
39
|
+
If you are using bash you can simply put following line into your .bashrc:
|
40
|
+
|
41
|
+
$ export RUBYLIB="$HOME/path/to/repo/lib/"
|
42
|
+
|
43
|
+
Of course you should put the real path instead, you can also add multiple
|
44
|
+
paths, or create your personal `site_ruby`:
|
45
|
+
|
46
|
+
$ export RUBYLIB="$HOME/ruby/ramaze/lib:$HOME/.site_ruby:$HOME/ruby/bacon/lib"
|
47
|
+
|
48
|
+
* use `require 'ramaze'` systemwide from everywhere
|
49
|
+
|
50
|
+
add a file to your `site_ruby` directory named 'ramaze.rb'
|
51
|
+
the content should be: `require '/path/to/git/repo/ramaze/lib/ramaze'`
|
52
|
+
|
53
|
+
* Pull the latest version
|
54
|
+
|
55
|
+
$ git pull
|
56
|
+
|
57
|
+
* Reset the repo to original state (if you screw up something)
|
58
|
+
|
59
|
+
$ git reset --hard # resets the whole repo
|
60
|
+
|
61
|
+
* Revert changes to (for example) lib/ramaze.rb only
|
62
|
+
|
63
|
+
$ git checkout master lib/ramaze.rb
|
64
|
+
|
65
|
+
* Add and commit all changes.
|
66
|
+
|
67
|
+
$ git commit -a
|
68
|
+
|
69
|
+
* Adding only specific changes.
|
70
|
+
|
71
|
+
# Add hunks you want to commit to the staging area (index)
|
72
|
+
$ git add -p
|
73
|
+
|
74
|
+
* Commit the changes into the history of your repository
|
75
|
+
|
76
|
+
# Create a commit from the hunks added
|
77
|
+
$ git commit
|
78
|
+
|
79
|
+
* output your patches into a bundle ready to be mailed (compress it before
|
80
|
+
sending to make sure it arrives in the way you sent it)
|
81
|
+
|
82
|
+
At the end of this process you will have a tar.bz2 for all your changes
|
83
|
+
that you can mail to ramaze@googlegroups.com
|
84
|
+
|
85
|
+
# make sure you are on latest revision to avoid conflicts
|
86
|
+
$ git pull
|
87
|
+
|
88
|
+
# create 00xx-blah.patch files against the remote repo
|
89
|
+
$ git format-patch origin/HEAD
|
90
|
+
|
91
|
+
# From here on you can use either git-send-email or go the manual route
|
92
|
+
$ tar -cjf ramaze_bundle.tar.bz2 *.patch
|
data/doc/LEGAL
CHANGED
data/doc/meta/announcement.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
This time we are proud to announce Version
|
1
|
+
This time we are proud to announce Version 2008.06 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,15 @@ 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:
|
14
|
-
Screencasts:
|
13
|
+
Home page: http://ramaze.net
|
14
|
+
Screencasts: http://ramaze.net/screencasts
|
15
15
|
|
16
|
-
View source:
|
17
|
-
|
16
|
+
View source: http://source.ramaze.net
|
17
|
+
Github: http://github.com/manveru/ramaze
|
18
|
+
|
19
|
+
Nightly gems: http://gems.ramaze.net
|
20
|
+
Git clone: git://github.com/manveru/ramaze
|
21
|
+
Current tarball: http://github.com/manveru/ramaze/tarball/master
|
18
22
|
|
19
23
|
IRC: #ramaze on irc.freenode.net
|
20
24
|
|
@@ -32,59 +36,44 @@ Simple example:
|
|
32
36
|
Ramaze.start
|
33
37
|
|
34
38
|
|
35
|
-
|
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.
|
44
|
+
|
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.
|
36
49
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
skaar - first patch!
|
46
|
-
|
47
|
-
|
48
|
-
Selected summary of the 62 patches from 0.3.0 to 0.3.5:
|
49
|
-
|
50
|
-
Core
|
51
|
-
- Ramaze::Contrib::Route made available by default as Ramaze::Route
|
52
|
-
(backwards compatibility retained)
|
53
|
-
- Support added for ETag and If-Modified-Since in Dispatcher::File
|
54
|
-
- Adapter for LiteSpeed webserver added
|
55
|
-
- Added ability to set default session cookie options using Session::COOKIE
|
56
|
-
- Support added for Content-Language based localization and gettext
|
57
|
-
|
58
|
-
Templates
|
59
|
-
- Support added for passing in locals to render_template
|
60
|
-
- Added support for symbol argument to template_root
|
61
|
-
- render_template no longer requires template extensions
|
62
|
-
- Dots allowed in template extensions (template.html.erb)
|
63
|
-
|
64
|
-
Templating Engines
|
65
|
-
- Builder templating engine added to produce XML
|
66
|
-
- RedCloth templating engine added
|
67
|
-
- Amrita2 templating engine updated to latest release
|
68
|
-
|
69
|
-
Helpers
|
70
|
-
- Simple EmailHelper added
|
71
|
-
- IdentityHelper updated for latest ruby-openid
|
72
|
-
- MarukuHelper added
|
73
|
-
- AuthHelper cleaned up
|
74
|
-
- LinkHelper improved: A(), R(), Rs() and breadcrumbs
|
75
|
-
|
76
|
-
Examples
|
77
|
-
- All examples were standardized to include rubygems
|
78
|
-
- Simple file upload example added
|
79
|
-
- Search and diff functionality added to Rapaste
|
80
|
-
|
81
|
-
Misc
|
82
|
-
- Read and read/write issues fixed in Ramaze::Store
|
83
|
-
- Fix applied for running Ramaze apps within IDEs on Windows
|
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.
|
56
|
+
|
57
|
+
Special (alphabetic) thanks go to:
|
84
58
|
|
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
|
85
74
|
|
86
75
|
A complete Changelog is available at
|
87
|
-
http://
|
76
|
+
http://github.com/manveru/ramaze/tree/master/doc/CHANGELOG?raw=true
|
88
77
|
|
89
78
|
|
90
79
|
Known issues:
|
data/doc/meta/configuration.txt
CHANGED
@@ -18,9 +18,10 @@ Global with Ramaze so it is written Ramaze::Global.
|
|
18
18
|
|
19
19
|
#### Basic assignment:
|
20
20
|
|
21
|
-
Global.
|
21
|
+
Global.port = 10
|
22
22
|
|
23
|
-
if you do that before calling Ramaze::start Ramaze will
|
23
|
+
if you do that before calling Ramaze::start Ramaze will choose the given number
|
24
|
+
as port.
|
24
25
|
|
25
26
|
|
26
27
|
#### Multiple assignment:
|
@@ -29,10 +29,10 @@ Examples include:
|
|
29
29
|
Not yet fully functional, but coming along.
|
30
30
|
|
31
31
|
* examples/whywiki
|
32
|
-
A basic examples of a minimalistic application, based on the Wiki of _why in
|
32
|
+
A basic examples of a minimalistic application, based on the Wiki of \_why in
|
33
33
|
his camping-framework.
|
34
34
|
|
35
35
|
* examples/templates
|
36
36
|
examples of real usage of the templating-engines. Tries to implement the same
|
37
|
-
functionality in each template_*.rb file using a different engine.
|
37
|
+
functionality in each `template_*.rb` file using a different engine.
|
38
38
|
|
@@ -1,46 +1,92 @@
|
|
1
1
|
* via RubyGems
|
2
2
|
|
3
|
-
The simplest way of installing Ramaze is via
|
3
|
+
The simplest way of installing Ramaze is via the gem.
|
4
4
|
|
5
|
-
|
5
|
+
[Rubygems](http://rubygems.org) is the package manager for ruby apps and
|
6
|
+
libraries and provides you with the last tagged version of Ramaze.
|
6
7
|
|
7
|
-
|
8
|
+
$ gem install ramaze
|
8
9
|
|
10
|
+
Versions are made as we see fit and get an announcment out (usually that's
|
11
|
+
the major obstacle as there is a lot to announce).
|
9
12
|
|
10
|
-
|
13
|
+
If you want to install the nightly gem of Ramaze you can do this with:
|
14
|
+
|
15
|
+
$ gem install ramaze --source=http://gem.ramaze.net/
|
16
|
+
|
17
|
+
We also use the gem building process on github, which locates gems at
|
18
|
+
http://gems.github.com - so you can get a version from there as well:
|
19
|
+
|
20
|
+
$ gem install manveru-ramaze --source=http://gems.github.com/
|
21
|
+
|
22
|
+
* via git
|
11
23
|
|
12
24
|
To get the latest and sweetest, you can just pull from the repository and run
|
13
25
|
Ramaze that way.
|
14
26
|
|
15
|
-
|
27
|
+
$ git clone git://github.com/manveru/ramaze.git
|
16
28
|
|
17
|
-
Please read the man
|
29
|
+
Please read the `man git` or `git help` for more information about updating
|
18
30
|
and creating your own patches.
|
19
|
-
This is at the moment the premier way to use Ramaze, since it is the way I
|
20
|
-
it.
|
31
|
+
This is at the moment the premier way to use Ramaze, since it is the way I
|
32
|
+
use it.
|
33
|
+
|
34
|
+
Some hints for the usage of Git.
|
35
|
+
|
36
|
+
* use `require 'ramaze'` from everywhere
|
37
|
+
|
38
|
+
Simply add the path to your repository to the RUBYLIB environment variable.
|
39
|
+
If you are using bash you can simply put following line into your .bashrc:
|
40
|
+
|
41
|
+
$ export RUBYLIB="$HOME/path/to/repo/lib/"
|
42
|
+
|
43
|
+
Of course you should put the real path instead, you can also add multiple
|
44
|
+
paths, or create your personal `site_ruby`:
|
45
|
+
|
46
|
+
$ export RUBYLIB="$HOME/ruby/ramaze/lib:$HOME/.site_ruby:$HOME/ruby/bacon/lib"
|
47
|
+
|
48
|
+
* use `require 'ramaze'` systemwide from everywhere
|
49
|
+
|
50
|
+
add a file to your `site_ruby` directory named 'ramaze.rb'
|
51
|
+
the content should be: `require '/path/to/git/repo/ramaze/lib/ramaze'`
|
52
|
+
|
53
|
+
* Pull the latest version
|
54
|
+
|
55
|
+
$ git pull
|
56
|
+
|
57
|
+
* Reset the repo to original state (if you screw up something)
|
58
|
+
|
59
|
+
$ git reset --hard # resets the whole repo
|
60
|
+
|
61
|
+
* Revert changes to (for example) lib/ramaze.rb only
|
21
62
|
|
22
|
-
|
63
|
+
$ git checkout master lib/ramaze.rb
|
23
64
|
|
24
|
-
*
|
65
|
+
* Add and commit all changes.
|
25
66
|
|
26
|
-
|
27
|
-
the content should be: "require '/path/to/darcs/repo/ramaze/lib/ramaze'"
|
67
|
+
$ git commit -a
|
28
68
|
|
29
|
-
*
|
69
|
+
* Adding only specific changes.
|
30
70
|
|
31
|
-
|
71
|
+
# Add hunks you want to commit to the staging area (index)
|
72
|
+
$ git add -p
|
32
73
|
|
33
|
-
*
|
74
|
+
* Commit the changes into the history of your repository
|
34
75
|
|
35
|
-
|
76
|
+
# Create a commit from the hunks added
|
77
|
+
$ git commit
|
36
78
|
|
37
79
|
* output your patches into a bundle ready to be mailed (compress it before
|
38
80
|
sending to make sure it arrives in the way you sent it)
|
39
81
|
|
40
|
-
|
41
|
-
|
82
|
+
At the end of this process you will have a tar.bz2 for all your changes
|
83
|
+
that you can mail to ramaze@googlegroups.com
|
42
84
|
|
85
|
+
# make sure you are on latest revision to avoid conflicts
|
86
|
+
$ git pull
|
43
87
|
|
44
|
-
|
88
|
+
# create 00xx-blah.patch files against the remote repo
|
89
|
+
$ git format-patch origin/HEAD
|
45
90
|
|
46
|
-
|
91
|
+
# From here on you can use either git-send-email or go the manual route
|
92
|
+
$ tar -cjf ramaze_bundle.tar.bz2 *.patch
|
data/doc/tutorial/todolist.html
CHANGED
@@ -1,128 +1,86 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
<
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
<ol><a href="#Tenth_Step,_Configuration">Tenth Step, Configuration</a></ol>
|
42
|
-
<ol><a href="#Eleventh_Step,_Refactor_with_AspectHelper">Eleventh Step, Refactor with AspectHelper</a></ol>
|
43
|
-
<ol><a href="#Twelfth_Step,_Validation_and_Errors">Twelfth Step, Validation and Errors</a></ol>
|
44
|
-
</li>
|
45
|
-
</div>
|
46
|
-
|
47
|
-
|
48
|
-
<a name="Step_Zero,_Introduction"><h2>Step Zero, Introduction</h2></a>
|
49
|
-
|
50
|
-
<p>Welcome to our official tutorial, the mandatory to-do list.
|
51
|
-
I'm writing this while doing the steps to assure it will work for you.</p>
|
52
|
-
|
53
|
-
<p>The tutorial assumes that you have Ramaze installed already. The easiest way to
|
54
|
-
do that is <code>gem install ramaze</code>, for other ways of installation please see the
|
55
|
-
documentation at http://ramaze.rubyforge.org</p>
|
56
|
-
|
57
|
-
<p>Should you encounter any problems while doing this tutorial, this might either
|
58
|
-
be because Ramaze changed (which happens very often while it is still young)
|
59
|
-
or I actually made some mistake while writing it.</p>
|
60
|
-
|
61
|
-
<p>In either case it would make me (and all other poor fellows who happen to try
|
62
|
-
this tutorial) very happy if you could spare some time and report the issue
|
63
|
-
either on the Bug tracker at http://rubyforge.org/projects/ramaze or just
|
64
|
-
drop by on IRC ( irc.freenode.org channel: #ramaze ).</p>
|
65
|
-
|
66
|
-
<p>There is also a Mailing list available where you can keep yourself updated on
|
67
|
-
what is going on with little effort, it is also located on the project-page at
|
68
|
-
RubyForge.</p>
|
69
|
-
|
70
|
-
<p>Additionally, we now have added tests for the resulting application that you
|
71
|
-
can find in spec/examples/todolist.rb</p>
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
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
|
+
<html xml:lang="en" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/1999/xhtml">
|
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>
|
25
|
+
<body>
|
26
|
+
<h1 id="todo_list_tutorial">To-do List Tutorial</h1>
|
27
|
+
<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>
|
28
|
+
<h2 id="step_zero_introduction">Step Zero, Introduction</h2>
|
29
|
+
|
30
|
+
<p>Welcome to our official tutorial, the mandatory to-do list. I’m writing this while doing the steps to assure it will work for you.</p>
|
31
|
+
|
32
|
+
<p>The tutorial assumes that you have Ramaze installed already. The easiest way to do that is <code>gem install ramaze</code>, for other ways of installation please see the documentation at http://ramaze.rubyforge.org</p>
|
33
|
+
|
34
|
+
<p>Should you encounter any problems while doing this tutorial, this might either be because Ramaze changed (which happens very often while it is still young) or I actually made some mistake while writing it.</p>
|
35
|
+
|
36
|
+
<p>In either case it would make me (and all other poor fellows who happen to try this tutorial) very happy if you could spare some time and report the issue either on the Bug tracker at http://rubyforge.org/projects/ramaze or just drop by on IRC ( irc.freenode.org channel: #ramaze ).</p>
|
37
|
+
|
38
|
+
<p>There is also a Mailing list available where you can keep yourself updated on what is going on with little effort, it is also located on the project-page at RubyForge.</p>
|
39
|
+
|
40
|
+
<p>Additionally, we now have added tests for the resulting application that you can find in spec/examples/todolist.rb</p>
|
72
41
|
|
73
42
|
<p>Date of last update: Thu Jan 31 04:37:16 JST 2008</p>
|
74
43
|
|
75
|
-
<p>Thanks in advance.
|
76
|
-
The author of the tutorial, Michael 'manveru' Fellinger</p>
|
44
|
+
<p>Thanks in advance. The author of the tutorial, Michael ‘manveru’ Fellinger</p>
|
77
45
|
|
78
|
-
<
|
46
|
+
<h2 id="first_step_create">First Step, Create</h2>
|
79
47
|
|
80
|
-
<p>We are using <code>ramaze --create todolist</code> to create a new application.
|
81
|
-
Ramaze will then create the directory and fill it with a skeleton of a quite
|
82
|
-
sophisticated hello-world example out of which we will create the actual
|
83
|
-
to-do list.</p>
|
48
|
+
<p>We are using <code>ramaze --create todolist</code> to create a new application. Ramaze will then create the directory and fill it with a skeleton of a quite sophisticated hello-world example out of which we will create the actual to-do list.</p>
|
84
49
|
|
85
50
|
<p>So run:</p>
|
86
51
|
|
87
|
-
<pre><code>$ ramaze --create todolist
|
88
|
-
</code></pre>
|
52
|
+
<pre><code>$ ramaze --create todolist</code></pre>
|
89
53
|
|
90
54
|
<p>done.</p>
|
91
55
|
|
92
|
-
<
|
56
|
+
<h2 id="second_step_m_like_model">Second Step, M, like Model</h2>
|
93
57
|
|
94
|
-
<p>Ramaze comes at the moment only with a simple wrapper of the YAML::Store.
|
95
|
-
So we are going to base this on the tools available, you can just do the same
|
96
|
-
with your ORM or database-library of choice.</p>
|
58
|
+
<p>Ramaze comes at the moment only with a simple wrapper of the YAML::Store. So we are going to base this on the tools available, you can just do the same with your ORM or database-library of choice.</p>
|
97
59
|
|
98
60
|
<p>So first, create a <code>model/todolist.rb</code> for our application:</p>
|
99
61
|
|
100
|
-
<pre><code>require
|
101
|
-
TodoList = Ramaze
|
102
|
-
</code></pre>
|
62
|
+
<pre><code class="ruby" lang="ruby"><span class="ident">require</span> <span class="punct">'</span><span class="string">ramaze/store/default</span><span class="punct">'</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">('</span><span class="string">todolist.yaml</span><span class="punct">')</span></code></pre>
|
103
64
|
|
104
|
-
<p>Let
|
65
|
+
<p>Let’s add some items as well to have a base to start from.</p>
|
105
66
|
|
106
|
-
<pre><code>{
|
107
|
-
|
108
|
-
}
|
109
|
-
TodoList[title] = value
|
110
|
-
end
|
111
|
-
</code></pre>
|
67
|
+
<pre><code class="ruby" lang="ruby"><span class="punct">{</span> <span class="punct">'</span><span class="string">Laundry</span><span class="punct">'</span> <span class="punct">=></span> <span class="punct">{</span><span class="symbol">:done</span> <span class="punct">=></span> <span class="constant">false</span><span class="punct">},</span>
|
68
|
+
<span class="punct">'</span><span class="string">Wash dishes</span><span class="punct">'</span> <span class="punct">=></span> <span class="punct">{</span><span class="symbol">:done</span> <span class="punct">=></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>
|
112
72
|
|
113
|
-
<
|
73
|
+
<h2 id="third_step_v_like_view">Third Step, V, like View</h2>
|
114
74
|
|
115
|
-
<p>Now let
|
75
|
+
<p>Now let’s get our hands dirty and just edit the templates for our to-do list.</p>
|
116
76
|
|
117
|
-
<p>Start with editing <code>view/index.xhtml</code>, it is using the default templating
|
118
|
-
of Ramaze, called Ezamar.</p>
|
77
|
+
<p>Start with editing <code>view/index.xhtml</code>, it is using the default templating of Ramaze, called Ezamar.</p>
|
119
78
|
|
120
79
|
<p>The index.xhtml currently contains a default welcome page, remove the contents.</p>
|
121
80
|
|
122
|
-
<p>Let
|
123
|
-
simple.</p>
|
81
|
+
<p>Let’s put some things in there, I’ll explain the syntax as we go, it’s quite simple.</p>
|
124
82
|
|
125
|
-
<pre><code><html>
|
83
|
+
<pre><code class="nagoro" lang="nagoro"><html>
|
126
84
|
<head>
|
127
85
|
<title>TodoList</title>
|
128
86
|
</head>
|
@@ -131,139 +89,111 @@ simple.</p>
|
|
131
89
|
<ul>
|
132
90
|
<?r
|
133
91
|
TodoList.each do |title, value|
|
134
|
-
status = value[:done] ?
|
92
|
+
status = value[:done] ? 'done' : 'not done'
|
135
93
|
?>
|
136
94
|
<li>#{c title}: #{status}</li>
|
137
95
|
<?r end ?>
|
138
96
|
</ul>
|
139
97
|
</body>
|
140
|
-
</html>
|
141
|
-
</code></pre>
|
98
|
+
</html></code></pre>
|
142
99
|
|
143
|
-
<p>I will assume that you are familiar with basic Ruby already, so we will
|
144
|
-
concentrate on the things new here.</p>
|
100
|
+
<p>I will assume that you are familiar with basic Ruby already, so we will concentrate on the things new here.</p>
|
145
101
|
|
146
|
-
<p><code><?r ?></code> defines an area of ruby-code. Later, when the template is transformed
|
147
|
-
into pure Ruby it will be evaluated. We iterate over the TodoList model and
|
148
|
-
pass the title and value into a block. In that block we can just get the values
|
149
|
-
of title and status (which we define based on the value) displayed on the
|
150
|
-
page.</p>
|
102
|
+
<p><code><?r ?></code> defines an area of ruby-code. Later, when the template is transformed into pure Ruby it will be evaluated. We iterate over the TodoList model and pass the title and value into a block. In that block we can just get the values of title and status (which we define based on the value) displayed on the page.</p>
|
151
103
|
|
152
|
-
<p>The whole Template would expand to something like this (only showing the
|
153
|
-
interesting part)</p>
|
104
|
+
<p>The whole Template would expand to something like this (only showing the interesting part)</p>
|
154
105
|
|
155
|
-
<pre><code><ul>
|
106
|
+
<pre><code class="nagoro" lang="nagoro"><ul>
|
156
107
|
<li>Laundry: not done</li>
|
157
108
|
<li>Wash dishes: not done</li>
|
158
|
-
</ul>
|
159
|
-
</code></pre>
|
109
|
+
</ul></code></pre>
|
160
110
|
|
161
|
-
<p>That wasn
|
111
|
+
<p>That wasn’t too bad, huh?</p>
|
162
112
|
|
163
|
-
<p>Now, so we can get our instant pleasure of seeing the result of our (hard) work,
|
164
|
-
let's see how to start ramaze.</p>
|
113
|
+
<p>Now, so we can get our instant pleasure of seeing the result of our (hard) work, let’s see how to start ramaze.</p>
|
165
114
|
|
166
115
|
<p>In the <code>todolist</code> directory run <code>ramaze</code>.</p>
|
167
116
|
|
168
|
-
<p>This will start an instance of Ramaze and run your application on it. You can
|
169
|
-
now access it by browsing to http://localhost:7000/</p>
|
117
|
+
<p>This will start an instance of Ramaze and run your application on it. You can now access it by browsing to http://localhost:7000/</p>
|
170
118
|
|
171
|
-
<p>7000 is the default-port Ramaze will run on, to change it you can just run
|
172
|
-
<code>ramaze -p 7070</code> or similar. Also be sure to look at the output of
|
173
|
-
<code>ramaze --help</code> to see some other options.</p>
|
119
|
+
<p>7000 is the default-port Ramaze will run on, to change it you can just run <code>ramaze -p 7070</code> or similar. Also be sure to look at the output of <code>ramaze --help</code> to see some other options.</p>
|
174
120
|
|
175
|
-
<
|
121
|
+
<h2 id="fourth_step_c_like_controller">Fourth Step, C, like Controller</h2>
|
176
122
|
|
177
123
|
<p>The last part of the MVC-paradigm is the Controller.</p>
|
178
124
|
|
179
|
-
<p>Wouldn
|
180
|
-
Editing the model every time would be quite tiresome and limited.</p>
|
125
|
+
<p>Wouldn’t it be nice to have a way to add and remove items on our to-do list? Editing the model every time would be quite tiresome and limited.</p>
|
181
126
|
|
182
|
-
<p>Well, come along, I
|
127
|
+
<p>Well, come along, I’ll introduce you to Controller.</p>
|
183
128
|
|
184
|
-
<p>In the way MVC is structured, the Controller provides the data in a nice way
|
185
|
-
for the View, removing all of the data-preparation and most of the logic from
|
186
|
-
the templates. This makes it firstly simple to change the front end of your
|
187
|
-
application and secondly provides excellent ways of changing the complete
|
188
|
-
Structure of the Model or View independent from each other.</p>
|
129
|
+
<p>In the way MVC is structured, the Controller provides the data in a nice way for the View, removing all of the data-preparation and most of the logic from the templates. This makes it firstly simple to change the front end of your application and secondly provides excellent ways of changing the complete Structure of the Model or View independent from each other.</p>
|
189
130
|
|
190
|
-
<p>OK, enough of the theory, you will see the benefits in an instant. Go on and
|
191
|
-
edit the file <code>controller/main.rb</code>.</p>
|
131
|
+
<p>OK, enough of the theory, you will see the benefits in an instant. Go on and edit the file <code>controller/main.rb</code>.</p>
|
192
132
|
|
193
133
|
<p>The contents of it are like following:</p>
|
194
134
|
|
195
|
-
<pre><code>class MainController
|
196
|
-
def index
|
197
|
-
|
198
|
-
end
|
135
|
+
<pre><code class="ruby" lang="ruby"><span class="keyword">class </span><span class="class">MainController</span> <span class="punct"><</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">"</span><span class="string">Welcome to Ramaze!</span><span class="punct">"</span>
|
138
|
+
<span class="keyword">end</span>
|
199
139
|
|
200
|
-
def notemplate
|
201
|
-
"there is no template associated with this action"
|
202
|
-
end
|
203
|
-
end
|
204
|
-
</code></pre>
|
140
|
+
<span class="keyword">def </span><span class="method">notemplate</span>
|
141
|
+
<span class="punct">"</span><span class="string">there is no template associated with this action</span><span class="punct">"</span>
|
142
|
+
<span class="keyword">end</span>
|
143
|
+
<span class="keyword">end</span></code></pre>
|
205
144
|
|
206
|
-
<p>The only methods right now are <code>#index</code> and <code>#notemplate</code>.
|
207
|
-
The relationship between the methods on the controller and the templates is
|
208
|
-
1:1, so the method <code>#index</code> is combined with the template <code>index.xhtml</code>. This
|
209
|
-
combination is called an <code>action</code>.</p>
|
145
|
+
<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>
|
210
146
|
|
211
|
-
<p>Let
|
147
|
+
<p>Let’s get back to editing and change the method <code>#index</code> to this:</p>
|
212
148
|
|
213
|
-
<pre><code>def index
|
214
|
-
|
215
|
-
|
216
|
-
status = value[
|
217
|
-
|
218
|
-
end
|
219
|
-
end
|
220
|
-
</code></pre>
|
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">'</span><span class="string">done</span><span class="punct">'</span> <span class="punct">:</span> <span class="punct">'</span><span class="string">not done</span><span class="punct">'</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>
|
221
156
|
|
222
|
-
<p>This will take care of the logic inside the template, which now should be
|
223
|
-
changed to do following:</p>
|
157
|
+
<p>This will take care of the logic inside the template, which now should be changed to do following:</p>
|
224
158
|
|
225
|
-
<pre><code><
|
226
|
-
|
227
|
-
|
228
|
-
<
|
229
|
-
|
230
|
-
|
159
|
+
<pre><code class="ruby" lang="ruby"><span class="punct"><</span><span class="ident">html</span><span class="punct">></span>
|
160
|
+
<span class="punct"><</span><span class="ident">head</span><span class="punct">></span>
|
161
|
+
<span class="punct"><</span><span class="ident">title</span><span class="punct">></span><span class="constant">TodoList</span><span class="punct"></</span><span class="regex">title>
|
162
|
+
<</span><span class="punct">/</span><span class="ident">head</span><span class="punct">></span>
|
163
|
+
<span class="punct"><</span><span class="ident">body</span><span class="punct">></span>
|
164
|
+
<span class="punct"><</span><span class="ident">h1</span><span class="punct">></span><span class="constant">TodoList</span><span class="punct"></</span><span class="regex">h1>
|
231
165
|
<?r if @tasks.empty? ?>
|
232
166
|
No Tasks
|
233
167
|
<?r else ?>
|
234
168
|
<ul>
|
235
169
|
<?r @tasks.each do |title, status| ?>
|
236
|
-
<li>
|
237
|
-
|
238
|
-
|
170
|
+
<li><span class="expr">#{c title}</span>: <span class="expr">#{status}</span><</span><span class="punct">/</span><span class="ident">li</span><span class="punct">></span>
|
171
|
+
<span class="punct"><</span><span class="char">?r</span> <span class="keyword">end</span> <span class="char">?></span>
|
172
|
+
<span class="punct"></</span><span class="regex">ul>
|
239
173
|
<?r end ?>
|
240
|
-
<
|
241
|
-
|
242
|
-
</code></pre>
|
174
|
+
<</span><span class="punct">/</span><span class="ident">body</span><span class="punct">></span>
|
175
|
+
<span class="punct"></</span><span class="regex">html></span></code></pre>
|
243
176
|
|
244
177
|
<p>The rest of the template can stay the same.</p>
|
245
178
|
|
246
|
-
<p>Now, if you browse to http://localhost:7000/ again you will not notice any
|
247
|
-
change, which is how it should be. The only change is that if there are no
|
248
|
-
Tasks it will say so.</p>
|
179
|
+
<p>Now, if you browse to http://localhost:7000/ again you will not notice any change, which is how it should be. The only change is that if there are no Tasks it will say so.</p>
|
249
180
|
|
250
181
|
<p>Some things you should know:</p>
|
251
182
|
|
252
183
|
<ul>
|
253
184
|
<li>Instance-variables defined in the Controller are available in the View.</li>
|
185
|
+
|
254
186
|
<li>The return-value of the Controller does not matter if a template is present.</li>
|
255
187
|
</ul>
|
256
188
|
|
257
|
-
<
|
189
|
+
<h2 id="fifth_step_getting_dynamic">Fifth Step, getting dynamic</h2>
|
258
190
|
|
259
|
-
<p>We set out to build the ultimate to-do list, but there are still some things
|
260
|
-
missing. First off, we want to add new tasks, so let's get that done.</p>
|
191
|
+
<p>We set out to build the ultimate to-do list, but there are still some things missing. First off, we want to add new tasks, so let’s get that done.</p>
|
261
192
|
|
262
193
|
<p>Add a link on the <code>view/index.xhtml</code> like this:</p>
|
263
194
|
|
264
195
|
<pre><code><h1>TodoList</h1>
|
265
|
-
<a href
|
266
|
-
</code></pre>
|
196
|
+
<a href="/new">New Task</a></code></pre>
|
267
197
|
|
268
198
|
<p>Open a new file <code>view/new.xhtml</code> with a form to add a new task.</p>
|
269
199
|
|
@@ -273,160 +203,124 @@ missing. First off, we want to add new tasks, so let's get that done.</p>
|
|
273
203
|
</head>
|
274
204
|
<body>
|
275
205
|
<h1>New Task</h1>
|
276
|
-
<a href
|
277
|
-
<form method
|
278
|
-
Task: <input type
|
279
|
-
<input type
|
206
|
+
<a href="/">Back to TodoList</a>
|
207
|
+
<form method="POST" action="create">
|
208
|
+
Task: <input type="text" name="title" /><br />
|
209
|
+
<input type="submit" />
|
280
210
|
</form>
|
281
211
|
</body>
|
282
|
-
</html>
|
283
|
-
</code></pre>
|
212
|
+
</html></code></pre>
|
284
213
|
|
285
|
-
<p>We will not need a method for this on our controller, in fact, actions can
|
286
|
-
consist of either method and template or only one of them. The Controller
|
287
|
-
can act as a View and the View can work like you may know it from PHP.</p>
|
214
|
+
<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>
|
288
215
|
|
289
|
-
<p>If you try to use this form you will notice that we have not yet defined a way
|
290
|
-
to actually create the task.</p>
|
216
|
+
<p>If you try to use this form you will notice that we have not yet defined a way to actually create the task.</p>
|
291
217
|
|
292
|
-
<p>You will get the default Ramaze error-page instead. Please take your time to
|
293
|
-
explore it and see how Ramaze reacted on the error.</p>
|
218
|
+
<p>You will get the default Ramaze error-page instead. Please take your time to explore it and see how Ramaze reacted on the error.</p>
|
294
219
|
|
295
|
-
<p>It will show you the back trace and what state the application is in at the
|
296
|
-
moment, the request and response and the contents of the session. This is very
|
297
|
-
useful for debugging and development, you can provide your own set of
|
298
|
-
error-pages before going into production (or deactivate them fully) though.</p>
|
220
|
+
<p>It will show you the back trace and what state the application is in at the moment, the request and response and the contents of the session. This is very useful for debugging and development, you can provide your own set of error-pages before going into production (or deactivate them fully) though.</p>
|
299
221
|
|
300
|
-
<p>OK, let
|
301
|
-
requests parameters and create a new task for it, this looks like following on
|
302
|
-
your MainController.</p>
|
222
|
+
<p>OK, let’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>
|
303
223
|
|
304
|
-
<pre><code>def create
|
305
|
-
title = request[
|
306
|
-
TodoList[title] = {
|
307
|
-
redirect Rs()
|
308
|
-
end
|
309
|
-
</code></pre>
|
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">['</span><span class="string">title</span><span class="punct">']</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">=></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>
|
310
229
|
|
311
|
-
<p>That
|
230
|
+
<p>That’s all folks!</p>
|
312
231
|
|
313
|
-
<p>We get the title from the request-object, put it into our TodoList as undone
|
314
|
-
and redirect back to the mapping of the current Controller ('/' in this case).</p>
|
232
|
+
<p>We get the title from the request-object, put it into our TodoList as undone and redirect back to the mapping of the current Controller (’/’ in this case).</p>
|
315
233
|
|
316
|
-
<p>Now you can create as many tasks as you want, please don
|
234
|
+
<p>Now you can create as many tasks as you want, please don’t get overworked ;)</p>
|
317
235
|
|
318
|
-
<
|
236
|
+
<h2 id="sixth_step_open_and_close_tasks">Sixth Step, open and close tasks</h2>
|
319
237
|
|
320
|
-
<p>Since the nature of tasks is to be done eventually
|
321
|
-
we will need some way to mark it as done or open tasks again.</p>
|
238
|
+
<p>Since the nature of tasks is to be done eventually we will need some way to mark it as done or open tasks again.</p>
|
322
239
|
|
323
240
|
<p>Jump into <code>view/index.xhtml</code> and do the following:</p>
|
324
241
|
|
325
|
-
<pre><code><
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
<?r end
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
<
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
status =
|
341
|
-
toggle = A(
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
end
|
348
|
-
@tasks.sort!
|
349
|
-
end
|
350
|
-
</code></pre>
|
242
|
+
<pre><code class="ruby" lang="ruby"><span class="punct"><</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">?></span>
|
243
|
+
<span class="punct"><</span><span class="ident">li</span><span class="punct">></span>
|
244
|
+
<span class="comment">#{c title}: #{status} - [ #{toggle} ]</span>
|
245
|
+
<span class="punct"></</span><span class="regex">li>
|
246
|
+
<?r end</span></code></pre>
|
247
|
+
|
248
|
+
<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
|
+
|
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">'</span><span class="string">done</span><span class="punct">'</span>
|
255
|
+
<span class="ident">toggle</span> <span class="punct">=</span> <span class="constant">A</span><span class="punct">('</span><span class="string">Open Task</span><span class="punct">',</span> <span class="symbol">:href</span> <span class="punct">=></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">'</span><span class="string">not done</span><span class="punct">'</span>
|
258
|
+
<span class="ident">toggle</span> <span class="punct">=</span> <span class="constant">A</span><span class="punct">('</span><span class="string">Close Task</span><span class="punct">',</span> <span class="symbol">:href</span> <span class="punct">=></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"><<</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>
|
351
264
|
|
352
265
|
<p>Wow, quite some new stuff here. Let me explain that in detail.</p>
|
353
266
|
|
354
|
-
<p>We first decide whether a task is done or not, then go on and provide a link to
|
355
|
-
toggle the status, A and Rs are both methods that help you do that.
|
356
|
-
The result will be something like:</p>
|
267
|
+
<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>
|
357
268
|
|
358
|
-
<pre><code><a href
|
359
|
-
</code></pre>
|
269
|
+
<pre><code><a href="/open/Wash+dishes">Close Task</a></code></pre>
|
360
270
|
|
361
|
-
<p>Rs actually is responsible to build the links href, for more information please
|
362
|
-
take a look at the RDoc for LinkHelper.</p>
|
271
|
+
<p>Rs actually is responsible to build the links href, for more information please take a look at the RDoc for LinkHelper.</p>
|
363
272
|
|
364
|
-
<p>Also, you might have noticed that the tasks were changing order on every reload,
|
365
|
-
which is because we were using an Hash, which are per definition unsorted, so
|
366
|
-
now we use an array to hold our tasks and sort it.</p>
|
273
|
+
<p>Also, you might have noticed that the tasks were changing order on every reload, which is because we were using an Hash, which are per definition unsorted, so now we use an array to hold our tasks and sort it.</p>
|
367
274
|
|
368
|
-
<p>As usual since the links for open and close don
|
369
|
-
corresponding methods to the Controller:</p>
|
275
|
+
<p>As usual since the links for open and close don’t lead anywhere, add the corresponding methods to the Controller:</p>
|
370
276
|
|
371
|
-
<pre><code>def open title
|
372
|
-
task_status title
|
373
|
-
redirect Rs()
|
374
|
-
end
|
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>
|
375
281
|
|
376
|
-
def close title
|
377
|
-
task_status title
|
378
|
-
redirect Rs()
|
379
|
-
end
|
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>
|
380
286
|
|
381
|
-
private
|
287
|
+
<span class="ident">private</span>
|
382
288
|
|
383
|
-
def task_status title
|
384
|
-
task = TodoList[title]
|
385
|
-
task[
|
386
|
-
TodoList[title] = task
|
387
|
-
end
|
388
|
-
</code></pre>
|
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>
|
389
294
|
|
390
|
-
<p>Oh, now what have we got here?
|
391
|
-
<code>private</code> declares that methods from here on are only to be used within the
|
392
|
-
Controller itself, we define an <code>#task_status</code> method that takes the title and
|
393
|
-
status to be set so we don't have to repeat that code in <code>#open</code> and <code>#close</code>
|
394
|
-
and follow the DRY (Don't repeat yourself) paradigm.</p>
|
295
|
+
<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’t have to repeat that code in <code>#open</code> and <code>#close</code> and follow the DRY (Don’t repeat yourself) paradigm.</p>
|
395
296
|
|
396
|
-
<p>Another thing we have not encountered so far is that you can define your public
|
397
|
-
methods to take parameters on their own, they will be calculated from requests.</p>
|
297
|
+
<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>
|
398
298
|
|
399
|
-
<pre><code
|
400
|
-
</code></pre>
|
299
|
+
<pre><code class="ruby" lang="ruby"><span class="punct">'</span><span class="string">/open/Wash+dishes</span><span class="punct">'</span></code></pre>
|
401
300
|
|
402
301
|
<p>will translate into:</p>
|
403
302
|
|
404
|
-
<pre><code>open(
|
405
|
-
</code></pre>
|
303
|
+
<pre><code class="ruby" lang="ruby"><span class="ident">open</span><span class="punct">('</span><span class="string">Wash dishes</span><span class="punct">')</span></code></pre>
|
406
304
|
|
407
|
-
<p>Which in turn will call <code>task_status(
|
305
|
+
<p>Which in turn will call <code>task_status('Wash dishes', false)</code></p>
|
408
306
|
|
409
|
-
<p>That
|
307
|
+
<p>That’s it, go on and try it :)</p>
|
410
308
|
|
411
|
-
<
|
309
|
+
<h2 id="seventh_step_delete_tasks">Seventh Step, delete tasks</h2>
|
412
310
|
|
413
|
-
<p>Well, creating, opening and closing work now, one of the things you will
|
414
|
-
consider is to delete a task permanently.</p>
|
311
|
+
<p>Well, creating, opening and closing work now, one of the things you will consider is to delete a task permanently.</p>
|
415
312
|
|
416
|
-
<p>This is just two little changes away, so let
|
417
|
-
Controller:</p>
|
313
|
+
<p>This is just two little changes away, so let’s add the link for deletion in our Controller:</p>
|
418
314
|
|
419
|
-
<pre><code>delete = A(
|
420
|
-
|
421
|
-
</code></pre>
|
315
|
+
<pre><code class="ruby" lang="ruby"><span class="ident">delete</span> <span class="punct">=</span> <span class="constant">A</span><span class="punct">('</span><span class="string">Delete</span><span class="punct">',</span> <span class="symbol">:href</span> <span class="punct">=></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"><<</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>
|
422
317
|
|
423
|
-
<p>and an corresponding method while we
|
318
|
+
<p>and an corresponding method while we’re at it:</p>
|
424
319
|
|
425
|
-
<pre><code>def delete title
|
426
|
-
TodoList
|
427
|
-
redirect Rs()
|
428
|
-
end
|
429
|
-
</code></pre>
|
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>
|
430
324
|
|
431
325
|
<p>Now jumping to <code>view/index.xhtml</code> again, change it so it shows the link:</p>
|
432
326
|
|
@@ -434,22 +328,17 @@ end
|
|
434
328
|
<li>
|
435
329
|
#{c title}: #{status} [ #{toggle} | #{delete} ]
|
436
330
|
</li>
|
437
|
-
<?r end ?>
|
438
|
-
</code></pre>
|
331
|
+
<?r end ?></code></pre>
|
439
332
|
|
440
333
|
<p>Voilà, you now have acquired the Certificate of Ramazeness.</p>
|
441
334
|
|
442
|
-
<p>Just kidding, but that really are the basics, in the next few steps I will
|
443
|
-
explain some more advanced concepts of Ramaze and Ezamar.</p>
|
335
|
+
<p>Just kidding, but that really are the basics, in the next few steps I will explain some more advanced concepts of Ramaze and Ezamar.</p>
|
444
336
|
|
445
|
-
<
|
337
|
+
<h2 id="eighth_step_elements">Eighth Step, Elements</h2>
|
446
338
|
|
447
|
-
<pre><code><Page></Page>
|
448
|
-
</code></pre>
|
339
|
+
<pre><code><Page></Page></code></pre>
|
449
340
|
|
450
|
-
<p>This is called an Element, Ramaze will go and search for a class that matches
|
451
|
-
the name Page and responds to <code>#render</code>. Then it will go and hand the content in
|
452
|
-
between to that Element.</p>
|
341
|
+
<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>
|
453
342
|
|
454
343
|
<p>Sounds weird?</p>
|
455
344
|
|
@@ -462,71 +351,63 @@ between to that Element.</p>
|
|
462
351
|
<body>
|
463
352
|
<h1>some title</h1>
|
464
353
|
</body>
|
465
|
-
</html>
|
466
|
-
</code></pre>
|
354
|
+
</html></code></pre>
|
467
355
|
|
468
356
|
<p>How about replacing that with something short and reusable:</p>
|
469
357
|
|
470
|
-
<pre><code><Page title
|
358
|
+
<pre><code><Page title="TodoList">
|
471
359
|
your other content
|
472
|
-
</Page>
|
473
|
-
</code></pre>
|
360
|
+
</Page></code></pre>
|
474
361
|
|
475
|
-
<p>Would be nice of course, and when you start having more templates it makes an
|
476
|
-
awful lot of sense being able to change the enclosing stuff in one place.</p>
|
362
|
+
<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>
|
477
363
|
|
478
|
-
<p>So let
|
364
|
+
<p>So let’s apply DRY here as well.</p>
|
479
365
|
|
480
366
|
<p>Take a look at the <code>src/element/page.rb</code></p>
|
481
367
|
|
482
|
-
<pre><code>class Page
|
483
|
-
def render
|
484
|
-
|
368
|
+
<pre><code class="ruby" lang="ruby"><span class="keyword">class </span><span class="class">Page</span> <span class="punct"><</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">
|
485
371
|
<html>
|
486
372
|
<head>
|
487
373
|
<title>Welcome to Ramaze</title>
|
488
374
|
</head>
|
489
375
|
<body>
|
490
|
-
|
376
|
+
<span class="expr">#{content}</span>
|
491
377
|
</body>
|
492
378
|
</html>
|
493
|
-
}
|
494
|
-
end
|
495
|
-
end
|
496
|
-
</code></pre>
|
379
|
+
</span><span class="punct">}</span>
|
380
|
+
<span class="keyword">end</span>
|
381
|
+
<span class="keyword">end</span></code></pre>
|
497
382
|
|
498
|
-
<p>Alright, most things we need are in place already, the most important thing
|
499
|
-
is the <code>#content</code> method that we call with <code>#{content}</code> inside the string in
|
500
|
-
<code>#render</code>.</p>
|
383
|
+
<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>
|
501
384
|
|
502
|
-
<p>Just adopt it to your liking, I
|
503
|
-
so far:</p>
|
385
|
+
<p>Just adopt it to your liking, I’ll just use the things we had in our templates so far:</p>
|
504
386
|
|
505
|
-
<pre><code>class Page
|
506
|
-
def render
|
507
|
-
|
387
|
+
<pre><code class="ruby" lang="ruby"><span class="keyword">class </span><span class="class">Page</span> <span class="punct"><</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">
|
508
390
|
<html>
|
509
391
|
<head>
|
510
392
|
<title>TodoList</title>
|
511
393
|
</head>
|
512
394
|
<body>
|
513
|
-
<h1>
|
514
|
-
|
395
|
+
<h1><span class="expr">#{@title}</span></h1>
|
396
|
+
<span class="expr">#{content}</span>
|
515
397
|
</body>
|
516
398
|
</html>
|
517
|
-
}
|
518
|
-
end
|
519
|
-
end
|
520
|
-
</code></pre>
|
399
|
+
</span><span class="punct">}</span>
|
400
|
+
<span class="keyword">end</span>
|
401
|
+
<span class="keyword">end</span></code></pre>
|
521
402
|
|
522
403
|
<p>Please note that instance variables reflecting the parameters are set.</p>
|
523
404
|
|
524
|
-
<p>And let
|
405
|
+
<p>And let’s change our templates as well.</p>
|
525
406
|
|
526
407
|
<p>First the <code>view/index.xhtml</code></p>
|
527
408
|
|
528
|
-
<pre><code><Page title
|
529
|
-
<a href
|
409
|
+
<pre><code><Page title="TodoList">
|
410
|
+
<a href="/new">New Task</a>
|
530
411
|
<?r if @tasks.empty? ?>
|
531
412
|
No Tasks
|
532
413
|
<?r else ?>
|
@@ -538,27 +419,23 @@ end
|
|
538
419
|
<?r end ?>
|
539
420
|
</ul>
|
540
421
|
<?r end ?>
|
541
|
-
</Page>
|
542
|
-
</code></pre>
|
422
|
+
</Page></code></pre>
|
543
423
|
|
544
424
|
<p>and the <code>view/new.xhtml</code></p>
|
545
425
|
|
546
|
-
<pre><code><Page title
|
547
|
-
<a href
|
548
|
-
<form method
|
549
|
-
Task: <input type
|
550
|
-
<input type
|
426
|
+
<pre><code><Page title="New Task">
|
427
|
+
<a href="/">Back to TodoList</a>
|
428
|
+
<form method="POST" action="create">
|
429
|
+
Task: <input type="text" name="title" /><br />
|
430
|
+
<input type="submit" />
|
551
431
|
</form>
|
552
|
-
</Page>
|
553
|
-
</code></pre>
|
432
|
+
</Page></code></pre>
|
554
433
|
|
555
|
-
<p>Alright, now just go and look at the result in the browser, try changing
|
556
|
-
the things inside the Element and look at how it behaves.</p>
|
434
|
+
<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>
|
557
435
|
|
558
|
-
<
|
436
|
+
<h2 id="ninth_step_prettify">Ninth Step, Prettify</h2>
|
559
437
|
|
560
|
-
<p>We structure the data inside the list a little bit, in this case into a table,
|
561
|
-
to get it line up properly and look actually structured.</p>
|
438
|
+
<p>We structure the data inside the list a little bit, in this case into a table, to get it line up properly and look actually structured.</p>
|
562
439
|
|
563
440
|
<p>So, from what we have right now:</p>
|
564
441
|
|
@@ -568,25 +445,22 @@ to get it line up properly and look actually structured.</p>
|
|
568
445
|
#{c title}: #{status} [ #{toggle} | #{delete} ]
|
569
446
|
</li>
|
570
447
|
<?r end ?>
|
571
|
-
</ul>
|
572
|
-
</code></pre>
|
448
|
+
</ul></code></pre>
|
573
449
|
|
574
450
|
<p>To something like this:</p>
|
575
451
|
|
576
452
|
<pre><code><table>
|
577
453
|
<?r @tasks.each do |title, status, toggle, delete| ?>
|
578
454
|
<tr>
|
579
|
-
<td class
|
580
|
-
<td class
|
581
|
-
<td class
|
582
|
-
<td class
|
455
|
+
<td class="title"> #{c title} </td>
|
456
|
+
<td class="status"> #{status} </td>
|
457
|
+
<td class="toggle"> #{toggle} </td>
|
458
|
+
<td class="delete"> #{delete} </td>
|
583
459
|
</tr>
|
584
460
|
<?r end ?>
|
585
|
-
</table>
|
586
|
-
</code></pre>
|
461
|
+
</table></code></pre>
|
587
462
|
|
588
|
-
<p>And, since we have proper classes to address some style sheets, jump into the
|
589
|
-
Page element and add some style sheet:</p>
|
463
|
+
<p>And, since we have proper classes to address some style sheets, jump into the Page element and add some style sheet:</p>
|
590
464
|
|
591
465
|
<pre><code><head>
|
592
466
|
<title>TodoList</title>
|
@@ -598,219 +472,163 @@ Page element and add some style sheet:</p>
|
|
598
472
|
td.status { margin: 1em; }
|
599
473
|
a { color: #3a3; }
|
600
474
|
</style>
|
601
|
-
</head>
|
602
|
-
</code></pre>
|
475
|
+
</head></code></pre>
|
603
476
|
|
604
|
-
<p>That looks quite a bit nicer, right?
|
605
|
-
this is an entirely legit use in my opinion) you can just do it like you want,
|
606
|
-
using nested lists or divs/spans, replacing the open/close and delete links with
|
607
|
-
nice images and changing the style according to the status.</p>
|
477
|
+
<p>That looks quite a bit nicer, right? And yes, if you don’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>
|
608
478
|
|
609
479
|
<p>I will leave this as an exercise to the reader.</p>
|
610
480
|
|
611
|
-
<
|
481
|
+
<h2 id="tenth_step_configuration">Tenth Step, Configuration</h2>
|
612
482
|
|
613
|
-
<p>To round up this tutorial a bit, let
|
614
|
-
This will not go into full depth of possibilities or a total coverage of the
|
615
|
-
options, since they are bound to change over time.</p>
|
483
|
+
<p>To round up this tutorial a bit, let’s introduce you to configuration in Ramaze. This will not go into full depth of possibilities or a total coverage of the options, since they are bound to change over time.</p>
|
616
484
|
|
617
|
-
<p>First of all, the default port Ramaze runs on is 7000, but to make it a usual
|
618
|
-
webserver it has to run on port 80. So, let's add following line in your
|
619
|
-
start.rb right after the lines of require you added before:</p>
|
485
|
+
<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’s add following line in your start.rb right after the lines of require you added before:</p>
|
620
486
|
|
621
|
-
<pre><code>Ramaze
|
622
|
-
</code></pre>
|
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>
|
623
488
|
|
624
|
-
<p>Alright, that wasn
|
625
|
-
Let's say now you also want to run Mongrel instead of WEBrick, to get nice a bit
|
626
|
-
of performance:</p>
|
489
|
+
<p>Alright, that wasn’t that hard. Let’s say now you also want to run Mongrel instead of WEBrick, to get nice a bit of performance:</p>
|
627
490
|
|
628
|
-
<pre><code>Ramaze
|
629
|
-
</code></pre>
|
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>
|
630
492
|
|
631
493
|
<p>To do this in a DRY way you could also do following:</p>
|
632
494
|
|
633
|
-
<pre><code>Ramaze
|
634
|
-
g
|
635
|
-
g
|
636
|
-
end
|
637
|
-
</code></pre>
|
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>
|
638
499
|
|
639
|
-
<p>It seems to be quite common to put this configuration into separate files so you
|
640
|
-
can just require it on demand. There are other, slightly stronger way to set
|
641
|
-
options, which is either using flags on the ramaze executable, or like this:</p>
|
500
|
+
<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>
|
642
501
|
|
643
|
-
<pre><code>Ramaze
|
644
|
-
</code></pre>
|
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">=></span> <span class="number">80</span><span class="punct">,</span> <span class="symbol">:adapter</span> <span class="punct">=></span> <span class="symbol">:mongrel</span></code></pre>
|
645
503
|
|
646
|
-
<p>We haven
|
647
|
-
ramaze executable and just run your application by <code>ruby start.rb</code>.</p>
|
504
|
+
<p>We haven’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>
|
648
505
|
|
649
|
-
<
|
506
|
+
<h2 id="eleventh_step_refactor_with_aspecthelper">Eleventh Step, Refactor with AspectHelper</h2>
|
650
507
|
|
651
508
|
<p>Now, if you take a closer look at the Controller you will see:</p>
|
652
509
|
|
653
|
-
<pre><code>def create
|
654
|
-
title = request[
|
655
|
-
TodoList[title] = {
|
656
|
-
redirect R(self)
|
657
|
-
end
|
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">['</span><span class="string">title</span><span class="punct">']</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">=></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>
|
658
515
|
|
659
|
-
def open title
|
660
|
-
task_status title
|
661
|
-
redirect R(self)
|
662
|
-
end
|
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>
|
663
520
|
|
664
|
-
def close title
|
665
|
-
task_status title
|
666
|
-
redirect R(self)
|
667
|
-
end
|
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>
|
668
525
|
|
669
|
-
def delete title
|
670
|
-
TodoList
|
671
|
-
redirect R(self)
|
672
|
-
end
|
673
|
-
</code></pre>
|
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>
|
674
530
|
|
675
|
-
<p>We did some refactoring before, by introducing <code>#task_status</code>, but here we have
|
676
|
-
repetition again: <code>redirect Rs()</code> <em>after</em> each method did its job.</p>
|
531
|
+
<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>
|
677
532
|
|
678
|
-
<p>However, we can take advantage of one of the helpers Ramaze offers, the
|
679
|
-
AspectHelper.
|
680
|
-
It allows you to easily wrap actions in your controller with other methods</p>
|
533
|
+
<p>However, we can take advantage of one of the helpers Ramaze offers, the AspectHelper. It allows you to easily wrap actions in your controller with other methods</p>
|
681
534
|
|
682
535
|
<p>In your Controller, replace the previous chunk with following:</p>
|
683
536
|
|
684
|
-
<pre><code>def create
|
685
|
-
title = request[
|
686
|
-
TodoList[title] = {
|
687
|
-
end
|
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">['</span><span class="string">title</span><span class="punct">']</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">=></span> <span class="constant">false</span><span class="punct">}</span>
|
540
|
+
<span class="keyword">end</span>
|
688
541
|
|
689
|
-
def open title
|
690
|
-
task_status title
|
691
|
-
end
|
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>
|
692
545
|
|
693
|
-
def close title
|
694
|
-
task_status title
|
695
|
-
end
|
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>
|
696
549
|
|
697
|
-
def delete title
|
698
|
-
TodoList
|
699
|
-
end
|
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>
|
700
553
|
|
701
|
-
helper
|
702
|
-
after(
|
703
|
-
</code></pre>
|
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>
|
704
556
|
|
705
557
|
<p>Alright, that looks a lot nicer already and is definitely easier to maintain.</p>
|
706
558
|
|
707
|
-
<p>There is a symmetrical <code>before</code> aspect that you could take advantage of as
|
708
|
-
well, and in case you want to add required authentication for all actions of a
|
709
|
-
Controller you could use <code>before_all</code> and <code>after_all</code> instead of a list of
|
710
|
-
action-names.</p>
|
559
|
+
<p>There is a symmetrical <code>before</code> aspect that you could take advantage of as well, and in case you want to add required authentication for all actions of a Controller you could use <code>before_all</code> and <code>after_all</code> instead of a list of action-names.</p>
|
711
560
|
|
712
|
-
<
|
561
|
+
<h2 id="twelfth_step_validation_and_errors">Twelfth Step, Validation and Errors</h2>
|
713
562
|
|
714
|
-
<p>Right now, all kinds of things could still go wrong when you do things like
|
715
|
-
creating tasks with no title at all or try to open/close a task that does not
|
716
|
-
exist. So in this step we will add some little checks for these cases.</p>
|
563
|
+
<p>Right now, all kinds of things could still go wrong when you do things like creating tasks with no title at all or try to open/close a task that does not exist. So in this step we will add some little checks for these cases.</p>
|
717
564
|
|
718
565
|
<p>First we head over to the Controller again and take a look at <code>#create</code>:</p>
|
719
566
|
|
720
|
-
<pre><code>def create
|
721
|
-
title = request[
|
722
|
-
TodoList[title] = {
|
723
|
-
end
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
<
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
<p>
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
specifically useful for giving the user feedback while keeping a stateless
|
750
|
-
approach.</p>
|
751
|
-
|
752
|
-
<p>Let me show you our <code>#failed</code> method (it goes in the private section to
|
753
|
-
<code>#task_status</code>):</p>
|
754
|
-
|
755
|
-
<pre><code>def failed(message)
|
756
|
-
flash[:error] = message
|
757
|
-
end
|
758
|
-
</code></pre>
|
759
|
-
|
760
|
-
<p>Duh, you may say, wouldn't that fit in the one line instead of the call to
|
761
|
-
<code>#failed</code>?
|
762
|
-
Indeed, it would, but let me remind you, we have no checks for changing the
|
763
|
-
status of a task yet. We will need error-handling there as well, so we just keep
|
764
|
-
our code DRY and maintainable by collecting shared behaviour in small pieces.</p>
|
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">['</span><span class="string">title</span><span class="punct">']</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">=></span> <span class="constant">false</span><span class="punct">}</span>
|
570
|
+
<span class="keyword">end</span></code></pre>
|
571
|
+
|
572
|
+
<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’s apply this advice.</p>
|
573
|
+
|
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">['</span><span class="string">title</span><span class="punct">']</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">("</span><span class="string">Please enter a title</span><span class="punct">")</span>
|
579
|
+
<span class="ident">redirect</span> <span class="punct">'</span><span class="string">/new</span><span class="punct">'</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">=></span> <span class="constant">false</span><span class="punct">}</span>
|
582
|
+
<span class="keyword">end</span>
|
583
|
+
<span class="keyword">end</span></code></pre>
|
584
|
+
|
585
|
+
<p>First of all we check if we got a request with a value for ‘title’, 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
|
+
|
587
|
+
<p>Ramaze has a helper called FlashHelper, that will keep a hash associated with the session for one request, afterwards the hash is thrown away. This is specifically useful for giving the user feedback while keeping a stateless approach.</p>
|
588
|
+
|
589
|
+
<p>Let me show you our <code>#failed</code> method (it goes in the private section to <code>#task_status</code>):</p>
|
590
|
+
|
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>
|
594
|
+
|
595
|
+
<p>Duh, you may say, wouldn’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>
|
765
596
|
|
766
597
|
<p>Now on to the <code>#task_status</code>:</p>
|
767
598
|
|
768
|
-
<pre><code>def task_status title
|
769
|
-
unless task = TodoList[title]
|
770
|
-
failed "No such Task:
|
771
|
-
redirect_referer
|
772
|
-
end
|
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">"</span><span class="string">No such Task: `<span class="expr">#{title}</span>'</span><span class="punct">"</span>
|
602
|
+
<span class="ident">redirect_referer</span>
|
603
|
+
<span class="keyword">end</span>
|
773
604
|
|
774
|
-
task[
|
775
|
-
TodoList[title] = task
|
776
|
-
end
|
777
|
-
</code></pre>
|
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>
|
778
608
|
|
779
609
|
<p>That used to look like this:</p>
|
780
610
|
|
781
|
-
<pre><code>def task_status title
|
782
|
-
task = TodoList[title]
|
783
|
-
task[
|
784
|
-
TodoList[title] = task
|
785
|
-
end
|
786
|
-
</code></pre>
|
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>
|
787
616
|
|
788
|
-
<p>So in fact all we added is a check whether a task already exists, set an
|
789
|
-
error-message in case it doesn't and redirect to wherever the browser came from.</p>
|
617
|
+
<p>So in fact all we added is a check whether a task already exists, set an error-message in case it doesn’t and redirect to wherever the browser came from.</p>
|
790
618
|
|
791
|
-
<p>But what about actually showing the error-messages we so carefully set? Well,
|
792
|
-
where do we change the view? Right, in the templates. But both templates we have
|
793
|
-
so far (index and new) share this behaviour, so we head over to the Element
|
794
|
-
and add in the right place:</p>
|
619
|
+
<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>
|
795
620
|
|
796
621
|
<pre><code><body>
|
797
622
|
<h1>#{@title}</h1>
|
798
623
|
<?r if flash[:error] ?>
|
799
|
-
<div class
|
800
|
-
|
624
|
+
<div class="error">
|
625
|
+
\\#{flash[:error]}
|
801
626
|
</div>
|
802
627
|
<?r end ?>
|
803
628
|
#{content}
|
804
|
-
</body>
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
As a note, If you read this as pure markaby, the double backslash is to output
|
811
|
-
properly to HTML, just use one instead.
|
812
|
-
Again, you can add some nifty style for that.</p>
|
813
|
-
|
814
|
-
<p>To be continued...</p>
|
815
|
-
</body>
|
816
|
-
</html>
|
629
|
+
</body></code></pre>
|
630
|
+
|
631
|
+
<p>The only thing special about it is the <code>\\#{flash[:error]}</code>, we have to escape the <code>#</code> so it won’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
|
+
|
633
|
+
<p>To be continued…</p>
|
634
|
+
</body></html>
|