utopia 2.14.0 → 2.16.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bake/utopia/{yarn.rb → node.rb} +11 -5
- data/lib/utopia/command.rb +2 -2
- data/lib/utopia/command/site.rb +1 -1
- data/lib/utopia/content.rb +7 -5
- data/lib/utopia/content/markup.rb +1 -1
- data/lib/utopia/content/node.rb +2 -2
- data/lib/utopia/content/response.rb +3 -3
- data/lib/utopia/controller.rb +0 -17
- data/lib/utopia/controller/base.rb +27 -3
- data/lib/utopia/controller/respond.rb +50 -107
- data/lib/utopia/extensions/array_split.rb +2 -2
- data/lib/utopia/http.rb +3 -3
- data/lib/utopia/middleware.rb +2 -2
- data/lib/utopia/path.rb +13 -5
- data/lib/utopia/redirection.rb +0 -2
- data/lib/utopia/responder.rb +76 -0
- data/lib/utopia/version.rb +1 -1
- data/setup/site/.gitignore +8 -7
- metadata +71 -396
- data/.codeclimate.yml +0 -5
- data/.github/workflows/development.yml +0 -62
- data/.gitignore +0 -8
- data/.rspec +0 -4
- data/.yardopts +0 -2
- data/Gemfile +0 -28
- data/README.md +0 -90
- data/benchmark/call_vs_check.rb +0 -38
- data/benchmark/const_vs_hash.rb +0 -35
- data/benchmark/hash_vs_openstruct.rb +0 -54
- data/benchmark/string_vs_symbol.rb +0 -14
- data/benchmark/struct_vs_class.rb +0 -91
- data/docs/.nojekyll +0 -0
- data/docs/_components/jquery-litebox/jquery.litebox.css +0 -23
- data/docs/_components/jquery-litebox/jquery.litebox.gallery.css +0 -48
- data/docs/_components/jquery-litebox/jquery.litebox.js +0 -30
- data/docs/_components/jquery-syntax/base/jquery.syntax.brush.apache.css +0 -12
- data/docs/_components/jquery-syntax/base/jquery.syntax.brush.applescript.css +0 -5
- data/docs/_components/jquery-syntax/base/jquery.syntax.brush.assembly.css +0 -8
- data/docs/_components/jquery-syntax/base/jquery.syntax.brush.bash-script.css +0 -6
- data/docs/_components/jquery-syntax/base/jquery.syntax.brush.bash.css +0 -4
- data/docs/_components/jquery-syntax/base/jquery.syntax.brush.clang.css +0 -6
- data/docs/_components/jquery-syntax/base/jquery.syntax.brush.css.css +0 -14
- data/docs/_components/jquery-syntax/base/jquery.syntax.brush.diff.css +0 -16
- data/docs/_components/jquery-syntax/base/jquery.syntax.brush.html.css +0 -5
- data/docs/_components/jquery-syntax/base/jquery.syntax.brush.ocaml.css +0 -3
- data/docs/_components/jquery-syntax/base/jquery.syntax.brush.protobuf.css +0 -2
- data/docs/_components/jquery-syntax/base/jquery.syntax.brush.python.css +0 -6
- data/docs/_components/jquery-syntax/base/jquery.syntax.brush.ruby.css +0 -2
- data/docs/_components/jquery-syntax/base/jquery.syntax.brush.xml.css +0 -18
- data/docs/_components/jquery-syntax/base/jquery.syntax.core.css +0 -58
- data/docs/_components/jquery-syntax/base/jquery.syntax.editor.css +0 -6
- data/docs/_components/jquery-syntax/base/theme.js +0 -1
- data/docs/_components/jquery-syntax/bright/jquery.syntax.core.css +0 -27
- data/docs/_components/jquery-syntax/bright/theme.js +0 -1
- data/docs/_components/jquery-syntax/jquery.syntax.brush.apache.js +0 -3
- data/docs/_components/jquery-syntax/jquery.syntax.brush.applescript.js +0 -5
- data/docs/_components/jquery-syntax/jquery.syntax.brush.assembly.js +0 -3
- data/docs/_components/jquery-syntax/jquery.syntax.brush.bash-script.js +0 -4
- data/docs/_components/jquery-syntax/jquery.syntax.brush.bash.js +0 -2
- data/docs/_components/jquery-syntax/jquery.syntax.brush.basic.js +0 -5
- data/docs/_components/jquery-syntax/jquery.syntax.brush.clang.js +0 -5
- data/docs/_components/jquery-syntax/jquery.syntax.brush.csharp.js +0 -4
- data/docs/_components/jquery-syntax/jquery.syntax.brush.css.js +0 -5
- data/docs/_components/jquery-syntax/jquery.syntax.brush.diff.js +0 -2
- data/docs/_components/jquery-syntax/jquery.syntax.brush.go.js +0 -3
- data/docs/_components/jquery-syntax/jquery.syntax.brush.haskell.js +0 -3
- data/docs/_components/jquery-syntax/jquery.syntax.brush.html.js +0 -4
- data/docs/_components/jquery-syntax/jquery.syntax.brush.io.js +0 -3
- data/docs/_components/jquery-syntax/jquery.syntax.brush.java.js +0 -4
- data/docs/_components/jquery-syntax/jquery.syntax.brush.javascript.js +0 -3
- data/docs/_components/jquery-syntax/jquery.syntax.brush.kai.js +0 -2
- data/docs/_components/jquery-syntax/jquery.syntax.brush.lisp.js +0 -2
- data/docs/_components/jquery-syntax/jquery.syntax.brush.lua.js +0 -3
- data/docs/_components/jquery-syntax/jquery.syntax.brush.nginx.js +0 -2
- data/docs/_components/jquery-syntax/jquery.syntax.brush.ocaml.js +0 -4
- data/docs/_components/jquery-syntax/jquery.syntax.brush.ooc.js +0 -4
- data/docs/_components/jquery-syntax/jquery.syntax.brush.pascal.js +0 -4
- data/docs/_components/jquery-syntax/jquery.syntax.brush.perl5.js +0 -3
- data/docs/_components/jquery-syntax/jquery.syntax.brush.php-script.js +0 -4
- data/docs/_components/jquery-syntax/jquery.syntax.brush.php.js +0 -2
- data/docs/_components/jquery-syntax/jquery.syntax.brush.plain.js +0 -2
- data/docs/_components/jquery-syntax/jquery.syntax.brush.protobuf.js +0 -3
- data/docs/_components/jquery-syntax/jquery.syntax.brush.python.js +0 -5
- data/docs/_components/jquery-syntax/jquery.syntax.brush.ruby.js +0 -5
- data/docs/_components/jquery-syntax/jquery.syntax.brush.scala.js +0 -4
- data/docs/_components/jquery-syntax/jquery.syntax.brush.smalltalk.js +0 -2
- data/docs/_components/jquery-syntax/jquery.syntax.brush.sql.js +0 -4
- data/docs/_components/jquery-syntax/jquery.syntax.brush.super-collider.js +0 -3
- data/docs/_components/jquery-syntax/jquery.syntax.brush.swift.js +0 -3
- data/docs/_components/jquery-syntax/jquery.syntax.brush.trenni.js +0 -2
- data/docs/_components/jquery-syntax/jquery.syntax.brush.xml.js +0 -4
- data/docs/_components/jquery-syntax/jquery.syntax.brush.yaml.js +0 -2
- data/docs/_components/jquery-syntax/jquery.syntax.cache.js +0 -7
- data/docs/_components/jquery-syntax/jquery.syntax.core.js +0 -34
- data/docs/_components/jquery-syntax/jquery.syntax.editor.js +0 -11
- data/docs/_components/jquery-syntax/jquery.syntax.js +0 -8
- data/docs/_components/jquery-syntax/jquery.syntax.min.js +0 -13
- data/docs/_components/jquery-syntax/paper/jquery.syntax.core.css +0 -31
- data/docs/_components/jquery-syntax/paper/theme.js +0 -1
- data/docs/_components/jquery/jquery.js +0 -10872
- data/docs/_components/jquery/jquery.min.js +0 -2
- data/docs/_components/jquery/jquery.min.map +0 -1
- data/docs/_components/jquery/jquery.slim.js +0 -8777
- data/docs/_components/jquery/jquery.slim.min.js +0 -2
- data/docs/_components/jquery/jquery.slim.min.map +0 -1
- data/docs/_static/icon.png +0 -0
- data/docs/_static/site.css +0 -191
- data/docs/development-environment-setup/index.html +0 -54
- data/docs/faq/what-is-xnode/index.html +0 -73
- data/docs/index.html +0 -86
- data/docs/javascript/index.html +0 -108
- data/docs/middleware/content/index.html +0 -58
- data/docs/middleware/controller/actions/index.html +0 -111
- data/docs/middleware/controller/index.html +0 -98
- data/docs/middleware/controller/rewrite/index.html +0 -105
- data/docs/middleware/localization/index.html +0 -53
- data/docs/middleware/redirection/index.html +0 -55
- data/docs/middleware/session/index.html +0 -65
- data/docs/middleware/static/index.html +0 -51
- data/docs/server-setup/index.html +0 -87
- data/docs/testing/index.html +0 -53
- data/docs/updating-utopia/index.html +0 -102
- data/docs/your-first-page/index.html +0 -74
- data/materials/utopia.png +0 -0
- data/materials/utopia.svg +0 -1
- data/setup/site/.yarnrc +0 -1
- data/spec/mock_node.rb +0 -16
- data/spec/spec_helper.rb +0 -13
- data/spec/utopia/command_spec.rb +0 -164
- data/spec/utopia/content/document_spec.rb +0 -60
- data/spec/utopia/content/links/bar/index.xnode +0 -0
- data/spec/utopia/content/links/bar/parent/child/index.en.xnode +0 -0
- data/spec/utopia/content/links/bar/parent/child/index.ja.xnode +0 -0
- data/spec/utopia/content/links/bar/parent/links.yaml +0 -2
- data/spec/utopia/content/links/foo/index.xnode +0 -0
- data/spec/utopia/content/links/foo/links.yaml +0 -2
- data/spec/utopia/content/links/foo/test.de.xnode +0 -0
- data/spec/utopia/content/links/foo/test.en.xnode +0 -0
- data/spec/utopia/content/links/index.xnode +0 -0
- data/spec/utopia/content/links/links.yaml +0 -18
- data/spec/utopia/content/links/redirect/links.yaml +0 -2
- data/spec/utopia/content/links/welcome.xnode +0 -0
- data/spec/utopia/content/links_spec.rb +0 -218
- data/spec/utopia/content/localized/five/index.en.xnode +0 -0
- data/spec/utopia/content/localized/four/index.en.xnode +0 -0
- data/spec/utopia/content/localized/four/index.zh.xnode +0 -0
- data/spec/utopia/content/localized/four/links.yaml +0 -4
- data/spec/utopia/content/localized/links.yaml +0 -13
- data/spec/utopia/content/localized/one.xnode +0 -0
- data/spec/utopia/content/localized/three/index.xnode +0 -0
- data/spec/utopia/content/localized/two.en.xnode +0 -0
- data/spec/utopia/content/localized/two.zh.xnode +0 -0
- data/spec/utopia/content/markup_spec.rb +0 -96
- data/spec/utopia/content/namespace_spec.rb +0 -45
- data/spec/utopia/content/node/lookup/content.xnode +0 -1
- data/spec/utopia/content/node/lookup/index.xnode +0 -1
- data/spec/utopia/content/node/ordered/first.xnode +0 -0
- data/spec/utopia/content/node/ordered/index.xnode +0 -0
- data/spec/utopia/content/node/ordered/links.yaml +0 -4
- data/spec/utopia/content/node/ordered/second.xnode +0 -0
- data/spec/utopia/content/node/related/foo.en.xnode +0 -0
- data/spec/utopia/content/node/related/foo.ja.xnode +0 -0
- data/spec/utopia/content/node/related/links.yaml +0 -4
- data/spec/utopia/content/node_spec.rb +0 -97
- data/spec/utopia/content/response_spec.rb +0 -54
- data/spec/utopia/content/tags_spec.rb +0 -82
- data/spec/utopia/content_spec.rb +0 -100
- data/spec/utopia/content_spec.ru +0 -6
- data/spec/utopia/content_spec/_heading.xnode +0 -1
- data/spec/utopia/content_spec/content/_show-value.xnode +0 -1
- data/spec/utopia/content_spec/content/links.yaml +0 -2
- data/spec/utopia/content_spec/content/test-partial.xnode +0 -1
- data/spec/utopia/content_spec/index.xnode +0 -1
- data/spec/utopia/content_spec/node/index.xnode +0 -1
- data/spec/utopia/content_spec/test.xnode +0 -10
- data/spec/utopia/controller/actions_spec.rb +0 -62
- data/spec/utopia/controller/middleware_spec.rb +0 -88
- data/spec/utopia/controller/middleware_spec.ru +0 -6
- data/spec/utopia/controller/middleware_spec/controller/controller.rb +0 -27
- data/spec/utopia/controller/middleware_spec/controller/index.xnode +0 -1
- data/spec/utopia/controller/middleware_spec/controller/nested/controller.rb +0 -7
- data/spec/utopia/controller/middleware_spec/empty/controller.rb +0 -0
- data/spec/utopia/controller/middleware_spec/redirect/controller.rb +0 -12
- data/spec/utopia/controller/middleware_spec/redirect/test/controller.rb +0 -9
- data/spec/utopia/controller/respond_spec.rb +0 -174
- data/spec/utopia/controller/respond_spec.ru +0 -12
- data/spec/utopia/controller/respond_spec/api/controller.rb +0 -28
- data/spec/utopia/controller/respond_spec/errors/controller.rb +0 -14
- data/spec/utopia/controller/respond_spec/errors/file-not-found.xnode +0 -8
- data/spec/utopia/controller/respond_spec/html/controller.rb +0 -11
- data/spec/utopia/controller/respond_spec/rewrite/controller.rb +0 -13
- data/spec/utopia/controller/rewrite_spec.rb +0 -80
- data/spec/utopia/controller/sequence_spec.rb +0 -135
- data/spec/utopia/controller/variables_spec.rb +0 -59
- data/spec/utopia/controller/websocket_spec.rb +0 -68
- data/spec/utopia/controller/websocket_spec.ru +0 -5
- data/spec/utopia/controller/websocket_spec/server/controller.rb +0 -11
- data/spec/utopia/exceptions/handler_spec.rb +0 -47
- data/spec/utopia/exceptions/handler_spec.ru +0 -8
- data/spec/utopia/exceptions/handler_spec/controller.rb +0 -19
- data/spec/utopia/exceptions/mailer_spec.rb +0 -43
- data/spec/utopia/exceptions/mailer_spec.ru +0 -10
- data/spec/utopia/extensions_spec.rb +0 -73
- data/spec/utopia/http/status_spec.rb +0 -44
- data/spec/utopia/locale_spec.rb +0 -58
- data/spec/utopia/localization_spec.rb +0 -92
- data/spec/utopia/localization_spec.ru +0 -15
- data/spec/utopia/localization_spec/controller.rb +0 -21
- data/spec/utopia/localization_spec/localized.de.txt +0 -1
- data/spec/utopia/localization_spec/localized.en.txt +0 -1
- data/spec/utopia/localization_spec/localized.ja.txt +0 -1
- data/spec/utopia/localization_spec/test.txt +0 -1
- data/spec/utopia/middleware_spec.rb +0 -31
- data/spec/utopia/path/matcher_spec.rb +0 -66
- data/spec/utopia/path_spec.rb +0 -207
- data/spec/utopia/performance_spec.rb +0 -92
- data/spec/utopia/performance_spec/cache/head/readme.txt +0 -1
- data/spec/utopia/performance_spec/cache/meta/readme.txt +0 -1
- data/spec/utopia/performance_spec/config.ru +0 -35
- data/spec/utopia/performance_spec/lib/readme.txt +0 -1
- data/spec/utopia/performance_spec/pages/_heading.xnode +0 -2
- data/spec/utopia/performance_spec/pages/_page.xnode +0 -26
- data/spec/utopia/performance_spec/pages/api/controller.rb +0 -8
- data/spec/utopia/performance_spec/pages/errors/exception.xnode +0 -5
- data/spec/utopia/performance_spec/pages/errors/file-not-found.xnode +0 -5
- data/spec/utopia/performance_spec/pages/links.yaml +0 -2
- data/spec/utopia/performance_spec/pages/welcome/index.xnode +0 -17
- data/spec/utopia/rack_helper.rb +0 -32
- data/spec/utopia/redirection_spec.rb +0 -77
- data/spec/utopia/redirection_spec.ru +0 -27
- data/spec/utopia/session_spec.rb +0 -189
- data/spec/utopia/session_spec.ru +0 -24
- data/spec/utopia/setup_spec.rb +0 -56
- data/spec/utopia/static_spec.rb +0 -49
- data/spec/utopia/static_spec.ru +0 -5
- data/spec/utopia/static_spec/test.txt +0 -1
- data/utopia.gemspec +0 -52
- data/wiki/Gemfile +0 -9
- data/wiki/config.ru +0 -7
- data/wiki/pages/development-environment-setup/index.md +0 -16
- data/wiki/pages/faq/links.yaml +0 -2
- data/wiki/pages/faq/what-is-xnode/index.md +0 -37
- data/wiki/pages/faq/what-is-xnode/links.yaml +0 -2
- data/wiki/pages/index.md +0 -35
- data/wiki/pages/javascript/index.md +0 -77
- data/wiki/pages/javascript/links.yaml +0 -2
- data/wiki/pages/links.yaml +0 -2
- data/wiki/pages/middleware/content/index.md +0 -21
- data/wiki/pages/middleware/controller/actions/index.md +0 -76
- data/wiki/pages/middleware/controller/index.md +0 -62
- data/wiki/pages/middleware/controller/links.yaml +0 -4
- data/wiki/pages/middleware/controller/rewrite/index.md +0 -69
- data/wiki/pages/middleware/localization/index.md +0 -16
- data/wiki/pages/middleware/redirection/index.md +0 -17
- data/wiki/pages/middleware/session/index.md +0 -29
- data/wiki/pages/middleware/static/index.md +0 -13
- data/wiki/pages/server-setup/index.md +0 -52
- data/wiki/pages/testing/index.md +0 -15
- data/wiki/pages/updating-utopia/index.md +0 -63
- data/wiki/pages/your-first-page/index.md +0 -38
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
|
|
5
|
-
<title>Content</title>
|
|
6
|
-
|
|
7
|
-
<meta charset="UTF-8"/>
|
|
8
|
-
|
|
9
|
-
<link rel="icon" type="image/png" href="../../_static/icon.png"/>
|
|
10
|
-
<link rel="stylesheet" href="../../_static/site.css" type="text/css" media="screen"/>
|
|
11
|
-
|
|
12
|
-
<script src="../../_components/jquery/jquery.min.js"></script>
|
|
13
|
-
<script src="../../_components/jquery-syntax/jquery.syntax.min.js"></script>
|
|
14
|
-
|
|
15
|
-
<script type="text/javascript">
|
|
16
|
-
//<![CDATA[
|
|
17
|
-
jQuery(function($) {
|
|
18
|
-
$.syntax();
|
|
19
|
-
});
|
|
20
|
-
//]]>
|
|
21
|
-
</script>
|
|
22
|
-
</head>
|
|
23
|
-
|
|
24
|
-
<body class="show">
|
|
25
|
-
|
|
26
|
-
<nav> › <a href="../../index.html">Wiki</a> › <span>Middleware</span> › <a href="index.html">Content</a></nav>
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
<main>
|
|
30
|
-
<h1 id="content">Content</h1>
|
|
31
|
-
<p>A tag based content generation system which integrates nicely with HTML5. Supports structures which separate generic page templates from dynamically generated content in an easy and consistent way.</p>
|
|
32
|
-
|
|
33
|
-
<pre><code class="language-ruby">use Utopia::Content,
|
|
34
|
-
cache_templates: (RACK_ENV == :production)
|
|
35
|
-
</code></pre>
|
|
36
|
-
|
|
37
|
-
<p>A basic template <code>create.xnode</code> looks something like:</p>
|
|
38
|
-
|
|
39
|
-
<pre><code class="language-trenni"><content:page>
|
|
40
|
-
<content:heading>Create User</content:heading>
|
|
41
|
-
<form action="#">
|
|
42
|
-
<input name="name" />
|
|
43
|
-
<input type="submit" />
|
|
44
|
-
</form>
|
|
45
|
-
</content:page>
|
|
46
|
-
</code></pre>
|
|
47
|
-
|
|
48
|
-
<p>This template would typically be designed with supporting <code>_page.xnode</code> and <code>_heading.xnode</code> in the same directory or, more typically, somewhere further up the directory hierarchy.</p>
|
|
49
|
-
|
|
50
|
-
</main>
|
|
51
|
-
|
|
52
|
-
<footer>
|
|
53
|
-
Last Modified: 2020-04-28 11:35:36 +1200
|
|
54
|
-
— middleware/content/index.md
|
|
55
|
-
</footer>
|
|
56
|
-
|
|
57
|
-
</body>
|
|
58
|
-
</html>
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
|
|
5
|
-
<title>Actions</title>
|
|
6
|
-
|
|
7
|
-
<meta charset="UTF-8"/>
|
|
8
|
-
|
|
9
|
-
<link rel="icon" type="image/png" href="../../../_static/icon.png"/>
|
|
10
|
-
<link rel="stylesheet" href="../../../_static/site.css" type="text/css" media="screen"/>
|
|
11
|
-
|
|
12
|
-
<script src="../../../_components/jquery/jquery.min.js"></script>
|
|
13
|
-
<script src="../../../_components/jquery-syntax/jquery.syntax.min.js"></script>
|
|
14
|
-
|
|
15
|
-
<script type="text/javascript">
|
|
16
|
-
//<![CDATA[
|
|
17
|
-
jQuery(function($) {
|
|
18
|
-
$.syntax();
|
|
19
|
-
});
|
|
20
|
-
//]]>
|
|
21
|
-
</script>
|
|
22
|
-
</head>
|
|
23
|
-
|
|
24
|
-
<body class="show">
|
|
25
|
-
|
|
26
|
-
<nav> › <a href="../../../index.html">Wiki</a> › <span>Middleware</span> › <a href="../index.html">Controller</a> › <a href="index.html">Actions</a></nav>
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
<main>
|
|
30
|
-
<h1 id="controlleractions">Controller::Actions</h1>
|
|
31
|
-
|
|
32
|
-
<p>Actions let you match path patterns in your controller and execute code. In your <code>controller.rb</code> simply add:</p>
|
|
33
|
-
|
|
34
|
-
<pre><code class="language-ruby">prepend Actions
|
|
35
|
-
</code></pre>
|
|
36
|
-
|
|
37
|
-
<p>If you are adding multiple things, like rewriting, they should come earlier in the chain, e.g:</p>
|
|
38
|
-
|
|
39
|
-
<pre><code class="language-ruby">prepend Rewrite, Actions
|
|
40
|
-
</code></pre>
|
|
41
|
-
|
|
42
|
-
<p>A simple CRUD controller might look like:</p>
|
|
43
|
-
|
|
44
|
-
<pre><code class="language-ruby">prepend Actions
|
|
45
|
-
|
|
46
|
-
on 'index' do
|
|
47
|
-
@users = User.all
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
on 'new' do |request|
|
|
51
|
-
@user = User.new
|
|
52
|
-
|
|
53
|
-
if request.post?
|
|
54
|
-
@user.update_attributes(request.params['user'])
|
|
55
|
-
|
|
56
|
-
redirect! "index"
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
on 'edit' do |request|
|
|
61
|
-
@user = User.find(request.params['id'])
|
|
62
|
-
|
|
63
|
-
if request.post?
|
|
64
|
-
@user.update_attributes(request.params['user'])
|
|
65
|
-
|
|
66
|
-
redirect! "index"
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
on 'delete' do |request|
|
|
71
|
-
User.find(request.params['id']).destroy
|
|
72
|
-
|
|
73
|
-
redirect! "index"
|
|
74
|
-
end
|
|
75
|
-
</code></pre>
|
|
76
|
-
|
|
77
|
-
<h2 id="path-matching">Path Matching</h2>
|
|
78
|
-
|
|
79
|
-
<p>Path matching works from right to left, and <code>'**'</code> is a greedy operator. Controllers are invoked with a path relative to the controller’s <code>URI_PATH</code>, so all lookups are relative to the controller.</p>
|
|
80
|
-
|
|
81
|
-
<dl>
|
|
82
|
-
<dt><code class="language-ruby">"*"</code></dt>
|
|
83
|
-
<dd>Match a single path element</dd>
|
|
84
|
-
<dt><code class="language-ruby">"**"</code></dt>
|
|
85
|
-
<dd>Match all remaining path elements</dd>
|
|
86
|
-
<dt><code class="language-ruby">String</code></dt>
|
|
87
|
-
<dd>Match a named path component, e.g. <code class="language-ruby">"edit"</code>.</dd>
|
|
88
|
-
<dt><code class="language-ruby">Symbol</code></dt>
|
|
89
|
-
<dd>Equivalent to <code class="language-ruby">["**", symbol.to_s]</code>, e.g. <code class="language-ruby">:logout</code>.</dd>
|
|
90
|
-
</dl>
|
|
91
|
-
|
|
92
|
-
<h2 id="otherwise-matching">Otherwise Matching</h2>
|
|
93
|
-
|
|
94
|
-
<p>If no action was matched, it is sometimes useful to perform some specific behaviour. You can specify this by using the otherwise handler:</p>
|
|
95
|
-
|
|
96
|
-
<pre><code class="language-ruby">otherwise do |request, path|
|
|
97
|
-
fail! :teapot
|
|
98
|
-
end
|
|
99
|
-
</code></pre>
|
|
100
|
-
|
|
101
|
-
<p>If you are doing this to perform some kind of rewriting, it may be preferable to use the <a href="../rewrite/index.html">Rewrite</a> controller layer.</p>
|
|
102
|
-
|
|
103
|
-
</main>
|
|
104
|
-
|
|
105
|
-
<footer>
|
|
106
|
-
Last Modified: 2020-04-28 23:19:19 +1200
|
|
107
|
-
— middleware/controller/actions/index.md
|
|
108
|
-
</footer>
|
|
109
|
-
|
|
110
|
-
</body>
|
|
111
|
-
</html>
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
|
|
5
|
-
<title>Controller</title>
|
|
6
|
-
|
|
7
|
-
<meta charset="UTF-8"/>
|
|
8
|
-
|
|
9
|
-
<link rel="icon" type="image/png" href="../../_static/icon.png"/>
|
|
10
|
-
<link rel="stylesheet" href="../../_static/site.css" type="text/css" media="screen"/>
|
|
11
|
-
|
|
12
|
-
<script src="../../_components/jquery/jquery.min.js"></script>
|
|
13
|
-
<script src="../../_components/jquery-syntax/jquery.syntax.min.js"></script>
|
|
14
|
-
|
|
15
|
-
<script type="text/javascript">
|
|
16
|
-
//<![CDATA[
|
|
17
|
-
jQuery(function($) {
|
|
18
|
-
$.syntax();
|
|
19
|
-
});
|
|
20
|
-
//]]>
|
|
21
|
-
</script>
|
|
22
|
-
</head>
|
|
23
|
-
|
|
24
|
-
<body class="show">
|
|
25
|
-
|
|
26
|
-
<nav> › <a href="../../index.html">Wiki</a> › <span>Middleware</span> › <a href="index.html">Controller</a></nav>
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
<main>
|
|
30
|
-
<h1 id="controller">Controller</h1>
|
|
31
|
-
|
|
32
|
-
<p>A simple recursive controller layer which works in isolation from the view rendering middleware.</p>
|
|
33
|
-
|
|
34
|
-
<pre><code class="language-ruby">use Utopia::Controller,
|
|
35
|
-
# The root directory where `controller.rb` files can be found.
|
|
36
|
-
root: 'path/to/root',
|
|
37
|
-
# The base class to use for all controllers:
|
|
38
|
-
base: Utopia::Controller::Base,
|
|
39
|
-
# Whether or not to cache controller classes:
|
|
40
|
-
cache_controllers: (RACK_ENV == :production)
|
|
41
|
-
</code></pre>
|
|
42
|
-
|
|
43
|
-
<p>A controller is a file within the root directory (or subdirectory) with the name <code>controller.rb</code>. This code is dynamically loaded into an anonymous class and executed. The default controller has only a single function:</p>
|
|
44
|
-
|
|
45
|
-
<pre><code class="language-ruby">def passthrough(request, path)
|
|
46
|
-
# Call one of:
|
|
47
|
-
|
|
48
|
-
# This will cause the middleware to generate a response.
|
|
49
|
-
# def respond!(response)
|
|
50
|
-
|
|
51
|
-
# This will cause the controller to skip the request.
|
|
52
|
-
# def ignore!
|
|
53
|
-
|
|
54
|
-
# Request relative redirect. Respond with a redirect to the given target.
|
|
55
|
-
# def redirect! (target, status = 302)
|
|
56
|
-
|
|
57
|
-
# Controller relative redirect.
|
|
58
|
-
# def goto!(target, status = 302)
|
|
59
|
-
|
|
60
|
-
# Respond with an error which indiciates some kind of failure.
|
|
61
|
-
# def fail!(error = 400, message = nil)
|
|
62
|
-
|
|
63
|
-
# Succeed the request and immediately respond.
|
|
64
|
-
# def succeed!(status: 200, headers: {}, **options)
|
|
65
|
-
# options may include content: string or body: Enumerable (as per Rack specifications
|
|
66
|
-
end
|
|
67
|
-
</code></pre>
|
|
68
|
-
|
|
69
|
-
<p>The controller layer can do more complex operations by prepending modules into it.</p>
|
|
70
|
-
|
|
71
|
-
<pre><code class="language-ruby">prepend Rewrite, Actions
|
|
72
|
-
|
|
73
|
-
# Extracts an Integer
|
|
74
|
-
rewrite.extract_prefix id: Integer do
|
|
75
|
-
@user = User.find_by_id(@id)
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
on 'edit' do |request, path|
|
|
79
|
-
if request.post?
|
|
80
|
-
@user.update_attributes(request[:user])
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
otherwise do |request, path|
|
|
85
|
-
# Executed if no specific named actions were executed.
|
|
86
|
-
succeed!
|
|
87
|
-
end
|
|
88
|
-
</code></pre>
|
|
89
|
-
|
|
90
|
-
</main>
|
|
91
|
-
|
|
92
|
-
<footer>
|
|
93
|
-
Last Modified: 2020-04-28 11:35:36 +1200
|
|
94
|
-
— middleware/controller/index.md
|
|
95
|
-
</footer>
|
|
96
|
-
|
|
97
|
-
</body>
|
|
98
|
-
</html>
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
|
|
5
|
-
<title>Rewrite</title>
|
|
6
|
-
|
|
7
|
-
<meta charset="UTF-8"/>
|
|
8
|
-
|
|
9
|
-
<link rel="icon" type="image/png" href="../../../_static/icon.png"/>
|
|
10
|
-
<link rel="stylesheet" href="../../../_static/site.css" type="text/css" media="screen"/>
|
|
11
|
-
|
|
12
|
-
<script src="../../../_components/jquery/jquery.min.js"></script>
|
|
13
|
-
<script src="../../../_components/jquery-syntax/jquery.syntax.min.js"></script>
|
|
14
|
-
|
|
15
|
-
<script type="text/javascript">
|
|
16
|
-
//<![CDATA[
|
|
17
|
-
jQuery(function($) {
|
|
18
|
-
$.syntax();
|
|
19
|
-
});
|
|
20
|
-
//]]>
|
|
21
|
-
</script>
|
|
22
|
-
</head>
|
|
23
|
-
|
|
24
|
-
<body class="show">
|
|
25
|
-
|
|
26
|
-
<nav> › <a href="../../../index.html">Wiki</a> › <span>Middleware</span> › <a href="../index.html">Controller</a> › <a href="index.html">Rewrite</a></nav>
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
<main>
|
|
30
|
-
<h1 id="controllerrewrite">Controller::Rewrite</h1>
|
|
31
|
-
|
|
32
|
-
<p>The <code class="language-ruby">Controller::Rewrite</code> layer can match and rewrite requests before they processed. This allows you to handle URLs like <code>/post/15/view</code> or <code>/blog/123-pictures-of-my-cat</code> easily. The basic rewrite operation is to extract some part of the path and optionally executes a block. That means that the path is modified before being passed on to the next layer in the controller, and controller instance variables may be set.</p>
|
|
33
|
-
|
|
34
|
-
<h2 id="regular-expressions">Regular Expressions</h2>
|
|
35
|
-
|
|
36
|
-
<p>In your <code>controller.rb</code>:</p>
|
|
37
|
-
|
|
38
|
-
<pre><code class="language-ruby">prepend Rewrite, Actions
|
|
39
|
-
|
|
40
|
-
rewrite.extract_prefix permalink: /(?<id>\d+)-(?<title>.*)/ do |request, path, match|
|
|
41
|
-
# The rewrite matched, but there was no valid post, so we fail:
|
|
42
|
-
fail! unless @post = Post.find(@permalink[:id])
|
|
43
|
-
|
|
44
|
-
# If the path matched, but there was no suffix, we make it default to the post action:
|
|
45
|
-
if match.post_match.empty?
|
|
46
|
-
match.post_match.components << "post"
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
on 'post' do
|
|
51
|
-
# You can do further processing here.
|
|
52
|
-
fail! unless @post.published?
|
|
53
|
-
|
|
54
|
-
@comments = @post.comments.first(5)
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
on 'edit' do
|
|
58
|
-
# You can do further processing here.
|
|
59
|
-
fail! unless @current_user&.editor?
|
|
60
|
-
end
|
|
61
|
-
</code></pre>
|
|
62
|
-
|
|
63
|
-
<p>In your <code>post.xnode</code>, as an example:</p>
|
|
64
|
-
|
|
65
|
-
<pre><code class="language-trenni"><content:page>
|
|
66
|
-
<content:heading>Post #{attributes[:permalink][:id]} about #{attributes[:permalink][:title]}</content:heading>
|
|
67
|
-
|
|
68
|
-
<p>#{attributes[:post].content}</p>
|
|
69
|
-
</content:page>
|
|
70
|
-
</code></pre>
|
|
71
|
-
|
|
72
|
-
<p>Keep in mind, that URLs like <code>/123-pictures-of-my-cat/edit</code> will work as expected, and hit the <code>edit</code> action of the controller.</p>
|
|
73
|
-
|
|
74
|
-
<h2 id="restful-resources">Restful Resources</h2>
|
|
75
|
-
|
|
76
|
-
<p>Similar to the above, if we were solely interested in IDs, we could do the following:</p>
|
|
77
|
-
|
|
78
|
-
<pre><code class="language-ruby">prepend Rewrite, Actions
|
|
79
|
-
|
|
80
|
-
rewrite.extract_prefix post_id: Integer do |request, path, match|
|
|
81
|
-
# The rewrite matched, but there was no valid post, so we fail:
|
|
82
|
-
fail! unless @post = Post.find(@post_id)
|
|
83
|
-
|
|
84
|
-
# If the path matched, but there was no suffix, we make it default to the post action:
|
|
85
|
-
if match.post_match.empty?
|
|
86
|
-
match.post_match.components << "post"
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
</code></pre>
|
|
90
|
-
|
|
91
|
-
<p>This will only match complete integers. Assuming this code is in <code>/blog/controller.rb</code>, it would match something like <code>/blog/123/view</code> and assign <code class="language-ruby">Integer("123")</code> to <code class="language-ruby">@post_id</code>.</p>
|
|
92
|
-
|
|
93
|
-
<h3 id="matching-other-things">Matching.. other things</h3>
|
|
94
|
-
|
|
95
|
-
<p>It’s possible to match using <code class="language-ruby">Integer</code>, <code class="language-ruby">Float</code>, <code class="language-ruby">String</code>, and you can provide your own class which will be instantiated. If it doesn’t match, raise an exception and the rewrite rule will fail.</p>
|
|
96
|
-
|
|
97
|
-
</main>
|
|
98
|
-
|
|
99
|
-
<footer>
|
|
100
|
-
Last Modified: 2020-04-28 11:35:36 +1200
|
|
101
|
-
— middleware/controller/rewrite/index.md
|
|
102
|
-
</footer>
|
|
103
|
-
|
|
104
|
-
</body>
|
|
105
|
-
</html>
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
|
|
5
|
-
<title>Localization</title>
|
|
6
|
-
|
|
7
|
-
<meta charset="UTF-8"/>
|
|
8
|
-
|
|
9
|
-
<link rel="icon" type="image/png" href="../../_static/icon.png"/>
|
|
10
|
-
<link rel="stylesheet" href="../../_static/site.css" type="text/css" media="screen"/>
|
|
11
|
-
|
|
12
|
-
<script src="../../_components/jquery/jquery.min.js"></script>
|
|
13
|
-
<script src="../../_components/jquery-syntax/jquery.syntax.min.js"></script>
|
|
14
|
-
|
|
15
|
-
<script type="text/javascript">
|
|
16
|
-
//<![CDATA[
|
|
17
|
-
jQuery(function($) {
|
|
18
|
-
$.syntax();
|
|
19
|
-
});
|
|
20
|
-
//]]>
|
|
21
|
-
</script>
|
|
22
|
-
</head>
|
|
23
|
-
|
|
24
|
-
<body class="show">
|
|
25
|
-
|
|
26
|
-
<nav> › <a href="../../index.html">Wiki</a> › <span>Middleware</span> › <a href="index.html">Localization</a></nav>
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
<main>
|
|
30
|
-
<h1 id="localization">Localization</h1>
|
|
31
|
-
|
|
32
|
-
<p>The localization middleware uses the <code>Accept-Language</code> header to guess the preferred locale out of the given options. If a request path maps to a resource, that resource is returned. Otherwise, a localized request is made.</p>
|
|
33
|
-
|
|
34
|
-
<pre><code class="language-ruby">use Utopia::Localization,
|
|
35
|
-
:default_locale => 'en',
|
|
36
|
-
:locales => ['en', 'de', 'ja', 'zh']
|
|
37
|
-
</code></pre>
|
|
38
|
-
|
|
39
|
-
<p>Somewhere further down the chain, you can localize a resource:</p>
|
|
40
|
-
|
|
41
|
-
<pre><code class="language-ruby">localization = Utopia::Localization[request]
|
|
42
|
-
show_welcome(localization.current_locale)
|
|
43
|
-
</code></pre>
|
|
44
|
-
|
|
45
|
-
</main>
|
|
46
|
-
|
|
47
|
-
<footer>
|
|
48
|
-
Last Modified: 2020-04-28 11:35:36 +1200
|
|
49
|
-
— middleware/localization/index.md
|
|
50
|
-
</footer>
|
|
51
|
-
|
|
52
|
-
</body>
|
|
53
|
-
</html>
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
|
|
5
|
-
<title>Redirection</title>
|
|
6
|
-
|
|
7
|
-
<meta charset="UTF-8"/>
|
|
8
|
-
|
|
9
|
-
<link rel="icon" type="image/png" href="../../_static/icon.png"/>
|
|
10
|
-
<link rel="stylesheet" href="../../_static/site.css" type="text/css" media="screen"/>
|
|
11
|
-
|
|
12
|
-
<script src="../../_components/jquery/jquery.min.js"></script>
|
|
13
|
-
<script src="../../_components/jquery-syntax/jquery.syntax.min.js"></script>
|
|
14
|
-
|
|
15
|
-
<script type="text/javascript">
|
|
16
|
-
//<![CDATA[
|
|
17
|
-
jQuery(function($) {
|
|
18
|
-
$.syntax();
|
|
19
|
-
});
|
|
20
|
-
//]]>
|
|
21
|
-
</script>
|
|
22
|
-
</head>
|
|
23
|
-
|
|
24
|
-
<body class="show">
|
|
25
|
-
|
|
26
|
-
<nav> › <a href="../../index.html">Wiki</a> › <span>Middleware</span> › <a href="index.html">Redirection</a></nav>
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
<main>
|
|
30
|
-
<h1 id="redirection">Redirection</h1>
|
|
31
|
-
|
|
32
|
-
<p>A set of flexible URI rewriting middleware which includes support for string mappings, regular expressions and status codes (e.g. 404 errors).</p>
|
|
33
|
-
|
|
34
|
-
<pre><code class="language-ruby"># String (fast hash lookup) rewriting:
|
|
35
|
-
use Utopia::Redirection::Rewrite,
|
|
36
|
-
'/' => '/welcome/index'
|
|
37
|
-
|
|
38
|
-
# Redirect directories (e.g. /) to an index file (e.g. /index):
|
|
39
|
-
use Utopia::Redirection::DirectoryIndex,
|
|
40
|
-
index: 'index.html'
|
|
41
|
-
|
|
42
|
-
# Redirect (error) status codes to actual pages:
|
|
43
|
-
use Utopia::Redirection::Errors,
|
|
44
|
-
404 => '/errors/file-not-found'
|
|
45
|
-
</code></pre>
|
|
46
|
-
|
|
47
|
-
</main>
|
|
48
|
-
|
|
49
|
-
<footer>
|
|
50
|
-
Last Modified: 2020-04-28 11:35:36 +1200
|
|
51
|
-
— middleware/redirection/index.md
|
|
52
|
-
</footer>
|
|
53
|
-
|
|
54
|
-
</body>
|
|
55
|
-
</html>
|