From 3d354446b6bfeed1aa7eca229dd395873e24cfc2 Mon Sep 17 00:00:00 2001 From: Thomas Burkhalter Date: Thu, 28 Nov 2024 15:16:37 +0100 Subject: [PATCH] WIP: Add example newsletter --- .../newsletter_templates/test/show.erb | 132 ++++++++++++++++++ .../newsletter_templates/test_cell.rb | 68 +++++++++ .../test_settings_form/show.erb | 23 +++ .../test_settings_form_cell.rb | 6 + .../initializers/newsletter_templates/test.rb | 32 +++++ config/locales/de.yml | 5 + 6 files changed, 266 insertions(+) create mode 100644 app/cells/decidim_zuerich/newsletter_templates/test/show.erb create mode 100644 app/cells/decidim_zuerich/newsletter_templates/test_cell.rb create mode 100644 app/cells/decidim_zuerich/newsletter_templates/test_settings_form/show.erb create mode 100644 app/cells/decidim_zuerich/newsletter_templates/test_settings_form_cell.rb create mode 100644 config/initializers/newsletter_templates/test.rb diff --git a/app/cells/decidim_zuerich/newsletter_templates/test/show.erb b/app/cells/decidim_zuerich/newsletter_templates/test/show.erb new file mode 100644 index 00000000..a93ca213 --- /dev/null +++ b/app/cells/decidim_zuerich/newsletter_templates/test/show.erb @@ -0,0 +1,132 @@ +<% if organization_primary_color %> + +<% end %> + + + + + + + + +
+ + + + + + + +
+ + + + +
+
+
+ + + + +
+
+ <%= render partial: "layouts/decidim/mailer_logo.html", locals: { organization: organization } %> +
+
+
+ + + + +
+ <% if organization.official_img_header.attached? %> + <%= link_to organization.official_url do %> + <%= image_tag organization.attached_uploader(:official_img_header).url(host: organization.host), alt: "", style: "max-height: 50px", class: "float-right" %> + <% end %> + <% end %> +
+
+
+ + + + + + +
+ + <% if has_main_image? %> + + + + + +
+ <%= main_image %> +
+ <% end %> + + + + + + +
+ <%= introduction %> + + <% if has_cta? %> +

 

+ + + + +
+ + + + +
+ <%= link_to cta_text, cta_url, target: :blank %> +
+
+

 

+ <% end %> + + <%= body %> + +
+ <% fields.each do |field| %> + <%= field %> +
+ <% end %> + +
+ + + + + + +
+
+ + + + + + +
+ +
+
diff --git a/app/cells/decidim_zuerich/newsletter_templates/test_cell.rb b/app/cells/decidim_zuerich/newsletter_templates/test_cell.rb new file mode 100644 index 00000000..b1edc9fa --- /dev/null +++ b/app/cells/decidim_zuerich/newsletter_templates/test_cell.rb @@ -0,0 +1,68 @@ +require "cell/partial" + +module DecidimZuerich + module NewsletterTemplates + class TestCell < Decidim::NewsletterTemplates::BaseCell + def show + render :show + end + + def introduction + parse_interpolations(uninterpolated_introduction, recipient_user, newsletter.id) + end + + def uninterpolated_introduction + translated_attribute(model.settings.introduction) + end + + def body + parse_interpolations(uninterpolated_body, recipient_user, newsletter.id) + end + + def fields + %i[boolean integer string text].map do |type| + field = model.settings.send("field_#{type}") + translated = translated_attribute(field) + parse_interpolations(translated, recipient_user, newsletter.id) + end + end + + def uninterpolated_body + translated_attribute(model.settings.body) + end + + def has_cta? + cta_text.present? && cta_url.present? + end + + def cta_text + parse_interpolations( + translated_attribute(model.settings.cta_text), + recipient_user, + newsletter.id + ) + end + + def cta_url + translated_attribute(model.settings.cta_url) + end + + def has_main_image? + newsletter.template.images_container.main_image.attached? + end + + def main_image + image_tag main_image_url + end + + def main_image_url + newsletter.template.images_container.attached_uploader(:main_image).url(host: organization.host) + end + + def organization_primary_color + organization.colors["primary"] + end + end + end +end + diff --git a/app/cells/decidim_zuerich/newsletter_templates/test_settings_form/show.erb b/app/cells/decidim_zuerich/newsletter_templates/test_settings_form/show.erb new file mode 100644 index 00000000..61dfb1e2 --- /dev/null +++ b/app/cells/decidim_zuerich/newsletter_templates/test_settings_form/show.erb @@ -0,0 +1,23 @@ +<% form.fields_for :settings, form.object.settings do |settings_fields| %> + <%= settings_fields.translated :editor, :introduction, label: t(".introduction") %> + + <%= settings_fields.translated :text_field, :cta_text, label: t(".cta_text") %> + + <%= settings_fields.text_field :cta_url, label: t(".cta_url") %> + + <%= settings_fields.translated :editor, :body, label: t(".body") %> + + <%= settings_fields.check_box :field_boolean, label: "Boolean" %> + <%= settings_fields.number_field :field_integer, label: "Integer" %> + <%= settings_fields.translated :text_field, :field_string, label: "String" %> + <%= settings_fields.translated :editor, :field_text, label: "Text" %> +<% end %> + +<% form.fields_for :images, form.object.images do |images_fields| %> + <%= images_fields.upload :main_image, label: t(".main_image") %> +<% end %> + +
+ <%= t(".interpolations_hint") %> +
+ diff --git a/app/cells/decidim_zuerich/newsletter_templates/test_settings_form_cell.rb b/app/cells/decidim_zuerich/newsletter_templates/test_settings_form_cell.rb new file mode 100644 index 00000000..73c2213f --- /dev/null +++ b/app/cells/decidim_zuerich/newsletter_templates/test_settings_form_cell.rb @@ -0,0 +1,6 @@ +module DecidimZuerich + module NewsletterTemplates + class TestSettingsFormCell < Decidim::NewsletterTemplates::BaseSettingsFormCell + end + end +end diff --git a/config/initializers/newsletter_templates/test.rb b/config/initializers/newsletter_templates/test.rb new file mode 100644 index 00000000..63323290 --- /dev/null +++ b/config/initializers/newsletter_templates/test.rb @@ -0,0 +1,32 @@ +Decidim.content_blocks.register(:newsletter_template, :test) do |content_block| + content_block.cell = "decidim_zuerich/newsletter_templates/test" + content_block.settings_form_cell = "decidim_zuerich/newsletter_templates/test_settings_form" + content_block.public_name_key = "decidim_zuerich.newsletter_templates.test.name" + + content_block.images = [ + { + name: :main_image, + uploader: "Decidim::NewsletterTemplateImageUploader", + preview: -> { ActionController::Base.helpers.asset_pack_path("media/images/placeholder.jpg") } + } + ] + + t = -> (key) { I18n.t("decidim_zuerich.newsletter_templates.test.#{key}") } + opts = -> (map) { {type: :text, translated: true, preview: "-"}.merge(map) } + + content_block.settings do |settings| + settings.attribute(:introduction, opts.(preview: -> { t.("introduction_preview") })) + settings.attribute(:body, opts.(preview: -> { t.("body_preview") } )) + settings.attribute(:cta_text, opts.(preview: -> { t.("cta_text_preview") } )) + settings.attribute(:cta_url, opts.(preview: "http://google.com" )) + settings.attribute(:field_boolean, opts.(type: :boolean, preview: "Wahrheit" )) + settings.attribute(:field_integer, opts.(type: :integer, preview: "Zahl" )) + settings.attribute(:field_string, opts.(type: :string, preview: "String" )) + settings.attribute(:field_text, opts.(type: :text, preview: "Text" )) + settings.attribute(:field_array, opts.(type: :array, preview: "Array" )) + settings.attribute(:field_enum, opts.(type: :enum, preview: "Enum" )) + settings.attribute(:field_select, opts.(type: :select, preview: "Select" )) + settings.attribute(:field_scope, opts.(type: :scope, preview: "Scope" )) + settings.attribute(:field_time, opts.(type: :time, preview: "Zeit" )) + end +end diff --git a/config/locales/de.yml b/config/locales/de.yml index b3fd99d6..83b4d615 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -121,6 +121,11 @@ de: gis_zh: basiskarte_schraeg: Stadt Zürich Basiskarte orthofoto: Stadt Zürich Luftbild + newsletter_templates: + test: + introduction_preview: Einführung der Test Mail + cta_text_preview: Google + body_preview: Inhalt der Test Mail participatory_processes: participatory_process_helper: step_dates: