bridgetown-routes 1.2.0.beta2 → 1.2.0.beta4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bridgetown-routes/manifest.rb +26 -1
- data/lib/bridgetown-routes/manifest_router.rb +29 -16
- data/lib/roda/plugins/bridgetown_routes.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d25f883860757364304b62c272eda2e32a75f89b0822d0dcacb1cffbd9b520bc
|
4
|
+
data.tar.gz: aa1c4341ecfaa9d337d233d2e7cff360aa45784d39e67152c400d84c94c63c7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54f32ecbd983c9beec9b010ba27208c6c68811d837bb9a44b7e2057ffc6b9d0acb7414d6e967fe3e5d22a2442d4fb02ecd83acf6cea1cce505b0053b595c71d0
|
7
|
+
data.tar.gz: fc1e5cafcbcbe048ca6e49bea10c0f026efa42ca2c7d678c539db22e921448b963cd1f25069c7a22f814c691ef80088a9c27d060c52d590514d52cebc20aa98e
|
@@ -32,7 +32,10 @@ module Bridgetown
|
|
32
32
|
":#{Regexp.last_match(1)}"
|
33
33
|
end
|
34
34
|
|
35
|
-
|
35
|
+
# generate localized file slugs
|
36
|
+
localized_file_slugs = generate_localized_file_slugs(site, file_slug)
|
37
|
+
|
38
|
+
[file, localized_file_slugs, segment_keys]
|
36
39
|
end
|
37
40
|
|
38
41
|
new_manifest += sort_routes!(routes)
|
@@ -57,6 +60,28 @@ module Bridgetown
|
|
57
60
|
end
|
58
61
|
end.reverse!
|
59
62
|
end
|
63
|
+
|
64
|
+
def locale_for(slug, site)
|
65
|
+
possible_locale_segment = slug.split("/").first.to_sym
|
66
|
+
|
67
|
+
if site.config.available_locales.include? possible_locale_segment
|
68
|
+
possible_locale_segment
|
69
|
+
else
|
70
|
+
site.config.default_locale
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def generate_localized_file_slugs(site, file_slug)
|
77
|
+
site.config.available_locales.map do |locale|
|
78
|
+
if locale == site.config.default_locale && !site.config.prefix_default_locale
|
79
|
+
file_slug
|
80
|
+
else
|
81
|
+
"#{locale}/#{file_slug}"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
60
85
|
end
|
61
86
|
end
|
62
87
|
end
|
@@ -16,27 +16,40 @@ module Bridgetown
|
|
16
16
|
end
|
17
17
|
|
18
18
|
Bridgetown::Routes::Manifest.generate_manifest(bridgetown_site).each do |route|
|
19
|
-
file,
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
# eval_route_file caches when Bridgetown.env.production?
|
24
|
-
Bridgetown::Routes::CodeBlocks.eval_route_file file, file_slug, @_roda_app
|
25
|
-
|
26
|
-
segment_values.each_with_index do |value, index|
|
27
|
-
r.params[segment_keys[index]] ||= value
|
28
|
-
end
|
29
|
-
|
30
|
-
route_block = Bridgetown::Routes::CodeBlocks.route_block(file_slug)
|
31
|
-
response.instance_variable_set(
|
32
|
-
:@_route_file_code, route_block.instance_variable_get(:@_route_file_code)
|
33
|
-
) # could be nil
|
34
|
-
@_roda_app.instance_exec(r, &route_block)
|
19
|
+
file, localized_file_slugs, segment_keys = route
|
20
|
+
|
21
|
+
localized_file_slugs.each do |file_slug|
|
22
|
+
add_route(r, file, file_slug, segment_keys)
|
35
23
|
end
|
36
24
|
end
|
37
25
|
|
38
26
|
nil
|
39
27
|
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def add_route(route, file, file_slug, segment_keys)
|
32
|
+
route.on file_slug do |*segment_values|
|
33
|
+
response["X-Bridgetown-SSR"] = "1"
|
34
|
+
# eval_route_file caches when Bridgetown.env.production?
|
35
|
+
Bridgetown::Routes::CodeBlocks.eval_route_file file, file_slug, @_roda_app
|
36
|
+
|
37
|
+
segment_values.each_with_index do |value, index|
|
38
|
+
route.params[segment_keys[index]] ||= value
|
39
|
+
end
|
40
|
+
|
41
|
+
# set route locale
|
42
|
+
locale = Bridgetown::Routes::Manifest.locale_for(file_slug, bridgetown_site)
|
43
|
+
I18n.locale = locale
|
44
|
+
route.params[:locale] = locale
|
45
|
+
|
46
|
+
route_block = Bridgetown::Routes::CodeBlocks.route_block(file_slug)
|
47
|
+
response.instance_variable_set(
|
48
|
+
:@_route_file_code, route_block.instance_variable_get(:@_route_file_code)
|
49
|
+
) # could be nil
|
50
|
+
@_roda_app.instance_exec(route, &route_block)
|
51
|
+
end
|
52
|
+
end
|
40
53
|
end
|
41
54
|
end
|
42
55
|
end
|
@@ -21,7 +21,7 @@ class Roda
|
|
21
21
|
app.plugin :slash_path_empty # now /hello and /hello/ are both matched
|
22
22
|
app.plugin :placeholder_string_matchers
|
23
23
|
app.plugin :flash
|
24
|
-
app.plugin :route_csrf
|
24
|
+
app.plugin :route_csrf
|
25
25
|
end
|
26
26
|
|
27
27
|
def self.configure(app, _opts = {})
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bridgetown-routes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.0.
|
4
|
+
version: 1.2.0.beta4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bridgetown Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bridgetown-core
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.2.0.
|
19
|
+
version: 1.2.0.beta4
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.2.0.
|
26
|
+
version: 1.2.0.beta4
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: roda-route_list
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|