-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
266 additions
and
0 deletions.
There are no files selected for viewing
132 changes: 132 additions & 0 deletions
132
app/cells/decidim_zuerich/newsletter_templates/test/show.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
<% if organization_primary_color %> | ||
<style> | ||
table.button table td { | ||
background: <%= organization_primary_color %> !important | ||
} | ||
</style> | ||
<% end %> | ||
|
||
<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> | ||
<%= render partial: "layouts/decidim/mailer_logo.html", locals: { organization: organization } %> | ||
</center> | ||
</th> | ||
</tr> | ||
</table> | ||
</th> | ||
<th class="small-3 large-3 last columns decidim-bar"> | ||
<table> | ||
<tr> | ||
<th> | ||
<% 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 %> | ||
</th> | ||
</tr> | ||
</table> | ||
</th> | ||
<th class="expander"></th> | ||
</tr> | ||
</table> | ||
</td> | ||
</tr> | ||
<tr> | ||
<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> </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> </p> | ||
<% end %> | ||
|
||
<%= body %> | ||
|
||
<br /> | ||
<% fields.each do |field| %> | ||
<%= field %> | ||
<br /> | ||
<% end %> | ||
|
||
</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> |
68 changes: 68 additions & 0 deletions
68
app/cells/decidim_zuerich/newsletter_templates/test_cell.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
23 changes: 23 additions & 0 deletions
23
app/cells/decidim_zuerich/newsletter_templates/test_settings_form/show.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 %> | ||
|
||
<div class="row column"> | ||
<%= t(".interpolations_hint") %> | ||
</div> | ||
|
6 changes: 6 additions & 0 deletions
6
app/cells/decidim_zuerich/newsletter_templates/test_settings_form_cell.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module DecidimZuerich | ||
module NewsletterTemplates | ||
class TestSettingsFormCell < Decidim::NewsletterTemplates::BaseSettingsFormCell | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters