Skip to content

Commit

Permalink
Add custom colors and logo to newsletter templates (#124)
Browse files Browse the repository at this point in the history
* Add custom colors to newsletter settings

* Add overrides test

* Add custom header logo to newsletters

* Some refactor and fix details

* Remove overrides locales

* Fixes in CI workflows

* Update override checksum

* Use :test storage service for test env

* Apply decidim_decidim_awesome:webpacker:install with updated some packages

* Add test for new settings

* Fix decorator

---------

Co-authored-by: Oliver Valls <[email protected]>
  • Loading branch information
laurajaime and tramuntanal authored Sep 27, 2023
1 parent 0364ccd commit 82e89c0
Show file tree
Hide file tree
Showing 28 changed files with 1,386 additions and 237 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci_age_action_authorization.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
${{ runner.OS }}-rubydeps-
${{ runner.OS }}-
- name: Set bundle local config configvendor/bundle path
- name: Set bundle local config vendor/bundle path
run: bundle config set --local path 'vendor/bundle'

- name: Install Ruby deps
Expand Down
20 changes: 7 additions & 13 deletions .github/workflows/ci_app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,13 @@ jobs:
retry_on: error
command: bundle install --jobs 4 --retry 3

- name: npm install
uses: actions/setup-node@v2
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- run: npm install

- name: Generate test_app
run: |
RAILS_ENV=test bundle exec rails db:create
RAILS_ENV=test bundle exec rails db:migrate
RAILS_ENV=test bundle exec rails assets:precompile
- uses: actions/setup-node@v2
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- run: npm install
- run: bundle exec rake db:test:prepare
name: Setup database
- name: Run RSpec
uses: nick-invision/retry@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_census.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
${{ runner.OS }}-rubydeps-
${{ runner.OS }}-
- name: Set bundle local config configvendor/bundle path
- name: Set bundle local config vendor/bundle path
run: bundle config set --local path 'vendor/bundle'

- name: Install Ruby deps
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_diba_census_api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
${{ runner.OS }}-rubydeps-
${{ runner.OS }}-
- name: Set bundle local config configvendor/bundle path
- name: Set bundle local config vendor/bundle path
run: bundle config set --local path 'vendor/bundle'

- name: Install Ruby deps
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_ldap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
${{ runner.OS }}-rubydeps-
${{ runner.OS }}-
- name: Set bundle local config configvendor/bundle path
- name: Set bundle local config vendor/bundle path
run: bundle config set --local path 'vendor/bundle'

- name: Install Ruby deps
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
${{ runner.OS }}-rubydeps-
${{ runner.OS }}-
- name: Set bundle local config configvendor/bundle path
- name: Set bundle local config vendor/bundle path
run: bundle config set --local path 'vendor/bundle'

- name: Install Ruby deps
Expand Down
24 changes: 24 additions & 0 deletions app/cells/_mailer_logo.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<%# START DIBA CUSTOMIZATION %>
<% if organization %>
<% if defined?(custom_url_for_mail_root) && custom_url_for_mail_root.present? %>
<% url = custom_url_for_mail_root %>
<% else %>
<% url = decidim.root_url(host: organization.host) %>
<% end %>
<%= link_to url do %>
<% if has_image?("header_logo") %>
<%= image_tag(header_logo_url("header_logo"), style: "max-height: 50px") %>
<% elsif organization.logo.attached? %>
<%= image_tag(
organization.attached_uploader(:logo).variant_url(:medium, host: organization.host),
style: "max-height: 50px",
alt: "#{organization.name}"
) %>
<% else %>
<span><%= organization.name %></span>
<% end %>
<% end %>
<% else %>
<%= Decidim.application_name %>
<% end %>
<%# END DIBA CUSTOMIZATION %>
110 changes: 110 additions & 0 deletions app/cells/decidim/newsletter_templates/basic_only_text/show.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<%# START DIBA CUSTOMIZATION %>
<style>
table td .decidim-bar {
background-color: <%= header_background_color %> !important;
}

.newsletter-body {
background-color: <%= body_background_color %> !important;
}

.newsletter-body p {
color: <%= body_font_color %> !important;
}
</style>
<%# END DIBA CUSTOMIZATION %>

<table class="main container">
<tr>
<td class="decidim-bar">
<table class="row collapse">
<tr>
<th class="small-3 large-3 first columns decidim-bar">
<table>
<tr>
<th>
</th>
</tr>
</table>
</th>
<th class="small-6 large-6 columns decidim-bar">
<table>
<tr>
<th>
<center>
<%# START DIBA CUSTOMIZATION %>
<%= render partial: "mailer_logo", locals: { organization: organization, custom_url_for_mail_root: custom_url_for_mail_root } %>
<%# END DIBA CUSTOMIZATION %>
</center>
</th>
</tr>
</table>
</th>
<th class="small-3 large-3 last columns decidim-bar">
<table>
<tr>
<th>
<%# START DIBA CUSTOMIZATION %>
<% unless has_image?("header_logo") %>
<% if organization.official_img_header.attached? %>
<%= link_to newsletter.organization_official_url do %>
<%= image_tag organization.attached_uploader(:official_img_header).path, alt: "", style: "max-height: 50px", class: "float-right" %>
<% end %>
<% end %>
<% end %>
<%# END DIBA CUSTOMIZATION %>
</th>
</tr>
</table>
</th>
<th class="expander"></th>
</tr>
</table>
</td>
</tr>
<%# START DIBA CUSTOMIZATION %>
<tr class="newsletter-body">
<%# END DIBA CUSTOMIZATION %>
<td>
<table class="spacer">
<tbody>
<tr>
<td height="40px" style="font-size:40px;line-height:40px;"> </td>
</tr>
</tbody>
</table>

<table class="row content">
<tr>
<th class="small-12 first columns">
<%= body %>
</th>
<th class="expander"></th>
</tr>
</table>

<table class="row">
<tr>
<th class="small-12 first columns">
</th>
<th class="expander"></th>
</tr>
</table>

<table class="row">
<tr>
<th class="expander"></th>
<th class="small-12 first columns cityhall-bar">
<div class="decidim-logo" style="float: right; text-align: right; padding-right: 16px">
<% if custom_url_for_mail_root.present? %>
<%= link_to organization.name.html_safe, custom_url_for_mail_root %>
<% else %>
<%= link_to organization.name.html_safe, decidim.root_url(host: organization.host) %>
<% end %>
</div>
</th>
</tr>
</table>
</td>
</tr>
</table>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<% form.fields_for :settings, form.object.settings do |settings_fields| %>
<%= settings_fields.translated :editor, :body, label: t(".body") %>
<%# START DIBA CUSTOMIZATION %>
<div class="newsletter-colors-selector">
<%= settings_fields.text_field :header_background_color, label: t(".header_background_color"), type: "color", value: form.object.settings.header_background_color || "#1a181d" %>
<%= settings_fields.text_field :body_background_color, label: t(".body_background_color"), type: "color", value: form.object.settings.body_background_color || "#fefefe" %>
<%= settings_fields.text_field :body_font_color, label: t(".body_font_color"), type: "color" %>
</div>
<% form.fields_for :images, form.object.images do |images_fields| %>
<%= images_fields.upload :header_logo, label: t(".header_logo") %>
<% end %>
<%# END DIBA CUSTOMIZATION %>
<% end %>

<div class="row column">
<%= t(".interpolations_hint") %>
</div>
147 changes: 147 additions & 0 deletions app/cells/decidim/newsletter_templates/image_text_cta/show.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
<style>
<% if organization_primary_color %>
table.button table td {
background: <%= organization_primary_color %> !important
}
<% end %>

/* START DIBA CUSTOMIZATION */
table td .decidim-bar {
background-color: <%= header_background_color %> !important;
}

.newsletter-body {
background-color: <%= body_background_color %> !important;
}

.newsletter-body p {
color: <%= body_font_color %> !important;
}
/* END DIBA CUSTOMIZATION */
</style>

<table class="main container">
<tr>
<td class="decidim-bar">
<table class="row collapse">
<tr>
<th class="small-3 large-3 first columns decidim-bar">
<table>
<tr>
<th>
</th>
</tr>
</table>
</th>
<th class="small-6 large-6 columns decidim-bar">
<table>
<tr>
<th>
<center>
<%# START DIBA CUSTOMIZATION %>
<%= render partial: "mailer_logo", locals: { organization: organization, custom_url_for_mail_root: custom_url_for_mail_root } %>
<%# END DIBA CUSTOMIZATION %>
</center>
</th>
</tr>
</table>
</th>
<th class="small-3 large-3 last columns decidim-bar">
<table>
<tr>
<th>
<%# START DIBA CUSTOMIZATION %>
<% unless has_image?("header_logo") %>
<% if organization.official_img_header.attached? %>
<%= link_to newsletter.organization_official_url do %>
<%= image_tag organization.attached_uploader(:official_img_header).path, alt: "", style: "max-height: 50px", class: "float-right" %>
<% end %>
<% end %>
<% end %>
<%# END DIBA CUSTOMIZATION %>
</th>
</tr>
</table>
</th>
<th class="expander"></th>
</tr>
</table>
</td>
</tr>
<%# START DIBA CUSTOMIZATION %>
<tr class="newsletter-body">
<%# END DIBA CUSTOMIZATION %>
<td>
<table class="spacer">
<tbody>
<tr>
<td height="40px" style="font-size:40px;line-height:40px;"> </td>
</tr>
</tbody>
</table>

<% if has_main_image? %>
<table class="row content image">
<tr>
<th class="small-12 first columns">
<%= main_image %>
</th>
<th class="expander"></th>
</tr>
</table>
<% end %>

<table class="row content">
<tr>
<th class="small-12 first columns">
<%= introduction %>
<% if has_cta? %>
<p>&nbsp;</p>
<table class="button expanded radius">
<tr>
<td>
<table>
<tr>
<td>
<%= link_to cta_text, cta_url, target: :blank %>
</td>
</tr>
</table>
</td>
</tr>
</table>
<p>&nbsp;</p>
<% end %>
<%= body %>
</th>
<th class="expander"></th>
</tr>
</table>

<table class="row">
<tr>
<th class="small-12 first columns">
</th>
<th class="expander"></th>
</tr>
</table>

<table class="row">
<tr>
<th class="expander"></th>
<th class="small-12 first columns cityhall-bar">
<div class="decidim-logo" style="float: right; text-align: right; padding-right: 16px">
<% if custom_url_for_mail_root.present? %>
<%= link_to organization.name.html_safe, custom_url_for_mail_root %>
<% else %>
<%= link_to organization.name.html_safe, decidim.root_url(host: organization.host) %>
<% end %>
</div>
</th>
</tr>
</table>
</td>
</tr>
</table>
Loading

0 comments on commit 82e89c0

Please sign in to comment.