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.
Files changed (261) hide show
  1. checksums.yaml +4 -4
  2. data/bake/utopia/{yarn.rb → node.rb} +11 -5
  3. data/lib/utopia/command.rb +2 -2
  4. data/lib/utopia/command/site.rb +1 -1
  5. data/lib/utopia/content.rb +7 -5
  6. data/lib/utopia/content/markup.rb +1 -1
  7. data/lib/utopia/content/node.rb +2 -2
  8. data/lib/utopia/content/response.rb +3 -3
  9. data/lib/utopia/controller.rb +0 -17
  10. data/lib/utopia/controller/base.rb +27 -3
  11. data/lib/utopia/controller/respond.rb +50 -107
  12. data/lib/utopia/extensions/array_split.rb +2 -2
  13. data/lib/utopia/http.rb +3 -3
  14. data/lib/utopia/middleware.rb +2 -2
  15. data/lib/utopia/path.rb +13 -5
  16. data/lib/utopia/redirection.rb +0 -2
  17. data/lib/utopia/responder.rb +76 -0
  18. data/lib/utopia/version.rb +1 -1
  19. data/setup/site/.gitignore +8 -7
  20. metadata +71 -396
  21. data/.codeclimate.yml +0 -5
  22. data/.github/workflows/development.yml +0 -62
  23. data/.gitignore +0 -8
  24. data/.rspec +0 -4
  25. data/.yardopts +0 -2
  26. data/Gemfile +0 -28
  27. data/README.md +0 -90
  28. data/benchmark/call_vs_check.rb +0 -38
  29. data/benchmark/const_vs_hash.rb +0 -35
  30. data/benchmark/hash_vs_openstruct.rb +0 -54
  31. data/benchmark/string_vs_symbol.rb +0 -14
  32. data/benchmark/struct_vs_class.rb +0 -91
  33. data/docs/.nojekyll +0 -0
  34. data/docs/_components/jquery-litebox/jquery.litebox.css +0 -23
  35. data/docs/_components/jquery-litebox/jquery.litebox.gallery.css +0 -48
  36. data/docs/_components/jquery-litebox/jquery.litebox.js +0 -30
  37. data/docs/_components/jquery-syntax/base/jquery.syntax.brush.apache.css +0 -12
  38. data/docs/_components/jquery-syntax/base/jquery.syntax.brush.applescript.css +0 -5
  39. data/docs/_components/jquery-syntax/base/jquery.syntax.brush.assembly.css +0 -8
  40. data/docs/_components/jquery-syntax/base/jquery.syntax.brush.bash-script.css +0 -6
  41. data/docs/_components/jquery-syntax/base/jquery.syntax.brush.bash.css +0 -4
  42. data/docs/_components/jquery-syntax/base/jquery.syntax.brush.clang.css +0 -6
  43. data/docs/_components/jquery-syntax/base/jquery.syntax.brush.css.css +0 -14
  44. data/docs/_components/jquery-syntax/base/jquery.syntax.brush.diff.css +0 -16
  45. data/docs/_components/jquery-syntax/base/jquery.syntax.brush.html.css +0 -5
  46. data/docs/_components/jquery-syntax/base/jquery.syntax.brush.ocaml.css +0 -3
  47. data/docs/_components/jquery-syntax/base/jquery.syntax.brush.protobuf.css +0 -2
  48. data/docs/_components/jquery-syntax/base/jquery.syntax.brush.python.css +0 -6
  49. data/docs/_components/jquery-syntax/base/jquery.syntax.brush.ruby.css +0 -2
  50. data/docs/_components/jquery-syntax/base/jquery.syntax.brush.xml.css +0 -18
  51. data/docs/_components/jquery-syntax/base/jquery.syntax.core.css +0 -58
  52. data/docs/_components/jquery-syntax/base/jquery.syntax.editor.css +0 -6
  53. data/docs/_components/jquery-syntax/base/theme.js +0 -1
  54. data/docs/_components/jquery-syntax/bright/jquery.syntax.core.css +0 -27
  55. data/docs/_components/jquery-syntax/bright/theme.js +0 -1
  56. data/docs/_components/jquery-syntax/jquery.syntax.brush.apache.js +0 -3
  57. data/docs/_components/jquery-syntax/jquery.syntax.brush.applescript.js +0 -5
  58. data/docs/_components/jquery-syntax/jquery.syntax.brush.assembly.js +0 -3
  59. data/docs/_components/jquery-syntax/jquery.syntax.brush.bash-script.js +0 -4
  60. data/docs/_components/jquery-syntax/jquery.syntax.brush.bash.js +0 -2
  61. data/docs/_components/jquery-syntax/jquery.syntax.brush.basic.js +0 -5
  62. data/docs/_components/jquery-syntax/jquery.syntax.brush.clang.js +0 -5
  63. data/docs/_components/jquery-syntax/jquery.syntax.brush.csharp.js +0 -4
  64. data/docs/_components/jquery-syntax/jquery.syntax.brush.css.js +0 -5
  65. data/docs/_components/jquery-syntax/jquery.syntax.brush.diff.js +0 -2
  66. data/docs/_components/jquery-syntax/jquery.syntax.brush.go.js +0 -3
  67. data/docs/_components/jquery-syntax/jquery.syntax.brush.haskell.js +0 -3
  68. data/docs/_components/jquery-syntax/jquery.syntax.brush.html.js +0 -4
  69. data/docs/_components/jquery-syntax/jquery.syntax.brush.io.js +0 -3
  70. data/docs/_components/jquery-syntax/jquery.syntax.brush.java.js +0 -4
  71. data/docs/_components/jquery-syntax/jquery.syntax.brush.javascript.js +0 -3
  72. data/docs/_components/jquery-syntax/jquery.syntax.brush.kai.js +0 -2
  73. data/docs/_components/jquery-syntax/jquery.syntax.brush.lisp.js +0 -2
  74. data/docs/_components/jquery-syntax/jquery.syntax.brush.lua.js +0 -3
  75. data/docs/_components/jquery-syntax/jquery.syntax.brush.nginx.js +0 -2
  76. data/docs/_components/jquery-syntax/jquery.syntax.brush.ocaml.js +0 -4
  77. data/docs/_components/jquery-syntax/jquery.syntax.brush.ooc.js +0 -4
  78. data/docs/_components/jquery-syntax/jquery.syntax.brush.pascal.js +0 -4
  79. data/docs/_components/jquery-syntax/jquery.syntax.brush.perl5.js +0 -3
  80. data/docs/_components/jquery-syntax/jquery.syntax.brush.php-script.js +0 -4
  81. data/docs/_components/jquery-syntax/jquery.syntax.brush.php.js +0 -2
  82. data/docs/_components/jquery-syntax/jquery.syntax.brush.plain.js +0 -2
  83. data/docs/_components/jquery-syntax/jquery.syntax.brush.protobuf.js +0 -3
  84. data/docs/_components/jquery-syntax/jquery.syntax.brush.python.js +0 -5
  85. data/docs/_components/jquery-syntax/jquery.syntax.brush.ruby.js +0 -5
  86. data/docs/_components/jquery-syntax/jquery.syntax.brush.scala.js +0 -4
  87. data/docs/_components/jquery-syntax/jquery.syntax.brush.smalltalk.js +0 -2
  88. data/docs/_components/jquery-syntax/jquery.syntax.brush.sql.js +0 -4
  89. data/docs/_components/jquery-syntax/jquery.syntax.brush.super-collider.js +0 -3
  90. data/docs/_components/jquery-syntax/jquery.syntax.brush.swift.js +0 -3
  91. data/docs/_components/jquery-syntax/jquery.syntax.brush.trenni.js +0 -2
  92. data/docs/_components/jquery-syntax/jquery.syntax.brush.xml.js +0 -4
  93. data/docs/_components/jquery-syntax/jquery.syntax.brush.yaml.js +0 -2
  94. data/docs/_components/jquery-syntax/jquery.syntax.cache.js +0 -7
  95. data/docs/_components/jquery-syntax/jquery.syntax.core.js +0 -34
  96. data/docs/_components/jquery-syntax/jquery.syntax.editor.js +0 -11
  97. data/docs/_components/jquery-syntax/jquery.syntax.js +0 -8
  98. data/docs/_components/jquery-syntax/jquery.syntax.min.js +0 -13
  99. data/docs/_components/jquery-syntax/paper/jquery.syntax.core.css +0 -31
  100. data/docs/_components/jquery-syntax/paper/theme.js +0 -1
  101. data/docs/_components/jquery/jquery.js +0 -10872
  102. data/docs/_components/jquery/jquery.min.js +0 -2
  103. data/docs/_components/jquery/jquery.min.map +0 -1
  104. data/docs/_components/jquery/jquery.slim.js +0 -8777
  105. data/docs/_components/jquery/jquery.slim.min.js +0 -2
  106. data/docs/_components/jquery/jquery.slim.min.map +0 -1
  107. data/docs/_static/icon.png +0 -0
  108. data/docs/_static/site.css +0 -191
  109. data/docs/development-environment-setup/index.html +0 -54
  110. data/docs/faq/what-is-xnode/index.html +0 -73
  111. data/docs/index.html +0 -86
  112. data/docs/javascript/index.html +0 -108
  113. data/docs/middleware/content/index.html +0 -58
  114. data/docs/middleware/controller/actions/index.html +0 -111
  115. data/docs/middleware/controller/index.html +0 -98
  116. data/docs/middleware/controller/rewrite/index.html +0 -105
  117. data/docs/middleware/localization/index.html +0 -53
  118. data/docs/middleware/redirection/index.html +0 -55
  119. data/docs/middleware/session/index.html +0 -65
  120. data/docs/middleware/static/index.html +0 -51
  121. data/docs/server-setup/index.html +0 -87
  122. data/docs/testing/index.html +0 -53
  123. data/docs/updating-utopia/index.html +0 -102
  124. data/docs/your-first-page/index.html +0 -74
  125. data/materials/utopia.png +0 -0
  126. data/materials/utopia.svg +0 -1
  127. data/setup/site/.yarnrc +0 -1
  128. data/spec/mock_node.rb +0 -16
  129. data/spec/spec_helper.rb +0 -13
  130. data/spec/utopia/command_spec.rb +0 -164
  131. data/spec/utopia/content/document_spec.rb +0 -60
  132. data/spec/utopia/content/links/bar/index.xnode +0 -0
  133. data/spec/utopia/content/links/bar/parent/child/index.en.xnode +0 -0
  134. data/spec/utopia/content/links/bar/parent/child/index.ja.xnode +0 -0
  135. data/spec/utopia/content/links/bar/parent/links.yaml +0 -2
  136. data/spec/utopia/content/links/foo/index.xnode +0 -0
  137. data/spec/utopia/content/links/foo/links.yaml +0 -2
  138. data/spec/utopia/content/links/foo/test.de.xnode +0 -0
  139. data/spec/utopia/content/links/foo/test.en.xnode +0 -0
  140. data/spec/utopia/content/links/index.xnode +0 -0
  141. data/spec/utopia/content/links/links.yaml +0 -18
  142. data/spec/utopia/content/links/redirect/links.yaml +0 -2
  143. data/spec/utopia/content/links/welcome.xnode +0 -0
  144. data/spec/utopia/content/links_spec.rb +0 -218
  145. data/spec/utopia/content/localized/five/index.en.xnode +0 -0
  146. data/spec/utopia/content/localized/four/index.en.xnode +0 -0
  147. data/spec/utopia/content/localized/four/index.zh.xnode +0 -0
  148. data/spec/utopia/content/localized/four/links.yaml +0 -4
  149. data/spec/utopia/content/localized/links.yaml +0 -13
  150. data/spec/utopia/content/localized/one.xnode +0 -0
  151. data/spec/utopia/content/localized/three/index.xnode +0 -0
  152. data/spec/utopia/content/localized/two.en.xnode +0 -0
  153. data/spec/utopia/content/localized/two.zh.xnode +0 -0
  154. data/spec/utopia/content/markup_spec.rb +0 -96
  155. data/spec/utopia/content/namespace_spec.rb +0 -45
  156. data/spec/utopia/content/node/lookup/content.xnode +0 -1
  157. data/spec/utopia/content/node/lookup/index.xnode +0 -1
  158. data/spec/utopia/content/node/ordered/first.xnode +0 -0
  159. data/spec/utopia/content/node/ordered/index.xnode +0 -0
  160. data/spec/utopia/content/node/ordered/links.yaml +0 -4
  161. data/spec/utopia/content/node/ordered/second.xnode +0 -0
  162. data/spec/utopia/content/node/related/foo.en.xnode +0 -0
  163. data/spec/utopia/content/node/related/foo.ja.xnode +0 -0
  164. data/spec/utopia/content/node/related/links.yaml +0 -4
  165. data/spec/utopia/content/node_spec.rb +0 -97
  166. data/spec/utopia/content/response_spec.rb +0 -54
  167. data/spec/utopia/content/tags_spec.rb +0 -82
  168. data/spec/utopia/content_spec.rb +0 -100
  169. data/spec/utopia/content_spec.ru +0 -6
  170. data/spec/utopia/content_spec/_heading.xnode +0 -1
  171. data/spec/utopia/content_spec/content/_show-value.xnode +0 -1
  172. data/spec/utopia/content_spec/content/links.yaml +0 -2
  173. data/spec/utopia/content_spec/content/test-partial.xnode +0 -1
  174. data/spec/utopia/content_spec/index.xnode +0 -1
  175. data/spec/utopia/content_spec/node/index.xnode +0 -1
  176. data/spec/utopia/content_spec/test.xnode +0 -10
  177. data/spec/utopia/controller/actions_spec.rb +0 -62
  178. data/spec/utopia/controller/middleware_spec.rb +0 -88
  179. data/spec/utopia/controller/middleware_spec.ru +0 -6
  180. data/spec/utopia/controller/middleware_spec/controller/controller.rb +0 -27
  181. data/spec/utopia/controller/middleware_spec/controller/index.xnode +0 -1
  182. data/spec/utopia/controller/middleware_spec/controller/nested/controller.rb +0 -7
  183. data/spec/utopia/controller/middleware_spec/empty/controller.rb +0 -0
  184. data/spec/utopia/controller/middleware_spec/redirect/controller.rb +0 -12
  185. data/spec/utopia/controller/middleware_spec/redirect/test/controller.rb +0 -9
  186. data/spec/utopia/controller/respond_spec.rb +0 -174
  187. data/spec/utopia/controller/respond_spec.ru +0 -12
  188. data/spec/utopia/controller/respond_spec/api/controller.rb +0 -28
  189. data/spec/utopia/controller/respond_spec/errors/controller.rb +0 -14
  190. data/spec/utopia/controller/respond_spec/errors/file-not-found.xnode +0 -8
  191. data/spec/utopia/controller/respond_spec/html/controller.rb +0 -11
  192. data/spec/utopia/controller/respond_spec/rewrite/controller.rb +0 -13
  193. data/spec/utopia/controller/rewrite_spec.rb +0 -80
  194. data/spec/utopia/controller/sequence_spec.rb +0 -135
  195. data/spec/utopia/controller/variables_spec.rb +0 -59
  196. data/spec/utopia/controller/websocket_spec.rb +0 -68
  197. data/spec/utopia/controller/websocket_spec.ru +0 -5
  198. data/spec/utopia/controller/websocket_spec/server/controller.rb +0 -11
  199. data/spec/utopia/exceptions/handler_spec.rb +0 -47
  200. data/spec/utopia/exceptions/handler_spec.ru +0 -8
  201. data/spec/utopia/exceptions/handler_spec/controller.rb +0 -19
  202. data/spec/utopia/exceptions/mailer_spec.rb +0 -43
  203. data/spec/utopia/exceptions/mailer_spec.ru +0 -10
  204. data/spec/utopia/extensions_spec.rb +0 -73
  205. data/spec/utopia/http/status_spec.rb +0 -44
  206. data/spec/utopia/locale_spec.rb +0 -58
  207. data/spec/utopia/localization_spec.rb +0 -92
  208. data/spec/utopia/localization_spec.ru +0 -15
  209. data/spec/utopia/localization_spec/controller.rb +0 -21
  210. data/spec/utopia/localization_spec/localized.de.txt +0 -1
  211. data/spec/utopia/localization_spec/localized.en.txt +0 -1
  212. data/spec/utopia/localization_spec/localized.ja.txt +0 -1
  213. data/spec/utopia/localization_spec/test.txt +0 -1
  214. data/spec/utopia/middleware_spec.rb +0 -31
  215. data/spec/utopia/path/matcher_spec.rb +0 -66
  216. data/spec/utopia/path_spec.rb +0 -207
  217. data/spec/utopia/performance_spec.rb +0 -92
  218. data/spec/utopia/performance_spec/cache/head/readme.txt +0 -1
  219. data/spec/utopia/performance_spec/cache/meta/readme.txt +0 -1
  220. data/spec/utopia/performance_spec/config.ru +0 -35
  221. data/spec/utopia/performance_spec/lib/readme.txt +0 -1
  222. data/spec/utopia/performance_spec/pages/_heading.xnode +0 -2
  223. data/spec/utopia/performance_spec/pages/_page.xnode +0 -26
  224. data/spec/utopia/performance_spec/pages/api/controller.rb +0 -8
  225. data/spec/utopia/performance_spec/pages/errors/exception.xnode +0 -5
  226. data/spec/utopia/performance_spec/pages/errors/file-not-found.xnode +0 -5
  227. data/spec/utopia/performance_spec/pages/links.yaml +0 -2
  228. data/spec/utopia/performance_spec/pages/welcome/index.xnode +0 -17
  229. data/spec/utopia/rack_helper.rb +0 -32
  230. data/spec/utopia/redirection_spec.rb +0 -77
  231. data/spec/utopia/redirection_spec.ru +0 -27
  232. data/spec/utopia/session_spec.rb +0 -189
  233. data/spec/utopia/session_spec.ru +0 -24
  234. data/spec/utopia/setup_spec.rb +0 -56
  235. data/spec/utopia/static_spec.rb +0 -49
  236. data/spec/utopia/static_spec.ru +0 -5
  237. data/spec/utopia/static_spec/test.txt +0 -1
  238. data/utopia.gemspec +0 -52
  239. data/wiki/Gemfile +0 -9
  240. data/wiki/config.ru +0 -7
  241. data/wiki/pages/development-environment-setup/index.md +0 -16
  242. data/wiki/pages/faq/links.yaml +0 -2
  243. data/wiki/pages/faq/what-is-xnode/index.md +0 -37
  244. data/wiki/pages/faq/what-is-xnode/links.yaml +0 -2
  245. data/wiki/pages/index.md +0 -35
  246. data/wiki/pages/javascript/index.md +0 -77
  247. data/wiki/pages/javascript/links.yaml +0 -2
  248. data/wiki/pages/links.yaml +0 -2
  249. data/wiki/pages/middleware/content/index.md +0 -21
  250. data/wiki/pages/middleware/controller/actions/index.md +0 -76
  251. data/wiki/pages/middleware/controller/index.md +0 -62
  252. data/wiki/pages/middleware/controller/links.yaml +0 -4
  253. data/wiki/pages/middleware/controller/rewrite/index.md +0 -69
  254. data/wiki/pages/middleware/localization/index.md +0 -16
  255. data/wiki/pages/middleware/redirection/index.md +0 -17
  256. data/wiki/pages/middleware/session/index.md +0 -29
  257. data/wiki/pages/middleware/static/index.md +0 -13
  258. data/wiki/pages/server-setup/index.md +0 -52
  259. data/wiki/pages/testing/index.md +0 -15
  260. data/wiki/pages/updating-utopia/index.md +0 -63
  261. 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">&lt;content:page&gt;
40
- &lt;content:heading&gt;Create User&lt;/content:heading&gt;
41
- &lt;form action=&quot;#&quot;&gt;
42
- &lt;input name=&quot;name&quot; /&gt;
43
- &lt;input type=&quot;submit&quot; /&gt;
44
- &lt;/form&gt;
45
- &lt;/content:page&gt;
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: /(?&lt;id&gt;\d+)-(?&lt;title&gt;.*)/ 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 &lt;&lt; &quot;post&quot;
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&amp;.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">&lt;content:page&gt;
66
- &lt;content:heading&gt;Post #{attributes[:permalink][:id]} about #{attributes[:permalink][:title]}&lt;/content:heading&gt;
67
-
68
- &lt;p&gt;#{attributes[:post].content}&lt;/p&gt;
69
- &lt;/content:page&gt;
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 &lt;&lt; &quot;post&quot;
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 =&gt; 'en',
36
- :locales =&gt; ['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
- '/' =&gt; '/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 =&gt; '/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>