From c23842d8ee26fa4bb23c19ac1d4da580cc752bb8 Mon Sep 17 00:00:00 2001 From: Arnaud Levy <contact@arnaudlevy.com> Date: Wed, 8 Jun 2022 08:30:40 +0200 Subject: [PATCH] refactored previews --- app/helpers/admin/blocks_helper.rb | 4 +++- .../communication/blocks/components/_preview.html.erb | 10 ++++++++++ .../blocks/components/image/_preview.html.erb | 7 +++---- .../blocks/components/layout/_static.html.erb | 2 +- .../blocks/components/rich_text/_preview.html.erb | 1 - .../blocks/components/string/_preview.html.erb | 2 +- .../blocks/components/text/_preview.html.erb | 2 +- 7 files changed, 19 insertions(+), 9 deletions(-) diff --git a/app/helpers/admin/blocks_helper.rb b/app/helpers/admin/blocks_helper.rb index 354b7d742..b553623fe 100644 --- a/app/helpers/admin/blocks_helper.rb +++ b/app/helpers/admin/blocks_helper.rb @@ -5,7 +5,9 @@ module Admin::BlocksHelper end def block_component_preview(property, **options) - block_component_render :preview, property, **options + render "admin/communication/blocks/components/preview", + property: property, + **options end def block_component_static(property, **options) diff --git a/app/views/admin/communication/blocks/components/_preview.html.erb b/app/views/admin/communication/blocks/components/_preview.html.erb index e69de29bb..17720e3b4 100644 --- a/app/views/admin/communication/blocks/components/_preview.html.erb +++ b/app/views/admin/communication/blocks/components/_preview.html.erb @@ -0,0 +1,10 @@ +<% +template ||= @block.template +component = template.public_send "#{property}_component" +value = template.public_send(property).to_s +local_assigns[:template] = template +local_assigns[:component] = component +local_assigns[:value] = value +partial = "admin/communication/blocks/components/#{component.kind}/preview" +%> +<%= render partial, **local_assigns %> diff --git a/app/views/admin/communication/blocks/components/image/_preview.html.erb b/app/views/admin/communication/blocks/components/image/_preview.html.erb index 86c97ebd9..e9a76da24 100644 --- a/app/views/admin/communication/blocks/components/image/_preview.html.erb +++ b/app/views/admin/communication/blocks/components/image/_preview.html.erb @@ -1,6 +1,5 @@ <% -image = template.public_send "#{property}_component" +blob = component.blob +return unless blob %> -<%= kamifusen_tag image.blob, - width: 400, - class: 'img-fluid' if image.blob %> +<%= kamifusen_tag blob, width: 600, class: 'img-fluid' %> diff --git a/app/views/admin/communication/blocks/components/layout/_static.html.erb b/app/views/admin/communication/blocks/components/layout/_static.html.erb index 2d29f732a..ee75aafce 100644 --- a/app/views/admin/communication/blocks/components/layout/_static.html.erb +++ b/app/views/admin/communication/blocks/components/layout/_static.html.erb @@ -1 +1 @@ - layout: <%= template.layout %> +<%= indentation %>layout: <%= template.layout %> diff --git a/app/views/admin/communication/blocks/components/rich_text/_preview.html.erb b/app/views/admin/communication/blocks/components/rich_text/_preview.html.erb index 0a579ffcd..c3042cff6 100644 --- a/app/views/admin/communication/blocks/components/rich_text/_preview.html.erb +++ b/app/views/admin/communication/blocks/components/rich_text/_preview.html.erb @@ -1,2 +1 @@ -<% value = template.public_send(property).to_s %> <%= value.html_safe %> diff --git a/app/views/admin/communication/blocks/components/string/_preview.html.erb b/app/views/admin/communication/blocks/components/string/_preview.html.erb index 5411e2b13..39fbb33ec 100644 --- a/app/views/admin/communication/blocks/components/string/_preview.html.erb +++ b/app/views/admin/communication/blocks/components/string/_preview.html.erb @@ -1 +1 @@ -<%= template.public_send(property).to_s %> +<%= value %> diff --git a/app/views/admin/communication/blocks/components/text/_preview.html.erb b/app/views/admin/communication/blocks/components/text/_preview.html.erb index 5591ba8da..b8c9c330c 100644 --- a/app/views/admin/communication/blocks/components/text/_preview.html.erb +++ b/app/views/admin/communication/blocks/components/text/_preview.html.erb @@ -1 +1 @@ -<%= simple_format template.public_send(property).to_s %> +<%= simple_format value %> -- GitLab