ptomato-ramaze 2009.02
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +481 -0
- data/Rakefile +248 -0
- 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 +80 -0
- data/doc/AUTHORS +29 -0
- data/doc/CHANGELOG +19530 -0
- data/doc/COPYING +56 -0
- data/doc/FAQ +92 -0
- data/doc/GPL +339 -0
- data/doc/INSTALL +92 -0
- data/doc/LEGAL +26 -0
- data/doc/TODO +29 -0
- data/doc/meta/announcement.txt +99 -0
- data/doc/meta/configuration.txt +163 -0
- data/doc/meta/internals.txt +278 -0
- data/doc/meta/users.kml +64 -0
- data/doc/readme_chunks/appendix.txt +10 -0
- data/doc/readme_chunks/examples.txt +38 -0
- data/doc/readme_chunks/features.txt +148 -0
- data/doc/readme_chunks/getting_help.txt +5 -0
- data/doc/readme_chunks/getting_started.txt +18 -0
- data/doc/readme_chunks/installing.txt +92 -0
- data/doc/readme_chunks/introduction.txt +18 -0
- data/doc/readme_chunks/principles.txt +56 -0
- data/doc/readme_chunks/thanks.txt +59 -0
- data/doc/tutorial/todolist.html +742 -0
- data/doc/tutorial/todolist.mkd +787 -0
- data/examples/app/auth/auth.rb +54 -0
- data/examples/app/auth/template/layout.haml +20 -0
- data/examples/app/auth/template/login.haml +16 -0
- data/examples/app/blog/README +3 -0
- data/examples/app/blog/controller/main.rb +29 -0
- data/examples/app/blog/model/entry.rb +30 -0
- data/examples/app/blog/public/styles/blog.css +132 -0
- data/examples/app/blog/spec/blog.rb +87 -0
- data/examples/app/blog/start.rb +7 -0
- data/examples/app/blog/view/edit.xhtml +17 -0
- data/examples/app/blog/view/index.xhtml +17 -0
- data/examples/app/blog/view/layout.xhtml +11 -0
- data/examples/app/blog/view/new.xhtml +16 -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/app/rapaste/Rakefile +34 -0
- data/examples/app/rapaste/controller/paste.rb +101 -0
- data/examples/app/rapaste/model/paste.rb +58 -0
- data/examples/app/rapaste/public/css/active4d.css +114 -0
- data/examples/app/rapaste/public/css/all_hallows_eve.css +72 -0
- data/examples/app/rapaste/public/css/amy.css +147 -0
- data/examples/app/rapaste/public/css/blackboard.css +88 -0
- data/examples/app/rapaste/public/css/brilliance_black.css +605 -0
- data/examples/app/rapaste/public/css/brilliance_dull.css +599 -0
- data/examples/app/rapaste/public/css/cobalt.css +149 -0
- data/examples/app/rapaste/public/css/dawn.css +121 -0
- data/examples/app/rapaste/public/css/display.css +197 -0
- data/examples/app/rapaste/public/css/eiffel.css +121 -0
- data/examples/app/rapaste/public/css/espresso_libre.css +109 -0
- data/examples/app/rapaste/public/css/idle.css +62 -0
- data/examples/app/rapaste/public/css/iplastic.css +80 -0
- data/examples/app/rapaste/public/css/lazy.css +73 -0
- data/examples/app/rapaste/public/css/mac_classic.css +123 -0
- data/examples/app/rapaste/public/css/magicwb_amiga.css +104 -0
- data/examples/app/rapaste/public/css/pastels_on_dark.css +188 -0
- data/examples/app/rapaste/public/css/slush_poppies.css +85 -0
- data/examples/app/rapaste/public/css/spacecadet.css +51 -0
- data/examples/app/rapaste/public/css/sunburst.css +180 -0
- data/examples/app/rapaste/public/css/twilight.css +137 -0
- data/examples/app/rapaste/public/css/zenburnesque.css +91 -0
- data/examples/app/rapaste/public/js/jquery.js +11 -0
- data/examples/app/rapaste/spec/rapaste.rb +51 -0
- data/examples/app/rapaste/start.rb +25 -0
- data/examples/app/rapaste/view/copy.xhtml +10 -0
- data/examples/app/rapaste/view/index.xhtml +9 -0
- data/examples/app/rapaste/view/layout.xhtml +25 -0
- data/examples/app/rapaste/view/list.xhtml +29 -0
- data/examples/app/rapaste/view/search.xhtml +41 -0
- data/examples/app/rapaste/view/view.xhtml +40 -0
- data/examples/app/sourceview/public/coderay.css +104 -0
- data/examples/app/sourceview/public/images/file.gif +0 -0
- data/examples/app/sourceview/public/images/folder.gif +0 -0
- data/examples/app/sourceview/public/images/tv-collapsable-last.gif +0 -0
- data/examples/app/sourceview/public/images/tv-collapsable.gif +0 -0
- data/examples/app/sourceview/public/images/tv-expandable-last.gif +0 -0
- data/examples/app/sourceview/public/images/tv-expandable.gif +0 -0
- data/examples/app/sourceview/public/images/tv-item-last.gif +0 -0
- data/examples/app/sourceview/public/images/tv-item.gif +0 -0
- data/examples/app/sourceview/public/jquery.js +11 -0
- data/examples/app/sourceview/public/jquery.treeview.css +48 -0
- data/examples/app/sourceview/public/jquery.treeview.js +223 -0
- data/examples/app/sourceview/public/sourceview.js +52 -0
- data/examples/app/sourceview/sourceview.rb +77 -0
- data/examples/app/sourceview/template/index.haml +59 -0
- data/examples/app/todolist/README +1 -0
- data/examples/app/todolist/public/favicon.ico +0 -0
- data/examples/app/todolist/public/js/jquery.js +1923 -0
- data/examples/app/todolist/public/ramaze.png +0 -0
- data/examples/app/todolist/spec/todolist.rb +132 -0
- data/examples/app/todolist/src/controller/main.rb +70 -0
- data/examples/app/todolist/src/element/page.rb +31 -0
- data/examples/app/todolist/src/model.rb +14 -0
- data/examples/app/todolist/start.rb +11 -0
- data/examples/app/todolist/template/index.xhtml +17 -0
- data/examples/app/todolist/template/new.xhtml +7 -0
- data/examples/app/upload/start.rb +19 -0
- data/examples/app/upload/view/index.xhtml +25 -0
- data/examples/app/whywiki/spec/whywiki.rb +58 -0
- data/examples/app/whywiki/start.rb +46 -0
- data/examples/app/whywiki/template/edit.xhtml +14 -0
- data/examples/app/whywiki/template/show.xhtml +18 -0
- data/examples/app/wikore/spec/wikore.rb +111 -0
- data/examples/app/wikore/src/controller.rb +80 -0
- data/examples/app/wikore/src/model.rb +53 -0
- data/examples/app/wikore/start.rb +9 -0
- data/examples/app/wikore/template/index.xhtml +8 -0
- data/examples/app/wiktacular/README +2 -0
- data/examples/app/wiktacular/mkd/link/2007-07-20_19-45-51.mkd +1 -0
- data/examples/app/wiktacular/mkd/link/current.mkd +1 -0
- data/examples/app/wiktacular/mkd/main/2007-07-20_16-31-33.mkd +1 -0
- data/examples/app/wiktacular/mkd/main/2007-07-20_19-21-12.mkd +1 -0
- data/examples/app/wiktacular/mkd/main/2007-07-20_19-23-10.mkd +2 -0
- data/examples/app/wiktacular/mkd/main/2007-07-20_19-45-07.mkd +2 -0
- data/examples/app/wiktacular/mkd/main/current.mkd +2 -0
- data/examples/app/wiktacular/mkd/markdown/current.mkd +3 -0
- data/examples/app/wiktacular/mkd/testing/2007-07-20_16-43-46.mkd +2 -0
- data/examples/app/wiktacular/mkd/testing/2007-07-20_19-43-50.mkd +3 -0
- data/examples/app/wiktacular/mkd/testing/2007-07-21_18-46-01.mkd +11 -0
- data/examples/app/wiktacular/mkd/testing/2007-07-21_18-46-32.mkd +13 -0
- data/examples/app/wiktacular/mkd/testing/2007-07-21_18-47-08.mkd +17 -0
- data/examples/app/wiktacular/mkd/testing/2007-07-21_18-47-54.mkd +17 -0
- data/examples/app/wiktacular/mkd/testing/current.mkd +17 -0
- data/examples/app/wiktacular/public/favicon.ico +0 -0
- data/examples/app/wiktacular/public/screen.css +72 -0
- data/examples/app/wiktacular/spec/wiktacular.rb +157 -0
- data/examples/app/wiktacular/src/controller.rb +55 -0
- data/examples/app/wiktacular/src/model.rb +102 -0
- data/examples/app/wiktacular/start.rb +8 -0
- data/examples/app/wiktacular/template/edit.xhtml +6 -0
- data/examples/app/wiktacular/template/html_layout.xhtml +27 -0
- data/examples/app/wiktacular/template/index.xhtml +9 -0
- data/examples/app/wiktacular/template/new.xhtml +6 -0
- data/examples/basic/element.rb +45 -0
- data/examples/basic/gestalt.rb +27 -0
- data/examples/basic/hello.rb +15 -0
- data/examples/basic/layout.rb +28 -0
- data/examples/basic/linking.rb +29 -0
- data/examples/basic/partial.rb +28 -0
- data/examples/basic/simple.rb +56 -0
- data/examples/helpers/cache.rb +31 -0
- data/examples/helpers/form_with_sequel.rb +24 -0
- data/examples/helpers/httpdigest.rb +108 -0
- data/examples/helpers/identity.rb +18 -0
- data/examples/helpers/nitro_form.rb +23 -0
- data/examples/helpers/paginate.rb +71 -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/misc/css.rb +37 -0
- data/examples/misc/facebook.rb +159 -0
- data/examples/misc/memleak_detector.rb +32 -0
- data/examples/misc/nagoro_element.rb +43 -0
- data/examples/misc/ramaise.rb +132 -0
- data/examples/misc/rapp.rb +45 -0
- data/examples/misc/sequel_scaffolding.rb +34 -0
- data/examples/misc/simple_auth.rb +35 -0
- data/examples/templates/template/external.amrita +19 -0
- data/examples/templates/template/external.haml +22 -0
- data/examples/templates/template/external.liquid +28 -0
- data/examples/templates/template/external.mab +30 -0
- data/examples/templates/template/external.nag +28 -0
- data/examples/templates/template/external.redcloth +19 -0
- data/examples/templates/template/external.rem +30 -0
- data/examples/templates/template/external.rhtml +28 -0
- data/examples/templates/template/external.tenjin +28 -0
- data/examples/templates/template/external.xsl +57 -0
- data/examples/templates/template/external.zmr +28 -0
- data/examples/templates/template_amrita2.rb +74 -0
- data/examples/templates/template_erubis.rb +53 -0
- data/examples/templates/template_ezamar.rb +50 -0
- data/examples/templates/template_haml.rb +50 -0
- data/examples/templates/template_liquid.rb +65 -0
- data/examples/templates/template_markaby.rb +58 -0
- data/examples/templates/template_nagoro.rb +51 -0
- data/examples/templates/template_redcloth.rb +59 -0
- data/examples/templates/template_remarkably.rb +55 -0
- data/examples/templates/template_tenjin.rb +53 -0
- data/examples/templates/template_xslt.rb +49 -0
- data/lib/proto/controller/init.rb +11 -0
- data/lib/proto/controller/main.rb +20 -0
- data/lib/proto/model/init.rb +4 -0
- data/lib/proto/public/.htaccess +24 -0
- data/lib/proto/public/css/ramaze_error.css +90 -0
- data/lib/proto/public/dispatch.fcgi +11 -0
- data/lib/proto/public/favicon.ico +0 -0
- data/lib/proto/public/js/jquery.js +3549 -0
- data/lib/proto/public/ramaze.png +0 -0
- data/lib/proto/spec/main.rb +25 -0
- data/lib/proto/start.rb +12 -0
- data/lib/proto/start.ru +16 -0
- data/lib/proto/view/error.xhtml +64 -0
- data/lib/proto/view/index.xhtml +34 -0
- data/lib/proto/view/page.xhtml +27 -0
- data/lib/ramaze/action/render.rb +192 -0
- data/lib/ramaze/action.rb +159 -0
- data/lib/ramaze/adapter/base.rb +128 -0
- data/lib/ramaze/adapter/cgi.rb +20 -0
- data/lib/ramaze/adapter/ebb.rb +18 -0
- data/lib/ramaze/adapter/evented_mongrel.rb +7 -0
- data/lib/ramaze/adapter/fake.rb +12 -0
- data/lib/ramaze/adapter/fcgi.rb +18 -0
- data/lib/ramaze/adapter/lsws.rb +19 -0
- data/lib/ramaze/adapter/mongrel.rb +21 -0
- data/lib/ramaze/adapter/scgi.rb +18 -0
- data/lib/ramaze/adapter/swiftiplied_mongrel.rb +7 -0
- data/lib/ramaze/adapter/thin.rb +17 -0
- data/lib/ramaze/adapter/webrick.rb +43 -0
- data/lib/ramaze/adapter.rb +97 -0
- data/lib/ramaze/cache/file.rb +71 -0
- data/lib/ramaze/cache/memcached.rb +69 -0
- data/lib/ramaze/cache/memory.rb +6 -0
- data/lib/ramaze/cache/yaml_store.rb +68 -0
- data/lib/ramaze/cache.rb +114 -0
- data/lib/ramaze/contrib/email.rb +86 -0
- data/lib/ramaze/contrib/facebook/facebook.rb +171 -0
- data/lib/ramaze/contrib/facebook.rb +23 -0
- data/lib/ramaze/contrib/file_cache.rb +3 -0
- data/lib/ramaze/contrib/gems.rb +78 -0
- data/lib/ramaze/contrib/gettext/mo.rb +155 -0
- data/lib/ramaze/contrib/gettext/parser.rb +46 -0
- data/lib/ramaze/contrib/gettext/po.rb +109 -0
- data/lib/ramaze/contrib/gettext.rb +113 -0
- data/lib/ramaze/contrib/gzip_filter.rb +69 -0
- data/lib/ramaze/contrib/maruku_uv.rb +59 -0
- data/lib/ramaze/contrib/profiling.rb +36 -0
- data/lib/ramaze/contrib/rest.rb +17 -0
- data/lib/ramaze/contrib/sequel/create_join.rb +25 -0
- data/lib/ramaze/contrib/sequel/fill.rb +12 -0
- data/lib/ramaze/contrib/sequel/form_field.rb +129 -0
- data/lib/ramaze/contrib/sequel/image.rb +198 -0
- data/lib/ramaze/contrib/sequel/relation.rb +82 -0
- data/lib/ramaze/contrib/sequel_cache.rb +92 -0
- data/lib/ramaze/contrib.rb +82 -0
- data/lib/ramaze/controller/error.rb +46 -0
- data/lib/ramaze/controller/main.rb +2 -0
- data/lib/ramaze/controller/resolve.rb +278 -0
- data/lib/ramaze/controller.rb +288 -0
- data/lib/ramaze/current/request.rb +231 -0
- data/lib/ramaze/current/response.rb +37 -0
- data/lib/ramaze/current/session/flash.rb +88 -0
- data/lib/ramaze/current/session/hash.rb +62 -0
- data/lib/ramaze/current/session.rb +179 -0
- data/lib/ramaze/current.rb +51 -0
- data/lib/ramaze/dispatcher/action.rb +50 -0
- data/lib/ramaze/dispatcher/directory.rb +119 -0
- data/lib/ramaze/dispatcher/error.rb +108 -0
- data/lib/ramaze/dispatcher/file.rb +100 -0
- data/lib/ramaze/dispatcher.rb +145 -0
- data/lib/ramaze/error.rb +24 -0
- data/lib/ramaze/gestalt.rb +124 -0
- data/lib/ramaze/helper/aspect.rb +106 -0
- data/lib/ramaze/helper/auth.rb +125 -0
- data/lib/ramaze/helper/bench.rb +43 -0
- data/lib/ramaze/helper/cache.rb +140 -0
- data/lib/ramaze/helper/cgi.rb +39 -0
- data/lib/ramaze/helper/flash.rb +74 -0
- data/lib/ramaze/helper/form.rb +284 -0
- data/lib/ramaze/helper/formatting.rb +162 -0
- data/lib/ramaze/helper/gestalt.rb +15 -0
- data/lib/ramaze/helper/gravatar.rb +32 -0
- data/lib/ramaze/helper/httpdigest.rb +88 -0
- data/lib/ramaze/helper/identity.rb +119 -0
- data/lib/ramaze/helper/link.rb +122 -0
- data/lib/ramaze/helper/markaby.rb +31 -0
- data/lib/ramaze/helper/maruku.rb +9 -0
- data/lib/ramaze/helper/nitroform.rb +14 -0
- data/lib/ramaze/helper/pager.rb +366 -0
- data/lib/ramaze/helper/paginate.rb +233 -0
- data/lib/ramaze/helper/partial.rb +105 -0
- data/lib/ramaze/helper/redirect.rb +100 -0
- data/lib/ramaze/helper/rest.rb +43 -0
- data/lib/ramaze/helper/sendfile.rb +16 -0
- data/lib/ramaze/helper/sequel.rb +55 -0
- data/lib/ramaze/helper/simple_captcha.rb +31 -0
- data/lib/ramaze/helper/stack.rb +77 -0
- data/lib/ramaze/helper/tagz.rb +19 -0
- data/lib/ramaze/helper/thread.rb +17 -0
- data/lib/ramaze/helper/ultraviolet.rb +44 -0
- data/lib/ramaze/helper/user.rb +110 -0
- data/lib/ramaze/helper/xhtml.rb +23 -0
- data/lib/ramaze/helper.rb +87 -0
- data/lib/ramaze/log/analogger.rb +40 -0
- data/lib/ramaze/log/growl.rb +38 -0
- data/lib/ramaze/log/hub.rb +41 -0
- data/lib/ramaze/log/informer.rb +128 -0
- data/lib/ramaze/log/knotify.rb +28 -0
- data/lib/ramaze/log/logger.rb +26 -0
- data/lib/ramaze/log/logging.rb +89 -0
- data/lib/ramaze/log/rotatinginformer.rb +168 -0
- data/lib/ramaze/log/syslog.rb +51 -0
- data/lib/ramaze/log/xosd.rb +92 -0
- data/lib/ramaze/log.rb +27 -0
- data/lib/ramaze/option/dsl.rb +45 -0
- data/lib/ramaze/option/holder.rb +131 -0
- data/lib/ramaze/option/merger.rb +108 -0
- data/lib/ramaze/option.rb +156 -0
- data/lib/ramaze/reloader/watch_inotify.rb +85 -0
- data/lib/ramaze/reloader/watch_stat.rb +58 -0
- data/lib/ramaze/reloader.rb +170 -0
- data/lib/ramaze/route.rb +97 -0
- data/lib/ramaze/setup.rb +50 -0
- data/lib/ramaze/snippets/array/put_within.rb +44 -0
- data/lib/ramaze/snippets/binding/locals.rb +25 -0
- data/lib/ramaze/snippets/blankslate.rb +7 -0
- data/lib/ramaze/snippets/dictionary.rb +504 -0
- data/lib/ramaze/snippets/divide.rb +22 -0
- data/lib/ramaze/snippets/fiber.rb +63 -0
- data/lib/ramaze/snippets/kernel/constant.rb +41 -0
- data/lib/ramaze/snippets/kernel/pretty_inspect.rb +21 -0
- data/lib/ramaze/snippets/metaid.rb +17 -0
- data/lib/ramaze/snippets/numeric/filesize_format.rb +32 -0
- data/lib/ramaze/snippets/numeric/time.rb +63 -0
- data/lib/ramaze/snippets/object/__dir__.rb +29 -0
- data/lib/ramaze/snippets/object/acquire.rb +37 -0
- data/lib/ramaze/snippets/object/instance_variable_defined.rb +19 -0
- data/lib/ramaze/snippets/object/pretty.rb +16 -0
- data/lib/ramaze/snippets/object/scope.rb +18 -0
- data/lib/ramaze/snippets/object/traits.rb +76 -0
- data/lib/ramaze/snippets/ordered_set.rb +51 -0
- data/lib/ramaze/snippets/proc/locals.rb +19 -0
- data/lib/ramaze/snippets/ramaze/acquire.rb +31 -0
- data/lib/ramaze/snippets/ramaze/caller_info.rb +30 -0
- data/lib/ramaze/snippets/ramaze/caller_lines.rb +51 -0
- data/lib/ramaze/snippets/ramaze/deprecated.rb +21 -0
- data/lib/ramaze/snippets/ramaze/fiber.rb +24 -0
- data/lib/ramaze/snippets/ramaze/state.rb +86 -0
- data/lib/ramaze/snippets/ramaze/struct.rb +45 -0
- data/lib/ramaze/snippets/string/camel_case.rb +21 -0
- data/lib/ramaze/snippets/string/color.rb +31 -0
- data/lib/ramaze/snippets/string/each.rb +19 -0
- data/lib/ramaze/snippets/string/end_with.rb +20 -0
- data/lib/ramaze/snippets/string/esc.rb +34 -0
- data/lib/ramaze/snippets/string/ord.rb +21 -0
- data/lib/ramaze/snippets/string/snake_case.rb +21 -0
- data/lib/ramaze/snippets/string/start_with.rb +19 -0
- data/lib/ramaze/snippets/string/unindent.rb +28 -0
- data/lib/ramaze/snippets/thread/into.rb +18 -0
- data/lib/ramaze/snippets.rb +22 -0
- data/lib/ramaze/spec/helper/bacon.rb +7 -0
- data/lib/ramaze/spec/helper/browser.rb +88 -0
- data/lib/ramaze/spec/helper/mock_http.rb +64 -0
- data/lib/ramaze/spec/helper/pretty_output.rb +82 -0
- data/lib/ramaze/spec/helper/requester.rb +63 -0
- data/lib/ramaze/spec/helper/simple_http.rb +434 -0
- data/lib/ramaze/spec/helper/snippets.rb +14 -0
- data/lib/ramaze/spec/helper.rb +135 -0
- data/lib/ramaze/spec.rb +1 -0
- data/lib/ramaze/store/default.rb +109 -0
- data/lib/ramaze/template/amrita2.rb +49 -0
- data/lib/ramaze/template/builder.rb +28 -0
- data/lib/ramaze/template/erubis.rb +41 -0
- data/lib/ramaze/template/ezamar/element.rb +169 -0
- data/lib/ramaze/template/ezamar/engine.rb +76 -0
- data/lib/ramaze/template/ezamar/morpher.rb +135 -0
- data/lib/ramaze/template/ezamar/render_partial.rb +39 -0
- data/lib/ramaze/template/ezamar/textpow.syntax +34 -0
- data/lib/ramaze/template/ezamar.rb +42 -0
- data/lib/ramaze/template/haml.rb +37 -0
- data/lib/ramaze/template/liquid.rb +36 -0
- data/lib/ramaze/template/markaby.rb +52 -0
- data/lib/ramaze/template/maruku.rb +34 -0
- data/lib/ramaze/template/nagoro.rb +52 -0
- data/lib/ramaze/template/none.rb +14 -0
- data/lib/ramaze/template/redcloth.rb +25 -0
- data/lib/ramaze/template/remarkably.rb +38 -0
- data/lib/ramaze/template/sass.rb +38 -0
- data/lib/ramaze/template/tagz.rb +79 -0
- data/lib/ramaze/template/tenjin.rb +74 -0
- data/lib/ramaze/template/xslt.rb +100 -0
- data/lib/ramaze/template.rb +87 -0
- data/lib/ramaze/tool/create.rb +48 -0
- data/lib/ramaze/tool/daemonize.rb +37 -0
- data/lib/ramaze/tool/localize.rb +202 -0
- data/lib/ramaze/tool/mime.rb +35 -0
- data/lib/ramaze/tool/mime_types.yaml +615 -0
- data/lib/ramaze/tool/project_creator.rb +111 -0
- data/lib/ramaze/tool/record.rb +6 -0
- data/lib/ramaze/tool.rb +9 -0
- data/lib/ramaze/trinity.rb +16 -0
- data/lib/ramaze/version.rb +6 -0
- data/lib/ramaze.rb +139 -0
- data/lib/vendor/bacon.rb +323 -0
- data/rake_tasks/conf.rake +71 -0
- data/rake_tasks/coverage.rake +45 -0
- data/rake_tasks/gem.rake +74 -0
- data/rake_tasks/git.rake +41 -0
- data/rake_tasks/maintenance.rake +386 -0
- data/rake_tasks/metric.rake +24 -0
- data/rake_tasks/release.rake +76 -0
- data/rake_tasks/spec.rake +61 -0
- data/ramaze.gemspec +611 -0
- data/spec/contrib/profiling.rb +29 -0
- data/spec/contrib/sequel/fill.rb +47 -0
- data/spec/examples/caching.rb +19 -0
- data/spec/examples/css.rb +15 -0
- data/spec/examples/element.rb +15 -0
- data/spec/examples/hello.rb +11 -0
- data/spec/examples/linking.rb +18 -0
- data/spec/examples/simple.rb +45 -0
- data/spec/examples/simple_auth.rb +32 -0
- data/spec/examples/templates/template_amrita2.rb +16 -0
- data/spec/examples/templates/template_erubis.rb +23 -0
- data/spec/examples/templates/template_ezamar.rb +23 -0
- data/spec/examples/templates/template_haml.rb +23 -0
- data/spec/examples/templates/template_liquid.rb +29 -0
- data/spec/examples/templates/template_markaby.rb +23 -0
- data/spec/examples/templates/template_redcloth.rb +28 -0
- data/spec/examples/templates/template_remarkably.rb +23 -0
- data/spec/examples/templates/template_tenjin.rb +28 -0
- data/spec/helper.rb +3 -0
- data/spec/ramaze/action/basics.rb +36 -0
- data/spec/ramaze/action/cache.rb +87 -0
- data/spec/ramaze/action/file_cache.rb +70 -0
- data/spec/ramaze/action/layout.rb +190 -0
- data/spec/ramaze/action/render.rb +31 -0
- data/spec/ramaze/action/view/bar.xhtml +1 -0
- data/spec/ramaze/action/view/instancevars/layout.xhtml +1 -0
- data/spec/ramaze/action/view/other_wrapper.xhtml +1 -0
- data/spec/ramaze/action/view/single_wrapper.xhtml +1 -0
- data/spec/ramaze/action/view/sub/sub_wrapper.xhtml +1 -0
- data/spec/ramaze/adapter/ebb.rb +12 -0
- data/spec/ramaze/adapter/mongrel.rb +12 -0
- data/spec/ramaze/adapter/record.rb +31 -0
- data/spec/ramaze/adapter/webrick.rb +12 -0
- data/spec/ramaze/adapter.rb +49 -0
- data/spec/ramaze/cache.rb +140 -0
- data/spec/ramaze/controller/actionless_templates.rb +32 -0
- data/spec/ramaze/controller/resolve.rb +32 -0
- data/spec/ramaze/controller/subclass.rb +36 -0
- data/spec/ramaze/controller/template_resolving.rb +113 -0
- data/spec/ramaze/controller/view/bar.xhtml +1 -0
- data/spec/ramaze/controller/view/base/another.xhtml +1 -0
- data/spec/ramaze/controller/view/greet.xhtml +1 -0
- data/spec/ramaze/controller/view/list.xhtml +1 -0
- data/spec/ramaze/controller/view/other/greet/other.xhtml +1 -0
- data/spec/ramaze/controller/view/other_wrapper.xhtml +1 -0
- data/spec/ramaze/controller.rb +180 -0
- data/spec/ramaze/current/request.rb +30 -0
- data/spec/ramaze/current/session.rb +97 -0
- data/spec/ramaze/dispatcher/directory.rb +55 -0
- data/spec/ramaze/dispatcher/file.rb +60 -0
- data/spec/ramaze/dispatcher/public/favicon.ico +0 -0
- data/spec/ramaze/dispatcher/public/file name.txt +1 -0
- data/spec/ramaze/dispatcher/public/test_download.css +141 -0
- data/spec/ramaze/dispatcher.rb +31 -0
- data/spec/ramaze/element.rb +107 -0
- data/spec/ramaze/error.rb +94 -0
- data/spec/ramaze/gestalt.rb +131 -0
- data/spec/ramaze/helper/aspect.rb +101 -0
- data/spec/ramaze/helper/auth.rb +66 -0
- data/spec/ramaze/helper/cache.rb +160 -0
- data/spec/ramaze/helper/cgi.rb +43 -0
- data/spec/ramaze/helper/file.rb +18 -0
- data/spec/ramaze/helper/flash.rb +133 -0
- data/spec/ramaze/helper/form.rb +118 -0
- data/spec/ramaze/helper/formatting.rb +54 -0
- data/spec/ramaze/helper/link.rb +124 -0
- data/spec/ramaze/helper/pager.rb +99 -0
- data/spec/ramaze/helper/partial.rb +88 -0
- data/spec/ramaze/helper/redirect.rb +112 -0
- data/spec/ramaze/helper/simple_captcha.rb +22 -0
- data/spec/ramaze/helper/stack.rb +73 -0
- data/spec/ramaze/helper/user.rb +43 -0
- data/spec/ramaze/helper/view/locals.xhtml +1 -0
- data/spec/ramaze/helper/view/loop.xhtml +4 -0
- data/spec/ramaze/helper/view/num.xhtml +1 -0
- data/spec/ramaze/helper/view/partial.xhtml +1 -0
- data/spec/ramaze/helper/view/recursive.xhtml +8 -0
- data/spec/ramaze/helper/view/recursive_local_ivars.xhtml +7 -0
- data/spec/ramaze/helper/view/recursive_locals.xhtml +7 -0
- data/spec/ramaze/helper/view/test_template.xhtml +1 -0
- data/spec/ramaze/localize.rb +89 -0
- data/spec/ramaze/log/informer.rb +72 -0
- data/spec/ramaze/log/syslog.rb +76 -0
- data/spec/ramaze/morpher.rb +111 -0
- data/spec/ramaze/params.rb +157 -0
- data/spec/ramaze/public/error404.xhtml +1 -0
- data/spec/ramaze/public/favicon.ico +0 -0
- data/spec/ramaze/public/ramaze.png +0 -0
- data/spec/ramaze/public/test_download.css +141 -0
- data/spec/ramaze/request/ebb.rb +9 -0
- data/spec/ramaze/request/mongrel.rb +9 -0
- data/spec/ramaze/request/thin.rb +9 -0
- data/spec/ramaze/request/webrick.rb +5 -0
- data/spec/ramaze/request.rb +185 -0
- data/spec/ramaze/rewrite/file.css +1 -0
- data/spec/ramaze/rewrite.rb +36 -0
- data/spec/ramaze/route.rb +131 -0
- data/spec/ramaze/session.rb +94 -0
- data/spec/ramaze/store/default.rb +71 -0
- data/spec/ramaze/struct.rb +47 -0
- data/spec/ramaze/template/amrita2/external.amrita +6 -0
- data/spec/ramaze/template/amrita2/sum.amrita +1 -0
- data/spec/ramaze/template/amrita2.rb +50 -0
- data/spec/ramaze/template/builder/external.rxml +3 -0
- data/spec/ramaze/template/builder.rb +51 -0
- data/spec/ramaze/template/erubis/sum.rhtml +1 -0
- data/spec/ramaze/template/erubis.rb +41 -0
- data/spec/ramaze/template/ezamar/another/long/action.zmr +1 -0
- data/spec/ramaze/template/ezamar/combined.zmr +1 -0
- data/spec/ramaze/template/ezamar/file_only.zmr +1 -0
- data/spec/ramaze/template/ezamar/index.zmr +1 -0
- data/spec/ramaze/template/ezamar/nested.zmr +1 -0
- data/spec/ramaze/template/ezamar/other__index.xhtml +1 -0
- data/spec/ramaze/template/ezamar/some__long__action.zmr +1 -0
- data/spec/ramaze/template/ezamar/sum.zmr +1 -0
- data/spec/ramaze/template/ezamar.rb +63 -0
- data/spec/ramaze/template/haml/index.haml +5 -0
- data/spec/ramaze/template/haml/locals.haml +2 -0
- data/spec/ramaze/template/haml/with_vars.haml +4 -0
- data/spec/ramaze/template/haml.rb +66 -0
- data/spec/ramaze/template/liquid/index.liquid +1 -0
- data/spec/ramaze/template/liquid/products.liquid +45 -0
- data/spec/ramaze/template/liquid.rb +99 -0
- data/spec/ramaze/template/markaby/external.mab +8 -0
- data/spec/ramaze/template/markaby/sum.mab +1 -0
- data/spec/ramaze/template/markaby.rb +61 -0
- data/spec/ramaze/template/nagoro/another/long/action.nag +1 -0
- data/spec/ramaze/template/nagoro/combined.nag +1 -0
- data/spec/ramaze/template/nagoro/file_only.nag +1 -0
- data/spec/ramaze/template/nagoro/index.nag +1 -0
- data/spec/ramaze/template/nagoro/nested.nag +1 -0
- data/spec/ramaze/template/nagoro/some__long__action.nag +1 -0
- data/spec/ramaze/template/nagoro/sum.nag +1 -0
- data/spec/ramaze/template/nagoro.rb +64 -0
- data/spec/ramaze/template/ramaze/external.test +1 -0
- data/spec/ramaze/template/redcloth/external.redcloth +1 -0
- data/spec/ramaze/template/redcloth.rb +38 -0
- data/spec/ramaze/template/remarkably/external.rem +8 -0
- data/spec/ramaze/template/remarkably/sum.rem +1 -0
- data/spec/ramaze/template/remarkably.rb +58 -0
- data/spec/ramaze/template/sass/file.css.sass +5 -0
- data/spec/ramaze/template/sass.rb +70 -0
- data/spec/ramaze/template/tagz/external.tagz +8 -0
- data/spec/ramaze/template/tagz/sum.tagz +1 -0
- data/spec/ramaze/template/tagz.rb +62 -0
- data/spec/ramaze/template/tenjin/external.tenjin +1 -0
- data/spec/ramaze/template/tenjin.rb +47 -0
- data/spec/ramaze/template/xslt/concat_words.xsl +16 -0
- data/spec/ramaze/template/xslt/index.xsl +14 -0
- data/spec/ramaze/template/xslt/products.xsl +32 -0
- data/spec/ramaze/template/xslt/ruby_version.xsl +14 -0
- data/spec/ramaze/template/xslt.rb +90 -0
- data/spec/ramaze/template.rb +128 -0
- data/spec/snippets/array/put_within.rb +33 -0
- data/spec/snippets/binding/locals.rb +9 -0
- data/spec/snippets/kernel/constant.rb +23 -0
- data/spec/snippets/numeric/filesize_format.rb +12 -0
- data/spec/snippets/numeric/time.rb +12 -0
- data/spec/snippets/object/__dir__.rb +14 -0
- data/spec/snippets/ordered_set.rb +63 -0
- data/spec/snippets/ramaze/acquire.rb +77 -0
- data/spec/snippets/ramaze/caller_info.rb +39 -0
- data/spec/snippets/ramaze/caller_lines.rb +30 -0
- data/spec/snippets/string/camel_case.rb +25 -0
- data/spec/snippets/string/color.rb +11 -0
- data/spec/snippets/string/snake_case.rb +24 -0
- data/spec/snippets/string/unindent.rb +43 -0
- data/spec/snippets/thread/into.rb +20 -0
- metadata +661 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module Ramaze
|
|
2
|
+
module Helper
|
|
3
|
+
module Gravatar
|
|
4
|
+
|
|
5
|
+
# fetches a gravatar from http//www.gravatar.com based on 'email'
|
|
6
|
+
# and 'size'. Falls back to 'fallback_path' if no gravatar is found.
|
|
7
|
+
# default 'fallback_path' is "/images/gravatar_default.jpg".
|
|
8
|
+
# example:
|
|
9
|
+
#
|
|
10
|
+
# class GravatarController < Ramaze::Controller
|
|
11
|
+
# helper :gravatar
|
|
12
|
+
#
|
|
13
|
+
# def index
|
|
14
|
+
# @gravatar_thumbnail_src = gravatar(session[:email] || 'riku@helloit.fi')
|
|
15
|
+
# end
|
|
16
|
+
# end
|
|
17
|
+
#
|
|
18
|
+
# /view/gravatar/index.html:
|
|
19
|
+
# <img src="#{@gravatar_thumbnail_src}" />
|
|
20
|
+
|
|
21
|
+
def gravatar(email, size = 32, fallback_path = "/images/gravatar_default.jpg")
|
|
22
|
+
emailhash = Digest::MD5.hexdigest(email)
|
|
23
|
+
|
|
24
|
+
fallback = Request.current.domain
|
|
25
|
+
fallback.path = fallback_path
|
|
26
|
+
default = Rack::Utils.escape(fallback.to_s)
|
|
27
|
+
|
|
28
|
+
return "http://www.gravatar.com/avatar.php?gravatar_id=#{emailhash}&default=#{default}&size=#{size}"
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
require 'uuid'
|
|
2
|
+
require 'md5'
|
|
3
|
+
|
|
4
|
+
module Ramaze
|
|
5
|
+
module Helper
|
|
6
|
+
module HttpDigest
|
|
7
|
+
|
|
8
|
+
UUID_GENERATOR = UUID.new
|
|
9
|
+
|
|
10
|
+
SESSION_NONCE = 'httpdigest_authentication_nonce'
|
|
11
|
+
SESSION_OPAQUE = 'httpdigest_authentication_opaque'
|
|
12
|
+
|
|
13
|
+
def httpdigest_logout
|
|
14
|
+
session.delete( SESSION_NONCE )
|
|
15
|
+
session.delete( SESSION_OPAQUE )
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def httpdigest_headers uid, realm
|
|
19
|
+
session[ SESSION_NONCE ] = UUID_GENERATOR.generate
|
|
20
|
+
session[ SESSION_OPAQUE ][ realm ][ uid ] = UUID_GENERATOR.generate
|
|
21
|
+
response['WWW-Authenticate'] =
|
|
22
|
+
%|Digest realm="#{realm}",| +
|
|
23
|
+
%|qop="auth,auth-int",| +
|
|
24
|
+
%|nonce="#{session[SESSION_NONCE]}",| +
|
|
25
|
+
%|opaque="#{session[SESSION_OPAQUE][realm][uid]}"|
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def httpdigest(uid, realm)
|
|
29
|
+
session[ SESSION_OPAQUE ] ||= {}
|
|
30
|
+
session[ SESSION_OPAQUE ][ realm ] ||= {}
|
|
31
|
+
|
|
32
|
+
if request.env['HTTP_AUTHORIZATION']
|
|
33
|
+
|
|
34
|
+
authorized = false
|
|
35
|
+
|
|
36
|
+
if session[ SESSION_NONCE ] and session[ SESSION_OPAQUE ][ realm ][ uid ]
|
|
37
|
+
|
|
38
|
+
auth_split = request.env['HTTP_AUTHORIZATION'].split
|
|
39
|
+
authentication_type = auth_split[0]
|
|
40
|
+
authorization = Rack::Auth::Digest::Params.parse( auth_split[1..-1].join(' ') )
|
|
41
|
+
|
|
42
|
+
digest_response, username, nonce, nc, cnonce, qop, opaque =
|
|
43
|
+
authorization.values_at(*%w[response username nonce nc cnonce qop opaque])
|
|
44
|
+
|
|
45
|
+
if authentication_type == 'Digest'
|
|
46
|
+
if nonce == session[SESSION_NONCE] and opaque == session[SESSION_OPAQUE][realm][uid]
|
|
47
|
+
h1 = nil
|
|
48
|
+
if respond_to?( :httpdigest_lookup_password )
|
|
49
|
+
ha1 = httpdigest_lookup_password( username )
|
|
50
|
+
else
|
|
51
|
+
if respond_to?( :httpdigest_lookup_plaintext_password )
|
|
52
|
+
ha1 = MD5.hexdigest( "#{username}:#{realm}:#{httpdigest_lookup_plaintext_password( username )}" )
|
|
53
|
+
else
|
|
54
|
+
if block_given?
|
|
55
|
+
ha1 = yield( username )
|
|
56
|
+
else
|
|
57
|
+
raise "No password lookup handler found"
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
ha2 = MD5.hexdigest([request.request_method,request.fullpath].join(':'))
|
|
62
|
+
md5 = MD5.hexdigest([ha1, nonce, nc, cnonce, qop, ha2].join(':'))
|
|
63
|
+
|
|
64
|
+
authorized = digest_response == md5
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
unless authorized
|
|
71
|
+
httpdigest_headers( uid, realm )
|
|
72
|
+
respond('Unauthorized', 401)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
else
|
|
76
|
+
|
|
77
|
+
httpdigest_headers( uid, realm )
|
|
78
|
+
httpdigest_failure if respond_to?( :httpdigest_failure )
|
|
79
|
+
respond('Unauthorized', 401)
|
|
80
|
+
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
authorization["username"]
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
|
|
2
|
+
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
|
+
|
|
4
|
+
require 'openid'
|
|
5
|
+
require 'openid/store/filesystem'
|
|
6
|
+
require 'openid/extensions/pape'
|
|
7
|
+
require 'openid/extensions/sreg'
|
|
8
|
+
|
|
9
|
+
module Ramaze
|
|
10
|
+
|
|
11
|
+
openid_store_file = ::File.join(Dir.tmpdir, 'openid-store')
|
|
12
|
+
|
|
13
|
+
# Constant for storing meta-information persistent
|
|
14
|
+
OpenIDStore = OpenID::Store::Filesystem.new(openid_store_file)
|
|
15
|
+
|
|
16
|
+
# This is called Identity to avoid collisions with the original openid.rb
|
|
17
|
+
# It provides a nice and simple way to provide and control access over the
|
|
18
|
+
# OpenID authentication model.
|
|
19
|
+
|
|
20
|
+
module Helper
|
|
21
|
+
module Identity
|
|
22
|
+
LOOKUP << self
|
|
23
|
+
|
|
24
|
+
# Simple form for use or overwriting.
|
|
25
|
+
# Has to provide the same functionality when overwritten or directly
|
|
26
|
+
# embedded into a page.
|
|
27
|
+
def openid_login_form(caption="login")
|
|
28
|
+
%{
|
|
29
|
+
<form method="GET" action="#{Rs(:openid_begin)}">
|
|
30
|
+
Identity URL: <input type="text" name="url" />
|
|
31
|
+
<input type="submit" value="#{caption}"/>
|
|
32
|
+
</form>
|
|
33
|
+
}
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# We land here from the openid_login_form and if we can find a matching
|
|
37
|
+
# OpenID server we redirect the user to it, the browser will return to
|
|
38
|
+
# openid_complete when the authentication is complete.
|
|
39
|
+
def openid_begin
|
|
40
|
+
# The OpenID URL pointing to a user's OpenID page,
|
|
41
|
+
# for example: http://username.myopenid.com)
|
|
42
|
+
url = request['url']
|
|
43
|
+
redirect_referrer if url.to_s.empty?
|
|
44
|
+
session[:openid] ||= {}
|
|
45
|
+
session[:openid][:entry] = request.referrer
|
|
46
|
+
|
|
47
|
+
openid_request = openid_consumer.begin(url)
|
|
48
|
+
|
|
49
|
+
# We want these communications to be a secure as the server can
|
|
50
|
+
# support!
|
|
51
|
+
papereq = OpenID::PAPE::Request.new
|
|
52
|
+
papereq.add_policy_uri(OpenID::PAPE::AUTH_PHISHING_RESISTANT)
|
|
53
|
+
papereq.max_auth_age = 2*60*60
|
|
54
|
+
openid_request.add_extension(papereq)
|
|
55
|
+
|
|
56
|
+
# Request information about the person
|
|
57
|
+
sregreq = OpenID::SReg::Request.new
|
|
58
|
+
sregreq.request_fields(['fullname', 'nickname', 'dob', 'email',
|
|
59
|
+
'gender', 'postcode', 'country', 'language',
|
|
60
|
+
'timezone'])
|
|
61
|
+
openid_request.add_extension(sregreq)
|
|
62
|
+
openid_request.return_to_args['did_pape'] = 'y'
|
|
63
|
+
|
|
64
|
+
root = "http://#{request.http_host}/"
|
|
65
|
+
return_to = request.domain(Rs(:openid_complete)).to_s
|
|
66
|
+
immediate = false
|
|
67
|
+
|
|
68
|
+
if openid_request.send_redirect?(root, return_to, immediate)
|
|
69
|
+
redirect_url =
|
|
70
|
+
openid_request.redirect_url(root, return_to, immediate)
|
|
71
|
+
raw_redirect redirect_url
|
|
72
|
+
else
|
|
73
|
+
# what the hell is @form_text ?
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
rescue OpenID::OpenIDError => ex
|
|
77
|
+
flash[:error] = "Discovery failed for #{url}: #{ex}"
|
|
78
|
+
raw_redirect Rs(:/)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# After having authenticated at the OpenID server browsers are redirected
|
|
82
|
+
# back here and on success we set the session[:openid][:identity] and a little
|
|
83
|
+
# default flash message. Then we redirect to wherever session[:openid][:entry]
|
|
84
|
+
# points us to, which was set on openid_begin to the referrer
|
|
85
|
+
#
|
|
86
|
+
# TODO:
|
|
87
|
+
# - maybe using StackHelper, but this is a really minimal overlap?
|
|
88
|
+
def openid_complete
|
|
89
|
+
openid_response = openid_consumer.complete(request.params, request.url)
|
|
90
|
+
|
|
91
|
+
case openid_response.status
|
|
92
|
+
when OpenID::Consumer::FAILURE
|
|
93
|
+
flash[:error] = "OpenID - Verification failed: #{openid_response.message}"
|
|
94
|
+
when OpenID::Consumer::SUCCESS
|
|
95
|
+
# Backwards compatibility
|
|
96
|
+
session[:openid][:identity] = openid_response.identity_url
|
|
97
|
+
session[:openid][:sreg] = OpenID::SReg::Response.from_success_response(openid_response)
|
|
98
|
+
|
|
99
|
+
# Forward compatibility :)
|
|
100
|
+
session[:openid_identity] = openid_response.identity_url
|
|
101
|
+
session[:openid_sreg] = OpenID::SReg::Response.from_success_response(openid_response)
|
|
102
|
+
|
|
103
|
+
flash[:success] = 'OpenID - Verification done.'
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
session.delete(:_openid_consumer_service)
|
|
107
|
+
|
|
108
|
+
raw_redirect session[:openid][:entry]
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
private
|
|
112
|
+
|
|
113
|
+
# Fetch/Create a OpenID::Consumer for current session.
|
|
114
|
+
def openid_consumer
|
|
115
|
+
OpenID::Consumer.new(session, Ramaze::OpenIDStore)
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
|
|
2
|
+
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
|
+
|
|
4
|
+
module Ramaze
|
|
5
|
+
# Helper::Link is included into the Controller by default
|
|
6
|
+
#
|
|
7
|
+
# Usage is shown in spec/ramaze/helper/link.rb and the rdocs below.
|
|
8
|
+
|
|
9
|
+
module Helper::Link
|
|
10
|
+
# Builds a basic <a> tag.
|
|
11
|
+
#
|
|
12
|
+
# `text` is mandatory, the second hash of options will be transformed into
|
|
13
|
+
# arguments of the tag, :href is a special case and its segments will be
|
|
14
|
+
# escaped.
|
|
15
|
+
#
|
|
16
|
+
# If you pass no :href, the text will be run through Rs and its result is
|
|
17
|
+
# used instead. If you really want an empty href, use :href => ''
|
|
18
|
+
#
|
|
19
|
+
# Usage:
|
|
20
|
+
# A('text') #> <a href="/text">text</a>
|
|
21
|
+
# A('foo/bar') #> <a href="/foo/bar">foo/bar</a>
|
|
22
|
+
# A('/foo?x=y') #> <a href="/foo?x=y">/foo?x=y</a>
|
|
23
|
+
# A('text', :href => '/foo?x=y') #> <a href="/foo?x=y">text</a>
|
|
24
|
+
# A('Home', :href => Rs(:/)) #> <a href="/foo/bar">Home</a>
|
|
25
|
+
|
|
26
|
+
def A(*args)
|
|
27
|
+
hash = args.last.respond_to?(:to_hash) ? args.pop : {}
|
|
28
|
+
|
|
29
|
+
hash[:href] ||= Rs(*args)
|
|
30
|
+
text = hash.delete(:text) || args.last || hash[:title] || hash[:href]
|
|
31
|
+
hash[:href] = hash[:href].to_s.gsub(/[^\/?;=]+/){|m| Rack::Utils.escape(m) }
|
|
32
|
+
|
|
33
|
+
args = ['']
|
|
34
|
+
hash.each {|k,v| args << %(#{k}="#{v}") if k and v }
|
|
35
|
+
|
|
36
|
+
%(<a#{args.join(' ')}>#{text}</a>)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Builds links out of segments.
|
|
40
|
+
#
|
|
41
|
+
# Pass it strings, symbols, controllers and it will produce a link out of
|
|
42
|
+
# it. Paths to Controllers are obtained from Global.mapping.
|
|
43
|
+
#
|
|
44
|
+
# For brevity, the mapping for the example below is following:
|
|
45
|
+
# { MC => '/', OC => '/o', ODC => '/od' }
|
|
46
|
+
#
|
|
47
|
+
# Usage:
|
|
48
|
+
# R(MC) #=> '/'
|
|
49
|
+
# R(OC) #=> '/o'
|
|
50
|
+
# R(ODC) #=> '/od'
|
|
51
|
+
# R(MC, :foo) #=> '/foo'
|
|
52
|
+
# R(OC, :foo) #=> '/o/foo'
|
|
53
|
+
# R(ODC, :foo) #=> '/od/foo'
|
|
54
|
+
# R(MC, :foo, :bar => :x) #=> '/foo?bar=x'
|
|
55
|
+
|
|
56
|
+
def R(*atoms)
|
|
57
|
+
args, atoms = atoms.flatten.partition{|a| a.is_a?(Hash) }
|
|
58
|
+
args = args.flatten.inject{|s,v| s.merge!(v) }
|
|
59
|
+
|
|
60
|
+
map = Global.mapping.invert
|
|
61
|
+
|
|
62
|
+
atoms.map! do |atom|
|
|
63
|
+
if atom.is_a?(Ramaze::Controller)
|
|
64
|
+
map[atom.class]
|
|
65
|
+
else
|
|
66
|
+
map[atom]
|
|
67
|
+
end or atom.to_s
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
front = [Global.prefix, *atoms].join('/').squeeze('/')
|
|
71
|
+
|
|
72
|
+
if args
|
|
73
|
+
rear = args.inject('?'){|s,(k,v)| s << "#{Rack::Utils.escape(k)}=#{Rack::Utils.escape(v)};"}[0..-2]
|
|
74
|
+
front + rear
|
|
75
|
+
else
|
|
76
|
+
front
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Uses R with Controller.current as first element.
|
|
81
|
+
|
|
82
|
+
def Rs(*atoms)
|
|
83
|
+
atoms.unshift Controller.current unless atoms.first.is_a?(Controller)
|
|
84
|
+
R(*atoms)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# Give it a path with character to split at and one to join the crumbs with.
|
|
88
|
+
# It will generate a list of links that act as pointers to previous pages on
|
|
89
|
+
# this path.
|
|
90
|
+
#
|
|
91
|
+
# Example:
|
|
92
|
+
# breadcrumbs('/path/to/somewhere')
|
|
93
|
+
#
|
|
94
|
+
# # results in this, newlines added for readability:
|
|
95
|
+
#
|
|
96
|
+
# <a href="/path">path</a>/
|
|
97
|
+
# <a href="/path/to">to</a>/
|
|
98
|
+
# <a href="/path/to/somewhere">somewhere</a>
|
|
99
|
+
#
|
|
100
|
+
# Optionally a href prefix can be specified which generate link
|
|
101
|
+
# names a above, but with the prefix prepended to the href path.
|
|
102
|
+
#
|
|
103
|
+
# Example:
|
|
104
|
+
# breadcrumbs('/path/to/somewhere', '/', '/', '/mycontroller/action')
|
|
105
|
+
#
|
|
106
|
+
# # results in this, newlines added for readability:
|
|
107
|
+
#
|
|
108
|
+
# <a href="/mycontroller/action/path">path</a>/
|
|
109
|
+
# <a href="/mycontroller/action/path/to">to</a>/
|
|
110
|
+
# <a href="/mycontroller/action/path/to/somewhere">somewhere</a>
|
|
111
|
+
|
|
112
|
+
def breadcrumbs(path, split = '/', join = '/', href_prefix = '')
|
|
113
|
+
atoms = path.split(split).reject{|a| a.empty?}
|
|
114
|
+
crumbs = atoms.inject([]){|s,v| s << [s.last,v]}
|
|
115
|
+
bread = crumbs.map do |a|
|
|
116
|
+
href_path = href_prefix + a*'/'
|
|
117
|
+
A(a[-1], :href=>(href_path))
|
|
118
|
+
end
|
|
119
|
+
bread.join(join)
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
|
|
2
|
+
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
|
+
|
|
4
|
+
module Ramaze
|
|
5
|
+
|
|
6
|
+
# Allows you to use some shortcuts for markaby in your Controller.
|
|
7
|
+
|
|
8
|
+
module Helper::Markaby
|
|
9
|
+
# use this inside your controller to directly build Markaby
|
|
10
|
+
# Refer to the Markaby-documentation and testsuite for more examples.
|
|
11
|
+
# Usage:
|
|
12
|
+
# mab { h1 "Apples & Oranges"} #=> "<h1>Apples & Oranges</h1>"
|
|
13
|
+
# mab { h1 'Apples', :class => 'fruits&floots' } #=> "<h1 class=\"fruits&floots\">Apples</h1>"
|
|
14
|
+
|
|
15
|
+
def markaby(ivs = {}, helpers = nil, &block)
|
|
16
|
+
builder = ::Markaby::Builder
|
|
17
|
+
builder.extend(Ramaze::Helper::Methods)
|
|
18
|
+
builder.send(:helper, :redirect, :link, :sendfile, :flash, :cgi, :partial)
|
|
19
|
+
|
|
20
|
+
iv_hash = {}
|
|
21
|
+
instance_variables.each do |iv|
|
|
22
|
+
key, value = iv.gsub('@', '').to_sym, instance_variable_get(iv)
|
|
23
|
+
iv_hash[key] = value
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
builder.new(iv_hash.merge(ivs), helpers, &block).to_s
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
alias mab markaby
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
|
|
2
|
+
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
|
+
|
|
4
|
+
require 'nitro/helper/form'
|
|
5
|
+
|
|
6
|
+
module Ramaze
|
|
7
|
+
module Helper
|
|
8
|
+
|
|
9
|
+
# This helper simply includes the Nitro::FormHelper so you can use its methods
|
|
10
|
+
# in your Controller.
|
|
11
|
+
|
|
12
|
+
Nitroform = ::Nitro::FormHelper
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
module Ramaze
|
|
2
|
+
|
|
3
|
+
# The BSD License
|
|
4
|
+
#
|
|
5
|
+
# Copyright (c) 2004-2007, George K. Moschovitis. (http://www.gmosx.com)
|
|
6
|
+
# All rights reserved.
|
|
7
|
+
#
|
|
8
|
+
# Redistribution and use in source and binary forms, with or without
|
|
9
|
+
# modification, are permitted provided that the following conditions are
|
|
10
|
+
# met:
|
|
11
|
+
#
|
|
12
|
+
# * Redistributions of source code must retain the above copyright
|
|
13
|
+
# notice, this list of conditions and the following disclaimer.
|
|
14
|
+
#
|
|
15
|
+
# * Redistributions in binary form must reproduce the above copyright
|
|
16
|
+
# notice, this list of conditions and the following disclaimer in the
|
|
17
|
+
# documentation and/or other materials provided with the distribution.
|
|
18
|
+
#
|
|
19
|
+
# * Neither the name of Nitro nor the names of its contributors may be
|
|
20
|
+
# used to endorse or promote products derived from this software
|
|
21
|
+
# without specific prior written permission.
|
|
22
|
+
#
|
|
23
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
24
|
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
25
|
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
26
|
+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
27
|
+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
28
|
+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
|
29
|
+
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
30
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
31
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
32
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
33
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
34
|
+
#
|
|
35
|
+
|
|
36
|
+
# Displays a collection of entitities in multiple pages.
|
|
37
|
+
#
|
|
38
|
+
# === Design
|
|
39
|
+
#
|
|
40
|
+
# This pager is carefully designed for scaleability. It stores only the items
|
|
41
|
+
# for one page. The key parameter is needed, multiple pagers can coexist in a
|
|
42
|
+
# single page. The pager leverages the SQL LIMIT option to optimize database
|
|
43
|
+
# interaction.
|
|
44
|
+
#
|
|
45
|
+
#
|
|
46
|
+
# === Example
|
|
47
|
+
#
|
|
48
|
+
# class MyController
|
|
49
|
+
# def index
|
|
50
|
+
# objs = (0..200).to_a
|
|
51
|
+
# @entries, @pager = paginate(objs, :limit => 20)
|
|
52
|
+
# end
|
|
53
|
+
# end
|
|
54
|
+
#
|
|
55
|
+
#
|
|
56
|
+
# <html>
|
|
57
|
+
# <head><title>Pager</title></head>
|
|
58
|
+
# <body>
|
|
59
|
+
# <?r if pager.navigation? ?>
|
|
60
|
+
# <div class="pager">#{@pager.navigation}</div>
|
|
61
|
+
# <?r end ?>
|
|
62
|
+
# <ul>
|
|
63
|
+
# <?r @entries.each do |entry| ?>
|
|
64
|
+
# <li>#{entry}</li>
|
|
65
|
+
# <?r end ?>
|
|
66
|
+
# </ul>
|
|
67
|
+
# </body>
|
|
68
|
+
# </html>
|
|
69
|
+
#
|
|
70
|
+
# === Styling
|
|
71
|
+
#
|
|
72
|
+
# The following classes can be used for styling with CSS (provided you put the
|
|
73
|
+
# pager in a element with class 'pager' like shown above):
|
|
74
|
+
#
|
|
75
|
+
# .pager {}
|
|
76
|
+
# .pager .first {}
|
|
77
|
+
# .pager .previous {}
|
|
78
|
+
# .pager .next {}
|
|
79
|
+
# .pager .last {}
|
|
80
|
+
# .pager ul {}
|
|
81
|
+
# .pager li {}
|
|
82
|
+
# .pager li.active {}
|
|
83
|
+
|
|
84
|
+
class Pager
|
|
85
|
+
include Ramaze::Helper::Link
|
|
86
|
+
|
|
87
|
+
# Items per page.
|
|
88
|
+
|
|
89
|
+
trait :limit => 10
|
|
90
|
+
|
|
91
|
+
# The request key.
|
|
92
|
+
|
|
93
|
+
trait :key => '_page'
|
|
94
|
+
|
|
95
|
+
# The current page.
|
|
96
|
+
|
|
97
|
+
attr_reader :page
|
|
98
|
+
|
|
99
|
+
# Items per page.
|
|
100
|
+
|
|
101
|
+
attr_reader :limit
|
|
102
|
+
|
|
103
|
+
# The total number of pages.
|
|
104
|
+
|
|
105
|
+
attr_reader :page_count
|
|
106
|
+
|
|
107
|
+
# Total count of items.
|
|
108
|
+
|
|
109
|
+
attr_reader :total_count
|
|
110
|
+
|
|
111
|
+
# Create a new Pager object.
|
|
112
|
+
#
|
|
113
|
+
# request:: Ramaze::Request object providing access to GET parameters
|
|
114
|
+
# limit:: how many elements go to one page
|
|
115
|
+
# total_count:: total element count
|
|
116
|
+
# key:: key used for getting the current page from GET paramaters
|
|
117
|
+
#
|
|
118
|
+
# Note: You never have to create this class yourself, use the `paginate()`
|
|
119
|
+
# convenience method from the Helper::Pager.
|
|
120
|
+
|
|
121
|
+
def initialize(request, limit, total_count, key = trait[:key])
|
|
122
|
+
raise 'limit should be > 0' unless limit > 0
|
|
123
|
+
|
|
124
|
+
@request, @key = request, key
|
|
125
|
+
@page = (request.params[key] || 1).to_i
|
|
126
|
+
@limit = limit
|
|
127
|
+
set_count(total_count)
|
|
128
|
+
@start_idx = (@page - 1) * limit
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# Return the first page index.
|
|
132
|
+
|
|
133
|
+
def first_page
|
|
134
|
+
1
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
# Is the first page displayed?
|
|
138
|
+
|
|
139
|
+
def first_page?
|
|
140
|
+
@page == 1
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
# Return the last page index.
|
|
144
|
+
|
|
145
|
+
def last_page
|
|
146
|
+
return @page_count
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
# Is the last page displayed?
|
|
150
|
+
|
|
151
|
+
def last_page?
|
|
152
|
+
@page == @page_count
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
# Return the index of the previous page.
|
|
156
|
+
|
|
157
|
+
def prev_page
|
|
158
|
+
[@page - 1, 1].max
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
# Return the index of the next page.
|
|
162
|
+
|
|
163
|
+
def next_page
|
|
164
|
+
[@page + 1, @page_count].min
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
# Returns each element for the current page
|
|
168
|
+
|
|
169
|
+
def each(&block)
|
|
170
|
+
@page_items.each(&block)
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
# Iterator
|
|
174
|
+
# Returns 1-based index.
|
|
175
|
+
|
|
176
|
+
def each_with_index(&block)
|
|
177
|
+
@page_items.each_with_index(&block)
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
# Is the pager empty, ie has one page only?
|
|
181
|
+
|
|
182
|
+
def empty?
|
|
183
|
+
@page_count < 2
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
# Returns true if a navigation is necessary (meaning there is more than one
|
|
187
|
+
# page)
|
|
188
|
+
|
|
189
|
+
def navigation?
|
|
190
|
+
!empty?
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
# Returns the amount of all elements in all pages.
|
|
194
|
+
|
|
195
|
+
def size
|
|
196
|
+
@total_count
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
# Override this method in your application if needed.
|
|
200
|
+
#--
|
|
201
|
+
# TODO: better markup.
|
|
202
|
+
#++
|
|
203
|
+
|
|
204
|
+
def navigation
|
|
205
|
+
nav = ""
|
|
206
|
+
|
|
207
|
+
unless first_page?
|
|
208
|
+
nav << %{
|
|
209
|
+
<div class="first"><a href="#{link_first_page}">First</a></div>
|
|
210
|
+
<div class="previous"><a href="#{link_prev_page}">Previous</a></div>
|
|
211
|
+
}
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
unless last_page?
|
|
215
|
+
nav << %{
|
|
216
|
+
<div class="last"><a href="#{link_last_page}">Last</a></div>
|
|
217
|
+
<div class="next"><a href="#{link_next_page}">Next</a></div>
|
|
218
|
+
}
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
nav << %{<ul>}
|
|
222
|
+
|
|
223
|
+
for i in nav_range()
|
|
224
|
+
if i == @page
|
|
225
|
+
nav << %{<li class="active">#{i}</li>}
|
|
226
|
+
else
|
|
227
|
+
nav << %{<li><a href="#{target_uri(i)}">#{i}</a></li>}
|
|
228
|
+
end
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
nav << %{</ul>}
|
|
232
|
+
|
|
233
|
+
return nav
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
# To be used with Og queries.
|
|
237
|
+
|
|
238
|
+
def limit
|
|
239
|
+
if @start_idx > 0
|
|
240
|
+
{ :limit => @limit, :offset => @start_idx }
|
|
241
|
+
else
|
|
242
|
+
{ :limit => @limit }
|
|
243
|
+
end
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
# Returns the index of the first element to go into the current page
|
|
247
|
+
|
|
248
|
+
def offset
|
|
249
|
+
@start_idx
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
private
|
|
253
|
+
|
|
254
|
+
# Generate the target URI.
|
|
255
|
+
|
|
256
|
+
def target_uri(page)
|
|
257
|
+
params = @request.params.merge(@key => page)
|
|
258
|
+
Rs(Action.current.name, params)
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
# Generate link for the first page.
|
|
262
|
+
|
|
263
|
+
def link_first_page; target_uri(first_page); end
|
|
264
|
+
|
|
265
|
+
# Generate link for the last page.
|
|
266
|
+
|
|
267
|
+
def link_last_page; target_uri(last_page); end
|
|
268
|
+
|
|
269
|
+
# Generate link for the previous page.
|
|
270
|
+
|
|
271
|
+
def link_prev_page; target_uri(prev_page); end
|
|
272
|
+
|
|
273
|
+
# Generate link for the next page.
|
|
274
|
+
|
|
275
|
+
def link_next_page; target_uri(next_page); end
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
# Returns the range of the current page.
|
|
279
|
+
|
|
280
|
+
def page_range
|
|
281
|
+
s = @idx
|
|
282
|
+
e = [@idx + @items_limit - 1, all_total_count].min
|
|
283
|
+
|
|
284
|
+
return [s, e]
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
# Returns the range of
|
|
288
|
+
# Override if needed.
|
|
289
|
+
|
|
290
|
+
def nav_range
|
|
291
|
+
# effective range = 10 pages.
|
|
292
|
+
s = [@page - 5, 1].max
|
|
293
|
+
e = [@page + 9, @page_count].min
|
|
294
|
+
|
|
295
|
+
d = 9 - (e - s)
|
|
296
|
+
e += d if d < 0
|
|
297
|
+
|
|
298
|
+
return (s..e)
|
|
299
|
+
end
|
|
300
|
+
|
|
301
|
+
# generates total and page count of the pager.
|
|
302
|
+
|
|
303
|
+
def set_count(total_count)
|
|
304
|
+
@total_count = total_count
|
|
305
|
+
@page_count = (@total_count.to_f / @limit).ceil
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
end
|
|
309
|
+
|
|
310
|
+
# Pager related helper methods.
|
|
311
|
+
|
|
312
|
+
module Helper::Pager
|
|
313
|
+
|
|
314
|
+
# Helper method that generates a collection of items and the
|
|
315
|
+
# associated pager object.
|
|
316
|
+
#
|
|
317
|
+
# === Example
|
|
318
|
+
#
|
|
319
|
+
# items = [ 'item1', 'item2', ... ]
|
|
320
|
+
# entries, pager = paginate(items, :limit => 10)
|
|
321
|
+
#
|
|
322
|
+
# <ul>
|
|
323
|
+
# <?r for entry in entries ?>
|
|
324
|
+
# <li>#{entry.to_link}</li>
|
|
325
|
+
# <?r end ?>
|
|
326
|
+
# </ul>
|
|
327
|
+
# #{pager.navigation}
|
|
328
|
+
#
|
|
329
|
+
# === Og Example
|
|
330
|
+
#
|
|
331
|
+
# entries, pager = paginate(Article, :where => 'title LIKE..', :limit => 10)
|
|
332
|
+
#
|
|
333
|
+
# or
|
|
334
|
+
#
|
|
335
|
+
# entries, pager = paginate(article.comments, :limit => 10)
|
|
336
|
+
|
|
337
|
+
def paginate(items, options = {})
|
|
338
|
+
limit = options.delete(:limit) || Pager.trait[:limit]
|
|
339
|
+
pager_key = options.delete(:pager_key) || Pager.trait[:key]
|
|
340
|
+
|
|
341
|
+
case items
|
|
342
|
+
when Array
|
|
343
|
+
pager = Pager.new(request, limit, items.size, pager_key)
|
|
344
|
+
items = items.slice(pager.offset, pager.limit[:limit])
|
|
345
|
+
return items, pager
|
|
346
|
+
end
|
|
347
|
+
|
|
348
|
+
if defined?(Og) && items.is_a?(Og::Collection)
|
|
349
|
+
pager = Pager.new(request, limit, items.count, pager_key)
|
|
350
|
+
options.update(pager.limit)
|
|
351
|
+
items = items.reload(options)
|
|
352
|
+
return items, pager
|
|
353
|
+
elsif defined?(Og::EntityMixin) && items.is_a?(Og::EntityMixin) ||
|
|
354
|
+
defined?(Og::Mixin) && items.is_a?(Og::Mixin) # Og <= 0.41
|
|
355
|
+
pager = Pager.new(request, limit, items.count(options), pager_key)
|
|
356
|
+
options.update(pager.limit)
|
|
357
|
+
items = items.all(options)
|
|
358
|
+
return items, pager
|
|
359
|
+
end
|
|
360
|
+
|
|
361
|
+
raise "No suitable pagination method for #{items.inspect}"
|
|
362
|
+
end
|
|
363
|
+
|
|
364
|
+
end
|
|
365
|
+
|
|
366
|
+
end
|