utopia 2.24.4 → 2.26.0
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
- checksums.yaml.gz.sig +0 -0
- data/bake/utopia/environment.rb +16 -12
- data/bake/utopia/node.rb +5 -5
- data/bake/utopia/server.rb +8 -8
- data/bake/utopia/shell.rb +3 -3
- data/bake/utopia/site.rb +16 -16
- data/bake/utopia/static.rb +8 -8
- data/bake/utopia.rb +4 -4
- data/lib/utopia/content/document.rb +4 -4
- data/lib/utopia/content/link.rb +10 -10
- data/lib/utopia/content/links.rb +5 -5
- data/lib/utopia/content/markup.rb +6 -6
- data/lib/utopia/content/node.rb +8 -8
- data/lib/utopia/content/response.rb +5 -5
- data/lib/utopia/content/tags.rb +8 -8
- data/lib/utopia/content.rb +18 -18
- data/lib/utopia/controller/actions.rb +5 -5
- data/lib/utopia/controller/base.rb +2 -2
- data/lib/utopia/controller/respond.rb +6 -6
- data/lib/utopia/controller/rewrite.rb +3 -3
- data/lib/utopia/controller.rb +10 -10
- data/lib/utopia/exceptions/handler.rb +3 -3
- data/lib/utopia/exceptions/mailer.rb +9 -9
- data/lib/utopia/exceptions.rb +3 -3
- data/lib/utopia/extensions/date_comparisons.rb +2 -2
- data/lib/utopia/http.rb +36 -36
- data/lib/utopia/locale.rb +3 -3
- data/lib/utopia/localization.rb +7 -7
- data/lib/utopia/middleware.rb +5 -5
- data/lib/utopia/path/matcher.rb +2 -2
- data/lib/utopia/path.rb +21 -21
- data/lib/utopia/redirection.rb +4 -4
- data/lib/utopia/responder.rb +2 -2
- data/lib/utopia/session/serialization.rb +4 -4
- data/lib/utopia/session.rb +8 -8
- data/lib/utopia/setup.rb +7 -7
- data/lib/utopia/shell.rb +5 -5
- data/lib/utopia/static/local_file.rb +8 -8
- data/lib/utopia/static/mime_types.rb +2 -2
- data/lib/utopia/static.rb +11 -11
- data/lib/utopia/version.rb +1 -1
- data/lib/utopia.rb +7 -8
- data/license.md +1 -1
- data/readme.md +1 -1
- data/setup/server/git/hooks/post-receive +10 -9
- data/setup/site/Guardfile +3 -2
- data/setup/site/bake.rb +3 -3
- data/setup/site/config/environment.rb +3 -3
- data/setup/site/config/sus.rb +3 -3
- data/setup/site/config.ru +8 -8
- data/setup/site/fixtures/website.rb +6 -6
- data/setup/site/gems.rb +13 -13
- data/setup/site/test/website.rb +3 -3
- data.tar.gz.sig +0 -0
- metadata +3 -9
- metadata.gz.sig +0 -0
- data/lib/utopia/content_length.rb +0 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d94f472431ddf09a1bb0002c02e1e94fb7cacf720bf93054286f5616c5ae9f7d
|
4
|
+
data.tar.gz: bf9576183c19dd53684c3a0f21c90aa8a785cb8301ef1ce712aea08890ed3918
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86a05f2d63c9f2e1cb140816329dec2c6ac22e1b03b505dbfb3b43efb316a05407f8c1004501a00751cfcded37ceee31f0d30743a1f07f78c38350afb1500094
|
7
|
+
data.tar.gz: facdc1eaea6987c92664ba4434ef8d19adfb62f990236c5fa84f03d732b7d80840ac7541d546d4ce1c555c1d47755cb41f36d28e7a2fa9a257b8bdeecb6ae00f
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/bake/utopia/environment.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2018-
|
4
|
+
# Copyright, 2018-2025, by Samuel Williams.
|
5
5
|
|
6
6
|
# Update environment variables in config/environment.yaml
|
7
7
|
def initialize(...)
|
8
8
|
super
|
9
9
|
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
10
|
+
require "securerandom"
|
11
|
+
require "yaml/store"
|
12
|
+
require "console"
|
13
13
|
end
|
14
14
|
|
15
15
|
# Setup default environemnts "testing" and "development".
|
@@ -26,7 +26,7 @@ def defaults(name, root: context.root)
|
|
26
26
|
update_environment(root, name) do |store|
|
27
27
|
Console.info(self) {"Setting up defaults for environment #{name}..."}
|
28
28
|
# Set some useful defaults for the environment.
|
29
|
-
store[
|
29
|
+
store["UTOPIA_SESSION_SECRET"] ||= SecureRandom.hex(40)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -51,10 +51,8 @@ def update(name, root: context.root, **variables)
|
|
51
51
|
yield store if block_given?
|
52
52
|
|
53
53
|
Console.info(self) do |buffer|
|
54
|
-
buffer.puts "Environment #{name} (#{path}):"
|
55
|
-
store.
|
56
|
-
value = store[key]
|
57
|
-
|
54
|
+
buffer.puts "Environment #{name.inspect} (#{path}):"
|
55
|
+
store.each do |key, value|
|
58
56
|
buffer.puts "#{key}=#{value.inspect}"
|
59
57
|
end
|
60
58
|
end
|
@@ -84,9 +82,15 @@ def update_environment(root, name)
|
|
84
82
|
environment_path = self.environment_path(root, name)
|
85
83
|
FileUtils.mkpath File.dirname(environment_path)
|
86
84
|
|
87
|
-
|
85
|
+
if File.exist?(environment_path)
|
86
|
+
store = YAML.load_file(environment_path)
|
87
|
+
else
|
88
|
+
store = Hash.new
|
89
|
+
end
|
90
|
+
|
91
|
+
yield store, name, environment_path
|
88
92
|
|
89
|
-
|
90
|
-
|
93
|
+
File.open(environment_path, "w") do |file|
|
94
|
+
YAML.dump(store, file)
|
91
95
|
end
|
92
96
|
end
|
data/bake/utopia/node.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2016-
|
4
|
+
# Copyright, 2016-2025, by Samuel Williams.
|
5
5
|
|
6
6
|
def update
|
7
|
-
require
|
8
|
-
require
|
7
|
+
require "fileutils"
|
8
|
+
require "utopia/path"
|
9
9
|
|
10
10
|
root = Pathname.new(context.root)
|
11
11
|
package_root = root + "node_modules"
|
@@ -23,7 +23,7 @@ def update
|
|
23
23
|
package_directory = package_path.relative_path_from(package_root)
|
24
24
|
install_path = install_root + package_directory
|
25
25
|
|
26
|
-
dist_path = package_path +
|
26
|
+
dist_path = package_path + "dist"
|
27
27
|
|
28
28
|
FileUtils::Verbose.rm_rf(install_path)
|
29
29
|
FileUtils::Verbose.mkpath(install_path.dirname)
|
@@ -47,7 +47,7 @@ def expand_package_paths(root, into = [])
|
|
47
47
|
paths.each do |path|
|
48
48
|
basename = path.basename.to_s
|
49
49
|
# Handle organisation sub-directories which start with an '@' symbol:
|
50
|
-
if basename.start_with?(
|
50
|
+
if basename.start_with?("@")
|
51
51
|
expand_package_paths(path, into)
|
52
52
|
else
|
53
53
|
into << path
|
data/bake/utopia/server.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2017-
|
4
|
+
# Copyright, 2017-2025, by Samuel Williams.
|
5
5
|
|
6
6
|
def initialize(...)
|
7
7
|
super
|
8
8
|
|
9
|
-
require
|
10
|
-
require
|
9
|
+
require "fileutils"
|
10
|
+
require "socket"
|
11
11
|
end
|
12
12
|
|
13
13
|
# Create a remote Utopia website suitable for deployment using git.
|
@@ -25,7 +25,7 @@ end
|
|
25
25
|
SETUP_ROOT = File.expand_path("../../setup", __dir__)
|
26
26
|
|
27
27
|
# The root directory of the template server deployment:
|
28
|
-
SERVER_ROOT = File.join(SETUP_ROOT,
|
28
|
+
SERVER_ROOT = File.join(SETUP_ROOT, "server")
|
29
29
|
|
30
30
|
# Update the git hooks in an existing server repository.
|
31
31
|
def update(root: context.root)
|
@@ -49,13 +49,13 @@ def update(root: context.root)
|
|
49
49
|
# Set some useful defaults for the environment.
|
50
50
|
recipe = context.lookup("utopia:environment:update")
|
51
51
|
recipe.instance.update("environment", root: root) do |store|
|
52
|
-
store[
|
53
|
-
store[
|
52
|
+
store["VARIANT"] ||= "production"
|
53
|
+
store["UTOPIA_SESSION_SECRET"] ||= SecureRandom.hex(40)
|
54
54
|
end
|
55
55
|
|
56
56
|
# Copy git hooks:
|
57
|
-
system("cp", "-r", File.join(SERVER_ROOT,
|
57
|
+
system("cp", "-r", File.join(SERVER_ROOT, "git", "hooks"), File.join(root, ".git")) or fail "could not copy git hooks"
|
58
58
|
# finally set everything in the .git directory to be group writable
|
59
59
|
# This failed for me and I had to do sudo chown http:http .git -R first.
|
60
|
-
system("chmod", "-Rf", "g+w", File.join(root,
|
60
|
+
system("chmod", "-Rf", "g+w", File.join(root, ".git")) or fail "could not update permissions of .git directory"
|
61
61
|
end
|
data/bake/utopia/shell.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2020-
|
4
|
+
# Copyright, 2020-2025, by Samuel Williams.
|
5
5
|
|
6
6
|
def shell
|
7
|
-
call
|
7
|
+
call "utopia:environment"
|
8
8
|
|
9
|
-
require
|
9
|
+
require "utopia/shell"
|
10
10
|
|
11
11
|
binding = Utopia::Shell.new(self.context).binding
|
12
12
|
|
data/bake/utopia/site.rb
CHANGED
@@ -1,24 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2017-
|
4
|
+
# Copyright, 2017-2025, by Samuel Williams.
|
5
5
|
# Copyright, 2020, by Michael Adams.
|
6
6
|
|
7
7
|
def initialize(...)
|
8
8
|
super
|
9
9
|
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
10
|
+
require "fileutils"
|
11
|
+
require "find"
|
12
|
+
require "console"
|
13
13
|
|
14
|
-
require_relative
|
14
|
+
require_relative "../../lib/utopia/version"
|
15
15
|
end
|
16
16
|
|
17
17
|
# The path to the setup directory in the gem:
|
18
18
|
SETUP_ROOT = File.expand_path("../../setup", __dir__)
|
19
19
|
|
20
20
|
# Configuration files which should be installed/updated:
|
21
|
-
CONFIGURATION_FILES = [
|
21
|
+
CONFIGURATION_FILES = [".gitignore", "config.ru", "config/environment.rb", "falcon.rb", "gems.rb", "Guardfile", "bake.rb", "test/website.rb", "fixtures/website.rb"]
|
22
22
|
|
23
23
|
# Directories that should exist:
|
24
24
|
DIRECTORIES = ["config", "lib", "pages", "public", "bake", "fixtures", "test"]
|
@@ -27,7 +27,7 @@ DIRECTORIES = ["config", "lib", "pages", "public", "bake", "fixtures", "test"]
|
|
27
27
|
OLD_PATHS = ["access_log", "cache", "tmp", "Rakefile", "tasks", ".bowerrc"]
|
28
28
|
|
29
29
|
# The root directory of the template site:
|
30
|
-
SITE_ROOT = File.join(SETUP_ROOT,
|
30
|
+
SITE_ROOT = File.join(SETUP_ROOT, "site")
|
31
31
|
|
32
32
|
# Create a new local Utopia website using the default template.
|
33
33
|
def create(root: context.root)
|
@@ -56,7 +56,7 @@ def create(root: context.root)
|
|
56
56
|
destination_path = File.join(root, configuration_file)
|
57
57
|
|
58
58
|
if File.exist?(destination_path)
|
59
|
-
buffer = File.read(destination_path).gsub(
|
59
|
+
buffer = File.read(destination_path).gsub("$UTOPIA_VERSION", Utopia::VERSION)
|
60
60
|
File.open(destination_path, "w") { |file| file.write(buffer) }
|
61
61
|
else
|
62
62
|
Console.warn(self) {"Could not open #{destination_path}, maybe it should be removed from CONFIGURATION_FILES?"}
|
@@ -65,9 +65,9 @@ def create(root: context.root)
|
|
65
65
|
|
66
66
|
system("bundle", "install", chdir: root) or warn "could not install bundled gems"
|
67
67
|
|
68
|
-
context.lookup(
|
68
|
+
context.lookup("utopia:environment:setup").call(root: root)
|
69
69
|
|
70
|
-
if !File.exist?(
|
70
|
+
if !File.exist?(".git")
|
71
71
|
Console.info(self) {"Setting up git repository..."}
|
72
72
|
|
73
73
|
system("git", "init", chdir: root) or warn "could not create git repository"
|
@@ -118,11 +118,11 @@ def upgrade(root: context.root)
|
|
118
118
|
Console.info(self) {"Updating #{destination_path}..."}
|
119
119
|
|
120
120
|
FileUtils.copy_entry(source_path, destination_path)
|
121
|
-
buffer = File.read(destination_path).gsub(
|
121
|
+
buffer = File.read(destination_path).gsub("$UTOPIA_VERSION", Utopia::VERSION)
|
122
122
|
File.open(destination_path, "w") { |file| file.write(buffer) }
|
123
123
|
end
|
124
124
|
|
125
|
-
context.lookup(
|
125
|
+
context.lookup("utopia:environment:setup").call(root: root)
|
126
126
|
|
127
127
|
# Stage any files that have been changed or removed:
|
128
128
|
system("git", "add", "-u", chdir: root) or fail "could not add files"
|
@@ -155,12 +155,12 @@ end
|
|
155
155
|
|
156
156
|
# Move legacy `pages/_static` to `public/_static`.
|
157
157
|
def move_static!(root)
|
158
|
-
old_static_path = File.expand_path(
|
158
|
+
old_static_path = File.expand_path("pages/_static", root)
|
159
159
|
|
160
160
|
# If public/_static doens't exist, we are done.
|
161
161
|
return unless File.exist?(old_static_path)
|
162
162
|
|
163
|
-
new_static_path = File.expand_path(
|
163
|
+
new_static_path = File.expand_path("public/_static", root)
|
164
164
|
|
165
165
|
if File.exist?(new_static_path)
|
166
166
|
if File.lstat(new_static_path).symlink?
|
@@ -179,13 +179,13 @@ end
|
|
179
179
|
|
180
180
|
# Move `Gemfile` to `gems.rb`.
|
181
181
|
def update_gemfile!(root)
|
182
|
-
gemfile_path = File.expand_path(
|
182
|
+
gemfile_path = File.expand_path("Gemfile", root)
|
183
183
|
|
184
184
|
# If `Gemfile` doens't exist, we are done:
|
185
185
|
return unless File.exist?(gemfile_path)
|
186
186
|
|
187
187
|
# If `gems.rb` already exists, we are done:
|
188
|
-
gems_path = File.expand_path(
|
188
|
+
gems_path = File.expand_path("gems.rb", root)
|
189
189
|
return if File.exist?(gems_path)
|
190
190
|
|
191
191
|
system("git", "mv", "Gemfile", "gems.rb", chdir: root)
|
data/bake/utopia/static.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2017-
|
4
|
+
# Copyright, 2017-2025, by Samuel Williams.
|
5
5
|
|
6
|
-
def generate(output_path:
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
6
|
+
def generate(output_path: "static")
|
7
|
+
require "falcon/server"
|
8
|
+
require "async/io"
|
9
|
+
require "async/http/endpoint"
|
10
|
+
require "async/container"
|
11
11
|
|
12
|
-
config_path = File.join(Dir.pwd,
|
12
|
+
config_path = File.join(Dir.pwd, "config.ru")
|
13
13
|
container_class = Async::Container::Threaded
|
14
14
|
server_port = 9090
|
15
15
|
|
@@ -33,7 +33,7 @@ def generate(output_path: 'static')
|
|
33
33
|
|
34
34
|
# Copy all public assets:
|
35
35
|
FileUtils::Verbose.mkpath(output_path)
|
36
|
-
Dir.glob(File.join(Dir.pwd,
|
36
|
+
Dir.glob(File.join(Dir.pwd, "public/*")) do |path|
|
37
37
|
FileUtils::Verbose.cp_r(path, output_path)
|
38
38
|
end
|
39
39
|
|
data/bake/utopia.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2017-
|
4
|
+
# Copyright, 2017-2025, by Samuel Williams.
|
5
5
|
|
6
6
|
def environment(name: nil)
|
7
7
|
if name
|
8
|
-
ENV[
|
8
|
+
ENV["UTOPIA_ENV"] = name
|
9
9
|
end
|
10
10
|
|
11
|
-
require File.expand_path(
|
11
|
+
require File.expand_path("config/environment", context.root)
|
12
12
|
end
|
13
13
|
|
14
14
|
# Start the development server.
|
15
15
|
def development
|
16
16
|
self.environment
|
17
17
|
|
18
|
-
exec(
|
18
|
+
exec("guard", "-g", "development")
|
19
19
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2015-
|
4
|
+
# Copyright, 2015-2025, by Samuel Williams.
|
5
5
|
|
6
|
-
require_relative
|
7
|
-
require_relative
|
8
|
-
require_relative
|
6
|
+
require_relative "links"
|
7
|
+
require_relative "response"
|
8
|
+
require_relative "markup"
|
9
9
|
|
10
10
|
module Utopia
|
11
11
|
class Content
|
data/lib/utopia/content/link.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2009-
|
4
|
+
# Copyright, 2009-2025, by Samuel Williams.
|
5
5
|
# Copyright, 2017, by Huba Nagy.
|
6
6
|
# Copyright, 2020, by Michael Adams.
|
7
7
|
|
8
|
-
require
|
9
|
-
require
|
8
|
+
require "yaml"
|
9
|
+
require "xrb/builder"
|
10
10
|
|
11
|
-
require
|
11
|
+
require "xrb/strings"
|
12
12
|
|
13
|
-
require_relative
|
14
|
-
require_relative
|
13
|
+
require_relative "../path"
|
14
|
+
require_relative "../locale"
|
15
15
|
|
16
16
|
module Utopia
|
17
17
|
class Content
|
@@ -75,7 +75,7 @@ module Utopia
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def relative_href(base = nil)
|
78
|
-
if base and href.start_with?
|
78
|
+
if base and href.start_with? "/"
|
79
79
|
Path.shortest_path(href, base)
|
80
80
|
else
|
81
81
|
href
|
@@ -87,18 +87,18 @@ module Utopia
|
|
87
87
|
end
|
88
88
|
|
89
89
|
def to_anchor(base: nil, content: self.title, builder: nil, **attributes)
|
90
|
-
attributes[:class] ||=
|
90
|
+
attributes[:class] ||= "link"
|
91
91
|
|
92
92
|
XRB::Builder.fragment(builder) do |inner_builder|
|
93
93
|
if href?
|
94
94
|
attributes[:href] ||= relative_href(base)
|
95
95
|
attributes[:target] ||= @info[:target]
|
96
96
|
|
97
|
-
inner_builder.inline(
|
97
|
+
inner_builder.inline("a", attributes) do
|
98
98
|
inner_builder.text(content)
|
99
99
|
end
|
100
100
|
else
|
101
|
-
inner_builder.inline(
|
101
|
+
inner_builder.inline("span", attributes) do
|
102
102
|
inner_builder.text(content)
|
103
103
|
end
|
104
104
|
end
|
data/lib/utopia/content/links.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2015-
|
4
|
+
# Copyright, 2015-2025, by Samuel Williams.
|
5
5
|
|
6
|
-
require_relative
|
6
|
+
require_relative "link"
|
7
7
|
|
8
|
-
require
|
8
|
+
require "concurrent/map"
|
9
9
|
|
10
10
|
module Utopia
|
11
11
|
class Content
|
12
12
|
# The file extension for markup nodes on disk.
|
13
|
-
XNODE_EXTENSION =
|
13
|
+
XNODE_EXTENSION = ".xnode"
|
14
14
|
INDEX = "index"
|
15
15
|
|
16
16
|
class Links
|
@@ -263,7 +263,7 @@ module Utopia
|
|
263
263
|
|
264
264
|
# After processing all directory entries, we are left with virtual links:
|
265
265
|
metadata.each do |key, info|
|
266
|
-
name, locale = key.split(
|
266
|
+
name, locale = key.split(".", 2)
|
267
267
|
localized = (virtuals[name] ||= {})
|
268
268
|
localized[locale] = info
|
269
269
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2009-
|
4
|
+
# Copyright, 2009-2025, by Samuel Williams.
|
5
5
|
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
6
|
+
require "xrb/parsers"
|
7
|
+
require "xrb/entities"
|
8
|
+
require "xrb/strings"
|
9
|
+
require "xrb/tag"
|
10
10
|
|
11
11
|
module Utopia
|
12
12
|
class Content
|
@@ -153,7 +153,7 @@ module Utopia
|
|
153
153
|
end
|
154
154
|
|
155
155
|
def cdata(string)
|
156
|
-
@delegate.
|
156
|
+
@delegate.write(string[9..-4])
|
157
157
|
end
|
158
158
|
|
159
159
|
def text(string)
|
data/lib/utopia/content/node.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2009-
|
4
|
+
# Copyright, 2009-2025, by Samuel Williams.
|
5
5
|
# Copyright, 2015, by Huba Nagy.
|
6
6
|
|
7
|
-
require_relative
|
8
|
-
require_relative
|
7
|
+
require_relative "markup"
|
8
|
+
require_relative "links"
|
9
9
|
|
10
|
-
require_relative
|
10
|
+
require_relative "document"
|
11
11
|
|
12
|
-
require
|
12
|
+
require "pathname"
|
13
13
|
|
14
14
|
module Utopia
|
15
15
|
class Content
|
@@ -35,7 +35,7 @@ module Utopia
|
|
35
35
|
@controller.lookup_node(parent_path + Path[path])
|
36
36
|
end
|
37
37
|
|
38
|
-
def local_path(path =
|
38
|
+
def local_path(path = ".", base = nil)
|
39
39
|
path = Path[path]
|
40
40
|
|
41
41
|
root = Pathname.new(@controller.root)
|
@@ -48,7 +48,7 @@ module Utopia
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
def relative_path(path =
|
51
|
+
def relative_path(path = ".")
|
52
52
|
path = Path[path]
|
53
53
|
base = uri_path.dirname
|
54
54
|
|
@@ -59,7 +59,7 @@ module Utopia
|
|
59
59
|
@uri_path.dirname
|
60
60
|
end
|
61
61
|
|
62
|
-
def links(path =
|
62
|
+
def links(path = ".", **options, &block)
|
63
63
|
path = uri_path.dirname + Path[path]
|
64
64
|
|
65
65
|
links = @controller.links(path, **options)
|
@@ -1,15 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2010-
|
4
|
+
# Copyright, 2010-2025, by Samuel Williams.
|
5
5
|
|
6
6
|
module Utopia
|
7
7
|
class Content
|
8
8
|
# Compatibility with older versions of rack:
|
9
|
-
EXPIRES =
|
10
|
-
CACHE_CONTROL =
|
11
|
-
CONTENT_TYPE =
|
12
|
-
NO_CACHE =
|
9
|
+
EXPIRES = "expires".freeze
|
10
|
+
CACHE_CONTROL = "cache-control".freeze
|
11
|
+
CONTENT_TYPE = "content-type".freeze
|
12
|
+
NO_CACHE = "no-cache".freeze
|
13
13
|
|
14
14
|
# A basic content response, including useful defaults for typical HTML5 content.
|
15
15
|
class Response
|
data/lib/utopia/content/tags.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2012-
|
4
|
+
# Copyright, 2012-2025, by Samuel Williams.
|
5
5
|
|
6
|
-
require_relative
|
6
|
+
require_relative "namespace"
|
7
7
|
|
8
|
-
require
|
8
|
+
require "variant"
|
9
9
|
|
10
10
|
module Utopia
|
11
11
|
class Content
|
@@ -15,7 +15,7 @@ module Utopia
|
|
15
15
|
|
16
16
|
# Invokes a node and renders a single node to the output stream.
|
17
17
|
# @param path [String] The path of the node to invoke.
|
18
|
-
tag(
|
18
|
+
tag("node") do |document, state|
|
19
19
|
path = Path[state[:path]]
|
20
20
|
|
21
21
|
node = document.lookup_node(path)
|
@@ -25,7 +25,7 @@ module Utopia
|
|
25
25
|
|
26
26
|
# Invokes a deferred tag from the current state. Works together with {Document::State#defer}.
|
27
27
|
# @param id [String] The id of the deferred to invoke.
|
28
|
-
tag(
|
28
|
+
tag("deferred") do |document, state|
|
29
29
|
id = state[:id].to_i
|
30
30
|
|
31
31
|
deferred = document.parent.deferred[id]
|
@@ -34,19 +34,19 @@ module Utopia
|
|
34
34
|
end
|
35
35
|
|
36
36
|
# Renders the content of the parent node into the output of the document.
|
37
|
-
tag(
|
37
|
+
tag("content") do |document, state|
|
38
38
|
# We are invoking this node within a parent who has content, and we want to generate output equal to that.
|
39
39
|
document.write(document.parent.content)
|
40
40
|
end
|
41
41
|
|
42
42
|
# Render the contents only if in the correct environment.
|
43
43
|
# @param only [String] A comma separated list of environments to check.
|
44
|
-
tag(
|
44
|
+
tag("environment") do |document, state|
|
45
45
|
variant = document.attributes.fetch(:variant) do
|
46
46
|
Variant.for(:utopia)
|
47
47
|
end.to_s
|
48
48
|
|
49
|
-
if state[:only].split(
|
49
|
+
if state[:only].split(",").include?(variant)
|
50
50
|
document.parse_markup(state.content)
|
51
51
|
end
|
52
52
|
end
|
data/lib/utopia/content.rb
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2009-
|
4
|
+
# Copyright, 2009-2025, by Samuel Williams.
|
5
5
|
|
6
|
-
require_relative
|
7
|
-
require_relative
|
6
|
+
require_relative "middleware"
|
7
|
+
require_relative "localization"
|
8
8
|
|
9
|
-
require_relative
|
10
|
-
require_relative
|
11
|
-
require_relative
|
12
|
-
require_relative
|
9
|
+
require_relative "content/links"
|
10
|
+
require_relative "content/node"
|
11
|
+
require_relative "content/markup"
|
12
|
+
require_relative "content/tags"
|
13
13
|
|
14
|
-
require
|
14
|
+
require "xrb/template"
|
15
15
|
|
16
|
-
require
|
16
|
+
require "concurrent/map"
|
17
17
|
|
18
|
-
require
|
18
|
+
require "traces/provider"
|
19
19
|
|
20
20
|
module Utopia
|
21
21
|
# A middleware which serves dynamically generated content based on markup files.
|
22
22
|
class Content
|
23
|
-
CONTENT_NAMESPACE =
|
24
|
-
UTOPIA_NAMESPACE =
|
25
|
-
DEFERRED_TAG_NAME =
|
26
|
-
CONTENT_TAG_NAME =
|
23
|
+
CONTENT_NAMESPACE = "content".freeze
|
24
|
+
UTOPIA_NAMESPACE = "utopia".freeze
|
25
|
+
DEFERRED_TAG_NAME = "utopia:deferred".freeze
|
26
|
+
CONTENT_TAG_NAME = "utopia:content".freeze
|
27
27
|
|
28
28
|
# @param root [String] The content root where pages will be generated from.
|
29
29
|
# @param namespaces [Hash<String,Library>] Tag namespaces for dynamic tag lookup.
|
@@ -130,7 +130,7 @@ module Utopia
|
|
130
130
|
private
|
131
131
|
|
132
132
|
def lookup_content(name, parent_path)
|
133
|
-
if String === name && name.index(
|
133
|
+
if String === name && name.index("/")
|
134
134
|
name = Path.create(name)
|
135
135
|
end
|
136
136
|
|
@@ -152,7 +152,7 @@ module Utopia
|
|
152
152
|
end
|
153
153
|
|
154
154
|
if String === name_path
|
155
|
-
tag_path = File.join(@root, components,
|
155
|
+
tag_path = File.join(@root, components, "_" + name_path)
|
156
156
|
|
157
157
|
if File.exist? tag_path
|
158
158
|
return Node.new(self, Path[components] + name, parent_path + name, tag_path)
|
@@ -186,8 +186,8 @@ module Utopia
|
|
186
186
|
Traces::Provider(Content) do
|
187
187
|
def respond(link, request)
|
188
188
|
attributes = {
|
189
|
-
|
190
|
-
|
189
|
+
"link.key" => link.key,
|
190
|
+
"link.href" => link.href
|
191
191
|
}
|
192
192
|
|
193
193
|
Traces.trace("utopia.content.respond", attributes: attributes) {super}
|