spina 2.12.0 → 2.13.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of spina might be problematic. Click here for more details.

Files changed (151) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +17 -17
  3. data/app/assets/builds/spina/tailwind.css +79 -47
  4. data/app/components/spina/application_component.rb +1 -1
  5. data/app/components/spina/forms/group_component.rb +2 -3
  6. data/app/components/spina/forms/label_component.rb +2 -3
  7. data/app/components/spina/forms/password_field_component.rb +1 -1
  8. data/app/components/spina/forms/switch_component.rb +2 -3
  9. data/app/components/spina/forms/text_field_component.rb +8 -9
  10. data/app/components/spina/forms/trix_toolbar_component.rb +1 -3
  11. data/app/components/spina/hooks/hook_component.rb +3 -5
  12. data/app/components/spina/hooks/partial_component.rb +4 -5
  13. data/app/components/spina/main_navigation/link_component.rb +1 -3
  14. data/app/components/spina/main_navigation/sub_nav_component.rb +6 -7
  15. data/app/components/spina/media_picker/image_component.rb +1 -3
  16. data/app/components/spina/media_picker/modal_component.rb +4 -6
  17. data/app/components/spina/pages/actions_component.rb +1 -3
  18. data/app/components/spina/pages/list_component.rb +3 -4
  19. data/app/components/spina/pages/location_component.rb +10 -11
  20. data/app/components/spina/pages/new_page_button_component.rb +4 -5
  21. data/app/components/spina/pages/page_component.rb +8 -9
  22. data/app/components/spina/pages/page_select_component.rb +3 -4
  23. data/app/components/spina/pages/tab_button_component.rb +1 -3
  24. data/app/components/spina/pages/translations_component.rb +9 -11
  25. data/app/components/spina/user_interface/dropdown_button_component.rb +4 -4
  26. data/app/components/spina/user_interface/dropdown_component.rb +8 -9
  27. data/app/components/spina/user_interface/flash_message_component.rb +3 -5
  28. data/app/components/spina/user_interface/header_component.rb +2 -2
  29. data/app/components/spina/user_interface/modal_component.rb +1 -3
  30. data/app/components/spina/user_interface/tab_link_component.rb +1 -3
  31. data/app/components/spina/user_interface/translations_component.rb +8 -10
  32. data/app/controllers/concerns/spina/api/paginable.rb +36 -37
  33. data/app/controllers/concerns/spina/current_spina_account.rb +1 -1
  34. data/app/controllers/concerns/spina/current_theme.rb +6 -7
  35. data/app/controllers/concerns/spina/frontend.rb +58 -44
  36. data/app/controllers/spina/admin/accounts_controller.rb +9 -10
  37. data/app/controllers/spina/admin/admin_controller.rb +18 -18
  38. data/app/controllers/spina/admin/attachments_controller.rb +15 -10
  39. data/app/controllers/spina/admin/embeds_controller.rb +17 -19
  40. data/app/controllers/spina/admin/images_controller.rb +24 -25
  41. data/app/controllers/spina/admin/layout_controller.rb +19 -20
  42. data/app/controllers/spina/admin/media_folders_controller.rb +4 -5
  43. data/app/controllers/spina/admin/media_picker_controller.rb +2 -4
  44. data/app/controllers/spina/admin/move_pages_controller.rb +8 -10
  45. data/app/controllers/spina/admin/navigation_items_controller.rb +13 -14
  46. data/app/controllers/spina/admin/navigations_controller.rb +26 -26
  47. data/app/controllers/spina/admin/page_translations_controller.rb +1 -3
  48. data/app/controllers/spina/admin/pages_controller.rb +34 -34
  49. data/app/controllers/spina/admin/parent_pages_controller.rb +1 -3
  50. data/app/controllers/spina/admin/password_resets_controller.rb +8 -9
  51. data/app/controllers/spina/admin/resources_controller.rb +14 -15
  52. data/app/controllers/spina/admin/sessions_controller.rb +2 -2
  53. data/app/controllers/spina/admin/settings_controller.rb +28 -29
  54. data/app/controllers/spina/admin/theme_controller.rb +10 -11
  55. data/app/controllers/spina/admin/users_controller.rb +28 -29
  56. data/app/controllers/spina/api/api_controller.rb +17 -17
  57. data/app/controllers/spina/api/images_controller.rb +1 -3
  58. data/app/controllers/spina/api/navigations_controller.rb +2 -4
  59. data/app/controllers/spina/api/pages_controller.rb +8 -9
  60. data/app/controllers/spina/api/resources_controller.rb +2 -4
  61. data/app/controllers/spina/application_controller.rb +4 -3
  62. data/app/controllers/spina/pages_controller.rb +4 -5
  63. data/app/controllers/spina/sitemaps_controller.rb +0 -2
  64. data/app/helpers/spina/admin/icons_helper.rb +151 -153
  65. data/app/helpers/spina/admin/images_helper.rb +0 -2
  66. data/app/helpers/spina/admin/pages_helper.rb +3 -5
  67. data/app/helpers/spina/attachments_helper.rb +1 -3
  68. data/app/helpers/spina/images_helper.rb +5 -7
  69. data/app/helpers/spina/pages_helper.rb +0 -2
  70. data/app/helpers/spina/spina_helper.rb +1 -3
  71. data/app/jobs/spina/replace_signed_id_job.rb +10 -11
  72. data/app/jobs/spina/resource_pages_update_job.rb +1 -1
  73. data/app/mailers/spina/application_mailer.rb +2 -2
  74. data/app/mailers/spina/user_mailer.rb +4 -6
  75. data/app/models/concerns/spina/gravatar.rb +11 -12
  76. data/app/models/concerns/spina/partable.rb +4 -6
  77. data/app/models/concerns/spina/translated_content.rb +5 -5
  78. data/app/models/spina/account.rb +9 -10
  79. data/app/models/spina/application_record.rb +2 -3
  80. data/app/models/spina/attachment.rb +3 -4
  81. data/app/models/spina/current.rb +1 -1
  82. data/app/models/spina/embeds/base.rb +2 -2
  83. data/app/models/spina/embeds/button.rb +4 -4
  84. data/app/models/spina/embeds/vimeo.rb +17 -18
  85. data/app/models/spina/embeds/youtube.rb +18 -19
  86. data/app/models/spina/image.rb +4 -4
  87. data/app/models/spina/media_folder.rb +1 -1
  88. data/app/models/spina/navigation.rb +1 -2
  89. data/app/models/spina/navigation_item.rb +2 -2
  90. data/app/models/spina/page.rb +32 -38
  91. data/app/models/spina/parts/attachment.rb +1 -2
  92. data/app/models/spina/parts/base.rb +5 -4
  93. data/app/models/spina/parts/image.rb +3 -4
  94. data/app/models/spina/parts/image_collection.rb +2 -3
  95. data/app/models/spina/parts/image_variant.rb +3 -4
  96. data/app/models/spina/parts/repeater_content.rb +2 -2
  97. data/app/models/spina/resource.rb +3 -4
  98. data/app/models/spina/rewrite_rule.rb +1 -1
  99. data/app/models/spina/setting.rb +0 -2
  100. data/app/models/spina/user.rb +3 -4
  101. data/app/presenters/spina/content_presenter.rb +11 -12
  102. data/app/presenters/spina/menu_presenter.rb +55 -55
  103. data/app/presenters/spina/rich_text_presenter.rb +28 -29
  104. data/app/serializers/spina/api/base_serializer.rb +1 -1
  105. data/app/serializers/spina/api/image_serializer.rb +6 -6
  106. data/app/serializers/spina/api/navigation_serializer.rb +4 -7
  107. data/app/serializers/spina/api/page_serializer.rb +9 -12
  108. data/app/serializers/spina/api/resource_serializer.rb +5 -5
  109. data/app/views/layouts/spina/admin/application.html.erb +1 -0
  110. data/app/views/spina/admin/parts/attachments/_attachment.html.erb +3 -0
  111. data/app/views/spina/admin/parts/attachments/_form.html.erb +22 -1
  112. data/app/views/spina/admin/parts/repeaters/_fields.html.erb +2 -2
  113. data/app/views/spina/admin/parts/repeaters/_form.html.erb +4 -4
  114. data/app/views/spina/admin/shared/_navigation.html.erb +3 -1
  115. data/app/views/spina/admin/shared/_version.html.erb +18 -0
  116. data/app/views/spina/sitemaps/show.xml.builder +1 -1
  117. data/config/initializers/importmap.rb +3 -3
  118. data/config/initializers/yaml_column_permitted_classes.rb +3 -3
  119. data/config/locales/de.yml +1 -0
  120. data/config/locales/en.yml +3 -0
  121. data/config/locales/nl.yml +4 -1
  122. data/config/routes.rb +10 -17
  123. data/db/migrate/1_create_spina_tables.rb +57 -57
  124. data/db/migrate/3_create_spina_navigations.rb +1 -1
  125. data/db/seeds.rb +0 -1
  126. data/lib/generators/spina/embed_generator.rb +5 -6
  127. data/lib/generators/spina/install_generator.rb +48 -41
  128. data/lib/generators/spina/tailwind_config_generator.rb +3 -4
  129. data/lib/generators/spina/templates/app/models/spina/embeds/embed.rb.tt +20 -18
  130. data/lib/generators/spina/templates/config/initializers/spina.rb +11 -11
  131. data/lib/generators/spina/templates/config/initializers/themes/default.rb +17 -17
  132. data/lib/generators/spina/templates/config/initializers/themes/demo.rb +22 -22
  133. data/lib/spina/admin_sectionable.rb +5 -8
  134. data/lib/spina/attr_json_monkeypatch.rb +4 -7
  135. data/lib/spina/attr_json_spina_parts_model.rb +1 -3
  136. data/lib/spina/authentication/basic.rb +9 -10
  137. data/lib/spina/authentication/sessions.rb +10 -11
  138. data/lib/spina/embeddable.rb +14 -17
  139. data/lib/spina/embeds/trix_conversion.rb +25 -26
  140. data/lib/spina/embeds.rb +1 -3
  141. data/lib/spina/engine.rb +18 -19
  142. data/lib/spina/part.rb +1 -6
  143. data/lib/spina/plugin.rb +9 -13
  144. data/lib/spina/railtie.rb +5 -7
  145. data/lib/spina/theme.rb +13 -17
  146. data/lib/spina/theme_reloader.rb +12 -13
  147. data/lib/spina/version.rb +1 -1
  148. data/lib/spina.rb +39 -40
  149. data/lib/tasks/install.rake +8 -14
  150. data/lib/tasks/tailwind.rake +10 -8
  151. metadata +18 -2
@@ -1,29 +1,28 @@
1
1
  module Spina::Pages
2
2
  class LocationComponent < Spina::ApplicationComponent
3
3
  attr_accessor :f
4
-
4
+
5
5
  def initialize(f, page = nil)
6
6
  @f = f
7
7
  @page = page
8
8
  end
9
-
9
+
10
10
  def resources
11
11
  [main_collection_option] + Spina::Resource.order(:label).map do |resource|
12
- [ resource.label, resource.id, data: {
13
- parent_pages_url: helpers.spina.admin_parent_pages_path(resource_id: resource.id)
12
+ [resource.label, resource.id, data: {
13
+ parent_pages_url: helpers.spina.admin_parent_pages_path(resource_id: resource.id)
14
14
  }]
15
15
  end
16
16
  end
17
-
17
+
18
18
  def main_collection_option
19
- [t('spina.pages.main_collection'), nil, data: {
20
- parent_pages_url: helpers.spina.admin_parent_pages_path
21
- }]
19
+ [t("spina.pages.main_collection"), nil, data: {
20
+ parent_pages_url: helpers.spina.admin_parent_pages_path
21
+ }]
22
22
  end
23
-
23
+
24
24
  def default_parent_pages_path
25
25
  helpers.spina.admin_parent_pages_path(resource_id: @page&.resource_id, parent_id: @page&.parent_id, page_id: @page&.id)
26
26
  end
27
-
28
27
  end
29
- end
28
+ end
@@ -1,19 +1,18 @@
1
1
  module Spina::Pages
2
2
  class NewPageButtonComponent < Spina::ApplicationComponent
3
3
  attr_reader :view_templates, :resource
4
-
4
+
5
5
  def initialize(view_templates = [], resource: nil)
6
6
  @view_templates = view_templates
7
7
  @resource = resource
8
8
  end
9
-
9
+
10
10
  def view_template
11
11
  view_templates.first
12
12
  end
13
-
13
+
14
14
  def render?
15
15
  view_templates.any?
16
16
  end
17
-
18
17
  end
19
- end
18
+ end
@@ -2,13 +2,13 @@ module Spina
2
2
  module Pages
3
3
  class PageComponent < ApplicationComponent
4
4
  attr_reader :sortable, :draggable
5
-
5
+
6
6
  def initialize(page:, sortable: true, draggable: true)
7
7
  @page = page
8
8
  @sortable = sortable
9
9
  @draggable = draggable
10
10
  end
11
-
11
+
12
12
  def label
13
13
  labels = []
14
14
  labels << t("spina.pages.concept") if @page.draft?
@@ -17,19 +17,19 @@ module Spina
17
17
  return nil if labels.size.zero?
18
18
  "(#{labels.join(", ")})"
19
19
  end
20
-
20
+
21
21
  def sortable?
22
22
  sortable
23
23
  end
24
-
24
+
25
25
  def draggable?
26
26
  draggable
27
27
  end
28
-
28
+
29
29
  def depth
30
30
  @page.depth
31
31
  end
32
-
32
+
33
33
  def css_class
34
34
  case depth
35
35
  when 1
@@ -38,11 +38,10 @@ module Spina
38
38
  "pl-10 bg-gray-200"
39
39
  end
40
40
  end
41
-
41
+
42
42
  def children
43
43
  @children ||= @page.children.active.sorted
44
44
  end
45
-
46
45
  end
47
46
  end
48
- end
47
+ end
@@ -1,7 +1,7 @@
1
1
  module Spina::Pages
2
2
  class PageSelectComponent < Spina::ApplicationComponent
3
3
  attr_accessor :name, :pages, :include_blank, :selected, :disabled
4
-
4
+
5
5
  def initialize(name, pages, include_blank: false, selected: nil, disabled: nil)
6
6
  @name = name
7
7
  @pages = pages
@@ -9,13 +9,12 @@ module Spina::Pages
9
9
  @selected = selected
10
10
  @disabled = disabled
11
11
  end
12
-
12
+
13
13
  def options
14
14
  Spina::Page.sort_by_ancestry(pages.arrange(order: :position)).map do |page|
15
- page_menu_title = page.menu_title.indent(page.depth, '')
15
+ page_menu_title = page.menu_title.indent(page.depth, "")
16
16
  [page_menu_title, page.id]
17
17
  end
18
18
  end
19
-
20
19
  end
21
20
  end
@@ -1,11 +1,9 @@
1
1
  module Spina
2
2
  module Pages
3
3
  class TabButtonComponent < ApplicationComponent
4
-
5
4
  def initialize(tab_name:)
6
5
  @tab_name = tab_name
7
6
  end
8
-
9
7
  end
10
8
  end
11
- end
9
+ end
@@ -1,32 +1,30 @@
1
1
  module Spina
2
2
  module Pages
3
3
  class TranslationsComponent < ApplicationComponent
4
-
5
4
  def initialize(page, label: nil)
6
5
  @page = page
7
6
  @label = label
8
7
  end
9
-
8
+
10
9
  def render?
11
10
  spina_locales.many?
12
11
  end
13
-
12
+
14
13
  def missing_locales
15
14
  spina_locales - existing_locales
16
15
  end
17
-
16
+
18
17
  def existing_locales
19
18
  @existing_locales ||= @page.translations.pluck(:locale).map(&:to_sym).sort_by do |locale|
20
19
  spina_locales.index(locale)
21
20
  end
22
21
  end
23
-
22
+
24
23
  private
25
-
26
- def spina_locales
27
- Spina.locales.map(&:to_sym)
28
- end
29
-
24
+
25
+ def spina_locales
26
+ Spina.locales.map(&:to_sym)
27
+ end
30
28
  end
31
29
  end
32
- end
30
+ end
@@ -2,15 +2,15 @@ module Spina
2
2
  module UserInterface
3
3
  class DropdownButtonComponent < ApplicationComponent
4
4
  attr_reader :disabled
5
-
5
+
6
6
  def initialize(disabled: false)
7
7
  @disabled = disabled
8
8
  end
9
-
9
+
10
10
  def call
11
11
  content_tag :button, content, {class: classes, type: :submit, disabled: disabled}
12
12
  end
13
-
13
+
14
14
  def classes
15
15
  if disabled
16
16
  "block w-full text-left px-3 py-2 text-sm leading-4 text-gray-400 font-medium cursor-default"
@@ -20,4 +20,4 @@ module Spina
20
20
  end
21
21
  end
22
22
  end
23
- end
23
+ end
@@ -1,28 +1,27 @@
1
1
  module Spina
2
2
  module UserInterface
3
- class DropdownComponent < ApplicationComponent
3
+ class DropdownComponent < ApplicationComponent
4
4
  renders_one :button, "ButtonComponent"
5
-
5
+
6
6
  renders_one :menu, "MenuComponent"
7
-
7
+
8
8
  class ButtonComponent < ApplicationComponent
9
9
  attr_reader :classes
10
-
10
+
11
11
  def initialize(classes:)
12
12
  @classes = classes
13
13
  end
14
-
14
+
15
15
  def call
16
- content_tag :button, content, {type: 'button', class: classes, data: {action: "reveal#toggle"}}
16
+ content_tag :button, content, {type: "button", class: classes, data: {action: "reveal#toggle"}}
17
17
  end
18
18
  end
19
-
19
+
20
20
  class MenuComponent < ApplicationComponent
21
21
  def call
22
22
  content_tag :div, content, {class: "origin-top-right absolute right-0 mt-2 w-56 rounded-md shadow-lg border border-gray-200 z-20 rounded-md bg-white shadow-xs py-1", hidden: true, data: {reveal: true, transition: true}}
23
23
  end
24
24
  end
25
-
26
25
  end
27
26
  end
28
- end
27
+ end
@@ -1,16 +1,15 @@
1
1
  module Spina
2
2
  module UserInterface
3
3
  class FlashMessageComponent < ApplicationComponent
4
-
5
4
  def initialize(type:, message:)
6
5
  @type = type
7
6
  @message = message
8
7
  end
9
-
8
+
10
9
  def confetti?
11
10
  @type == "confetti" && !Spina.config.party_pooper
12
11
  end
13
-
12
+
14
13
  def theme
15
14
  case @type
16
15
  when "alert", "error"
@@ -19,7 +18,6 @@ module Spina
19
18
  "bg-gray-400"
20
19
  end
21
20
  end
22
-
23
21
  end
24
22
  end
25
- end
23
+ end
@@ -1,9 +1,9 @@
1
1
  module Spina
2
2
  module UserInterface
3
- class HeaderComponent < ApplicationComponent
3
+ class HeaderComponent < ApplicationComponent
4
4
  renders_one :actions
5
5
  renders_one :navigation
6
6
  renders_one :after_breadcrumbs
7
7
  end
8
8
  end
9
- end
9
+ end
@@ -1,11 +1,9 @@
1
1
  module Spina
2
2
  module UserInterface
3
3
  class ModalComponent < ApplicationComponent
4
-
5
4
  def initialize(size: "max-w-lg")
6
5
  @size = size
7
6
  end
8
-
9
7
  end
10
8
  end
11
- end
9
+ end
@@ -1,14 +1,13 @@
1
1
  module Spina
2
2
  module UserInterface
3
3
  class TabLinkComponent < ApplicationComponent
4
-
5
4
  def initialize(name = nil, url = nil, active: false)
6
5
  url = name if url.nil?
7
6
  @url = url
8
7
  @name = name
9
8
  @active = active
10
9
  end
11
-
10
+
12
11
  def css_classes
13
12
  if @active
14
13
  "cursor-default text-gray-900 bg-spina-dark bg-opacity-10"
@@ -16,7 +15,6 @@ module Spina
16
15
  ""
17
16
  end
18
17
  end
19
-
20
18
  end
21
19
  end
22
20
  end
@@ -1,26 +1,24 @@
1
1
  module Spina
2
2
  module UserInterface
3
3
  class TranslationsComponent < ApplicationComponent
4
-
5
4
  def initialize(record, label: nil)
6
5
  @record = record
7
6
  @label = label
8
7
  end
9
-
8
+
10
9
  def render?
11
10
  spina_locales.many?
12
11
  end
13
-
12
+
14
13
  def locales
15
14
  spina_locales
16
15
  end
17
-
16
+
18
17
  private
19
-
20
- def spina_locales
21
- Spina.locales.map(&:to_sym)
22
- end
23
-
18
+
19
+ def spina_locales
20
+ Spina.locales.map(&:to_sym)
21
+ end
24
22
  end
25
23
  end
26
- end
24
+ end
@@ -2,43 +2,42 @@ module Spina
2
2
  module Api
3
3
  module Paginable
4
4
  extend ActiveSupport::Concern
5
-
5
+
6
6
  private
7
-
8
- def pagination(records)
9
- paginated_records = records.page(params[:page]).per(params[:per_page])
10
- [paginated_records, {
11
- meta: pagination_meta(paginated_records),
12
- links: pagination_links(paginated_records)
13
- }]
14
- end
15
-
16
- def pagination_meta(paginated_records)
17
- {
18
- current_page: paginated_records.current_page,
19
- total: paginated_records.total_count,
20
- per_page: paginated_records.limit_value,
21
- path: view_context.url_for(only_path: true)
22
- }
23
- end
24
-
25
- def pagination_links(paginated_records)
26
- {
27
- first: path_to_first_page,
28
- prev: view_context.path_to_prev_page(paginated_records),
29
- next: view_context.path_to_next_page(paginated_records),
30
- last: path_to_last_page(paginated_records)
31
- }
32
- end
33
-
34
- def path_to_first_page
35
- view_context.url_for(page: 1, per_page: params[:per_page], only_path: true)
36
- end
37
-
38
- def path_to_last_page(paginated_records)
39
- view_context.url_for(page: paginated_records.total_pages, per_page: params[:per_page], only_path: true)
40
- end
41
-
7
+
8
+ def pagination(records)
9
+ paginated_records = records.page(params[:page]).per(params[:per_page])
10
+ [paginated_records, {
11
+ meta: pagination_meta(paginated_records),
12
+ links: pagination_links(paginated_records)
13
+ }]
14
+ end
15
+
16
+ def pagination_meta(paginated_records)
17
+ {
18
+ current_page: paginated_records.current_page,
19
+ total: paginated_records.total_count,
20
+ per_page: paginated_records.limit_value,
21
+ path: view_context.url_for(only_path: true)
22
+ }
23
+ end
24
+
25
+ def pagination_links(paginated_records)
26
+ {
27
+ first: path_to_first_page,
28
+ prev: view_context.path_to_prev_page(paginated_records),
29
+ next: view_context.path_to_next_page(paginated_records),
30
+ last: path_to_last_page(paginated_records)
31
+ }
32
+ end
33
+
34
+ def path_to_first_page
35
+ view_context.url_for(page: 1, per_page: params[:per_page], only_path: true)
36
+ end
37
+
38
+ def path_to_last_page(paginated_records)
39
+ view_context.url_for(page: paginated_records.total_pages, per_page: params[:per_page], only_path: true)
40
+ end
42
41
  end
43
42
  end
44
- end
43
+ end
@@ -7,7 +7,7 @@ module Spina
7
7
  helper_method :current_spina_account
8
8
  helper_method :current_account
9
9
  end
10
-
10
+
11
11
  private
12
12
 
13
13
  def current_account
@@ -1,17 +1,16 @@
1
1
  module Spina
2
2
  module CurrentTheme
3
3
  extend ActiveSupport::Concern
4
-
4
+
5
5
  included do
6
6
  before_action :current_theme
7
7
  helper_method :current_theme
8
8
  end
9
-
9
+
10
10
  private
11
-
12
- def current_theme
13
- Spina::Current.theme ||= ::Spina::Theme.find_by_name(current_spina_account.theme)
14
- end
15
-
11
+
12
+ def current_theme
13
+ Spina::Current.theme ||= ::Spina::Theme.find_by_name(current_spina_account.theme)
14
+ end
16
15
  end
17
16
  end
@@ -6,7 +6,7 @@ module Spina
6
6
  rescue_from ActiveRecord::RecordNotFound, with: :redirect_or_render_404
7
7
 
8
8
  helper Spina::PagesHelper
9
-
9
+
10
10
  before_action :set_locale
11
11
  before_action :set_current_page
12
12
  before_action :set_current_spina_account
@@ -24,62 +24,76 @@ module Spina
24
24
 
25
25
  private
26
26
 
27
- def set_locale
28
- I18n.locale = params[:locale] || I18n.default_locale
29
- end
27
+ def set_locale
28
+ I18n.locale = params[:locale] || I18n.default_locale
29
+ end
30
30
 
31
- def set_current_page
32
- Spina::Current.page = page
33
- Spina::Current.page.view_context = view_context
34
- end
31
+ def set_current_page
32
+ Spina::Current.page = page
33
+ Spina::Current.page.view_context = view_context
34
+ end
35
35
 
36
- def set_current_spina_account
37
- Spina::Current.account = Spina::Account.first
38
- Spina::Current.account.view_context = view_context
39
- end
36
+ def set_current_spina_account
37
+ Spina::Current.account = Spina::Account.first
38
+ Spina::Current.account.view_context = view_context
39
+ end
40
40
 
41
- def page_by_locale(locale)
42
- I18n.with_locale(locale) do
43
- Page.i18n.find_by!(materialized_path: spina_request_path)
44
- end
41
+ def page_by_locale(locale)
42
+ I18n.with_locale(locale) do
43
+ Page.i18n.find_by!(materialized_path: spina_request_path)
45
44
  end
45
+ end
46
46
 
47
- def page
48
- @page = if action_name == 'homepage'
49
- Page.find_by!(name: 'homepage')
50
- else
51
- page_by_locale(I18n.locale) || page_by_locale(I18n.default_locale)
52
- end
47
+ def page
48
+ @page = if action_name == "homepage"
49
+ Page.find_by!(name: "homepage")
50
+ else
51
+ page_by_locale(I18n.locale) || page_by_locale(I18n.default_locale)
53
52
  end
53
+ end
54
54
 
55
- def spina_request_path
56
- segments = [Spina.mounted_at, params[:locale], params[:id]].compact
57
- File.join(*segments)
58
- end
55
+ def spina_request_path
56
+ segments = [Spina.mounted_at, params[:locale], params[:id]].compact
57
+ File.join(*segments)
58
+ end
59
59
 
60
- def should_skip_to_first_child?
61
- Spina::Current.page.skip_to_first_child && first_live_child
62
- end
60
+ def should_skip_to_first_child?
61
+ Spina::Current.page.skip_to_first_child && first_live_child
62
+ end
63
63
 
64
- def first_live_child
65
- Spina::Current.page.children.sorted.live.first
66
- end
64
+ def first_live_child
65
+ Spina::Current.page.children.sorted.live.first
66
+ end
67
67
 
68
- def redirect_or_render_404
69
- if rule = RewriteRule.find_by(old_path: spina_request_path)
70
- redirect_to rule.new_path, status: :moved_permanently
71
- else
72
- render_404
73
- end
68
+ def redirect_or_render_404
69
+ if (rule = RewriteRule.find_by(old_path: spina_request_path))
70
+ redirect_to rule.new_path, status: :moved_permanently
71
+ else
72
+ render_404
74
73
  end
74
+ end
75
75
 
76
- def render_404
77
- render file: "#{Rails.root}/public/404.html", status: 404, layout: false
78
- end
76
+ def render_with_template(page)
77
+ render layout: "#{current_theme.name.parameterize.underscore}/#{layout_template_for_page(page)}", template: "#{current_theme.name.parameterize.underscore}/pages/#{view_template_for_page(page)}"
78
+ end
79
79
 
80
- def render_with_template(page)
81
- render layout: "#{current_theme.name.parameterize.underscore}/#{page.layout_template || 'application'}", template: "#{current_theme.name.parameterize.underscore}/pages/#{Spina::Current.page.view_template || 'show'}"
80
+ def view_template_for_page(page)
81
+ page.view_template.presence || "show"
82
+ end
83
+
84
+ def layout_template_for_page(page)
85
+ return page.layout_template if page.layout_template.present?
86
+ view_template_config(page)[:layout].presence || "application"
87
+ end
88
+
89
+ def view_template_config(page)
90
+ current_theme.view_templates.find do |template|
91
+ template[:name] == view_template_for_page(page)
82
92
  end
93
+ end
83
94
 
95
+ def render_404
96
+ render file: "#{Rails.root}/public/404.html", status: 404, layout: false
97
+ end
84
98
  end
85
- end
99
+ end
@@ -2,7 +2,7 @@ module Spina
2
2
  module Admin
3
3
  class AccountsController < AdminController
4
4
  admin_section :settings
5
-
5
+
6
6
  before_action :set_breadcrumbs
7
7
 
8
8
  def edit
@@ -10,23 +10,22 @@ module Spina
10
10
 
11
11
  def update
12
12
  if current_spina_account.update(account_params)
13
- redirect_back fallback_location: spina.edit_admin_account_path, flash: {success: t('spina.accounts.saved')}
13
+ redirect_back fallback_location: spina.edit_admin_account_path, flash: {success: t("spina.accounts.saved")}
14
14
  else
15
- flash.now[:error] = t('spina.accounts.couldnt_be_saved')
15
+ flash.now[:error] = t("spina.accounts.couldnt_be_saved")
16
16
  render :edit, status: :unprocessable_entity
17
17
  end
18
18
  end
19
19
 
20
20
  private
21
21
 
22
- def account_params
23
- params.require(:account).permit!
24
- end
25
-
26
- def set_breadcrumbs
27
- add_breadcrumb I18n.t('spina.preferences.account'), spina.edit_admin_account_path
28
- end
22
+ def account_params
23
+ params.require(:account).permit!
24
+ end
29
25
 
26
+ def set_breadcrumbs
27
+ add_breadcrumb I18n.t("spina.preferences.account"), spina.edit_admin_account_path
28
+ end
30
29
  end
31
30
  end
32
31
  end