utopia 1.9.1 → 1.9.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1e43b609f07c8331def9621c56b40b2f9298d35b
4
- data.tar.gz: d137536094afd723da06e757ab0112b85dd31c50
3
+ metadata.gz: 7f08603b8fc77e5ffe85cf2f402be73c09502643
4
+ data.tar.gz: 81540559da3ee6823a0a3f1754c7446b28228b5a
5
5
  SHA512:
6
- metadata.gz: a6513105d8c673492b3f5c4269d6b25d28aab62e95f875c94a78fa48b727784c17c5a53b667c449ca60fdd6db88f04d5556b2f1e8d4f6320321dec3bb3956557
7
- data.tar.gz: 79fc5393a3babeea2f1cb03328d551c11dc8166f0693e862855fee02a3e215114282a77e3fd4c353d547efafb86f9a639d80f7a4ad098e93abadc52dd94b34ec
6
+ metadata.gz: caa96b4c7e561170b1bcfc4a1d783561d3e46b4e65f8c3ecadce76a3b43846f6d4fa2d26765d644aca197a77206b775ed30bed79f8e1c58bdc97459e90f815ce
7
+ data.tar.gz: 8e000468cebb8b29e356269e83e3dd6f79cfd7d64f41ad4155ca79943f1e74a28f8b2e3fb3bd1df0da9c7e64da8595f8795c7e1b38bd0c398406716311a67a91
@@ -0,0 +1,15 @@
1
+ <?r prev = nil ?>
2
+ <nav>
3
+ <?r
4
+ Utopia::Path[attributes[:path]].descend do |path|
5
+ next unless path.last
6
+
7
+ link = links(path.dirname, :name => path.last, :locale => localization.current_locale, :display => nil).first
8
+
9
+ if link and File.exist?(current.node.local_path(link.path + "content.md"))
10
+ ?> &rsaquo; <a href="#{link.path}">#{link.title}</a><?r
11
+ elsif link
12
+ ?> &rsaquo; <span>#{link.title}</span><?r
13
+ end
14
+ end ?>
15
+ </nav>
@@ -1,4 +1,4 @@
1
- # Welcome to Utopia
1
+ # Utopia Documentation Wiki
2
2
 
3
3
  This wiki includes documentation and examples showing how to use Utopia.
4
4
 
@@ -8,4 +8,5 @@ This wiki includes documentation and examples showing how to use Utopia.
8
8
 
9
9
  ## Advanced Topics
10
10
 
11
- - [Rewriting URLs](rewriting-urls/)
11
+ - [Controller Actions](controller/actions/)
12
+ - [Controller Rewrite](controller/rewrite/)
@@ -2,6 +2,7 @@
2
2
  prepend Actions
3
3
 
4
4
  on '**' do |request, path|
5
+ @full_path = URI_PATH + path
5
6
  @page_path = path.components[0..-2]
6
7
 
7
8
  @page_file = File.join(BASE_PATH, @page_path, "content.md")
@@ -0,0 +1,68 @@
1
+ # Controller::Actions
2
+
3
+ Actions let you match path patterns in your controller and execute code. In your `controller.rb` simply add:
4
+
5
+ prepend Actions
6
+
7
+ If you are adding multiple things, like rewriting, they should come earlier in the chain, e.g:
8
+
9
+ prepend Rewrite, Actions
10
+
11
+ A simple CRUD controller might look like:
12
+
13
+ prepend Actions
14
+
15
+ on 'index' do
16
+ @users = User.all
17
+ end
18
+
19
+ on 'new' do |request|
20
+ @user = User.new
21
+
22
+ if request.post?
23
+ @user.update_attributes(request.params['user'])
24
+
25
+ redirect! "index"
26
+ end
27
+ end
28
+
29
+ on 'edit' do |request|
30
+ @user = User.find(request.params['id'])
31
+
32
+ if request.post?
33
+ @user.update_attributes(request.params['user'])
34
+
35
+ redirect! "index"
36
+ end
37
+ end
38
+
39
+ on 'delete' do |request|
40
+ User.find(request.params['id']).destroy
41
+
42
+ redirect! "index"
43
+ end
44
+
45
+ ## Path Matching
46
+
47
+ Path matching works from right to left, and '**' is a greedy operator. Controllers are invoked with a path relative to the controller's `URI_PATH`, so all lookups are relative to the controller.
48
+
49
+ <dl>
50
+ <dt>"*"</dt>
51
+ <dd>Match a single path element</dd>
52
+ <dt>"**"<dt>
53
+ <dd>Match all remaining path elements</dd>
54
+ <dt>String</dt>
55
+ <dd>Match a named path component</dd>
56
+ <dt>Symbol</dt>
57
+ <dd>Equivalent to ["**", symbol.to_s]</dd>
58
+ </dl>
59
+
60
+ ## Otherwise Matching
61
+
62
+ If no action was matched, it is sometimes useful to perform some specific behaviour. You can specify this by using the otherwise handler:
63
+
64
+ otherwise do |request, path|
65
+ fail! :teapot
66
+ end
67
+
68
+ If you are doing this to perform some kind of rewriting, it may be preferable to use the [Rewrite](rewrite/) controller layer.
@@ -0,0 +1,4 @@
1
+ actions:
2
+ order: 1
3
+ rewrite:
4
+ order: 2
@@ -0,0 +1,64 @@
1
+ # Controller::Rewrite
2
+
3
+ The `Controller::Rewrite` layer can match and rewrite requests before they processed. This allows you to handle URLs like `/post/15/view` or `/blog/123-pictures-of-my-cat` 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.
4
+
5
+ ## Regular Expressions
6
+
7
+ In your `controller.rb`:
8
+
9
+ prepend Actions, Rewrite
10
+
11
+ rewrite.extract_prefix permalink: /(?<id>\d+)-(?<title>.*)/ do |request, path, match|
12
+ # The rewrite matched, but there was no valid post, so we fail:
13
+ fail! unless @post = Post.find(@permalink[:id])
14
+
15
+ # If the path matched, but there was no suffix, we make it default to the post action:
16
+ if match.post_match.empty?
17
+ match.post_match.components << "post"
18
+ end
19
+ end
20
+
21
+ on 'post' do
22
+ # You can do further processing here.
23
+ fail! unless @post.published?
24
+
25
+ @comments = @post.comments.first(5)
26
+ end
27
+
28
+ on 'edit' do
29
+ # You can do further processing here.
30
+ fail! unless @current_user&.editor?
31
+ end
32
+
33
+ In your `post.xnode`, as an example:
34
+
35
+ <page>
36
+ <heading>Post #{attributes[:permalink][:id]} about #{attributes[:permalink][:title]}</heading>
37
+
38
+ <p>#{attributes[:post].content}</p>
39
+ </page>
40
+
41
+ Keep in mind, that URLs like `/123-pictures-of-my-cat/edit` will work as expected, and hit the `edit` action of the controller.
42
+
43
+ ## Restful Resources
44
+
45
+ Similar to the above, if we were solely interested in IDs, we could do the following:
46
+
47
+ prepend Actions, Rewrite
48
+
49
+ rewrite.extract_prefix post_id: Integer do |request, path, match|
50
+ # The rewrite matched, but there was no valid post, so we fail:
51
+ fail! unless @post = Post.find(@post_id)
52
+
53
+ # If the path matched, but there was no suffix, we make it default to the post action:
54
+ if match.post_match.empty?
55
+ match.post_match.components << "post"
56
+ end
57
+ end
58
+
59
+ This will only match complete integers. Assuming this code is in `/blog/controller.rb`, it would match something like `/blog/123/view` and assign Integer("123") to `@post_id`.
60
+
61
+ ### Matching.. other things
62
+
63
+ It's possible to match using `Integer`, `Float`, `String`, 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.
64
+
@@ -0,0 +1,2 @@
1
+ index:
2
+ title: "Wiki"
@@ -1,7 +1,7 @@
1
1
  <page>
2
- <?r
3
- transaction.attributes[:title] ||= @page_title
4
- ?>
2
+ <?r transaction.attributes[:title] ||= @page_title ?>
3
+
4
+ #{partial 'navigation', path: attributes[:full_path].dirname}
5
5
 
6
6
  #{MarkupString.raw Kramdown::Document.new(self[:content]).to_html}
7
7
 
@@ -60,23 +60,23 @@ module Utopia
60
60
  attr :offset
61
61
 
62
62
  def to_s
63
- @tag.to_s
63
+ "<#{@tag.name}#{@tag.attributes.empty? ? '' : ' ...'}>"
64
64
  end
65
65
  end
66
66
 
67
67
  class UnbalancedTagError < StandardError
68
68
  def initialize(buffer, opening_tag, closing_tag = nil)
69
69
  @buffer = buffer
70
- @opening_tag = current_tag
70
+ @opening_tag = opening_tag
71
71
  @closing_tag = closing_tag
72
72
  end
73
73
 
74
74
  attr :buffer
75
- attr :current_tag
75
+ attr :opening_tag
76
76
  attr :closing_tag
77
77
 
78
78
  def start_location
79
- Trenni::Location.new(@buffer.read, current_tag.offset)
79
+ Trenni::Location.new(@buffer.read, opening_tag.offset)
80
80
  end
81
81
 
82
82
  def end_location
@@ -144,7 +144,7 @@ module Utopia
144
144
  tag = @current.tag
145
145
 
146
146
  if tag.name != name
147
- raise UnbalancedTagError.new(@buffer, tag, ParsedTag.new(name, offset))
147
+ raise UnbalancedTagError.new(@buffer, @current, ParsedTag.new(name, offset))
148
148
  end
149
149
 
150
150
  @delegate.tag_end(tag)
@@ -52,14 +52,16 @@ module Utopia
52
52
 
53
53
  def coerce(klass, value)
54
54
  if klass == Integer
55
- Integer(value) rescue nil
55
+ Integer(value)
56
56
  elsif klass == Float
57
- Float(value) rescue nil
57
+ Float(value)
58
58
  elsif klass == String
59
59
  value.to_s
60
60
  else
61
61
  klass.new(value)
62
62
  end
63
+ rescue
64
+ return nil
63
65
  end
64
66
 
65
67
  # This is a path prefix matching algorithm. The pattern is an array of String, Symbol, Regexp, or nil. The components is an array of String.
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Utopia
22
- VERSION = "1.9.1"
22
+ VERSION = "1.9.2"
23
23
  end
@@ -104,6 +104,13 @@ footer {
104
104
  color: #aaa;
105
105
  }
106
106
 
107
+ nav {
108
+ position: absolute;
109
+ margin: 2.5rem;
110
+ font-size: 0.8rem;
111
+ color: #aaa;
112
+ }
113
+
107
114
  section.features {
108
115
  display: flex;
109
116
  flex-wrap: wrap;
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: utopia
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.1
4
+ version: 1.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-30 00:00:00.000000000 Z
11
+ date: 2016-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trenni
@@ -200,11 +200,15 @@ files:
200
200
  - documentation/pages/errors/file-not-found.xnode
201
201
  - documentation/pages/links.yaml
202
202
  - documentation/pages/welcome/index.xnode
203
+ - documentation/pages/wiki/_navigation.xnode
203
204
  - documentation/pages/wiki/content.md
204
205
  - documentation/pages/wiki/controller.rb
206
+ - documentation/pages/wiki/controller/actions/content.md
207
+ - documentation/pages/wiki/controller/links.yaml
208
+ - documentation/pages/wiki/controller/rewrite/content.md
205
209
  - documentation/pages/wiki/development-environment-setup/content.md
206
210
  - documentation/pages/wiki/edit.xnode
207
- - documentation/pages/wiki/rewriting-urls/content.md
211
+ - documentation/pages/wiki/links.yaml
208
212
  - documentation/pages/wiki/server-setup/content.md
209
213
  - documentation/pages/wiki/show.xnode
210
214
  - documentation/pages/wiki/your-first-page/content.md
@@ -1,41 +0,0 @@
1
- # Rewriting URLs
2
-
3
- The `Controller::Rewrite` layer can match and rewrite requests before they processed. This allows you to have URLs like `/post/15/view` or `/blog/123-pictures-of-my-cat`. The basic rewrite operation is to extract some part of the path prefix. That means that the path is modified before being passed on to the next layer in the controller.
4
-
5
- ## Permalink Example
6
-
7
- In your `controller.rb`:
8
-
9
- prepend Actions, Rewrite
10
-
11
- rewrite.extract_prefix permalink: /(?<id>\d+)-(?<title>.*)/ do |request, path, match|
12
- # The rewrite matched, but there was no valid post, so we fail:
13
- fail! unless @post = Post.find(@permalink[:id])
14
-
15
- # If the path matched, but there was no suffix, we make it default to the post action:
16
- if match.post_match.empty?
17
- match.post_match.components << "post"
18
- end
19
- end
20
-
21
- on 'post' do
22
- # You can do further processing here.
23
- fail! unless @post.published?
24
-
25
- @comments = @post.comments.first(5)
26
- end
27
-
28
- on 'edit' do
29
- # You can do further processing here.
30
- fail! unless @current_user&.editor?
31
- end
32
-
33
- In your `post.xnode`, as an example:
34
-
35
- <page>
36
- <heading>Post #{attributes[:permalink][:id]} about #{attributes[:permalink][:title]}</heading>
37
-
38
- <p>#{attributes[:post].content}</p>
39
- </page>
40
-
41
- Keep in mind, that URLs like `/123-pictures-of-my-cat/edit` will work as expected, and hit the `edit` action of the controller.