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
@@ -5,12 +5,12 @@
5
5
 
6
6
  Spina::Theme.register do |theme|
7
7
  # All views are namespaced based on the theme's name
8
- theme.name = 'demo'
9
- theme.title = 'Demo theme'
8
+ theme.name = "demo"
9
+ theme.title = "Demo theme"
10
10
 
11
- # Parts
11
+ # Parts
12
12
  # Define all editable parts you want to use in your view templates
13
- #
13
+ #
14
14
  # Built-in part types:
15
15
  # - Line
16
16
  # - MultiLine
@@ -21,13 +21,13 @@ Spina::Theme.register do |theme|
21
21
  # - Option
22
22
  # - Repeater
23
23
  theme.parts = [
24
- {name: 'repeater', title: "Repeater", part_type: "Spina::Parts::Repeater", parts: %w(line image headline)},
25
- {name: 'line', title: "Line", part_type: "Spina::Parts::Line"},
26
- {name: 'body', title: "Body", hint: "Your content", part_type: "Spina::Parts::Text"},
24
+ {name: "repeater", title: "Repeater", part_type: "Spina::Parts::Repeater", item_name: "item", parts: %w[line image headline]},
25
+ {name: "line", title: "Line", part_type: "Spina::Parts::Line"},
26
+ {name: "body", title: "Body", hint: "Your content", part_type: "Spina::Parts::Text"},
27
27
  {name: "image_collection", title: "Image collection", part_type: "Spina::Parts::ImageCollection"},
28
- {name: 'image', title: "Image", part_type: "Spina::Parts::Image"},
29
- {name: 'headline', title: "Headline", hint: "Used in the header", part_type: "Spina::Parts::Line"},
30
- {name: 'footer', title: "Footer", part_type: "Spina::Parts::Text"}
28
+ {name: "image", title: "Image", part_type: "Spina::Parts::Image"},
29
+ {name: "headline", title: "Headline", hint: "Used in the header", part_type: "Spina::Parts::Line"},
30
+ {name: "footer", title: "Footer", part_type: "Spina::Parts::Text"}
31
31
  ]
32
32
 
33
33
  # View templates
@@ -35,41 +35,41 @@ Spina::Theme.register do |theme|
35
35
  # You define which parts you want to enable for every view template
36
36
  # by referencing them from the theme.parts configuration above.
37
37
  theme.view_templates = [
38
- {name: 'homepage', title: 'Homepage', parts: %w(headline body image_collection)},
39
- {name: 'show', title: 'Default', parts: %w(body image repeater)},
40
- {name: 'demo', title: 'Demo', parts: %w(body image_collection image repeater), exclude_from: %w(articles)}
38
+ {name: "homepage", title: "Homepage", parts: %w[headline body image_collection]},
39
+ {name: "show", title: "Default", parts: %w[body image repeater]},
40
+ {name: "demo", title: "Demo", parts: %w[body image_collection image repeater], exclude_from: %w[articles]}
41
41
  ]
42
42
 
43
43
  # Custom pages
44
44
  # Some pages should not be created by the user, but generated automatically.
45
45
  # By naming them you can reference them in your code.
46
46
  theme.custom_pages = [
47
- {name: 'homepage', title: 'Homepage', deletable: false, view_template: 'homepage'},
48
- {name: 'demo', title: 'Demo', deletable: true, view_template: 'demo'}
47
+ {name: "homepage", title: "Homepage", deletable: false, view_template: "homepage"},
48
+ {name: "demo", title: "Demo", deletable: true, view_template: "demo"}
49
49
  ]
50
-
50
+
51
51
  # Navigations (optional)
52
52
  # If your project has multiple navigations, it can be useful to configure multiple
53
53
  # navigations.
54
54
  theme.navigations = [
55
- {name: 'main', label: 'Main navigation'}
55
+ {name: "main", label: "Main navigation"}
56
56
  ]
57
-
57
+
58
58
  # Layout parts (optional)
59
59
  # You can create global content that doesn't belong to one specific page. We call these layout parts.
60
60
  # You only have to reference the name of the parts you want to have here.
61
61
  theme.layout_parts = []
62
-
62
+
63
63
  # Resources (optional)
64
64
  # Think of resources as a collection of pages. They are managed separately in Spina
65
65
  # allowing you to separate these pages from the 'main' collection of pages.
66
66
  theme.resources = [
67
- {name: 'articles', label: "Articles", view_template: "article", slug: "articles"}
67
+ {name: "articles", label: "Articles", view_template: "article", slug: "articles"}
68
68
  ]
69
69
 
70
70
  # Plugins (optional)
71
- theme.plugins = ['reviews']
72
-
71
+ theme.plugins = ["reviews"]
72
+
73
73
  # Embeds (optional)
74
74
  theme.embeds = []
75
75
  end
@@ -1,23 +1,20 @@
1
1
  module Spina
2
- module AdminSectionable
2
+ module AdminSectionable
3
3
  extend ActiveSupport::Concern
4
-
4
+
5
5
  included do |base|
6
6
  extend ClassMethods
7
-
7
+
8
8
  helper_method :admin_section
9
9
  attr_accessor :admin_section
10
10
  end
11
-
11
+
12
12
  module ClassMethods
13
-
14
13
  def admin_section(name)
15
14
  before_action do |controller|
16
15
  controller.send(:admin_section=, name.to_sym)
17
16
  end
18
17
  end
19
-
20
18
  end
21
-
22
19
  end
23
- end
20
+ end
@@ -1,13 +1,12 @@
1
1
  module Spina
2
- module AttrJsonMonkeypatch
2
+ module AttrJsonMonkeypatch
3
3
  extend ActiveSupport::Concern
4
-
4
+
5
5
  included do |base|
6
6
  extend ClassMethods
7
7
  end
8
-
8
+
9
9
  module ClassMethods
10
-
11
10
  def attr_json_setter_monkeypatch(name)
12
11
  # Ruby bug in 3.0.0 related to defined?(super) returning true
13
12
  # https://github.com/jrochkind/attr_json/issues/112
@@ -21,8 +20,6 @@ module Spina
21
20
  end
22
21
  end
23
22
  end
24
-
25
23
  end
26
-
27
24
  end
28
- end
25
+ end
@@ -1,11 +1,10 @@
1
- require 'attr_json/type/polymorphic_model'
1
+ require "attr_json/type/polymorphic_model"
2
2
 
3
3
  # Extending the PolymorphicModel to use the Spina::PARTS array as input
4
4
  # as opposed to arguments
5
5
  module AttrJson
6
6
  module Type
7
7
  class SpinaPartsModel < PolymorphicModel
8
-
9
8
  def model_names
10
9
  spina_parts_lookup.keys
11
10
  end
@@ -23,7 +22,6 @@ module AttrJson
23
22
  def type_for_model_name(model_name)
24
23
  spina_parts_lookup[model_name]
25
24
  end
26
-
27
25
  end
28
26
  end
29
27
  end
@@ -2,23 +2,22 @@ module Spina
2
2
  module Authentication
3
3
  module Basic
4
4
  extend ActiveSupport::Concern
5
-
5
+
6
6
  included do
7
7
  helper_method :logged_in?
8
8
  end
9
-
9
+
10
10
  def logged_in?
11
11
  authenticate
12
12
  end
13
-
13
+
14
14
  private
15
-
16
- def authenticate
17
- authenticate_or_request_with_http_basic do |username, password|
18
- username == Rails.application.credentials.dig(:spina, :username) && password == Rails.application.credentials.dig(:spina, :password)
19
- end
15
+
16
+ def authenticate
17
+ authenticate_or_request_with_http_basic do |username, password|
18
+ username == Rails.application.credentials.dig(:spina, :username) && password == Rails.application.credentials.dig(:spina, :password)
20
19
  end
21
-
20
+ end
22
21
  end
23
22
  end
24
- end
23
+ end
@@ -2,31 +2,30 @@ module Spina
2
2
  module Authentication
3
3
  module Sessions
4
4
  extend ActiveSupport::Concern
5
-
5
+
6
6
  included do
7
7
  helper_method :current_spina_user
8
8
  helper_method :logged_in?
9
9
  helper_method :logout_path
10
10
  end
11
-
11
+
12
12
  def current_spina_user
13
13
  Spina::Current.user ||= User.find_by(id: session[:spina_user_id]) if session[:spina_user_id]
14
14
  end
15
-
15
+
16
16
  def logged_in?
17
17
  current_spina_user
18
18
  end
19
-
19
+
20
20
  def logout_path
21
21
  spina.admin_logout_path
22
22
  end
23
-
23
+
24
24
  private
25
-
26
- def authenticate
27
- redirect_to admin_login_path, flash: {information: I18n.t('spina.notifications.login')} unless logged_in?
28
- end
29
-
25
+
26
+ def authenticate
27
+ redirect_to admin_login_path, flash: {information: I18n.t("spina.notifications.login")} unless logged_in?
28
+ end
30
29
  end
31
30
  end
32
- end
31
+ end
@@ -1,48 +1,45 @@
1
1
  module Spina
2
2
  module Embeddable
3
3
  extend ActiveSupport::Concern
4
-
4
+
5
5
  included do
6
6
  class_attribute :embed_attributes, default: []
7
7
  class_attribute :icon, default: nil
8
8
  end
9
-
9
+
10
10
  class_methods do
11
11
  def from_json(json)
12
- begin
13
- attributes = JSON.parse(json)
14
- attributes.transform_keys!(&:to_sym)
15
- new(attributes)
16
- rescue
17
- Rails.logger.error "[#{self.class.name}] Couldn't parse JSON"
18
- nil
19
- end
12
+ attributes = JSON.parse(json)
13
+ attributes.transform_keys!(&:to_sym)
14
+ new(attributes)
15
+ rescue
16
+ Rails.logger.error "[#{self.class.name}] Couldn't parse JSON"
17
+ nil
20
18
  end
21
-
19
+
22
20
  def attributes(*names)
23
21
  attr_accessor(*names.map(&:to_sym))
24
22
  self.embed_attributes += names.map(&:to_sym)
25
23
  end
26
-
24
+
27
25
  # Give it an icon
28
26
  def heroicon(name)
29
27
  self.icon = name
30
28
  end
31
29
  end
32
-
30
+
33
31
  def initialize(attributes = {})
34
32
  attributes.slice(*self.class.embed_attributes).each do |key, value|
35
33
  instance_variable_set("@#{key}", value)
36
34
  end
37
35
  end
38
-
36
+
39
37
  def to_fields_path
40
38
  "#{to_partial_path}_fields"
41
39
  end
42
-
40
+
43
41
  def to_trix_partial_path
44
42
  to_partial_path
45
43
  end
46
-
47
44
  end
48
- end
45
+ end
@@ -2,40 +2,39 @@ module Spina
2
2
  module Embeds
3
3
  module TrixConversion
4
4
  extend ActiveSupport::Concern
5
-
5
+
6
6
  # Wrap rendered partial in an <embed> tag for Trix
7
- def to_trix_attachment(content = trix_attachment_content)
7
+ def to_trix_attachment(content = trix_attachment_content)
8
8
  wrap_with_embed_tag(content)
9
9
  end
10
-
10
+
11
11
  def wrap_with_embed_tag(html)
12
12
  element = html_document.create_element("spina-embed", embed_tag_attributes)
13
13
  element.inner_html = html
14
14
  element.to_html
15
15
  end
16
-
16
+
17
17
  private
18
-
19
- def embed_tag_attributes
20
- spina_attributes.merge({"data-embed-attributes": embed_attributes_to_json})
21
- end
22
-
23
- def embed_attributes_to_json
24
- JSON.generate Hash[self.class.embed_attributes.map{|a| [a.to_s, send(a)]}]
25
- end
26
-
27
- def spina_attributes
28
- {"data-embed-type": self.class.name, "data-controller": "embed-tag"}
29
- end
30
-
31
- def trix_attachment_content
32
- ApplicationController.render(partial: to_trix_partial_path, formats: :html, object: self, as: model_name.element)
33
- end
34
-
35
- def html_document
36
- Nokogiri::HTML::Document.new.tap{|doc| doc.encoding = "UTF-8"}
37
- end
38
-
18
+
19
+ def embed_tag_attributes
20
+ spina_attributes.merge({"data-embed-attributes": embed_attributes_to_json})
21
+ end
22
+
23
+ def embed_attributes_to_json
24
+ JSON.generate self.class.embed_attributes.map { |a| [a.to_s, send(a)] }.to_h
25
+ end
26
+
27
+ def spina_attributes
28
+ {"data-embed-type": self.class.name, "data-controller": "embed-tag"}
29
+ end
30
+
31
+ def trix_attachment_content
32
+ ApplicationController.render(partial: to_trix_partial_path, formats: :html, object: self, as: model_name.element)
33
+ end
34
+
35
+ def html_document
36
+ Nokogiri::HTML::Document.new.tap { |doc| doc.encoding = "UTF-8" }
37
+ end
39
38
  end
40
39
  end
41
- end
40
+ end
data/lib/spina/embeds.rb CHANGED
@@ -1,11 +1,9 @@
1
1
  module Spina
2
2
  module Embeds
3
-
4
3
  def self.constantize(embeddable_type)
5
4
  return nil if embeddable_type.blank?
6
5
  name = embeddable_type.camelize.demodulize.to_s
7
6
  "Spina::Embeds::#{name}".safe_constantize
8
7
  end
9
-
10
8
  end
11
- end
9
+ end
data/lib/spina/engine.rb CHANGED
@@ -1,33 +1,33 @@
1
- require 'importmap-rails'
2
- require 'turbo-rails'
3
- require 'stimulus-rails'
4
- require 'ancestry'
5
- require 'breadcrumbs_on_rails'
6
- require 'kaminari'
7
- require 'mobility'
8
- require 'rack-rewrite'
9
- require 'babosa'
10
- require 'attr_json'
11
- require 'view_component'
12
- require 'jsonapi/serializer'
13
- require 'browser'
14
- require 'sprockets/railtie'
1
+ require "importmap-rails"
2
+ require "turbo-rails"
3
+ require "stimulus-rails"
4
+ require "ancestry"
5
+ require "breadcrumbs_on_rails"
6
+ require "kaminari"
7
+ require "mobility"
8
+ require "rack-rewrite"
9
+ require "babosa"
10
+ require "attr_json"
11
+ require "view_component"
12
+ require "jsonapi/serializer"
13
+ require "browser"
14
+ require "sprockets/railtie"
15
15
 
16
16
  module Spina
17
17
  class Engine < ::Rails::Engine
18
18
  isolate_namespace Spina
19
-
20
- config.autoload_paths += %W( #{config.root}/lib )
19
+
20
+ config.autoload_paths += %W[#{config.root}/lib]
21
21
 
22
22
  config.to_prepare do
23
- # Require decorators from main application
24
23
  unless Spina.config.disable_decorator_load
25
24
  Dir.glob(Rails.root + "app/decorators/**/*_decorator.rb").each do |decorator|
25
+ ActiveSupport::Deprecation.warn("using app/decorators is deprecated in favor of app/overrides. Read more about overriding Spina at spinacms.com/guides")
26
26
  require_dependency(decorator)
27
27
  end
28
28
  end
29
29
  end
30
-
30
+
31
31
  config.to_prepare do
32
32
  Spina::Part.register(
33
33
  Spina::Parts::Line,
@@ -40,6 +40,5 @@ module Spina
40
40
  Spina::Parts::Attachment
41
41
  )
42
42
  end
43
-
44
43
  end
45
44
  end
data/lib/spina/part.rb CHANGED
@@ -1,8 +1,6 @@
1
1
  module Spina
2
2
  class Part
3
-
4
3
  class << self
5
-
6
4
  def all
7
5
  ::Spina::PARTS
8
6
  end
@@ -13,15 +11,12 @@ module Spina
13
11
  all << part
14
12
  end
15
13
  end
16
-
14
+
17
15
  def unregister(part)
18
16
  all.delete_if do |registered_part|
19
17
  registered_part.name == part.name
20
18
  end
21
19
  end
22
-
23
20
  end
24
-
25
21
  end
26
22
  end
27
-
data/lib/spina/plugin.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  module Spina
2
2
  class Plugin
3
-
4
3
  attr_accessor :name, :namespace, :settings
5
4
 
6
5
  def create_setting_class!
@@ -10,15 +9,15 @@ module Spina
10
9
  klass = Class.new(::Spina::Setting) do
11
10
  include AttrJson::Record
12
11
  include Spina::AttrJsonMonkeypatch
13
-
12
+
14
13
  class_settings.each do |setting|
15
- attr_json *setting, container_attribute: "preferences"
14
+ attr_json(*setting, container_attribute: "preferences")
16
15
  attr_json_setter_monkeypatch setting.first
17
16
  end
18
17
 
19
- default_scope { where(plugin: "#{plugin_name}") }
18
+ default_scope { where(plugin: plugin_name.to_s) }
20
19
  end
21
- "Spina::#{namespace_class}".constantize.const_set 'Setting', klass
20
+ "Spina::#{namespace_class}".constantize.const_set :Setting, klass
22
21
  end
23
22
 
24
23
  private
@@ -32,11 +31,11 @@ module Spina
32
31
  end
33
32
 
34
33
  def namespace_class
35
- namespace.split('_').map{|part| part.camelize}.join
34
+ namespace.split("_").map { |part| part.camelize }.join
36
35
  end
37
36
 
38
37
  def data_mapped_settings_hash
39
- hash = Hash.new
38
+ hash = {}
40
39
  settings.each do |key, value|
41
40
  hash[key] = map_data_type(value)
42
41
  end
@@ -44,12 +43,11 @@ module Spina
44
43
  end
45
44
 
46
45
  class << self
47
-
48
46
  def all
49
47
  ::Spina::PLUGINS
50
48
  end
51
49
 
52
- def find_by(opts={})
50
+ def find_by(opts = {})
53
51
  all.find do |plugin|
54
52
  matches = true
55
53
  opts.each do |key, value|
@@ -62,8 +60,8 @@ module Spina
62
60
  def register
63
61
  plugin = new
64
62
  yield plugin
65
- raise 'Missing plugin name' if plugin.name.nil?
66
- raise 'Missing plugin namespace' if plugin.namespace.nil?
63
+ raise "Missing plugin name" if plugin.name.nil?
64
+ raise "Missing plugin namespace" if plugin.namespace.nil?
67
65
 
68
66
  if plugin.settings.present?
69
67
  plugin.create_setting_class!
@@ -72,8 +70,6 @@ module Spina
72
70
  all << plugin
73
71
  plugin
74
72
  end
75
-
76
73
  end
77
-
78
74
  end
79
75
  end
data/lib/spina/railtie.rb CHANGED
@@ -1,23 +1,21 @@
1
1
  module Spina
2
2
  class Railtie < Rails::Railtie
3
-
4
3
  initializer "spina.assets.precompile" do |app|
5
- app.config.assets.precompile += %w(spina/manifest)
4
+ app.config.assets.precompile += %w[spina/manifest]
6
5
  end
7
-
6
+
8
7
  initializer "spina.theme_reloader" do |app|
9
8
  reloader = ThemeReloader.new
10
9
  reloader.execute
11
-
10
+
12
11
  app.reloaders << reloader
13
12
  app.reloader.to_run do
14
13
  reloader.execute
15
14
  end
16
15
  end
17
-
16
+
18
17
  ActiveSupport.on_load(:action_controller) do
19
18
  ::ActionController::Base.send(:include, Spina::AdminSectionable)
20
19
  end
21
-
22
20
  end
23
- end
21
+ end
data/lib/spina/theme.rb CHANGED
@@ -1,14 +1,12 @@
1
1
  module Spina
2
2
  class Theme
3
-
4
3
  attr_accessor :name, :title, :parts, :page_parts, :structures, :view_templates, :layout_parts, :custom_pages, :plugins, :public_theme, :config, :navigations, :resources, :embeds
5
4
 
6
5
  class << self
7
-
8
6
  def all
9
7
  ::Spina::THEMES
10
8
  end
11
-
9
+
12
10
  def unregister(name)
13
11
  theme = find_by_name(name)
14
12
  all.delete(theme) if theme
@@ -21,30 +19,29 @@ module Spina
21
19
  def register
22
20
  theme = ::Spina::Theme.new
23
21
  yield theme
24
- raise 'Missing theme name' if theme.name.nil?
22
+ raise "Missing theme name" if theme.name.nil?
25
23
  unregister(theme.name)
26
24
  if theme.plugins.nil?
27
25
  theme.plugins = ::Spina::Plugin.all.map { |plugin| plugin.name }
28
26
  end
29
27
  all << theme
30
28
  end
31
-
32
29
  end
33
30
 
34
31
  def initialize
35
- @page_parts = []
36
- @structures = []
37
- @layout_parts = []
38
- @view_templates = []
39
- @custom_pages = []
40
- @navigations = []
41
- @resources = []
42
- @embeds = []
32
+ @page_parts = []
33
+ @structures = []
34
+ @layout_parts = []
35
+ @view_templates = []
36
+ @custom_pages = []
37
+ @navigations = []
38
+ @resources = []
39
+ @embeds = []
43
40
  @public_theme = false
44
41
  end
45
-
42
+
46
43
  def embeddables
47
- embeds.map{|embed| Embeds.constantize(embed)}
44
+ embeds.map { |embed| Embeds.constantize(embed) }
48
45
  end
49
46
 
50
47
  def new_page_templates(resource: nil)
@@ -52,7 +49,7 @@ module Spina
52
49
  @view_templates.map do |view_template|
53
50
  next if is_custom_undeletable_page?(view_template[:name])
54
51
  next if view_template[:exclude_from]&.include?(page_collection)
55
-
52
+
56
53
  OpenStruct.new({
57
54
  name: view_template[:name],
58
55
  title: view_template[:title],
@@ -68,6 +65,5 @@ module Spina
68
65
  def is_custom_undeletable_page?(view_template_name)
69
66
  @custom_pages.any? { |page| page[:view_template] == view_template_name && !page[:deletable] }
70
67
  end
71
-
72
68
  end
73
69
  end