spina 1.2.0 → 2.0.0.alpha

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 (142) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/images/spina/favicon.png +0 -0
  3. data/app/assets/javascripts/spina/admin/application.js +1 -2
  4. data/app/assets/javascripts/spina/admin/controllers/attachment_picker_controller.js +15 -0
  5. data/app/assets/javascripts/spina/admin/controllers/image_form_controller.js +5 -4
  6. data/app/assets/javascripts/spina/admin/controllers/infinite_scroll_controller.js +20 -22
  7. data/app/assets/javascripts/spina/admin/controllers/media_picker_controller.js +171 -0
  8. data/app/assets/javascripts/spina/admin/controllers/modal_controller.js +18 -0
  9. data/app/assets/javascripts/spina/admin/controllers/repeater_form_controller.js +38 -0
  10. data/app/assets/javascripts/spina/admin/media_gallery.coffee +0 -3
  11. data/app/assets/javascripts/spina/admin/notifications.coffee +1 -1
  12. data/app/assets/javascripts/spina/admin/pages.coffee.erb +3 -20
  13. data/app/assets/javascripts/spina/admin/scaffold.coffee +0 -3
  14. data/app/assets/javascripts/spina/admin/trix.coffee.erb +14 -18
  15. data/app/assets/stylesheets/spina.sass +10 -8
  16. data/app/assets/stylesheets/spina/_buttons.sass +57 -31
  17. data/app/assets/stylesheets/spina/_forms.sass +59 -73
  18. data/app/assets/stylesheets/spina/_gallery.sass +18 -2
  19. data/app/assets/stylesheets/spina/_media_picker.sass +133 -0
  20. data/app/assets/stylesheets/spina/_modal.sass +35 -2
  21. data/app/assets/stylesheets/spina/_notifications.sass +20 -14
  22. data/app/assets/stylesheets/spina/_pages.sass +131 -0
  23. data/app/assets/stylesheets/spina/_sortable_lists.sass +14 -8
  24. data/app/assets/stylesheets/spina/_trix_custom.sass +1 -1
  25. data/app/controllers/concerns/spina/frontend.rb +9 -0
  26. data/app/controllers/spina/admin/accounts_controller.rb +9 -13
  27. data/app/controllers/spina/admin/attachments_controller.rb +0 -22
  28. data/app/controllers/spina/admin/images_controller.rb +1 -1
  29. data/app/controllers/spina/admin/media_picker_controller.rb +18 -19
  30. data/app/controllers/spina/admin/pages_controller.rb +1 -5
  31. data/app/controllers/spina/admin/resources_controller.rb +9 -4
  32. data/app/controllers/spina/application_controller.rb +1 -1
  33. data/app/helpers/spina/admin/pages_helper.rb +22 -20
  34. data/app/helpers/spina/{files_helper.rb → attachments_helper.rb} +1 -1
  35. data/app/helpers/spina/images_helper.rb +6 -0
  36. data/app/helpers/spina/pages_helper.rb +23 -4
  37. data/app/models/concerns/spina/partable.rb +19 -7
  38. data/app/models/concerns/spina/translated_content.rb +19 -0
  39. data/app/models/spina/account.rb +3 -10
  40. data/app/models/spina/attachment.rb +0 -4
  41. data/app/models/spina/current.rb +1 -0
  42. data/app/models/spina/image.rb +0 -4
  43. data/app/models/spina/page.rb +7 -15
  44. data/app/models/spina/parts/attachment.rb +17 -0
  45. data/app/models/spina/parts/base.rb +12 -0
  46. data/app/models/spina/parts/image.rb +30 -0
  47. data/app/models/spina/parts/image_collection.rb +23 -0
  48. data/app/models/spina/parts/line.rb +7 -0
  49. data/app/models/spina/parts/option.rb +13 -0
  50. data/app/models/spina/parts/repeater.rb +10 -0
  51. data/app/models/spina/parts/repeater_content.rb +15 -0
  52. data/app/models/spina/parts/text.rb +7 -0
  53. data/app/models/spina/resource.rb +4 -0
  54. data/app/presenters/spina/content_presenter.rb +58 -0
  55. data/app/presenters/spina/menu_presenter.rb +2 -1
  56. data/app/views/layouts/spina/admin/admin.html.haml +3 -4
  57. data/app/views/layouts/spina/admin/pages.html.haml +5 -4
  58. data/app/views/spina/admin/accounts/_form.html.haml +13 -7
  59. data/app/views/spina/admin/accounts/analytics.html.haml +5 -3
  60. data/app/views/spina/admin/accounts/style.html.haml +26 -21
  61. data/app/views/spina/admin/images/index.html.haml +7 -5
  62. data/app/views/spina/admin/media_folders/show.html.haml +2 -2
  63. data/app/views/spina/admin/media_picker/_image.html.haml +3 -0
  64. data/app/views/spina/admin/media_picker/_media_picker.html.haml +32 -0
  65. data/app/views/spina/admin/media_picker/_media_picker_grid.html.haml +25 -0
  66. data/app/views/spina/admin/media_picker/infinite_scroll.js.erb +4 -4
  67. data/app/views/spina/admin/media_picker/select.js.erb +2 -0
  68. data/app/views/spina/admin/media_picker/show.html.haml +1 -0
  69. data/app/views/spina/admin/media_picker/show.js.erb +1 -1
  70. data/app/views/spina/admin/pages/_form.html.haml +9 -7
  71. data/app/views/spina/admin/pages/_form_advanced.html.haml +5 -5
  72. data/app/views/spina/admin/pages/_form_page_content.html.haml +14 -13
  73. data/app/views/spina/admin/pages/_form_page_seo.html.haml +9 -5
  74. data/app/views/spina/admin/pages/_page.html.haml +5 -3
  75. data/app/views/spina/admin/pages/_page_nested_list.html.haml +2 -3
  76. data/app/views/spina/admin/pages/index.html.haml +5 -4
  77. data/app/views/spina/admin/parts/attachments/_form.html.haml +6 -0
  78. data/app/views/spina/admin/parts/image_collections/_fields.html.haml +7 -0
  79. data/app/views/spina/admin/parts/image_collections/_form.html.haml +12 -0
  80. data/app/views/spina/admin/parts/images/_form.html.haml +18 -0
  81. data/app/views/spina/admin/parts/lines/_form.html.haml +2 -0
  82. data/app/views/spina/admin/parts/options/_form.html.haml +3 -0
  83. data/app/views/spina/admin/parts/repeaters/_fields.html.haml +15 -0
  84. data/app/views/spina/admin/parts/repeaters/_form.html.haml +18 -0
  85. data/app/views/spina/admin/parts/texts/_form.html.haml +6 -0
  86. data/app/views/spina/admin/resources/edit.html.haml +28 -5
  87. data/app/views/spina/admin/resources/show.html.haml +5 -2
  88. data/app/views/spina/admin/shared/_notifications.html.haml +4 -4
  89. data/db/migrate/12_add_url_title_to_spina_page_translations.rb +1 -1
  90. data/db/migrate/13_add_json_attributes_to_spina_accounts.rb +5 -0
  91. data/db/migrate/14_add_json_attributes_to_spina_pages.rb +5 -0
  92. data/db/migrate/15_add_slug_to_spina_resources.rb +5 -0
  93. data/lib/generators/spina/templates/app/views/demo/pages/demo.html.haml +13 -21
  94. data/lib/generators/spina/templates/app/views/demo/pages/homepage.html.haml +1 -1
  95. data/lib/generators/spina/templates/config/initializers/themes/default.rb +4 -4
  96. data/lib/generators/spina/templates/config/initializers/themes/demo.rb +32 -44
  97. data/lib/spina.rb +2 -0
  98. data/lib/spina/attr_json_spina_parts_model.rb +29 -0
  99. data/lib/spina/engine.rb +13 -2
  100. data/lib/spina/part.rb +19 -0
  101. data/lib/spina/theme.rb +1 -1
  102. data/lib/spina/version.rb +1 -1
  103. data/vendor/assets/javascripts/spina/sortable.js +2 -2
  104. metadata +54 -42
  105. data/app/assets/javascripts/spina/admin/account.coffee +0 -16
  106. data/app/models/concerns/spina/image_collectable.rb +0 -23
  107. data/app/models/concerns/spina/optionable.rb +0 -12
  108. data/app/models/concerns/spina/part.rb +0 -38
  109. data/app/models/spina/attachment_collection.rb +0 -20
  110. data/app/models/spina/image_collection.rb +0 -23
  111. data/app/models/spina/image_collections_image.rb +0 -6
  112. data/app/models/spina/layout_part.rb +0 -22
  113. data/app/models/spina/line.rb +0 -10
  114. data/app/models/spina/option.rb +0 -17
  115. data/app/models/spina/page_part.rb +0 -22
  116. data/app/models/spina/structure.rb +0 -14
  117. data/app/models/spina/structure_item.rb +0 -22
  118. data/app/models/spina/structure_part.rb +0 -20
  119. data/app/models/spina/text.rb +0 -10
  120. data/app/views/dummy/show.html.haml +0 -1
  121. data/app/views/spina/admin/attachments/_attachment_collection.html.haml +0 -2
  122. data/app/views/spina/admin/attachments/_select.html.haml +0 -17
  123. data/app/views/spina/admin/attachments/_select_collection.html.haml +0 -18
  124. data/app/views/spina/admin/attachments/insert.js.erb +0 -5
  125. data/app/views/spina/admin/attachments/insert_collection.js.coffee +0 -7
  126. data/app/views/spina/admin/attachments/select.js.erb +0 -2
  127. data/app/views/spina/admin/attachments/select_collection.js.erb +0 -2
  128. data/app/views/spina/admin/image_collections/_image_collection.html.haml +0 -5
  129. data/app/views/spina/admin/layout_partables/lines/_form.html.haml +0 -2
  130. data/app/views/spina/admin/partables/attachment_collections/_form.html.haml +0 -14
  131. data/app/views/spina/admin/partables/attachments/_form.html.haml +0 -13
  132. data/app/views/spina/admin/partables/image_collections/_form.html.haml +0 -16
  133. data/app/views/spina/admin/partables/images/_form.html.haml +0 -21
  134. data/app/views/spina/admin/partables/lines/_form.html.haml +0 -5
  135. data/app/views/spina/admin/partables/options/_form.html.haml +0 -7
  136. data/app/views/spina/admin/partables/photo_collections/_form.html.haml +0 -4
  137. data/app/views/spina/admin/partables/photos/_form.html.haml +0 -4
  138. data/app/views/spina/admin/partables/structures/_form.html.haml +0 -21
  139. data/app/views/spina/admin/partables/texts/_form.html.haml +0 -8
  140. data/app/views/spina/admin/structure_items/_fields.html.haml +0 -15
  141. data/app/views/spina/admin/structure_partables/attachment_collections/_form.html.haml +0 -14
  142. data/app/views/spina/admin/structure_partables/attachments/_form.html.haml +0 -13
@@ -1,6 +1,9 @@
1
1
  // Sortable lists
2
2
 
3
3
  .dd
4
+ border: 1px solid #e2e2e2
5
+ border-radius: 6px
6
+ box-shadow: 0 1px 1px rgba(0, 0, 0, .05)
4
7
  margin: -20px
5
8
  overflow: hidden
6
9
  position: relative
@@ -39,6 +42,9 @@
39
42
  padding: 0
40
43
  position: relative
41
44
 
45
+ .dd-item:last-child
46
+ border-bottom: none
47
+
42
48
  .dd-placeholder
43
49
  position: relative
44
50
 
@@ -54,16 +60,13 @@
54
60
 
55
61
  .dd-list
56
62
  background: tint(#f5f5fa, 50%)
57
- border-top: 1px solid #ddd
63
+ border-top: 1px solid #eee
58
64
 
59
65
  .dd-placeholder
60
66
  background: tint(#f5f5fa, 50%)
61
67
 
62
68
  &:after
63
69
  margin-left: 40px
64
-
65
- .dd-item:last-child
66
- border-bottom: none
67
70
 
68
71
  .dd-item
69
72
  padding-left: 20px
@@ -84,9 +87,6 @@
84
87
  .dd-collapsed .dd-list
85
88
  display: none
86
89
 
87
- .dd-item
88
- border-bottom: 1px solid #ddd
89
-
90
90
  .dd-item, .dd-empty, .dd-placeholder
91
91
  margin: 0
92
92
  padding: 0
@@ -103,16 +103,21 @@
103
103
  min-height: 100px
104
104
 
105
105
  .dd-item-inner
106
+ align-items: center
107
+ display: flex
106
108
  padding: 10px 20px
107
109
  text-decoration: none
108
110
 
109
111
  a
110
112
  margin: 0
111
113
 
114
+ a.sortable-link
115
+ flex: 1
116
+
112
117
  a.sortable-link, a.sortable-link:hover
113
118
  color: $primary-color
114
119
  font-size: 13px
115
- font-weight: 600
120
+ font-weight: 500
116
121
  padding-left: 0
117
122
 
118
123
  small
@@ -121,6 +126,7 @@
121
126
  margin-left: 13px
122
127
 
123
128
  .pull-right a
129
+ margin: 0
124
130
  opacity: 0
125
131
  transform: translateX(50px)
126
132
  transition: all .4s ease
@@ -179,7 +179,7 @@ trix-editor
179
179
  display: none
180
180
 
181
181
  img
182
- border-radius: 4px
182
+ border-radius: 6px
183
183
  display: block
184
184
  max-height: 150px
185
185
  max-width: 200px
@@ -4,9 +4,12 @@ module Spina
4
4
 
5
5
  included do
6
6
  rescue_from ActiveRecord::RecordNotFound, with: :redirect_or_render_404
7
+
8
+ helper Spina::PagesHelper
7
9
 
8
10
  before_action :set_locale
9
11
  before_action :set_current_page
12
+ before_action :set_current_account
10
13
  end
11
14
 
12
15
  def show
@@ -27,6 +30,12 @@ module Spina
27
30
 
28
31
  def set_current_page
29
32
  Spina::Current.page = page
33
+ Spina::Current.page.view_context = view_context
34
+ end
35
+
36
+ def set_current_account
37
+ Spina::Current.account = Spina::Account.first
38
+ Spina::Current.account.view_context = view_context
30
39
  end
31
40
 
32
41
  def page_by_locale(locale)
@@ -1,6 +1,7 @@
1
1
  module Spina
2
2
  module Admin
3
3
  class AccountsController < AdminController
4
+ before_action :set_locale
4
5
 
5
6
  def edit
6
7
  add_breadcrumb I18n.t('spina.preferences.account'), spina.edit_admin_account_path
@@ -22,23 +23,18 @@ module Spina
22
23
  def style
23
24
  add_breadcrumb I18n.t('spina.preferences.style'), spina.style_admin_account_path
24
25
  @themes = ::Spina::Theme.all
25
- @layout_parts = current_theme.layout_parts.map { |layout_part| current_account.layout_part(layout_part) }
26
26
  end
27
27
 
28
28
  private
29
29
 
30
- def account_params
31
- params.require(:account).permit(:address, :city, :email, :name, :phone,
32
- :postal_code, :preferences, :google_analytics,
33
- :google_site_verification, :facebook, :twitter, :google_plus,
34
- :instagram, :youtube, :linkedin,
35
- :kvk_identifier, :theme, :vat_identifier, :robots_allowed,
36
- layout_parts_attributes:
37
- [:id, :layout_partable_type, :layout_partable_id,
38
- :name, :title, :position, :content, :page_id,
39
- layout_partable_attributes:
40
- [:content, :photo_tokens, :attachment_tokens, :id]])
41
- end
30
+ def account_params
31
+ params.require(:account).permit!
32
+ end
33
+
34
+ def set_locale
35
+ @locale = params[:locale] || I18n.default_locale
36
+ end
37
+
42
38
  end
43
39
  end
44
40
  end
@@ -24,28 +24,6 @@ module Spina
24
24
  redirect_to spina.admin_attachments_url
25
25
  end
26
26
 
27
- def select
28
- @selected_attachment_id = Attachment.find_by(id: params[:selected_attachment_id]).try(:id)
29
- @hidden_field_id = params[:hidden_field_id]
30
- @attachments = Attachment.sorted
31
- @attachment = Attachment.new
32
- end
33
-
34
- def insert
35
- @attachment = Attachment.find(params[:attachment_id])
36
- Rails.logger.info "HAHA HA HA #{@attachment.id}"
37
- end
38
-
39
- def select_collection
40
- @selected_attachment_ids = Attachment.where(id: params[:selected_attachment_ids]).ids
41
- @attachments = Attachment.sorted
42
- @attachment = Attachment.new
43
- end
44
-
45
- def insert_collection
46
- @attachments = Attachment.where(id: params[:attachment_ids])
47
- end
48
-
49
27
  private
50
28
 
51
29
  def set_breadcrumbs
@@ -8,7 +8,7 @@ module Spina
8
8
  def index
9
9
  add_breadcrumb I18n.t('spina.website.images'), admin_images_path
10
10
  @media_folders = MediaFolder.order(:name)
11
- @images = Image.sorted.where(media_folder_id: nil).with_attached_file.page(params[:page])
11
+ @images = Image.sorted.where(media_folder_id: nil).with_attached_file.page(params[:page]).per(25)
12
12
  end
13
13
 
14
14
  # There's no file validation yet in ActiveStorage
@@ -2,39 +2,38 @@ module Spina
2
2
  module Admin
3
3
  class MediaPickerController < AdminController
4
4
  before_action :set_media_folders
5
+ before_action :set_selected_images
5
6
 
6
7
  def show
7
- if @media_folder.present?
8
- @images = @media_folder.images.page(params[:page])
9
- else
10
- @images = Image.where(media_folder_id: nil).page(params[:page])
11
- end
8
+ @images = Image.where(media_folder: @media_folder).order(created_at: :desc).page(params[:page]).per(25)
9
+ @mode = params[:mode]
12
10
 
13
- if params[:selected_ids].present?
14
- ids = params[:selected_ids].map(&:to_i).join(', ')
15
- @images = @images.order(Arel.sql("CASE WHEN id IN(#{ids}) THEN 0 ELSE 1 END, created_at DESC"))
16
- else
17
- @images = @images.sorted
11
+ if selected_ids.any?
12
+ @images = @images.reorder(Arel.sql("CASE WHEN id IN(#{selected_ids.join(', ')}) THEN 0 ELSE 1 END, created_at DESC"))
18
13
  end
19
14
 
20
- render params[:page].present? ? :infinite_scroll : :show
21
- end
22
-
23
- def select
24
- if params[:multiple]
25
- @images = Image.where(id: params[:image_ids].split("-"))
26
- else
27
- @image = Image.find(params[:image_id])
15
+ respond_to do |format|
16
+ format.html { render layout: false }
17
+ format.js { render :infinite_scroll if params[:page].present? }
28
18
  end
29
19
  end
30
20
 
31
21
  private
32
22
 
33
23
  def set_media_folders
34
- @media_folders = MediaFolder.order(:name)
24
+ @media_folders = MediaFolder.order(:name).joins(:images).uniq
35
25
  @media_folder = MediaFolder.find(params[:media_folder_id]) if params[:media_folder_id].present?
36
26
  end
37
27
 
28
+ def set_selected_images
29
+ @selected_images = Image.where(id: selected_ids).sort_by{|image| selected_ids.index(image.id)}
30
+ end
31
+
32
+ def selected_ids
33
+ params[:selected_ids].present? ? params[:selected_ids].map(&:to_i) : []
34
+ end
35
+ helper_method :selected_ids
36
+
38
37
  end
39
38
  end
40
39
  end
@@ -8,7 +8,7 @@ module Spina
8
8
  def index
9
9
  add_breadcrumb I18n.t('spina.website.pages'), spina.admin_pages_path
10
10
  redirect_to admin_pages_path unless current_admin_path.starts_with?('/pages')
11
- @pages = Page.active.sorted.roots.regular_pages
11
+ @pages = Page.active.sorted.roots.regular_pages.includes(:translations)
12
12
  end
13
13
 
14
14
  def new
@@ -19,7 +19,6 @@ module Spina
19
19
  @page.view_template = params[:view_template]
20
20
  end
21
21
  add_breadcrumb I18n.t('spina.pages.new')
22
- @page_parts = @page.view_template_page_parts(current_theme).map { |part| @page.part(part) }
23
22
  render layout: 'spina/admin/admin'
24
23
  end
25
24
 
@@ -30,7 +29,6 @@ module Spina
30
29
  @page.navigations << Spina::Navigation.where(auto_add_pages: true)
31
30
  redirect_to spina.edit_admin_page_url(@page), flash: {success: t('spina.pages.saved')}
32
31
  else
33
- @page_parts = @page.view_template_page_parts(current_theme).map { |part| @page.part(part) }
34
32
  render :new, layout: 'spina/admin/admin'
35
33
  end
36
34
  end
@@ -38,7 +36,6 @@ module Spina
38
36
  def edit
39
37
  add_index_breadcrumb
40
38
  add_breadcrumb @page.title
41
- @page_parts = @page.view_template_page_parts(current_theme).map { |part| @page.part(part) }
42
39
  render layout: 'spina/admin/admin'
43
40
  end
44
41
 
@@ -51,7 +48,6 @@ module Spina
51
48
  format.js
52
49
  else
53
50
  format.html do
54
- @page_parts = @page.view_template_page_parts(current_theme).map { |part| @page.part(part) }
55
51
  Mobility.locale = I18n.default_locale
56
52
  render :edit, layout: 'spina/admin/admin'
57
53
  end
@@ -1,7 +1,7 @@
1
1
  module Spina
2
2
  module Admin
3
3
  class ResourcesController < AdminController
4
-
4
+ before_action :set_locale
5
5
  before_action :set_resource, only: [:show, :edit, :update]
6
6
 
7
7
  def show
@@ -13,8 +13,8 @@ module Spina
13
13
  add_breadcrumb t('spina.edit')
14
14
  end
15
15
 
16
- def update
17
- if @resource.update(resource_params)
16
+ def update
17
+ if Mobility.with_locale(@locale) { @resource.update(resource_params) }
18
18
  redirect_to spina.admin_resource_path(@resource)
19
19
  else
20
20
  render :edit
@@ -24,12 +24,17 @@ module Spina
24
24
  private
25
25
 
26
26
  def resource_params
27
- params.require(:resource).permit(:label, :view_template, :order_by, :parent_page_id)
27
+ params.require(:resource).permit(:label, :slug, :view_template, :order_by, :parent_page_id)
28
28
  end
29
29
 
30
30
  def set_resource
31
31
  @resource = Resource.find(params[:id])
32
32
  end
33
+
34
+ def set_locale
35
+ @locale = params[:locale] || I18n.default_locale
36
+ end
37
+
33
38
  end
34
39
  end
35
40
  end
@@ -6,7 +6,7 @@ module Spina
6
6
  private
7
7
 
8
8
  def current_theme
9
- @current_theme = ::Spina::Theme.find_by_name(current_account.theme)
9
+ @current_theme ||= ::Spina::Theme.find_by_name(current_account.theme)
10
10
  end
11
11
  helper_method :current_theme
12
12
 
@@ -1,34 +1,36 @@
1
1
  module Spina
2
2
  module Admin
3
3
  module PagesHelper
4
- def link_to_add_structure_item_fields(f, &block)
5
- item = StructureItem.new
6
- fields = f.fields_for(:structure_items, item, child_index: item.object_id) do |builder|
7
- build_structure_parts(f.object.page_part.name, item)
8
- render("spina/admin/structure_items/fields", f: builder)
4
+
5
+ def link_to_add_repeater_fields(f)
6
+ repeater_content = Spina::Parts::RepeaterContent.new(name: f.object.name, title: f.object.title)
7
+ fields = f.fields_for(:content, [repeater_content], child_index: repeater_content.object_id) do |builder|
8
+ render("spina/admin/parts/repeaters/fields", f: builder)
9
9
  end
10
- link_to '#', class: "add_structure_item_fields button button-link", data: {id: item.object_id, fields: fields.gsub("\n", "")} do
10
+ link_to '#', class: "add_structure_item_fields button button-link", data: {id: repeater_content.object_id, fields: fields.gsub("\n", "")} do
11
11
  icon('plus')
12
12
  end
13
13
  end
14
14
 
15
- def build_structure_parts(name, item)
16
- structure = current_theme.structures.find { |structure| structure[:name] == name }
17
- return item.parts unless structure.present?
18
- structure[:structure_parts].map do |attributes|
19
- part = item.parts.where(name: attributes[:name]).first_or_initialize(attributes)
20
- part.partable = part.partable_type.constantize.new if part.partable.blank?
21
- part.options = attributes[:options]
22
- part
15
+ def data_attrs_for_image_collection(f)
16
+ image = Spina::Parts::Image.new
17
+ fields = f.fields_for(:images, [image], child_index: image.object_id) do |builder|
18
+ render("spina/admin/parts/image_collections/fields", f: builder)
23
19
  end
20
+ {fields: fields.gsub("\n", ""), id: image.object_id}
24
21
  end
25
22
 
26
- def partable_partial_namespace(partable)
27
- partable_type_partial_namespace(partable.model_name.to_s)
23
+ def build_parts(partable, parts)
24
+ I18n.with_locale(@locale) do
25
+ parts.map do |part|
26
+ part_attributes = current_theme.parts.find{|p|p[:name].to_s == part.to_s}
27
+ partable.part(part_attributes)
28
+ end
29
+ end
28
30
  end
29
31
 
30
- def partable_type_partial_namespace(partable_type)
31
- partable_type.tableize.sub(/\Aspina\//, '')
32
+ def parts_partial_namespace(part_type)
33
+ part_type.tableize.sub(/\Aspina\/parts\//, '')
32
34
  end
33
35
 
34
36
  def flatten_nested_hash(hash)
@@ -36,14 +38,14 @@ module Spina
36
38
  end
37
39
 
38
40
  def page_ancestry_options(page)
39
- pages = Spina::Page.active.regular_pages
41
+ pages = Spina::Page.active.regular_pages.includes(:translations)
40
42
  pages = pages.where.not(id: page.subtree.ids) unless page.new_record? || !page.methods.include?(:subtree)
41
43
 
42
44
  (flatten_nested_hash(pages.arrange(order: :position)).map do |page|
43
45
  next if page.depth >= Spina.config.max_page_depth - 1
44
46
  page_menu_title = page.depth.zero? ? page.menu_title : " #{page.menu_title}".indent(page.depth, '-')
45
47
  [page_menu_title, page.id]
46
- end << [page.parent&.menu_title, page&.parent_id].compact).uniq.compact
48
+ end << [page.parent&.menu_title, page&.parent_id].compact).map(&:presence).uniq.compact
47
49
  end
48
50
 
49
51
  def option_label(part, value)
@@ -1,5 +1,5 @@
1
1
  module Spina
2
- module FilesHelper
2
+ module AttachmentsHelper
3
3
 
4
4
  def file_url(file)
5
5
  main_app.rails_service_blob_path(file.signed_id, file.filename)
@@ -20,5 +20,11 @@ module Spina
20
20
  "https://placehold.it/100x100.png"
21
21
  end
22
22
  end
23
+
24
+ def thumbnail_url(image)
25
+ return "" if image.nil?
26
+ variant(image.file, resize: "400x300^", crop: "400x300+0+0")
27
+ end
28
+
23
29
  end
24
30
  end
@@ -1,17 +1,36 @@
1
1
  module Spina
2
2
  module PagesHelper
3
3
 
4
- def content(part_name)
5
- current_page.content(part_name)
4
+ def content(part_name = nil)
5
+ Current.page.content(part_name)
6
6
  end
7
7
 
8
8
  def has_content?(part_name)
9
- current_page.has_content?(part_name)
9
+ Current.page.has_content?(part_name)
10
+ end
11
+
12
+ def repeater(part)
13
+ part = Current.page.find_part(part)&.content unless part.is_a? Array
14
+ part&.each do |repeater_content|
15
+ repeater_content.view_context = self
16
+ yield(repeater_content)
17
+ end
18
+ end
19
+
20
+ def images(part)
21
+ part = Current.page.find_part(part)&.content unless part.is_a? Array
22
+ part&.each do |image|
23
+ yield(image)
24
+ end
10
25
  end
11
26
 
12
27
  def current_page
13
28
  Current.page
14
29
  end
15
30
 
31
+ def current_account
32
+ Current.account
33
+ end
34
+
16
35
  end
17
- end
36
+ end