diff --git a/app/helpers/admin/blocks_helper.rb b/app/helpers/admin/blocks_helper.rb new file mode 100644 index 0000000000000000000000000000000000000000..387ff3e0129c4160299e8b6fc0b11c63e2c859d5 --- /dev/null +++ b/app/helpers/admin/blocks_helper.rb @@ -0,0 +1,26 @@ +module Admin::BlocksHelper + + def block_component_edit(property, **options) + component = block_component property + partial = "admin/communication/blocks/components/#{component.kind}/edit" + render partial, property: property, **options + end + + def block_component_preview(property, **options) + component = block_component property + partial = "admin/communication/blocks/components/#{component.kind}/preview" + render partial, property: property, **options + end + + def block_component_static(property, **options) + component = block_component property + partial = "admin/communication/blocks/components/#{component.kind}/static" + render partial, property: property, **options + end + + protected + + def block_component(property) + @block.template.public_send "#{property}_component" + end +end diff --git a/app/models/communication/block/component/base.rb b/app/models/communication/block/component/base.rb index 290e1cb2de90bcc96c8867b0371445151af95a64..cd1d13e91c71531633a4031cc63a61b0960a0c57 100644 --- a/app/models/communication/block/component/base.rb +++ b/app/models/communication/block/component/base.rb @@ -13,4 +13,8 @@ class Communication::Block::Component::Base def data=(value) @data = value end + + def kind + self.class.name.demodulize.underscore + end end diff --git a/app/views/admin/communication/blocks/templates/chapter/_edit.html.erb b/app/views/admin/communication/blocks/templates/chapter/_edit.html.erb index cd0aa4f8d07567bdb1d9afc7449590bd7aba2e43..c455ecd9b996ce63cbaba56477e5bcc471f728ef 100644 --- a/app/views/admin/communication/blocks/templates/chapter/_edit.html.erb +++ b/app/views/admin/communication/blocks/templates/chapter/_edit.html.erb @@ -1,9 +1,9 @@ <div class="row mb-4"> <div class="col-md-6"> - <%= render 'admin/communication/blocks/components/rich_text/edit', property: :text %> - <%= render 'admin/communication/blocks/components/rich_text/edit', property: :notes %> + <%= block_component_edit :text %> + <%= block_component_edit :notes %> </div> <div class="col-md-6"> - <%= render 'admin/communication/blocks/components/image/edit', property: :image %> + <%= block_component_edit :image %> </div> </div> diff --git a/app/views/admin/communication/blocks/templates/chapter/_preview.html.erb b/app/views/admin/communication/blocks/templates/chapter/_preview.html.erb index 79f20d9198783f279000eaf1d1ef8d3021e97bdd..9a02f6ae9c5251c087b712c7e027d42442fb0e24 100644 --- a/app/views/admin/communication/blocks/templates/chapter/_preview.html.erb +++ b/app/views/admin/communication/blocks/templates/chapter/_preview.html.erb @@ -1,3 +1,3 @@ -<%= render 'admin/communication/blocks/components/image/preview', property: :image %> -<%= render 'admin/communication/blocks/components/rich_text/preview', property: :text %> -<%= render 'admin/communication/blocks/components/rich_text/preview', property: :notes %> +<%= block_component_preview :image %> +<%= block_component_preview :notes %> +<%= block_component_preview :text %> diff --git a/app/views/admin/communication/blocks/templates/chapter/_static.html.erb b/app/views/admin/communication/blocks/templates/chapter/_static.html.erb index 666bc43a736872e1ad4ec81f52aad16ee85b7335..fc59030371413ca29b4ed427dcec7e96f1c8bf28 100644 --- a/app/views/admin/communication/blocks/templates/chapter/_static.html.erb +++ b/app/views/admin/communication/blocks/templates/chapter/_static.html.erb @@ -1,3 +1,3 @@ -<%= render 'admin/communication/blocks/components/rich_text/static', property: :text %> -<%= render 'admin/communication/blocks/components/rich_text/static', property: :notes %> -<%= render 'admin/communication/blocks/components/image/static', property: :image %> +<%= block_component_static :text %> +<%= block_component_static :notes %> +<%= block_component_static :image %> diff --git a/app/views/admin/communication/blocks/templates/video/_edit.html.erb b/app/views/admin/communication/blocks/templates/video/_edit.html.erb index 7940e16601bc0025315c8614de8a1b7a7203c75d..48bd2e4217acc4f8ffc70dfb7d53610dda737f13 100644 --- a/app/views/admin/communication/blocks/templates/video/_edit.html.erb +++ b/app/views/admin/communication/blocks/templates/video/_edit.html.erb @@ -1,8 +1,8 @@ <div class="row mb-4"> <div class="col-md-6"> - <%= render 'admin/communication/blocks/components/string/edit', property: :url %> + <%= block_component_edit :url %> </div> <div class="col-md-6"> - <%= render 'admin/communication/blocks/components/text/edit', property: :transcription, rows: 10 %> + <%= block_component_edit :transcription, rows: 10 %> </div> </div> diff --git a/app/views/admin/communication/blocks/templates/video/_preview.html.erb b/app/views/admin/communication/blocks/templates/video/_preview.html.erb index d39427a0d10d52692b5ad662183bc32a5fbdd5d5..1421cdcef37eba0fd35a97fa4d2e2f54c5bfa905 100644 --- a/app/views/admin/communication/blocks/templates/video/_preview.html.erb +++ b/app/views/admin/communication/blocks/templates/video/_preview.html.erb @@ -1,3 +1,3 @@ <%# TODO iframe video %> -<%= render 'admin/communication/blocks/components/string/preview', property: :url %> -<%= render 'admin/communication/blocks/components/text/preview', property: :transcription %> +<%= block_component_preview :url %> +<%= block_component_preview :transcription %> diff --git a/app/views/admin/communication/blocks/templates/video/_static.html.erb b/app/views/admin/communication/blocks/templates/video/_static.html.erb index 1e134e6ae86a050651a37d66c5c83c572151d481..ddc52312d4414abf318ca520b0cb03707232d380 100644 --- a/app/views/admin/communication/blocks/templates/video/_static.html.erb +++ b/app/views/admin/communication/blocks/templates/video/_static.html.erb @@ -1,2 +1,2 @@ -<%= render 'admin/communication/blocks/components/string/static', property: :url %> -<%= render 'admin/communication/blocks/components/text/static', property: :transcription %> +<%= block_component_static :url %> +<%= block_component_static :transcription %>