utopia 2.16.1 → 2.18.1

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
  SHA256:
3
- metadata.gz: 8f7a327d1848543592fbdf7a17fa1f45893852cff6ff763ddfdb08c9cb64ad80
4
- data.tar.gz: 0bcf595720fb09061dfb130e9ca3fc68f6ac071b279e661b9a76a186736fec42
3
+ metadata.gz: 2e27bab1354cbb8b2d4ab415c3c2570db443ece1628692bbd17ef1f6e7bd2329
4
+ data.tar.gz: 155b3b5ff07f33d836297db25be41d534c84e50ed9133b4d2ab69eec6730aeb8
5
5
  SHA512:
6
- metadata.gz: 6a246d50f6dd455582454f62e49c313c1e9c851094febfc20929d4ead609532c7b8e9673ab05c4ed037994960ece9e3a59c9de364b2074d0845fe2c50aaa298b
7
- data.tar.gz: 906526e65a9c040d781ac7544cec1425556bb78614e89c0a63ae39d2b805a25a1ede314d78c17830a2348adf094bb5be1b2a748792742d477421377f06c5d1f6
6
+ metadata.gz: d73b02adae74b577cff9e5a9b47f2d226f5bf97b9e246baeb325c21728d83e3c46069c20b6b6e38309900951c74d72985800864e7c682e39b27681fc3bc58cf2
7
+ data.tar.gz: 8038fbd4bd0334ec21391e86e2c0e55cb3a0caeef59b7700f310c5772fdc50c71997e8fa4ab258a34ca1d36fe5f17f7c3363dc6645dcd1d25eed06e42795b2db
@@ -68,7 +68,8 @@ module Utopia
68
68
  system("git", "config", "receive.denyCurrentBranch", "ignore") or fail "could not set configuration"
69
69
  system("git", "config", "core.worktree", destination_root) or fail "could not set configuration"
70
70
 
71
- system("bundle", "config", "set", "--local", "deployment", "true")
71
+ # Doing this invokes a lot of behaviour that isn't always ideal...
72
+ # system("bundle", "config", "set", "--local", "deployment", "true")
72
73
  system("bundle", "config", "set", "--local", "without", "development")
73
74
 
74
75
  # In theory, to convert from non-shared to shared:
@@ -33,7 +33,7 @@ module Utopia
33
33
  # Local site setup commands.
34
34
  class Site < Samovar::Command
35
35
  # Configuration files which should be installed/updated:
36
- CONFIGURATION_FILES = ['.gitignore', 'config.ru', 'config/environment.rb', 'falcon.rb', 'Gemfile', 'Guardfile', 'bake.rb', 'spec/spec_helper.rb', 'spec/website_context.rb', 'spec/website_spec.rb']
36
+ CONFIGURATION_FILES = ['.gitignore', 'config.ru', 'config/environment.rb', 'falcon.rb', 'gems.rb', 'Guardfile', 'bake.rb', 'spec/spec_helper.rb', 'spec/website_context.rb', 'spec/website_spec.rb']
37
37
 
38
38
  # Directories that should exist:
39
39
  DIRECTORIES = ["config", "lib", "pages", "public", "tasks", "spec"]
@@ -142,6 +142,15 @@ module Utopia
142
142
  end
143
143
  end
144
144
 
145
+ # Move `Gemfile` to `gems.rb`.
146
+ def update_gemfile!
147
+ # If `Gemfile` doens't exist, we are done:
148
+ return unless File.exist?('Gemfile')
149
+
150
+ system("git", "mv", "Gemfile", "gems.rb")
151
+ system("git", "mv", "Gemfile.lock", "gems.locked")
152
+ end
153
+
145
154
  def call
146
155
  destination_root = parent.root
147
156
  branch_name = "utopia-upgrade-#{Utopia::VERSION}"
@@ -184,6 +193,7 @@ module Utopia
184
193
  system("git", "add", *Site::CONFIGURATION_FILES) or fail "could not add files"
185
194
 
186
195
  move_static!
196
+ update_gemfile!
187
197
 
188
198
  # Commit all changes:
189
199
  system("git", "commit", "-m", "Upgrade to utopia #{Utopia::VERSION}.") or fail "could not commit changes"
@@ -177,17 +177,19 @@ module Utopia
177
177
  end
178
178
 
179
179
  def content_tag(name, node)
180
- parent_path = node.parent_path
180
+ full_path = node.parent_path + name
181
+
182
+ name = full_path.pop
181
183
 
182
184
  # If the current node is called 'foo', we can't lookup 'foo' in the current directory or we will have infinite recursion.
183
- if name == node.name
184
- parent_path = parent_path.dirname
185
+ while full_path.last == name
186
+ full_path.pop
185
187
  end
186
188
 
187
- cache_key = parent_path + name
189
+ cache_key = full_path + name
188
190
 
189
191
  @node_cache.fetch_or_store(cache_key) do
190
- lookup_content(name, parent_path)
192
+ lookup_content(name, full_path)
191
193
  end
192
194
  end
193
195
  end
@@ -52,7 +52,9 @@ module Utopia
52
52
 
53
53
  def href
54
54
  @href ||= @info.fetch(:uri) do
55
- (@path.dirname + @path.basename).to_s if @path
55
+ @info.fetch(:href) do
56
+ (@path.dirname + @path.basename).to_s if @path
57
+ end
56
58
  end
57
59
  end
58
60
 
@@ -234,7 +234,7 @@ module Utopia
234
234
  end
235
235
 
236
236
  def load_index(name, locale, info)
237
- info ||= {}
237
+ info ||= {}
238
238
 
239
239
  if locale and defaults = @metadata[name]
240
240
  info = defaults.merge(info)
@@ -245,17 +245,20 @@ module Utopia
245
245
  yield Link.new(:index, name, locale, path, info, path[-2])
246
246
  end
247
247
 
248
+ DEFAULT_INDEX_INFO = {href: nil}.freeze
249
+
250
+ # The default index for a directory which has no contents.
248
251
  def load_default_index(name = INDEX, info = {})
249
252
  path = @top + name
250
253
 
251
254
  if info
252
- info = {uri: nil}.merge(info)
255
+ info = DEFAULT_INDEX_INFO.merge(info)
253
256
  else
254
- info = {uri: nil}
257
+ info = DEFAULT_INDEX_INFO
255
258
  end
256
259
 
257
260
  # Specify a nil uri if no index could be found for the directory:
258
- yield Link.new(:index, name, nil, @top, info, path[-2])
261
+ yield Link.new(:index, name, nil, @top.to_directory, info, path[-2])
259
262
  end
260
263
 
261
264
  def load_file(name, locale, info)
@@ -0,0 +1,76 @@
1
+ # Utopia::Controller::Actions
2
+
3
+ Actions let you match path patterns in your controller and execute code. In your `controller.rb` simply add:
4
+
5
+ ```ruby
6
+ prepend Actions
7
+ ```
8
+
9
+ If you are adding multiple things, like rewriting, they should come earlier in the chain, e.g:
10
+
11
+ ```ruby
12
+ prepend Rewrite, Actions
13
+ ```
14
+
15
+ A simple CRUD controller might look like:
16
+
17
+ ```ruby
18
+ prepend Actions
19
+
20
+ on 'index' do
21
+ @users = User.all
22
+ end
23
+
24
+ on 'new' do |request|
25
+ @user = User.new
26
+
27
+ if request.post?
28
+ @user.update_attributes(request.params['user'])
29
+
30
+ redirect! "index"
31
+ end
32
+ end
33
+
34
+ on 'edit' do |request|
35
+ @user = User.find(request.params['id'])
36
+
37
+ if request.post?
38
+ @user.update_attributes(request.params['user'])
39
+
40
+ redirect! "index"
41
+ end
42
+ end
43
+
44
+ on 'delete' do |request|
45
+ User.find(request.params['id']).destroy
46
+
47
+ redirect! "index"
48
+ end
49
+ ```
50
+
51
+ ## Path Matching
52
+
53
+ 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.
54
+
55
+ <dl>
56
+ <dt><code class="language-ruby">"*"</code></dt>
57
+ <dd>Match a single path element</dd>
58
+ <dt><code class="language-ruby">"**"</code></dt>
59
+ <dd>Match all remaining path elements</dd>
60
+ <dt><code class="language-ruby">String</code></dt>
61
+ <dd>Match a named path component, e.g. <code class="language-ruby">"edit"</code>.</dd>
62
+ <dt><code class="language-ruby">Symbol</code></dt>
63
+ <dd>Equivalent to <code class="language-ruby">["**", symbol.to_s]</code>, e.g. <code class="language-ruby">:logout</code>.</dd>
64
+ </dl>
65
+
66
+ ## Otherwise Matching
67
+
68
+ If no action was matched, it is sometimes useful to perform some specific behaviour. You can specify this by using the otherwise handler:
69
+
70
+ ```ruby
71
+ otherwise do |request, path|
72
+ fail! :teapot
73
+ end
74
+ ```
75
+
76
+ 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,69 @@
1
+ # Utopia::Controller::Rewrite
2
+
3
+ This module 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
+ ```ruby
10
+ prepend Rewrite, Actions
11
+
12
+ rewrite.extract_prefix permalink: /(?<id>\d+)-(?<title>.*)/ do |request, path, match|
13
+ # The rewrite matched, but there was no valid post, so we fail:
14
+ fail! unless @post = Post.find(@permalink[:id])
15
+
16
+ # If the path matched, but there was no suffix, we make it default to the post action:
17
+ if match.post_match.empty?
18
+ match.post_match.components << "post"
19
+ end
20
+ end
21
+
22
+ on 'post' do
23
+ # You can do further processing here.
24
+ fail! unless @post.published?
25
+
26
+ @comments = @post.comments.first(5)
27
+ end
28
+
29
+ on 'edit' do
30
+ # You can do further processing here.
31
+ fail! unless @current_user&.editor?
32
+ end
33
+ ```
34
+
35
+ In your `post.xnode`, as an example:
36
+
37
+ ```trenni
38
+ <content:page>
39
+ <content:heading>Post #{attributes[:permalink][:id]} about #{attributes[:permalink][:title]}</content:heading>
40
+
41
+ <p>#{attributes[:post].content}</p>
42
+ </content:page>
43
+ ```
44
+
45
+ Keep in mind, that URLs like `/123-pictures-of-my-cat/edit` will work as expected, and hit the `edit` action of the controller.
46
+
47
+ ## Restful Resources
48
+
49
+ Similar to the above, if we were solely interested in IDs, we could do the following:
50
+
51
+ ```ruby
52
+ prepend Rewrite, Actions
53
+
54
+ rewrite.extract_prefix post_id: Integer do |request, path, match|
55
+ # The rewrite matched, but there was no valid post, so we fail:
56
+ fail! unless @post = Post.find(@post_id)
57
+
58
+ # If the path matched, but there was no suffix, we make it default to the post action:
59
+ if match.post_match.empty?
60
+ match.post_match.components << "post"
61
+ end
62
+ end
63
+ ```
64
+
65
+ This will only match complete integers. Assuming this code is in `/blog/controller.rb`, it would match something like `/blog/123/view` and assign <code class="language-ruby">Integer("123")</code> to <code class="language-ruby">@post_id</code>.
66
+
67
+ ### Matching.. other things
68
+
69
+ 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.
@@ -25,7 +25,7 @@ module Utopia
25
25
  class Path
26
26
  include Comparable
27
27
 
28
- SEPARATOR = '/'.freeze
28
+ SEPARATOR = '/'
29
29
 
30
30
  def initialize(components = [])
31
31
  @components = components
@@ -34,6 +34,8 @@ module Utopia
34
34
  attr_accessor :components
35
35
 
36
36
  def freeze
37
+ return self if frozen?
38
+
37
39
  @components.freeze
38
40
 
39
41
  super
@@ -176,8 +178,14 @@ module Utopia
176
178
  @components
177
179
  end
178
180
 
181
+ # @parameter other [Array(String)] The path components to append.
179
182
  def join(other)
180
- self.class.new(@components + other).simplify
183
+ # Check whether other is an absolute path:
184
+ if other.first == ''
185
+ self.class.new(other)
186
+ else
187
+ self.class.new(@components + other).simplify
188
+ end
181
189
  end
182
190
 
183
191
  def expand(root)
@@ -235,6 +243,30 @@ module Utopia
235
243
  return self.class.new(result)
236
244
  end
237
245
 
246
+ # Returns the first path component.
247
+ def first
248
+ if absolute?
249
+ @components[1]
250
+ else
251
+ @components[0]
252
+ end
253
+ end
254
+
255
+ # Returns the last path component.
256
+ def last
257
+ if @components != ['']
258
+ @components.last
259
+ end
260
+ end
261
+
262
+ # Pops the last path component.
263
+ def pop
264
+ # We don't want to convert an absolute path to a relative path.
265
+ if @components != ['']
266
+ @components.pop
267
+ end
268
+ end
269
+
238
270
  # @return [String] the last path component without any file extension.
239
271
  def basename
240
272
  basename, _ = @components.last.split('.', 2)
@@ -284,7 +316,7 @@ module Utopia
284
316
  end
285
317
 
286
318
  def split(at)
287
- if at.kind_of? String
319
+ if at.kind_of?(String)
288
320
  at = @components.index(at)
289
321
  end
290
322
 
@@ -342,22 +374,6 @@ module Utopia
342
374
  @components.delete_at(component_offset(index))
343
375
  end
344
376
 
345
- def first
346
- if absolute?
347
- @components[1]
348
- else
349
- @components[0]
350
- end
351
- end
352
-
353
- def last
354
- if directory?
355
- @components[-2]
356
- else
357
- @components[-1]
358
- end
359
- end
360
-
361
377
  private
362
378
 
363
379
  # We adjust the index slightly so that indices reference path components rather than the directory markers at the start and end of the path components array.
@@ -21,5 +21,5 @@
21
21
  # THE SOFTWARE.
22
22
 
23
23
  module Utopia
24
- VERSION = "2.16.1"
24
+ VERSION = "2.18.1"
25
25
  end
@@ -62,7 +62,7 @@ Dir.chdir(GIT_WORK_TREE) do
62
62
  sudo %W{git checkout -f}
63
63
  sudo %W{git submodule update -i}
64
64
 
65
- if File.exist? 'Gemfile'
65
+ if File.exist? 'gems.rb'
66
66
  sudo %W{bundle install}
67
67
  end
68
68
 
File without changes
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: 2.16.1
4
+ version: 2.18.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-29 00:00:00.000000000 Z
11
+ date: 2020-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -192,34 +192,6 @@ dependencies:
192
192
  - - ">="
193
193
  - !ruby/object:Gem::Version
194
194
  version: '0'
195
- - !ruby/object:Gem::Dependency
196
- name: bake-bundler
197
- requirement: !ruby/object:Gem::Requirement
198
- requirements:
199
- - - ">="
200
- - !ruby/object:Gem::Version
201
- version: '0'
202
- type: :development
203
- prerelease: false
204
- version_requirements: !ruby/object:Gem::Requirement
205
- requirements:
206
- - - ">="
207
- - !ruby/object:Gem::Version
208
- version: '0'
209
- - !ruby/object:Gem::Dependency
210
- name: bake-modernize
211
- requirement: !ruby/object:Gem::Requirement
212
- requirements:
213
- - - ">="
214
- - !ruby/object:Gem::Version
215
- version: '0'
216
- type: :development
217
- prerelease: false
218
- version_requirements: !ruby/object:Gem::Requirement
219
- requirements:
220
- - - ">="
221
- - !ruby/object:Gem::Version
222
- version: '0'
223
195
  - !ruby/object:Gem::Dependency
224
196
  name: bundler
225
197
  requirement: !ruby/object:Gem::Requirement
@@ -276,22 +248,8 @@ dependencies:
276
248
  - - "~>"
277
249
  - !ruby/object:Gem::Version
278
250
  version: '3.6'
279
- - !ruby/object:Gem::Dependency
280
- name: utopia-project
281
- requirement: !ruby/object:Gem::Requirement
282
- requirements:
283
- - - ">="
284
- - !ruby/object:Gem::Version
285
- version: '0'
286
- type: :development
287
- prerelease: false
288
- version_requirements: !ruby/object:Gem::Requirement
289
- requirements:
290
- - - ">="
291
- - !ruby/object:Gem::Version
292
- version: '0'
293
- description:
294
- email:
251
+ description:
252
+ email:
295
253
  executables:
296
254
  - utopia
297
255
  extensions: []
@@ -303,15 +261,12 @@ files:
303
261
  - bake/utopia/static.rb
304
262
  - bake/utopia/test.rb
305
263
  - bin/utopia
306
- - lib/.DS_Store
307
264
  - lib/utopia.rb
308
- - lib/utopia/.DS_Store
309
265
  - lib/utopia/command.rb
310
266
  - lib/utopia/command/environment.rb
311
267
  - lib/utopia/command/server.rb
312
268
  - lib/utopia/command/site.rb
313
269
  - lib/utopia/content.rb
314
- - lib/utopia/content/.DS_Store
315
270
  - lib/utopia/content/document.rb
316
271
  - lib/utopia/content/link.rb
317
272
  - lib/utopia/content/links.rb
@@ -322,10 +277,11 @@ files:
322
277
  - lib/utopia/content/tags.rb
323
278
  - lib/utopia/content_length.rb
324
279
  - lib/utopia/controller.rb
325
- - lib/utopia/controller/.DS_Store
280
+ - lib/utopia/controller/actions.md
326
281
  - lib/utopia/controller/actions.rb
327
282
  - lib/utopia/controller/base.rb
328
283
  - lib/utopia/controller/respond.rb
284
+ - lib/utopia/controller/rewrite.md
329
285
  - lib/utopia/controller/rewrite.rb
330
286
  - lib/utopia/controller/variables.rb
331
287
  - lib/utopia/exceptions.rb
@@ -351,13 +307,9 @@ files:
351
307
  - lib/utopia/static/local_file.rb
352
308
  - lib/utopia/static/mime_types.rb
353
309
  - lib/utopia/version.rb
354
- - setup/.DS_Store
355
- - setup/server/.DS_Store
356
310
  - setup/server/git/hooks/post-receive
357
- - setup/site/.DS_Store
358
311
  - setup/site/.gitignore
359
312
  - setup/site/.rspec
360
- - setup/site/Gemfile
361
313
  - setup/site/Guardfile
362
314
  - setup/site/README.md
363
315
  - setup/site/bake.rb
@@ -365,15 +317,14 @@ files:
365
317
  - setup/site/config/README.md
366
318
  - setup/site/config/environment.rb
367
319
  - setup/site/falcon.rb
320
+ - setup/site/gems.rb
368
321
  - setup/site/lib/readme.txt
369
- - setup/site/pages/.DS_Store
370
322
  - setup/site/pages/_heading.xnode
371
323
  - setup/site/pages/_page.xnode
372
324
  - setup/site/pages/errors/exception.xnode
373
325
  - setup/site/pages/errors/file-not-found.xnode
374
326
  - setup/site/pages/links.yaml
375
327
  - setup/site/pages/welcome/index.xnode
376
- - setup/site/public/.DS_Store
377
328
  - setup/site/public/_static/icon.png
378
329
  - setup/site/public/_static/site.css
379
330
  - setup/site/public/_static/utopia-background.svg
@@ -382,13 +333,12 @@ files:
382
333
  - setup/site/spec/spec_helper.rb
383
334
  - setup/site/spec/website_context.rb
384
335
  - setup/site/spec/website_spec.rb
385
- - setup/site/tmp/Gemfile
386
336
  homepage: https://github.com/ioquatix/utopia
387
337
  licenses:
388
338
  - MIT
389
339
  metadata:
390
340
  funding_uri: https://github.com/sponsors/ioquatix/
391
- post_install_message:
341
+ post_install_message:
392
342
  rdoc_options: []
393
343
  require_paths:
394
344
  - lib
@@ -404,7 +354,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
404
354
  version: '0'
405
355
  requirements: []
406
356
  rubygems_version: 3.1.2
407
- signing_key:
357
+ signing_key:
408
358
  specification_version: 4
409
359
  summary: Utopia is a framework for building dynamic content-driven websites.
410
360
  test_files: []
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file