utopia 2.16.2 → 2.18.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f1833aabc2d72234952e6ee164138d234cafc5d0d2015b64edcb28cead480c95
4
- data.tar.gz: d6e9675b9921ae290547c25b11c8b5974860256393c65147705d0dd1472ba851
3
+ metadata.gz: 81571ecc204a4003d9ef8df29f89ca3384fa64f9233d2e3a1668f77003a581c7
4
+ data.tar.gz: ba5fe4eec823b47fb7df609fe67e204d8f6e9a857154600d6ac5f9a02c82a6b0
5
5
  SHA512:
6
- metadata.gz: cd8ee2bdd633f9bcd10be1bd18db664299e9cc8c16169ad7d84d934ba8abb301037d0a0f459608087204cd43ac51eb155e88c4af2e988d03b2c29859df5fc2a3
7
- data.tar.gz: 4a16550958bc3ddf8fc37760f8436cc450d3e84ee2178ba6f194ce557869e0e20bfee0f3412eb6f2364c7f5ccc831da2b8f440fce11a81e8fc7f436914d64dde
6
+ metadata.gz: 306232cdad9958be5d332c184e5bf25d67b52d9b21049cd316316353a3a5dd03085e463fd77537dd4eaaba2415421bf6125c1ed0adcdc913fa8812061ef018ea
7
+ data.tar.gz: 10bc60c17fc893b9ed46d42de522e55c5aece0df2e0327a61bd285022eefa774ad5e97d2c543340a17e3ba40fb6b439fd921f54be743ab40401f336f37020e19
@@ -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"
@@ -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
 
@@ -142,7 +142,7 @@ module Utopia
142
142
  def load_metadata(path)
143
143
  yaml_path = File.join(path, LINKS_YAML)
144
144
 
145
- if File.exist?(yaml_path) && data = YAML::load_file(yaml_path)
145
+ if File.exist?(yaml_path) && data = YAML.load_file(yaml_path)
146
146
  return symbolize_keys(data)
147
147
  else
148
148
  return {}
@@ -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.
@@ -155,7 +155,7 @@ module Utopia
155
155
  end
156
156
 
157
157
  if @dump_environment
158
- mail.attachments['environment.yaml'] = YAML::dump(env)
158
+ mail.attachments['environment.yaml'] = YAML.dump(env)
159
159
  end
160
160
 
161
161
  return mail
@@ -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
@@ -138,7 +140,7 @@ module Utopia
138
140
  if directory?
139
141
  return self
140
142
  else
141
- return join([''])
143
+ return self.class.new(@components + [''])
142
144
  end
143
145
  end
144
146
 
@@ -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,12 +243,28 @@ module Utopia
235
243
  return self.class.new(result)
236
244
  end
237
245
 
238
- def pop
239
- @components.pop
246
+ # Returns the first path component.
247
+ def first
248
+ if absolute?
249
+ @components[1]
250
+ else
251
+ @components[0]
252
+ end
240
253
  end
241
254
 
255
+ # Returns the last path component.
242
256
  def last
243
- @components.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
244
268
  end
245
269
 
246
270
  # @return [String] the last path component without any file extension.
@@ -350,22 +374,6 @@ module Utopia
350
374
  @components.delete_at(component_offset(index))
351
375
  end
352
376
 
353
- def first
354
- if absolute?
355
- @components[1]
356
- else
357
- @components[0]
358
- end
359
- end
360
-
361
- def last
362
- if directory?
363
- @components[-2]
364
- else
365
- @components[-1]
366
- end
367
- end
368
-
369
377
  private
370
378
 
371
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.2"
24
+ VERSION = "2.18.2"
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.2
4
+ version: 2.18.2
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-31 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: []
@@ -319,9 +277,11 @@ files:
319
277
  - lib/utopia/content/tags.rb
320
278
  - lib/utopia/content_length.rb
321
279
  - lib/utopia/controller.rb
280
+ - lib/utopia/controller/actions.md
322
281
  - lib/utopia/controller/actions.rb
323
282
  - lib/utopia/controller/base.rb
324
283
  - lib/utopia/controller/respond.rb
284
+ - lib/utopia/controller/rewrite.md
325
285
  - lib/utopia/controller/rewrite.rb
326
286
  - lib/utopia/controller/variables.rb
327
287
  - lib/utopia/exceptions.rb
@@ -350,7 +310,6 @@ files:
350
310
  - setup/server/git/hooks/post-receive
351
311
  - setup/site/.gitignore
352
312
  - setup/site/.rspec
353
- - setup/site/Gemfile
354
313
  - setup/site/Guardfile
355
314
  - setup/site/README.md
356
315
  - setup/site/bake.rb
@@ -358,6 +317,7 @@ files:
358
317
  - setup/site/config/README.md
359
318
  - setup/site/config/environment.rb
360
319
  - setup/site/falcon.rb
320
+ - setup/site/gems.rb
361
321
  - setup/site/lib/readme.txt
362
322
  - setup/site/pages/_heading.xnode
363
323
  - setup/site/pages/_page.xnode
@@ -378,7 +338,7 @@ licenses:
378
338
  - MIT
379
339
  metadata:
380
340
  funding_uri: https://github.com/sponsors/ioquatix/
381
- post_install_message:
341
+ post_install_message:
382
342
  rdoc_options: []
383
343
  require_paths:
384
344
  - lib
@@ -394,7 +354,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
394
354
  version: '0'
395
355
  requirements: []
396
356
  rubygems_version: 3.1.2
397
- signing_key:
357
+ signing_key:
398
358
  specification_version: 4
399
359
  summary: Utopia is a framework for building dynamic content-driven websites.
400
360
  test_files: []