seiten 1.0.2 → 1.1.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
- data/lib/seiten/page.rb +33 -1
- data/lib/seiten/routes_helper.rb +1 -1
- data/lib/seiten/version.rb +1 -1
- data/test/dummy/config/initializers/new_framework_defaults.rb +0 -4
- data/test/dummy/log/test.log +1750 -44482
- data/test/dummy/tmp/local_secret.txt +1 -0
- data/test/integration/navigation_test.rb +4 -6
- data/test/lib/seiten/page_translation_test.rb +64 -0
- metadata +11 -12
- data/test/dummy/log/development.log +0 -1716
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f11b589f94032def9f0ef35b5fd457e1acb0f3508cf39f1ac63fb0338ee8217a
|
|
4
|
+
data.tar.gz: 71e0543f85e054dac2cf348e6e9ecf1eebde83d1659921dca8c4460a734665b6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 186fe751f440f15e30944acc416a9dfac931bcf1afd0f65c4f58ba5b6e7c8a0ebd3fab9e8ad39260c39aebc26de7769cb5b829c4b05c7f35c30407806a97577a
|
|
7
|
+
data.tar.gz: 133f9dd5ac075f2805088865e309183c453a2e889b0cc090c970db1e94076e603f4a60a8f249685b97d674741b857a6e78112ce33f356c0e3aaaa64e73b1d8b5
|
data/lib/seiten/page.rb
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
module Seiten
|
|
4
4
|
class Page
|
|
5
|
-
attr_accessor :navigation_id, :id, :parent_id, :title, :slug, :refer, :data, :html_options
|
|
5
|
+
attr_accessor :navigation_id, :id, :parent_id, :title, :slug, :refer, :key, :data, :html_options
|
|
6
6
|
attr_writer :layout
|
|
7
7
|
|
|
8
8
|
# initialize Page object with attributes
|
|
@@ -13,6 +13,7 @@ module Seiten
|
|
|
13
13
|
@title = options[:title]
|
|
14
14
|
@slug = options[:slug]
|
|
15
15
|
@refer = options[:refer]
|
|
16
|
+
@key = options[:key]&.to_s
|
|
16
17
|
@layout = options[:layout]
|
|
17
18
|
@data = options[:data].each_with_object({}){|(k,v), h| h[k.to_sym] = v} if options[:data]
|
|
18
19
|
@data ||= {}
|
|
@@ -71,6 +72,37 @@ module Seiten
|
|
|
71
72
|
end
|
|
72
73
|
end
|
|
73
74
|
|
|
75
|
+
# The page's place in its navigation tree: the index among its siblings, from the root down
|
|
76
|
+
# (e.g. [2, 0] for the first child of the third top-level page).
|
|
77
|
+
def position
|
|
78
|
+
@position ||= (parent ? parent.position : []) + [navigation.pages.where(parent_id: parent_id).index(self)]
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# The same page in the navigation of the same name in another locale: the page at the same
|
|
82
|
+
# position, or, for a page with a `key`, the page with the same key. Nil when there is none.
|
|
83
|
+
def translation(locale)
|
|
84
|
+
locale = locale.to_s
|
|
85
|
+
return self if locale == navigation.locale
|
|
86
|
+
|
|
87
|
+
other = Seiten::Navigation.find_by(name: navigation.name, locale: locale)
|
|
88
|
+
return unless other
|
|
89
|
+
|
|
90
|
+
if key
|
|
91
|
+
other.pages.find_by(key: key)
|
|
92
|
+
else
|
|
93
|
+
page = other.pages.all.find { |candidate| candidate.position == position }
|
|
94
|
+
page unless page&.key
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# This page in every locale that has it, by locale (including its own).
|
|
99
|
+
def translations
|
|
100
|
+
Seiten::Navigation.where(name: navigation.name).each_with_object({}) do |other, translations|
|
|
101
|
+
page = translation(other.locale)
|
|
102
|
+
translations[other.locale] = page if page
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
74
106
|
# get children of page
|
|
75
107
|
def children
|
|
76
108
|
navigation.pages.where(parent_id: id)
|
data/lib/seiten/routes_helper.rb
CHANGED
|
@@ -15,7 +15,7 @@ class ActionDispatch::Routing::Mapper
|
|
|
15
15
|
# NOTE: See https://github.com/rails/rails/issues/31228
|
|
16
16
|
resource_options[:constraints] ||= ->(req) { req.path.exclude? 'rails/active_storage' }
|
|
17
17
|
|
|
18
|
-
get '(*slug)', resource_options
|
|
18
|
+
get '(*slug)', **resource_options
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
21
|
end
|
data/lib/seiten/version.rb
CHANGED
|
@@ -12,9 +12,5 @@ Rails.application.config.action_controller.per_form_csrf_tokens = false
|
|
|
12
12
|
# Enable origin-checking CSRF mitigation. Previous versions had false.
|
|
13
13
|
Rails.application.config.action_controller.forgery_protection_origin_check = false
|
|
14
14
|
|
|
15
|
-
# Make Ruby 2.4 preserve the timezone of the receiver when calling `to_time`.
|
|
16
|
-
# Previous versions had false.
|
|
17
|
-
ActiveSupport.to_time_preserves_timezone = false
|
|
18
|
-
|
|
19
15
|
# Require `belongs_to` associations by default. Previous versions had false.
|
|
20
16
|
# Rails.application.config.active_record.belongs_to_required_by_default = false
|