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
@@ -0,0 +1,6 @@
1
+ .page-form-label= f.object.title
2
+ .page-form-control{data: {controller: "attachment-picker"}}
3
+ = f.hidden_field :signed_blob_id, data: {target: "attachment-picker.signedBlobId"}
4
+ = f.hidden_field :filename, data: {target: "attachment-picker.filename"}
5
+ .select-dropdown
6
+ = f.select :attachment_id, Spina::Attachment.sorted.map{|attachment| [attachment.file&.filename, attachment.id, data: {signed_blob_id: attachment.file&.blob&.signed_id, filename: attachment.file&.filename}]}, {include_blank: t("spina.attachments.choose_attachment")}, {data: {action: "attachment-picker#chooseAttachment"}}
@@ -0,0 +1,7 @@
1
+ = f.hidden_field :image_id, class: 'image-id'
2
+ = f.hidden_field :signed_blob_id, class: 'signed-blob-id'
3
+ = f.hidden_field :filename, class: 'filename'
4
+ - if f.object.signed_blob_id.present? && f.object.spina_image
5
+ = image_tag main_app.url_for(f.object.spina_image.variant(resize: "400x300^", crop: "400x300+0+0"))
6
+ - else
7
+ = image_tag ""
@@ -0,0 +1,12 @@
1
+ .page-form-label= f.object.title
2
+ .page-form-control{data: {controller: "image-form"}}
3
+ .page-form-media-picker
4
+ = link_to admin_media_picker_path(selected_ids: f.object.image_ids, input: "media_picker_#{f.object.object_id}", mode: "multiple"), remote: true, class: 'images', data: {target: 'image-form.image'} do
5
+ .page-form-media-picker-placeholder=t "spina.images.choose"
6
+
7
+ %div{id: "media_picker_#{f.object.object_id}", data: data_attrs_for_image_collection(f)}
8
+ = f.fields_for :images do |ff|
9
+ = render partial: "spina/admin/parts/image_collections/fields", locals: {f: ff}
10
+
11
+ = button_tag type: :default, class: 'button button-small button-default', data: {action: "image-form#remove"} do
12
+ %i.icon.icon-cross{style: "margin: 0; font-size: 10px"}
@@ -0,0 +1,18 @@
1
+ .page-form-label= f.object.title
2
+ .page-form-control{data: {controller: "image-form"}}
3
+ .page-form-media-picker
4
+ %div{style: "width: 100%"}
5
+ = link_to admin_media_picker_path(selected_ids: [f.object.image_id], input: "media_picker_#{f.object.object_id}", mode: "single"), remote: true, class: 'image', data: {target: 'image-form.image'} do
6
+ .page-form-media-picker-placeholder=t "spina.images.choose_image"
7
+ %div{id: "media_picker_#{f.object.object_id}"}
8
+ = f.hidden_field :image_id, data: {target: 'image-form.imageId'}
9
+ = f.hidden_field :signed_blob_id, data: {target: 'image-form.signedBlobId'}
10
+ = f.hidden_field :filename, data: {target: 'image-form.filename'}
11
+ %div{style: "width: 200px; height: 150px; overflow: hidden"}
12
+ - if f.object.signed_blob_id.present? && f.object.spina_image.present?
13
+ = image_tag main_app.url_for(f.object.spina_image.variant(resize: "400x300^", crop: "400x300+0+0")), width: 200, height: 150
14
+
15
+ = f.text_field :alt, placeholder: "Alt text", class: 'page-form-media-picker-alt-text'
16
+
17
+ = button_tag type: :default, class: 'button button-small button-default', data: {action: "image-form#remove"} do
18
+ %i.icon.icon-cross{style: "margin: 0; font-size: 10px"}
@@ -0,0 +1,2 @@
1
+ .page-form-label= f.object.title
2
+ .page-form-control= f.text_field :content, placeholder: f.object.title
@@ -0,0 +1,3 @@
1
+ .page-form-label= f.object.title
2
+ .page-form-control
3
+ .select-dropdown= f.select :value, f.object.options, include_blank: t("spina.options.choose_option")
@@ -0,0 +1,15 @@
1
+ .structure-form-pane{class: ('active' if f.options[:child_index].zero?), id: "structure_form_pane_#{f.object.object_id}", data: {part_id: f.object.object_id, target: "repeater-form.pane"}}
2
+ = f.hidden_field :title
3
+ = f.hidden_field :name
4
+
5
+ - parts = current_theme.parts.find{|p|p[:name].to_s == f.object.name.to_s}&.dig(:parts) || []
6
+
7
+ = f.fields_for :parts, build_parts(f.object, parts) do |ff|
8
+ = ff.hidden_field :title
9
+ = ff.hidden_field :type, value: ff.object.class
10
+ = ff.hidden_field :name
11
+
12
+ .structure-form-part
13
+ = render "spina/admin/parts/#{parts_partial_namespace(ff.object.class.to_s)}/form", f: ff
14
+
15
+ = link_to t('spina.delete'), '#', class: 'button button-mini button-link pull-right', data: {action: "repeater-form#delete", part_id: f.object.object_id}
@@ -0,0 +1,18 @@
1
+ .page-form-label= f.object.title
2
+ .page-form-control
3
+ .structure-form{data: {controller: "repeater-form"}}
4
+ .structure-form-menu
5
+ %ul{data: {target: "repeater-form.list"}}
6
+ - (f.object.content || []).each.with_index do |repeater_content, index|
7
+ %li{class: ('active' if index.zero?), data: {part_id: repeater_content.object_id, target: "repeater-form.listItem"}}
8
+ = link_to "#structure_form_pane_#{repeater_content.object_id}" do
9
+ %i.icon.icon-bars.sortable-handle
10
+ = repeater_content.parts&.first&.content
11
+
12
+ %div{style: "margin-top: 6px; margin-left: 6px"}
13
+ = link_to_add_repeater_fields f do
14
+ = icon('plus')
15
+
16
+ .structure-form-content{data: {target: "repeater-form.content"}}
17
+ = f.fields_for :content do |ff|
18
+ = render 'spina/admin/parts/repeaters/fields', f: ff
@@ -0,0 +1,6 @@
1
+ .page-form-label= f.object.title
2
+ .page-form-content
3
+ .page-form-rich-text
4
+ = f.hidden_field :content, id: "#{f.object.object_id}_input"
5
+ %trix-editor.text-input.trix-content{ input: "#{f.object.object_id}_input" }
6
+
@@ -1,6 +1,6 @@
1
1
  - if @resource.errors.any?
2
2
  - content_for :notifications do
3
- .notification.notification-danger.animated.fadeInRight
3
+ .notification.notification-danger.animated.fadeInLeft
4
4
  = icon('exclamation')
5
5
  .notification-message
6
6
  =t 'spina.notifications.alert'
@@ -9,21 +9,44 @@
9
9
  = icon('cross')
10
10
 
11
11
  = form_with model: @resource, url: spina.admin_resource_path(@resource) do |f|
12
+ = hidden_field_tag :locale, @locale
13
+
12
14
  %header#header
13
- .breadcrumbs= render_breadcrumbs separator: '<div class="divider"></div>'
15
+ .breadcrumbs
16
+ = render_breadcrumbs separator: '<div class="divider"></div>'
17
+ %span{style: 'margin-left: 10px'}
18
+ - if Spina.config.locales.size > 1
19
+ %div{style: "display: inline-block", data: {dropdown: true}}
20
+ = link_to '#', class: 'button button-default button-small', style: 'margin-left: 0; margin-right: 0', data: {trigger: 'dropdown', target: '#locales'} do
21
+ = icon('comment')
22
+ =t "spina.languages.#{@locale}"
23
+ %i.icon.icon-chevron-down{style: 'font-size: 9px; margin-right: 0'}
24
+
25
+ %ul#locales
26
+ - Spina.config.locales.each do |locale|
27
+ %li
28
+ = link_to t("spina.languages.#{locale}"), "?locale=#{locale}", style: ('font-weight: 600' if @locale.to_s == locale.to_s).to_s
14
29
 
15
30
  #header_actions
16
31
  %button.button.button-primary{type: 'submit', style: 'margin-right: 0'}
17
32
  = icon('check')
18
33
  =t 'spina.save'
19
34
 
20
- .well
21
- .horizontal-form
35
+ .horizontal-form
36
+ %div{style: "margin: 40px 0"}
22
37
  .horizontal-form-group
23
38
  .horizontal-form-label
24
39
  = Spina::Resource.human_attribute_name :label
25
40
  .horizontal-form-content
26
- = f.text_field :label, placeholder: Spina::Resource.human_attribute_name(:label)
41
+ .page-form-control
42
+ = f.text_field :label, placeholder: Spina::Resource.human_attribute_name(:label)
43
+
44
+ .horizontal-form-group
45
+ .horizontal-form-label
46
+ = Spina::Resource.human_attribute_name :slug
47
+ .horizontal-form-content
48
+ .page-form-control
49
+ = f.text_field :slug, placeholder: Spina::Resource.human_attribute_name(:slug), value: f.object.slug(locale: @locale)&.parameterize
27
50
 
28
51
  .horizontal-form-group
29
52
  .horizontal-form-label
@@ -1,10 +1,13 @@
1
1
  - content_for(:header_actions) do
2
2
 
3
- = link_to spina.edit_admin_resource_path(@resource), class: 'button' do
4
- = t('spina.resources.edit')
3
+ = link_to spina.edit_admin_resource_path(@resource), class: 'button button-default' do
4
+ .button-content
5
+ = icon('pencil')
6
+ = t('spina.resources.edit')
5
7
 
6
8
  = link_to spina.new_admin_page_path(params: {resource_id: @resource.id, view_template: @resource.view_template.presence || 'show'}), class: 'button button-primary icon-only', style: 'margin-right: 0' do
7
9
  = icon('plus')
10
+ = t('spina.pages.new')
8
11
 
9
12
  .well
10
13
  .dd#pages_list
@@ -1,6 +1,6 @@
1
1
  %aside#notifications
2
2
  - if flash[:notice]
3
- .notification.animated.fadeInRight
3
+ .notification.animated.fadeInLeft
4
4
  = icon('info')
5
5
  .notification-message
6
6
  = flash[:notice].html_safe
@@ -9,7 +9,7 @@
9
9
  = icon('cross')
10
10
 
11
11
  - if flash[:alert]
12
- .notification.notification-danger.animated.fadeInRight
12
+ .notification.notification-danger.animated.fadeInLeft
13
13
  = icon('exclamation')
14
14
  .notification-message
15
15
  = flash[:alert].html_safe
@@ -18,8 +18,8 @@
18
18
  = icon('cross')
19
19
 
20
20
  - if flash[:success]
21
- .notification.notification-success.animated.fadeInRight
22
- = icon('large-check')
21
+ .notification.notification-success.animated.fadeInLeft
22
+ = icon('check')
23
23
  .notification-message
24
24
  = flash[:success].html_safe
25
25
  %small= flash[:success_small].try(:html_safe)
@@ -1,4 +1,4 @@
1
- class AddUrlTitleToSpinaPageTranslations < ActiveRecord::Migration[6.0]
1
+ class AddUrlTitleToSpinaPageTranslations < ActiveRecord::Migration[5.2]
2
2
  def change
3
3
  add_column :spina_page_translations, :url_title, :string
4
4
  end
@@ -0,0 +1,5 @@
1
+ class AddJsonAttributesToSpinaAccounts < ActiveRecord::Migration[5.2]
2
+ def change
3
+ add_column :spina_accounts, :json_attributes, :jsonb
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddJsonAttributesToSpinaPages < ActiveRecord::Migration[5.2]
2
+ def change
3
+ add_column :spina_pages, :json_attributes, :jsonb
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddSlugToSpinaResources < ActiveRecord::Migration[5.2]
2
+ def change
3
+ add_column :spina_resources, :slug, :jsonb
4
+ end
5
+ end
@@ -1,28 +1,20 @@
1
1
  %h1= current_page.title
2
+ = content :option
2
3
 
3
- %h5 Line
4
- %p= content :line
5
-
6
- %h5 Content
7
- != content :text
8
-
9
- %h5 Image
10
-
4
+ = content :headline
5
+ = content.text :headline
6
+ = content.html :body
11
7
  - if has_content?(:image)
12
- %p= image_tag content(:image).variant(resize: "200x100")
8
+ = content.image_tag :image, resize: '100x100'
13
9
 
14
- %h5 Image collection
10
+ = current_account.content :line
15
11
 
16
- %ul
17
- - content(:image_collection)&.images&.each do |image|
18
- %li= image_tag image.variant(resize: '100x100')
12
+ - repeater current_account.content(:repeater) do |repeater_content|
13
+ = repeater_content.content :line
19
14
 
20
- %h5 Structure
15
+ - images :image_collection do |image|
16
+ = content.image_tag image, resize: '50x50'
21
17
 
22
- %ul
23
- - content(:structure)&.structure_items&.each do |item|
24
- %li
25
- %h6 Title
26
- %p= item.content(:title)
27
- %h6 Description
28
- != item.content(:description)
18
+ - repeater :repeater do |project|
19
+ = project.content.html :line
20
+ = project.content.image_tag :image, resize: '50x50'
@@ -1,2 +1,2 @@
1
1
  %h1= current_page.title
2
- != content(:text)
2
+ = content.html :body
@@ -3,10 +3,10 @@
3
3
  theme.name = 'default'
4
4
  theme.title = 'Default Theme'
5
5
 
6
- theme.page_parts = [{
7
- name: 'text',
8
- title: 'Text',
9
- partable_type: 'Spina::Text'
6
+ theme.parts = [{
7
+ name: 'text',
8
+ title: "Text",
9
+ part_type: "Spina::Parts::Text"
10
10
  }]
11
11
 
12
12
  theme.view_templates = [{
@@ -3,69 +3,57 @@
3
3
  theme.name = 'demo'
4
4
  theme.title = 'Demo theme'
5
5
 
6
- theme.page_parts = [{
7
- name: 'line',
8
- title: 'Line',
9
- partable_type: 'Spina::Line'
6
+ theme.layout_parts = ['line', 'body']
7
+
8
+ # New config
9
+ theme.parts = [{
10
+ name: 'repeater',
11
+ title: "Repeater",
12
+ part_type: "Spina::Parts::Repeater",
13
+ parts: ['line', 'image', 'headline', 'image_collection']
10
14
  }, {
11
- name: 'text',
12
- title: 'Text',
13
- partable_type: 'Spina::Text'
15
+ name: 'line',
16
+ title: "Line",
17
+ part_type: "Spina::Parts::Line"
14
18
  }, {
15
- name: 'image',
16
- title: 'Image',
17
- partable_type: 'Spina::Image'
19
+ name: 'body',
20
+ title: "Body",
21
+ part_type: "Spina::Parts::Text"
18
22
  }, {
19
- name: 'image_collection',
20
- title: 'Image collection',
21
- partable_type: 'Spina::ImageCollection'
23
+ name: "image_collection",
24
+ title: "Image collection",
25
+ part_type: "Spina::Parts::ImageCollection"
22
26
  }, {
23
- name: 'attachment',
24
- title: 'Attachment',
25
- partable_type: 'Spina::Attachment'
27
+ name: 'image',
28
+ title: "Image",
29
+ part_type: "Spina::Parts::Image"
26
30
  }, {
27
- name: 'attachment_collection',
28
- title: 'Attachment collection',
29
- partable_type: 'Spina::AttachmentCollection'
31
+ name: 'headline',
32
+ title: "Headline",
33
+ part_type: "Spina::Parts::Line"
30
34
  }, {
31
- name: 'structure',
32
- title: 'Structure',
33
- partable_type: 'Spina::Structure'
34
- }]
35
-
36
- theme.structures = [{
37
- name: 'structure',
38
- structure_parts: [{
39
- name: 'title',
40
- title: 'Title',
41
- partable_type: 'Spina::Line'
42
- }, {
43
- name: 'description',
44
- title: 'Description',
45
- partable_type: 'Spina::Text'
46
- }]
47
- }]
48
-
49
- theme.layout_parts = [{
50
- name: 'line',
51
- title: 'Line',
52
- partable_type: 'Spina::Line'
35
+ name: 'footer',
36
+ title: "Footer",
37
+ part_type: "Spina::Parts::Text"
53
38
  }]
54
39
 
55
40
  theme.view_templates = [{
56
41
  name: 'homepage',
57
42
  title: 'Homepage',
58
- page_parts: ['text'],
43
+ page_parts: [],
44
+ parts: ['headline', 'body', 'image_collection']
59
45
  }, {
60
46
  name: 'show',
61
47
  title: 'Default',
62
48
  usage: 'Use for your content',
63
- page_parts: ['text']
49
+ page_parts: [],
50
+ parts: ['body', 'image', 'repeater']
64
51
  }, {
65
52
  name: 'demo',
66
53
  title: 'Demo',
67
54
  description: 'Contains examples of every page part',
68
- page_parts: ['line', 'text', 'image', 'image_collection', 'attachment', 'attachment_collection', 'structure']
55
+ page_parts: [],
56
+ parts: ['body', 'image_collection', 'image', 'repeater']
69
57
  }]
70
58
 
71
59
  theme.custom_pages = [{
@@ -2,11 +2,13 @@ require 'spina/engine'
2
2
  require 'spina/railtie'
3
3
  require 'spina/plugin'
4
4
  require 'spina/theme'
5
+ require 'spina/attr_json_spina_parts_model'
5
6
 
6
7
  module Spina
7
8
 
8
9
  include ActiveSupport::Configurable
9
10
 
11
+ PARTS = []
10
12
  PLUGINS = []
11
13
  THEMES = []
12
14
 
@@ -0,0 +1,29 @@
1
+ require 'attr_json/type/polymorphic_model'
2
+
3
+ # Extending the PolymorphicModel to use the Spina::PARTS array as input
4
+ # as opposed to arguments
5
+ module AttrJson
6
+ module Type
7
+ class SpinaPartsModel < PolymorphicModel
8
+
9
+ def model_names
10
+ spina_parts_lookup.keys
11
+ end
12
+
13
+ def model_types
14
+ spina_parts_lookup.values
15
+ end
16
+
17
+ def spina_parts_lookup
18
+ @spina_parts_lookup ||= Spina::PARTS.map(&:to_type).map do |type|
19
+ [type.model.name, type]
20
+ end.to_h
21
+ end
22
+
23
+ def type_for_model_name(model_name)
24
+ spina_parts_lookup[model_name]
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -1,4 +1,3 @@
1
- require 'spina'
2
1
  require 'haml-rails'
3
2
  require 'sass-rails'
4
3
  require 'coffee-rails'
@@ -11,6 +10,7 @@ require 'kaminari'
11
10
  require 'mobility'
12
11
  require 'rack-rewrite'
13
12
  require 'jsonb_accessor'
13
+ require 'attr_json'
14
14
 
15
15
  module Spina
16
16
  class Engine < ::Rails::Engine
@@ -22,11 +22,22 @@ module Spina
22
22
  config.to_prepare do
23
23
  # Load helpers from main application
24
24
  Spina::ApplicationController.helper Rails.application.helpers
25
-
25
+
26
26
  # Require decorators from main application
27
27
  [Rails.root].flatten.map { |p| Dir[p.join('app', 'decorators', '**', '*_decorator.rb')]}.flatten.uniq.each do |decorator|
28
28
  Rails.configuration.cache_classes ? require(decorator) : load(decorator)
29
29
  end
30
+
31
+ # Register JSON part types for editing content
32
+ Spina::Part.register(
33
+ Spina::Parts::Line,
34
+ Spina::Parts::Text,
35
+ Spina::Parts::Image,
36
+ Spina::Parts::ImageCollection,
37
+ Spina::Parts::Repeater,
38
+ Spina::Parts::Option,
39
+ Spina::Parts::Attachment
40
+ )
30
41
  end
31
42
  end
32
43
  end