From 3cd02baa09da20a0f0debe7408b2c481b35c0b49 Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Sat, 30 Nov 2024 11:34:02 -0800 Subject: [PATCH] Add `thumbnail_input` method to support form builder Just to clean up this relatively common input type! --- app/helpers/support_form_helper.rb | 10 +++++++++- app/views/alt_styles/edit.html.haml | 5 +---- app/views/items/edit.html.haml | 5 +---- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app/helpers/support_form_helper.rb b/app/helpers/support_form_helper.rb index a680862c..96650bae 100644 --- a/app/helpers/support_form_helper.rb +++ b/app/helpers/support_form_helper.rb @@ -1,7 +1,7 @@ module SupportFormHelper class SupportFormBuilder < ActionView::Helpers::FormBuilder attr_reader :template - delegate :concat, :content_tag, to: :template, private: true + delegate :concat, :content_tag, :image_tag, to: :template, private: true def fields(&block) content_tag(:ul, class: "fields", &block) @@ -30,6 +30,14 @@ module SupportFormHelper def radio_grid_fieldset(*args, &block) radio_fieldset(*args, "data-type": "radio-grid", &block) end + + def thumbnail_input(method) + url = object.send(method) + content_tag(:div, class: "thumbnail-input") do + concat image_tag(url, alt: "Thumbnail") if url.present? + concat url_field(method) + end + end end def support_form_with(**kwargs, &block) diff --git a/app/views/alt_styles/edit.html.haml b/app/views/alt_styles/edit.html.haml index 86844a16..8d15ac50 100644 --- a/app/views/alt_styles/edit.html.haml +++ b/app/views/alt_styles/edit.html.haml @@ -29,10 +29,7 @@ = f.field do = f.label :thumbnail_url, "Thumbnail" - .thumbnail-input - - if @alt_style.thumbnail_url? - = image_tag @alt_style.thumbnail_url - = f.url_field :thumbnail_url + = f.thumbnail_input :thumbnail_url .actions = f.submit "Save changes" diff --git a/app/views/items/edit.html.haml b/app/views/items/edit.html.haml index e2ed9054..e748ce06 100644 --- a/app/views/items/edit.html.haml +++ b/app/views/items/edit.html.haml @@ -23,10 +23,7 @@ = f.field do = f.label :thumbnail_url, "Thumbnail" - .thumbnail-input - - if @item.thumbnail_url? - = image_tag @item.thumbnail_url - = f.url_field :thumbnail_url + = f.thumbnail_input :thumbnail_url = f.field do = f.label :description