diff --git a/app/helpers/admin/application_helper.rb b/app/helpers/admin/application_helper.rb index edad92b4380db489a165277bec2341cfa5daab9f..8a02cf60fe154c4be4eec9b28c67b87e76318358 100644 --- a/app/helpers/admin/application_helper.rb +++ b/app/helpers/admin/application_helper.rb @@ -74,7 +74,7 @@ module Admin::ApplicationHelper end def prepare_text_for_static(text, depth = 1) - indentation = ' ' * depth # Beware, it works only at level one, with 2 spaces + indentation = ' ' * depth text = text.to_s.dup text = strip_tags text text = text.strip diff --git a/app/models/communication/block/component/image.rb b/app/models/communication/block/component/image.rb index 2976c5af0697c20428ac4f7403916b396211e5a9..12a1fd7e4c23d411ed67a587966e5d40eb3085b0 100644 --- a/app/models/communication/block/component/image.rb +++ b/app/models/communication/block/component/image.rb @@ -1,12 +1,7 @@ class Communication::Block::Component::Image < Communication::Block::Component::Base - # def data - # # Loading the blob when needed, not saved in the database - # @data['blob'] = template.blob_with_id @data['id'] if @data&.has_key? 'id' - # @data - # end - def blob + return if data['id'].blank? @blob ||= template.blob_with_id data['id'] end diff --git a/app/models/communication/block/component/layout.rb b/app/models/communication/block/component/layout.rb new file mode 100644 index 0000000000000000000000000000000000000000..6709b568c27eb5dd1c6d11aebb56d607d43f59f2 --- /dev/null +++ b/app/models/communication/block/component/layout.rb @@ -0,0 +1,3 @@ +class Communication::Block::Component::Layout < Communication::Block::Component::Base + +end diff --git a/app/models/communication/block/template/base.rb b/app/models/communication/block/template/base.rb index 7723cc8ad0c7364149efc3bcd4c9c154dd34a0df..72d29566849c3718affcf6bdf7a63e6bfc9db5af 100644 --- a/app/models/communication/block/template/base.rb +++ b/app/models/communication/block/template/base.rb @@ -27,6 +27,7 @@ class Communication::Block::Template::Base def self.has_layouts(list) self.layouts = list + has_component :layout, :layout end def self.has_elements(element_class) diff --git a/app/models/communication/block/template/chapter.rb b/app/models/communication/block/template/chapter.rb index e0d9a26b1c1e28ae6dd7caf88b920e92019776cb..688a91de7bc3a0965ab0d3627ce10cb018ae5141 100644 --- a/app/models/communication/block/template/chapter.rb +++ b/app/models/communication/block/template/chapter.rb @@ -1,11 +1,9 @@ class Communication::Block::Template::Chapter < Communication::Block::Template::Base + has_rich_text :text has_rich_text :notes has_image :image has_string :image_alt has_rich_text :image_credit - def build_git_dependencies - add_dependency image&.blob - end end diff --git a/app/models/communication/block/template/gallery.rb b/app/models/communication/block/template/gallery.rb index bf621dcf993be5e0267ab1027a51aa6f525d22bf..0fef23ebf55f5ca7d6361017177437dceda53471 100644 --- a/app/models/communication/block/template/gallery.rb +++ b/app/models/communication/block/template/gallery.rb @@ -3,18 +3,4 @@ class Communication::Block::Template::Gallery < Communication::Block::Template:: has_layouts [:grid, :carousel] has_elements Communication::Block::Template::Gallery::Image - def build_git_dependencies - add_dependency active_storage_blobs - end - - # def images_with_alt - # @images_with_alt ||= elements.map { |element| - # extract_image_alt_and_credit element, 'file' - # }.compact - # end - - # def active_storage_blobs - # @active_storage_blobs ||= images_with_alt.map { |hash| hash.blob } - # .compact - # end end diff --git a/app/views/admin/communication/blocks/components/image/_static.html.erb b/app/views/admin/communication/blocks/components/image/_static.html.erb index 8d2f396a9549cd23df9c170119f12f6885912899..af09d1a547133a5e075b834f2f102d6de75718a4 100644 --- a/app/views/admin/communication/blocks/components/image/_static.html.erb +++ b/app/views/admin/communication/blocks/components/image/_static.html.erb @@ -1,10 +1,11 @@ <% component = template.public_send "#{property}_component" blob = component.blob -indentation = ' ' +depth ||= 3 +indentation = ' ' * depth %> <% if blob %> -<%= indentation %>image: +<%= indentation %><%= property %>: <%= indentation %> id: "<%= blob.id %>" <%= indentation %> file: "<%= blob.id %>" <% end %> diff --git a/app/views/admin/communication/blocks/components/layouts/_edit.html.erb b/app/views/admin/communication/blocks/components/layout/_edit.html.erb similarity index 100% rename from app/views/admin/communication/blocks/components/layouts/_edit.html.erb rename to app/views/admin/communication/blocks/components/layout/_edit.html.erb diff --git a/app/views/admin/communication/blocks/components/layout/_static.html.erb b/app/views/admin/communication/blocks/components/layout/_static.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..21c135f27b97611eb6b69389f1e75d64d7fa97ba --- /dev/null +++ b/app/views/admin/communication/blocks/components/layout/_static.html.erb @@ -0,0 +1 @@ + layout: <%= @block.template.layout %> diff --git a/app/views/admin/communication/blocks/components/rich_text/_static.html.erb b/app/views/admin/communication/blocks/components/rich_text/_static.html.erb index baf754588c410d0c7e8552c7ec7c37825a432e6e..7c487d79030a555cfbc23caf56bab55956983b95 100644 --- a/app/views/admin/communication/blocks/components/rich_text/_static.html.erb +++ b/app/views/admin/communication/blocks/components/rich_text/_static.html.erb @@ -1,6 +1,7 @@ <% -value = @block.template.public_send property -indentation = ' ' +value = template.public_send property +depth ||= 3 +indentation = ' ' * depth %> <%= indentation %><%= property %>: >- <%= indentation %> <%= prepare_html_for_static value, @university %> diff --git a/app/views/admin/communication/blocks/components/string/_static.html.erb b/app/views/admin/communication/blocks/components/string/_static.html.erb index 40e2b9d7ed9bac35dd85bcb2310c054bd3efabac..72a8e7fc8fc8d8e16cec809f916193467c9b0d86 100644 --- a/app/views/admin/communication/blocks/components/string/_static.html.erb +++ b/app/views/admin/communication/blocks/components/string/_static.html.erb @@ -1,6 +1,7 @@ <% -indentation = ' ' -value = @block.template.public_send property +value = template.public_send property +depth ||= 3 +indentation = ' ' * depth %> <%= indentation %><%= property %>: >- -<%= indentation %> <%= prepare_text_for_static value, 4 %> +<%= indentation %> <%= prepare_text_for_static value, depth + 1 %> diff --git a/app/views/admin/communication/blocks/components/text/_static.html.erb b/app/views/admin/communication/blocks/components/text/_static.html.erb index 40e2b9d7ed9bac35dd85bcb2310c054bd3efabac..72a8e7fc8fc8d8e16cec809f916193467c9b0d86 100644 --- a/app/views/admin/communication/blocks/components/text/_static.html.erb +++ b/app/views/admin/communication/blocks/components/text/_static.html.erb @@ -1,6 +1,7 @@ <% -indentation = ' ' -value = @block.template.public_send property +value = template.public_send property +depth ||= 3 +indentation = ' ' * depth %> <%= indentation %><%= property %>: >- -<%= indentation %> <%= prepare_text_for_static value, 4 %> +<%= indentation %> <%= prepare_text_for_static value, depth + 1 %> diff --git a/app/views/admin/communication/blocks/templates/gallery/_edit.html.erb b/app/views/admin/communication/blocks/templates/gallery/_edit.html.erb index 8ae23ce25e2564abe9c3ea95a4261dc58c8ee83e..97fd09e1bb7a089ec532eaa2b7d5d6a422e15900 100644 --- a/app/views/admin/communication/blocks/templates/gallery/_edit.html.erb +++ b/app/views/admin/communication/blocks/templates/gallery/_edit.html.erb @@ -1,8 +1,7 @@ <% element = @block.template.default_element %> -<%= render 'admin/communication/blocks/components/layouts/edit', - horizontal: true %> +<%= block_component_edit :layout, horizontal: true %> <%= render 'admin/communication/blocks/components/add_element/edit', label: t('.add_image') %> diff --git a/app/views/admin/communication/blocks/templates/gallery/_static.html.erb b/app/views/admin/communication/blocks/templates/gallery/_static.html.erb index 0c2839e58548d3681037e4f95084e1204ac2bb4d..06a195a30351a3db4fc2f886d1a8ed92ea675412 100644 --- a/app/views/admin/communication/blocks/templates/gallery/_static.html.erb +++ b/app/views/admin/communication/blocks/templates/gallery/_static.html.erb @@ -1,6 +1,12 @@ - layout: <%= block.template.layout %> +<%= block_component_static :layout %> images: <% block.template.elements.each do |element| %> +<% next unless element.blob %> + - +<%= block_component_static :image, template: element, depth: 5 %> +<%= block_component_static :alt, template: element, depth: 6 %> +<%= block_component_static :credit, template: element, depth: 6 %> +<%= block_component_static :text, template: element, depth: 6 %> - id: "<%= element.blob.id %>" file: "<%= element.blob.id %>" alt: >