seiten 1.0.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 83d788eadd214b82c9e91e8da1a0d72d050a7d1bb46c635db58aefffd5f48712
4
- data.tar.gz: 469118c143991e25fcb35e5f5e8d55e58a6255a412e5d5cc40aad031e99f8ff1
3
+ metadata.gz: f11b589f94032def9f0ef35b5fd457e1acb0f3508cf39f1ac63fb0338ee8217a
4
+ data.tar.gz: 71e0543f85e054dac2cf348e6e9ecf1eebde83d1659921dca8c4460a734665b6
5
5
  SHA512:
6
- metadata.gz: 6e1a3a500817fed2ee4f2a9498f8369f0b721e7cc3ce34c4982578cc397f972bb783fa5b964fd9dcce40f0da64954903ac8f77d4fe1b2bb0120bddc9514f90ba
7
- data.tar.gz: da0aeed08ad91cee1183e7a3266f213d047d84a1ebf0ac0c99f240504865ad31f38709e1e6d72ef0be5c37a3952b5df94dd68359b36a5a1051703742580c3897
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)
@@ -27,7 +27,7 @@ module Seiten
27
27
  # Set refer
28
28
  if page["refer"]
29
29
  if page["refer"].is_a?(TrueClass)
30
- page["refer"] = "/" + Seiten::SlugBuilder.call(page["nodes"].first, page["slug"])
30
+ page["refer"] = "/" + Seiten::SlugBuilder.call(page["nodes"].first, slug)
31
31
  end
32
32
  raise Errors::PageError, "The `refer` option must be `true` or an absolute or external path" if page["refer"] != true && page["refer"][0] != "/" && !(page["refer"].match(/^https?:\/\/.+/))
33
33
  else
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Seiten
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -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