From 339ad715995b371eec30240491086e8162c2c14c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Verg=C3=A9s?= Date: Fri, 24 Nov 2023 15:40:09 +0100 Subject: [PATCH] fix theme properties (#27) * fix theme properties * add link color * fix tests --- .github/workflows/lint.yml | 4 +- .github/workflows/test.yml | 4 +- .ruby-version | 2 +- Gemfile.lock | 222 +++++++++--------- .../newsletter_agenda/theme_methods.rb | 72 ++++++ .../agenda_events/themes/capitalitat.erb | 12 +- .../newsletter_agenda/agenda_events_cell.rb | 66 +----- .../agenda_events_settings_form/show.erb | 28 +-- .../agenda_events_settings_form_cell.rb | 19 +- .../{capitalitat => }/capitalitat_twitter.png | Bin .../{capitalitat => }/capitalitat_youtube.png | Bin config/locales/en.yml | 5 +- lib/decidim/newsletter_agenda.rb | 48 +++- lib/decidim/newsletter_agenda/engine.rb | 19 +- spec/spec_helper.rb | 7 - spec/system/agenda_events_settings_spec.rb | 39 +-- 16 files changed, 289 insertions(+), 258 deletions(-) create mode 100644 app/cells/concerns/decidim/newsletter_agenda/theme_methods.rb rename app/packs/images/social/{capitalitat => }/capitalitat_twitter.png (100%) rename app/packs/images/social/{capitalitat => }/capitalitat_youtube.png (100%) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index f4da7d9..09e9a91 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -8,14 +8,14 @@ on: env: CI: "true" - RUBY_VERSION: 3.0.5 + RUBY_VERSION: 3.0.6 NODE_VERSION: 16.9.1 jobs: lint-report: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: fetch-depth: 1 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4d77f99..3889cd3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,7 +7,7 @@ on: pull_request: env: - RUBY_VERSION: 3.0.5 + RUBY_VERSION: 3.0.6 jobs: test-report: @@ -30,7 +30,7 @@ jobs: DATABASE_HOST: localhost steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: fetch-depth: 1 diff --git a/.ruby-version b/.ruby-version index 7da3c16..8ffc1ad 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.0.5 \ No newline at end of file +3.0.6 \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index 7c770f5..06f8efb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -9,40 +9,40 @@ PATH GEM remote: https://rubygems.org/ specs: - actioncable (6.1.7.4) - actionpack (= 6.1.7.4) - activesupport (= 6.1.7.4) + actioncable (6.1.7.6) + actionpack (= 6.1.7.6) + activesupport (= 6.1.7.6) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (6.1.7.4) - actionpack (= 6.1.7.4) - activejob (= 6.1.7.4) - activerecord (= 6.1.7.4) - activestorage (= 6.1.7.4) - activesupport (= 6.1.7.4) + actionmailbox (6.1.7.6) + actionpack (= 6.1.7.6) + activejob (= 6.1.7.6) + activerecord (= 6.1.7.6) + activestorage (= 6.1.7.6) + activesupport (= 6.1.7.6) mail (>= 2.7.1) - actionmailer (6.1.7.4) - actionpack (= 6.1.7.4) - actionview (= 6.1.7.4) - activejob (= 6.1.7.4) - activesupport (= 6.1.7.4) + actionmailer (6.1.7.6) + actionpack (= 6.1.7.6) + actionview (= 6.1.7.6) + activejob (= 6.1.7.6) + activesupport (= 6.1.7.6) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (6.1.7.4) - actionview (= 6.1.7.4) - activesupport (= 6.1.7.4) + actionpack (6.1.7.6) + actionview (= 6.1.7.6) + activesupport (= 6.1.7.6) rack (~> 2.0, >= 2.0.9) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (6.1.7.4) - actionpack (= 6.1.7.4) - activerecord (= 6.1.7.4) - activestorage (= 6.1.7.4) - activesupport (= 6.1.7.4) + actiontext (6.1.7.6) + actionpack (= 6.1.7.6) + activerecord (= 6.1.7.6) + activestorage (= 6.1.7.6) + activesupport (= 6.1.7.6) nokogiri (>= 1.8.5) - actionview (6.1.7.4) - activesupport (= 6.1.7.4) + actionview (6.1.7.6) + activesupport (= 6.1.7.6) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) @@ -50,22 +50,22 @@ GEM active_link_to (1.0.5) actionpack addressable - activejob (6.1.7.4) - activesupport (= 6.1.7.4) + activejob (6.1.7.6) + activesupport (= 6.1.7.6) globalid (>= 0.3.6) - activemodel (6.1.7.4) - activesupport (= 6.1.7.4) - activerecord (6.1.7.4) - activemodel (= 6.1.7.4) - activesupport (= 6.1.7.4) - activestorage (6.1.7.4) - actionpack (= 6.1.7.4) - activejob (= 6.1.7.4) - activerecord (= 6.1.7.4) - activesupport (= 6.1.7.4) + activemodel (6.1.7.6) + activesupport (= 6.1.7.6) + activerecord (6.1.7.6) + activemodel (= 6.1.7.6) + activesupport (= 6.1.7.6) + activestorage (6.1.7.6) + actionpack (= 6.1.7.6) + activejob (= 6.1.7.6) + activerecord (= 6.1.7.6) + activesupport (= 6.1.7.6) marcel (~> 1.0) mini_mime (>= 1.1.0) - activesupport (6.1.7.4) + activesupport (6.1.7.6) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) @@ -73,10 +73,10 @@ GEM zeitwerk (~> 2.3) acts_as_list (0.9.19) activerecord (>= 3.0) - addressable (2.8.4) + addressable (2.8.5) public_suffix (>= 2.0.2, < 6.0) ast (2.4.2) - axe-core-api (4.7.0) + axe-core-api (4.8.0) dumb_delegator virtus axe-core-rspec (4.1.0) @@ -87,8 +87,9 @@ GEM descendants_tracker (~> 0.0.4) ice_nine (~> 0.11.0) thread_safe (~> 0.3, >= 0.3.1) + base64 (0.2.0) batch-loader (1.5.0) - bcrypt (3.1.19) + bcrypt (3.1.20) better_html (1.0.16) actionview (>= 4.0) activesupport (>= 4.0) @@ -98,7 +99,7 @@ GEM parser (>= 2.4) smart_properties bindex (0.8.1) - bootsnap (1.16.0) + bootsnap (1.17.0) msgpack (~> 1.2) browser (2.7.1) builder (3.2.4) @@ -132,7 +133,7 @@ GEM actionpack (>= 5.0) cells (>= 4.1.6, < 5.0.0) charlock_holmes (0.7.7) - chef-utils (18.2.7) + chef-utils (18.3.0) concurrent-ruby childprocess (4.1.0) codecov (0.6.0) @@ -146,14 +147,14 @@ GEM coffee-script-source execjs coffee-script-source (1.12.2) - commonmarker (0.23.9) + commonmarker (0.23.10) concurrent-ruby (1.2.2) crack (0.4.5) rexml crass (1.0.6) - css_parser (1.14.0) + css_parser (1.16.0) addressable - date (3.3.3) + date (3.3.4) date_range_formatter (0.1.2) activesupport (>= 3.2.0) date_validator (0.12.0) @@ -334,15 +335,15 @@ GEM declarative-option (0.1.0) descendants_tracker (0.0.4) thread_safe (~> 0.3, >= 0.3.1) - devise (4.9.2) + devise (4.9.3) bcrypt (~> 3.0) orm_adapter (~> 0.1) railties (>= 4.1.0) responders warden (~> 1.2.3) - devise-i18n (1.11.0) + devise-i18n (1.12.0) devise (>= 4.9.0) - devise_invitable (2.0.8) + devise_invitable (2.0.9) actionmailer (>= 5.0) devise (>= 4.6) diff-lcs (1.5.0) @@ -351,7 +352,7 @@ GEM nokogiri (>= 1.13.2, < 1.15.0) rubyzip (~> 2.3.0) docile (1.4.0) - doorkeeper (5.6.6) + doorkeeper (5.6.7) railties (>= 5) doorkeeper-i18n (4.0.1) dumb_delegator (1.0.0) @@ -367,8 +368,8 @@ GEM temple erubi (1.12.0) escape_utils (1.3.0) - excon (0.100.0) - execjs (2.8.1) + excon (0.104.0) + execjs (2.9.1) extended-markdown-filter (0.7.0) html-pipeline (~> 2.9) factory_bot (4.11.1) @@ -378,11 +379,12 @@ GEM railties (>= 3.0.0) faker (2.23.0) i18n (>= 1.8.11, < 2) - faraday (2.7.10) + faraday (2.7.12) + base64 faraday-net_http (>= 2.0, < 3.1) ruby2_keywords (>= 0.0.4) faraday-net_http (3.0.2) - ffi (1.15.5) + ffi (1.16.3) file_validators (3.0.0) activemodel (>= 3.2) mime-types (>= 1.0) @@ -401,8 +403,8 @@ GEM railties (>= 4.1, < 7.1) gemoji (3.0.1) geocoder (1.8.2) - globalid (1.1.0) - activesupport (>= 5.0) + globalid (1.2.1) + activesupport (>= 6.1) graphql (1.12.24) graphql-docs (2.1.0) commonmarker (~> 0.16) @@ -433,7 +435,7 @@ GEM rails-i18n rainbow (>= 2.2.2, < 4.0) terminal-table (>= 1.5.1) - icalendar (2.8.0) + icalendar (2.10.0) ice_cube (~> 0.16) ice_cube (0.16.4) ice_nine (0.11.2) @@ -481,19 +483,19 @@ GEM net-smtp marcel (1.0.2) matrix (0.4.2) - mdl (0.12.0) + mdl (0.13.0) kramdown (~> 2.3) kramdown-parser-gfm (~> 1.1) mixlib-cli (~> 2.1, >= 2.1.1) mixlib-config (>= 2.2.1, < 4) mixlib-shellout method_source (1.0.0) - mime-types (3.4.1) + mime-types (3.5.1) mime-types-data (~> 3.2015) - mime-types-data (3.2023.0218.1) + mime-types-data (3.2023.1003) mini_magick (4.12.0) - mini_mime (1.1.2) - minitest (5.19.0) + mini_mime (1.1.5) + minitest (5.20.0) mixlib-cli (2.1.8) mixlib-config (3.0.27) tomlrb @@ -502,20 +504,16 @@ GEM msgpack (1.7.2) multi_xml (0.6.0) mustache (1.1.1) - net-imap (0.3.7) + net-imap (0.4.6) date net-protocol net-pop (0.1.2) net-protocol - net-protocol (0.2.1) + net-protocol (0.2.2) timeout - net-smtp (0.3.3) + net-smtp (0.4.0) net-protocol - nio4r (2.5.9) - nokogiri (1.14.5-arm64-darwin) - racc (~> 1.4) - nokogiri (1.14.5-x86_64-darwin) - racc (~> 1.4) + nio4r (2.6.1) nokogiri (1.14.5-x86_64-linux) racc (~> 1.4) oauth (1.1.0) @@ -561,7 +559,7 @@ GEM parallel (1.23.0) parallel_tests (3.13.0) parallel - parser (3.2.2.3) + parser (3.2.2.4) ast (~> 2.4.1) racc pg (1.1.4) @@ -576,41 +574,41 @@ GEM actionmailer (>= 3) net-smtp premailer (~> 1.7, >= 1.7.9) - public_suffix (5.0.3) - puma (5.6.6) + public_suffix (5.0.4) + puma (5.6.7) nio4r (~> 2.0) - racc (1.7.1) + racc (1.7.3) rack (2.2.8) rack-attack (6.7.0) rack (>= 1.0, < 4) rack-cors (1.1.1) rack (>= 2.0.0) - rack-protection (3.0.6) - rack - rack-proxy (0.7.6) + rack-protection (3.1.0) + rack (~> 2.2, >= 2.2.4) + rack-proxy (0.7.7) rack rack-test (2.1.0) rack (>= 1.3) - rails (6.1.7.4) - actioncable (= 6.1.7.4) - actionmailbox (= 6.1.7.4) - actionmailer (= 6.1.7.4) - actionpack (= 6.1.7.4) - actiontext (= 6.1.7.4) - actionview (= 6.1.7.4) - activejob (= 6.1.7.4) - activemodel (= 6.1.7.4) - activerecord (= 6.1.7.4) - activestorage (= 6.1.7.4) - activesupport (= 6.1.7.4) + rails (6.1.7.6) + actioncable (= 6.1.7.6) + actionmailbox (= 6.1.7.6) + actionmailer (= 6.1.7.6) + actionpack (= 6.1.7.6) + actiontext (= 6.1.7.6) + actionview (= 6.1.7.6) + activejob (= 6.1.7.6) + activemodel (= 6.1.7.6) + activerecord (= 6.1.7.6) + activestorage (= 6.1.7.6) + activesupport (= 6.1.7.6) bundler (>= 1.15.0) - railties (= 6.1.7.4) + railties (= 6.1.7.6) sprockets-rails (>= 2.0.0) rails-controller-testing (1.0.5) actionpack (>= 5.0.1.rc1) actionview (>= 5.0.1.rc1) activesupport (>= 5.0.1.rc1) - rails-dom-testing (2.1.1) + rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest nokogiri (>= 1.6) @@ -619,14 +617,14 @@ GEM rails-i18n (6.0.0) i18n (>= 0.7, < 2) railties (>= 6.0.0, < 7) - railties (6.1.7.4) - actionpack (= 6.1.7.4) - activesupport (= 6.1.7.4) + railties (6.1.7.6) + actionpack (= 6.1.7.6) + activesupport (= 6.1.7.6) method_source rake (>= 12.2) thor (~> 1.0) rainbow (3.1.1) - rake (13.0.6) + rake (13.1.0) ransack (2.4.2) activerecord (>= 5.2.4) activesupport (>= 5.2.4) @@ -636,10 +634,10 @@ GEM ffi (~> 1.0) redcarpet (3.6.0) redis (4.8.1) - regexp_parser (2.8.1) + regexp_parser (2.8.2) request_store (1.5.1) rack (>= 1.4) - responders (3.1.0) + responders (3.1.1) actionpack (>= 5.2) railties (>= 5.2) rexml (3.2.6) @@ -683,7 +681,7 @@ GEM rubocop-ast (>= 1.17.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.29.0) + rubocop-ast (1.30.0) parser (>= 3.2.1.0) rubocop-faker (1.1.0) faker (>= 2.12.0) @@ -695,7 +693,7 @@ GEM rubocop-rspec (2.11.1) rubocop (~> 1.19) ruby-progressbar (1.13.0) - ruby-vips (2.1.4) + ruby-vips (2.2.0) ffi (~> 1.12) ruby2_keywords (0.0.5) rubyXL (3.4.25) @@ -732,26 +730,26 @@ GEM spring-watcher-listen (2.0.1) listen (>= 2.7, < 4.0) spring (>= 1.2, < 3.0) - sprockets (4.2.0) + sprockets (4.2.1) concurrent-ruby (~> 1.0) rack (>= 2.2.4, < 4) sprockets-rails (3.4.2) actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) - ssrf_filter (1.1.1) - temple (0.10.2) + ssrf_filter (1.1.2) + temple (0.10.3) terminal-table (3.0.2) unicode-display_width (>= 1.1.1, < 3) - thor (1.2.2) + thor (1.3.0) thread_safe (0.3.6) - tilt (2.2.0) - timeout (0.4.0) + tilt (2.3.0) + timeout (0.4.1) tomlrb (2.0.3) tzinfo (2.0.6) concurrent-ruby (~> 1.0) uber (0.1.0) - unicode-display_width (2.4.2) + unicode-display_width (2.5.0) valid_email2 (2.3.1) activemodel (>= 3.2) mail (~> 2.5) @@ -770,12 +768,12 @@ GEM rexml (~> 3.2) warden (1.2.9) rack (>= 2.0.9) - web-console (4.2.0) + web-console (4.2.1) actionview (>= 6.0.0) activemodel (>= 6.0.0) bindex (>= 0.4.0) railties (>= 6.0.0) - webmock (3.18.1) + webmock (3.19.1) addressable (>= 2.8.0) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) @@ -790,18 +788,16 @@ GEM websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) - wicked_pdf (2.6.3) + wicked_pdf (2.7.0) activesupport wisper (2.0.1) wisper-rspec (1.1.0) wkhtmltopdf-binary (0.12.6.6) xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (2.6.10) + zeitwerk (2.6.12) PLATFORMS - arm64-darwin-22 - x86_64-darwin-22 x86_64-linux DEPENDENCIES @@ -821,7 +817,7 @@ DEPENDENCIES web-console RUBY VERSION - ruby 3.0.5p211 + ruby 3.0.6p216 BUNDLED WITH - 2.2.33 + 2.4.21 diff --git a/app/cells/concerns/decidim/newsletter_agenda/theme_methods.rb b/app/cells/concerns/decidim/newsletter_agenda/theme_methods.rb new file mode 100644 index 0000000..2871097 --- /dev/null +++ b/app/cells/concerns/decidim/newsletter_agenda/theme_methods.rb @@ -0,0 +1,72 @@ +# frozen_string_literal: true + +module Decidim + module NewsletterAgenda + module ThemeMethods + extend ActiveSupport::Concern + + included do + def theme + @theme ||= begin + manifest_name = model.respond_to?(:manifest_name) ? model.manifest_name : content_block.manifest_name + manifest_name.gsub("_agenda_events", "").to_sym + end + end + + def social_handlers + @social_handlers ||= NewsletterAgenda.social_handlers || + NewsletterAgenda.themes&.dig(theme, :social_handlers) || + [] + end + + def organization_handler_attributes + @organization_handler_attributes ||= begin + org = defined?(organization) ? organization : current_organization + org.attributes.select { |key| key.to_s.include?("handler") } + end + end + + def link_color + @link_color ||= model.settings.link_color.presence || + default_link_color + end + + def background_color + @background_color ||= model.settings.background_color.presence || + default_background_color + end + + def font_color_over_bg + @font_color_over_bg ||= model.settings.font_color_over_bg.presence || + default_font_color_over_bg + end + + def default_link_color + @default_link_color ||= NewsletterAgenda.default_link_color || + NewsletterAgenda.themes&.dig(theme, :default_link_color) || + current_organization.colors["primary"] || + "#39747f" + end + + def default_background_color + @default_background_color ||= NewsletterAgenda.default_background_color || + NewsletterAgenda.themes&.dig(theme, :default_background_color) || + current_organization.colors["primary"] || + "#39747f" + end + + def default_font_color_over_bg + @default_font_color_over_bg = NewsletterAgenda.default_font_color_over_bg || + NewsletterAgenda.themes&.dig(theme, :default_font_color_over_bg) || + "#FFFFFF" + end + + def default_address_text + @default_address_text ||= NewsletterAgenda.default_address_text || + NewsletterAgenda.themes.dig(theme, :default_address_text) || + "" + end + end + end + end +end diff --git a/app/cells/decidim/newsletter_agenda/agenda_events/themes/capitalitat.erb b/app/cells/decidim/newsletter_agenda/agenda_events/themes/capitalitat.erb index 9b9d9f8..7959f69 100644 --- a/app/cells/decidim/newsletter_agenda/agenda_events/themes/capitalitat.erb +++ b/app/cells/decidim/newsletter_agenda/agenda_events/themes/capitalitat.erb @@ -153,12 +153,12 @@ <% end %> -

+

<%= translated_text_for "body_box_date_time_#{num}" %>

-

+

<%= translated_text_for "body_box_title_#{num}" %>

@@ -172,7 +172,7 @@ <% if link %>

<%= link_to translated_text_for("body_box_link_text_#{num}"), link, - style: "color: #3998D4;font-weight: bold; text-decoration: underline;", + style: "color: #{link_color};font-weight: bold; text-decoration: underline;", target: :blank %>

<% end %> @@ -282,9 +282,9 @@ - - - + + +
diff --git a/app/cells/decidim/newsletter_agenda/agenda_events_cell.rb b/app/cells/decidim/newsletter_agenda/agenda_events_cell.rb index 5c47345..7a11831 100644 --- a/app/cells/decidim/newsletter_agenda/agenda_events_cell.rb +++ b/app/cells/decidim/newsletter_agenda/agenda_events_cell.rb @@ -6,17 +6,14 @@ module Decidim module NewsletterAgenda class AgendaEventsCell < NewsletterTemplates::BaseCell include Decidim::LayoutHelper + include ThemeMethods def show render :show end def body - parse_interpolations("", recipient_user, newsletter.id) - end - - def theme - model.manifest_name.gsub("_agenda_events", "") + @body ||= parse_interpolations("", recipient_user, newsletter.id) end def has_image?(attribute) @@ -72,56 +69,23 @@ def link_for(attribute) def social_links links = [] - allowed_networks = theme == "capitalitat" ? %w(twitter youtube) : all_handler_attributes.keys.map { |k| k.split("_").first } all_handler_attributes.each do |k, v| - next if v.blank? + next if v.strip.blank? network = k.split("_").first - next unless allowed_networks.include?(network) - - icon_path = if theme == "capitalitat" - asset_pack_url("media/images/capitalitat_#{network}.png", **host_options) - else - asset_pack_url("media/images/#{network}.png", **host_options) - end + path = "images/#{theme}_#{network}.png" + path = "images/#{network}.png" unless File.exist?(File.join(Decidim::NewsletterAgenda::Engine.root, "app/packs/#{path}")) - ico = tag.img(src: icon_path, alt: network.capitalize, class: "footer-social__icon", title: t("decidim.newsletter_agenda.agenda_events_settings_form.#{network}")) + ico = tag.img(src: asset_pack_url("media/#{path}", **host_options), alt: network.capitalize, class: "footer-social__icon", + title: t("decidim.newsletter_agenda.agenda_events_settings_form.#{network}")) links << link_to(ico, network_url(v, network), target: "_blank", rel: "noopener", class: "footer-social__icon") end links end - def background_image_top - asset_pack_url("media/images/background_top.gif", **host_options) - end - - def background_image_bottom_url - asset_pack_url("media/images/background_bottom.gif", **host_options) - end - - def footer_image_capitalitat - asset_pack_url("media/images/capital_logo.png", **host_options) - end - - def footer_image_metropolita - asset_pack_url("media/images/metropolita_logo.png", **host_options) - end - - def footer_image_ajuntament - asset_pack_url("media/images/ajuntament.png", **host_options) - end - - def background_color - model.settings.background_color.presence || NewsletterAgenda.default_background_color - end - - def font_color_over_bg - model.settings.font_color_over_bg.presence || NewsletterAgenda.default_font_color_over_bg || "#FFFFFF" - end - private def representation_url(image) @@ -135,21 +99,11 @@ def host_options end end - def organization_handler_attributes - organization.attributes.select { |key| key.to_s.include?("handler") } - end - - def additional_handler_attributes - additional_handler_attributes = {} - Decidim::NewsletterAgenda.additional_social_handlers.each do |handler| + def all_handler_attributes + @all_handler_attributes ||= social_handlers&.to_h do |handler| key = "#{handler}_handler" - additional_handler_attributes[key] = model.settings[key] if model.settings[key].present? + [key, model.settings[key] || organization_handler_attributes[key]] end - additional_handler_attributes - end - - def all_handler_attributes - organization_handler_attributes.merge(additional_handler_attributes) end def network_url(value, network) diff --git a/app/cells/decidim/newsletter_agenda/agenda_events_settings_form/show.erb b/app/cells/decidim/newsletter_agenda/agenda_events_settings_form/show.erb index 0288894..6a1b1cd 100644 --- a/app/cells/decidim/newsletter_agenda/agenda_events_settings_form/show.erb +++ b/app/cells/decidim/newsletter_agenda/agenda_events_settings_form/show.erb @@ -1,4 +1,5 @@ <% form.fields_for :settings, settings do |settings_fields| %> + <%= settings_fields.text_field :link_color, label: t(".link_color"), type: "color" %> <%= settings_fields.text_field :background_color, label: t(".background_color"), type: "color" %> <%= settings_fields.text_field :font_color_over_bg, label: t(".font_color_over_bg"), type: "color" %> <% end %> @@ -15,8 +16,8 @@ <% form.fields_for :settings, settings do |settings_fields| %> <%= settings_fields.translated :text_field, :intro_title, label: t(".intro_title") %> <%= settings_fields.translated :editor, :intro_text, label: t(".intro_text") %> - <%= settings_fields.translated :text_field, :intro_link_text, label: t(".intro_link_text") if theme == "capitalitat" %> - <%= settings_fields.text_field :intro_link_url, label: t(".intro_link_url") if theme == "capitalitat" %> + <%= settings_fields.translated :text_field, :intro_link_text, label: t(".intro_link_text") if theme == :capitalitat %> + <%= settings_fields.text_field :intro_link_url, label: t(".intro_link_url") if theme == :capitalitat %> <% end %> <% form.fields_for :images, form.object.images do |images_fields| %> <%= images_fields.upload :main_image, label: t(".main_image") %> @@ -28,8 +29,8 @@

<%= t(".tab_body_description") %>

<% form.fields_for :settings, settings do |settings_fields| %> - <%= settings_fields.translated :text_field, :body_title, label: t(".body_title") unless theme == "capitalitat" %> - <%= settings_fields.translated :text_field, :body_subtitle, label: t(".body_subtitle") unless theme == "capitalitat" %> + <%= settings_fields.translated :text_field, :body_title, label: t(".body_title") unless theme == :capitalitat %> + <%= settings_fields.translated :text_field, :body_subtitle, label: t(".body_subtitle") unless theme == :capitalitat %> - <%= settings_fields.editor :footer_address_text, label: t(".footer_address") unless theme == "capitalitat" %> + <%= settings_fields.editor :footer_address_text, label: t(".footer_address") unless theme == :capitalitat %> <%= settings_fields.translated :text_field, :footer_social_links_title, label: t(".footer_social_links_title") %> - <%= settings_fields.translated :text_field, :footer_additional_text if theme == "capitalitat" %> - <% unless theme == "capitalitat" %> + <%= settings_fields.translated :text_field, :footer_additional_text if theme == :capitalitat %> +
- <% Decidim::NewsletterAgenda.additional_social_handlers.each do |handler| %> -
- <%= settings_fields.text_field "#{handler}_handler", label: false %> + <% social_handlers&.each do |handler| %> + <% end %>
<% end %> - <% end %>
diff --git a/app/cells/decidim/newsletter_agenda/agenda_events_settings_form_cell.rb b/app/cells/decidim/newsletter_agenda/agenda_events_settings_form_cell.rb index 2971dd1..d460f06 100644 --- a/app/cells/decidim/newsletter_agenda/agenda_events_settings_form_cell.rb +++ b/app/cells/decidim/newsletter_agenda/agenda_events_settings_form_cell.rb @@ -3,12 +3,15 @@ module Decidim module NewsletterAgenda class AgendaEventsSettingsFormCell < NewsletterTemplates::BaseSettingsFormCell + include ThemeMethods + # rubocop:disable Metrics/CyclomaticComplexity # rubocop:disable Metrics/PerceivedComplexity def settings @settings ||= form.object.settings.tap do |settings| - settings[:background_color] ||= NewsletterAgenda.default_background_color || current_organization.colors["primary"] || "#7636D2" - settings[:font_color_over_bg] ||= NewsletterAgenda.default_font_color_over_bg + settings[:link_color] ||= default_link_color + settings[:background_color] ||= default_background_color + settings[:font_color_over_bg] ||= default_font_color_over_bg settings[:body_title].tap do |hash| I18n.available_locales.each do |locale| hash[locale] = I18n.t("decidim.newsletter_templates.agenda_events.body_title_preview", locale: locale) if hash[locale].nil? @@ -34,11 +37,12 @@ def settings hash[locale] = I18n.t("decidim.newsletter_templates.agenda_events.footer_social_links_title_preview", locale: locale) if hash[locale].nil? end end - settings[:footer_address_text] ||= NewsletterAgenda.default_address_text + + settings[:footer_address_text] = default_address_text if settings[:footer_address_text].blank? # social handlers - Decidim::NewsletterAgenda.additional_social_handlers.each do |handler| - settings["#{handler}_handler"] ||= "" + social_handlers&.each do |handler| + settings["#{handler}_handler"] ||= organization_handler_attributes["#{handler}_handler"] end # boxes @@ -59,11 +63,6 @@ def settings end end end - - def theme - content_block.manifest_name.gsub("_agenda_events", "") - end - # rubocop:enable Metrics/CyclomaticComplexity # rubocop:enable Metrics/PerceivedComplexity end diff --git a/app/packs/images/social/capitalitat/capitalitat_twitter.png b/app/packs/images/social/capitalitat_twitter.png similarity index 100% rename from app/packs/images/social/capitalitat/capitalitat_twitter.png rename to app/packs/images/social/capitalitat_twitter.png diff --git a/app/packs/images/social/capitalitat/capitalitat_youtube.png b/app/packs/images/social/capitalitat_youtube.png similarity index 100% rename from app/packs/images/social/capitalitat/capitalitat_youtube.png rename to app/packs/images/social/capitalitat_youtube.png diff --git a/config/locales/en.yml b/config/locales/en.yml index f54e70d..70739da 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -57,6 +57,7 @@ en: intro_text: Introduction text intro_title: Introduction title introduction: Introduction + link_color: Link color main_image: Introduction image mastodon: Mastodon peertube: PeerTube @@ -73,6 +74,7 @@ en: to fill in all 3 events, missing entries won't appear in the newsletter. telegram: Telegram twitter: Twitter + wont_show: Won't be shown youtube: Youtube newsletter_templates: agenda_events: @@ -82,6 +84,8 @@ en: body_box_title_preview: This is an event title for this agenda body_final_text_preview: But there's more body_title_preview: What is happening during the week + canodrom_name: Agenda events (edition Canòdrom) + capitalitat_name: Agenda events (edition Capitalitat) footer_additional_text_preview: This is a footer additional text for this agenda footer_box_date_time_preview: 7 – 15 Novembre, 10:00 @@ -102,4 +106,3 @@ en: enim. In eget magna sed enim efficitur elementum sit amet aliquam quam. Donec fermentum metus eget urna luctus pulvinar. Read more' intro_title_preview: Dummy title for the newsletter. - name: Agenda events diff --git a/lib/decidim/newsletter_agenda.rb b/lib/decidim/newsletter_agenda.rb index d050409..b7f2c6d 100644 --- a/lib/decidim/newsletter_agenda.rb +++ b/lib/decidim/newsletter_agenda.rb @@ -10,33 +10,59 @@ module NewsletterAgenda # The default background color for the newsletter agenda. # leave it empty (nil) to use the configured organization's main color. # this color can be overriden in the newsletter template builder. - # hex color code with #, e.g. "#733BCE" + # hex color code with #, e.g. "#39747f". + # If nil, it uses the one defined in the config accessor "themes" for the theme config_accessor :default_background_color do - "#7636D2" + nil end # The default font color over background for the newsletter agenda. + # leave it empty (nil) to use the one defined in the config accessor "themes" for the theme config_accessor :default_font_color_over_bg do - "#FFFFFF" + nil + end + + config_accessor :default_link_color do + nil end # The default address text for the newsletter agenda. + # leave it empty (nil) to use the one defined in the config accessor "themes" for the theme config_accessor :default_address_text do - "Canòdrom
" \ - "Ateneu d'Innovació Digital i Democràtica
" \ - "C/Concepció Arenal 165
09027 Barcelona canodrom.barcelona
" \ - "hola@canodrom.com" + nil end - # The additional social handlers for the newsletter agenda. - config_accessor :additional_social_handlers do - [:mastodon, :telegram, :peertube] + # The social handlers for the newsletter agenda. If defined in the organization will try to reuse them + # leave it empty (nil) to use the one defined in the config accessor "themes" for the theme + config_accessor :social_handlers do + nil end # Defines additional handlers for the newsletter template builder. # Available themes: :canodrom, :capitalitat config_accessor :themes do - [:canodrom, :capitalitat] + { + canodrom: { + default_background_color: "#7636D2", + default_font_color_over_bg: "#FFFFFF", + default_link_color: "#7636D2", + default_address_text: "Canòdrom
" \ + "Ateneu d'Innovació Digital i Democràtica
" \ + "C/Concepció Arenal 165
09027 Barcelona canodrom.barcelona
" \ + "hola@canodrom.com", + social_handlers: [:twitter, :instagram, :facebook, :youtube, :github, :mastodon, :telegram, :peertube] + + }, + capitalitat: { + default_background_color: "#524F9F", + default_font_color_over_bg: "#FFFFFF", + default_link_color: "#524F9F", + default_address_text: "European Capital of Democracy
" \ + "C/Concepció Arenal 165
09027 Barcelona capitalofdemocracy.barcelona
" \ + "rgpd@pemb.cat", + social_handlers: [:twitter, :youtube] + } + } end # To define the default first day for the agenda ranges. diff --git a/lib/decidim/newsletter_agenda/engine.rb b/lib/decidim/newsletter_agenda/engine.rb index f61cb8f..c54b00a 100644 --- a/lib/decidim/newsletter_agenda/engine.rb +++ b/lib/decidim/newsletter_agenda/engine.rb @@ -17,11 +17,11 @@ class Engine < ::Rails::Engine end initializer "decidim-newsletter_agenda.newsletter_templates" do - Decidim::NewsletterAgenda.themes.each do |theme| + Decidim::NewsletterAgenda.themes.each do |theme, properties| Decidim.content_blocks.register(:newsletter_template, "#{theme}_agenda_events") do |content_block| content_block.cell = "decidim/newsletter_agenda/agenda_events" content_block.settings_form_cell = "decidim/newsletter_agenda/agenda_events_settings_form" - content_block.public_name_key = "decidim.newsletter_templates.agenda_events.name" + content_block.public_name_key = "decidim.newsletter_templates.agenda_events.#{theme}_name" content_block.images = [ { @@ -47,15 +47,20 @@ class Engine < ::Rails::Engine end content_block.settings do |settings| + settings.attribute( + :link_color, + type: :text, + preview: -> { Decidim::NewsletterAgenda.default_link_color || properties[:default_link_color] || "#39747f" } + ) settings.attribute( :background_color, type: :text, - preview: -> { Decidim::NewsletterAgenda.default_background_color || "#733BCE" } + preview: -> { Decidim::NewsletterAgenda.default_background_color || properties[:default_background_color] || "#39747f" } ) settings.attribute( :font_color_over_bg, type: :text, - preview: -> { Decidim::NewsletterAgenda.default_font_color_over_bg || "#FFFFFF" } + preview: -> { Decidim::NewsletterAgenda.default_font_color_over_bg || properties[:default_font_color_over_bg] || "#FFFFFF" } ) settings.attribute( :intro_title, @@ -177,7 +182,7 @@ class Engine < ::Rails::Engine :footer_address_text, type: :text, translated: false, - preview: -> { NewsletterAgenda.default_address_text } + preview: -> { NewsletterAgenda.default_address_text || properties[:default_address_text] } ) settings.attribute( :footer_social_links_title, @@ -191,12 +196,12 @@ class Engine < ::Rails::Engine translated: true, preview: -> { I18n.t("decidim.newsletter_templates.agenda_events.footer_additional_text_preview") } ) - Decidim::NewsletterAgenda.additional_social_handlers.each do |handler| + (Decidim::NewsletterAgenda.social_handlers || properties[:social_handlers])&.each do |handler| settings.attribute( "#{handler}_handler", type: :text, translated: false, - preview: -> { "https://#{handler}.com/#{handler}" } + preview: -> { "my-#{handler}" } ) end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 24fdc46..932eabb 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,13 +2,6 @@ require "decidim/dev" -require "simplecov" -SimpleCov.start "rails" -if ENV["CODECOV"] - require "codecov" - SimpleCov.formatter = SimpleCov::Formatter::Codecov -end - ENV["ENGINE_ROOT"] = File.dirname(__dir__) Decidim::Dev.dummy_app_path = File.expand_path(File.join(__dir__, "decidim_dummy_app")) diff --git a/spec/system/agenda_events_settings_spec.rb b/spec/system/agenda_events_settings_spec.rb index c9dd3a3..481f37b 100644 --- a/spec/system/agenda_events_settings_spec.rb +++ b/spec/system/agenda_events_settings_spec.rb @@ -19,11 +19,12 @@ let(:settings) do { - background_color: organization.colors["primary"], - font_color_over_bg: Decidim::NewsletterAgenda.default_font_color_over_bg, - intro_title: "Intro title", - intro_text: "Intro text", - footer_address_text: Decidim::NewsletterAgenda.default_address_text + background_color: "#7636d1", + link_color: "#FF0FF0", + font_color_over_bg: "#FFFFF0", + intro_title_en: "Intro title", + intro_text_en: "Intro text", + footer_address_text: "Some address" } end @@ -52,9 +53,11 @@ end context "when automatic customizable settings" do - it "renders the correct the settings form" do + it "renders the default settings" do expect(page).to have_content("Background color") expect(page).to have_field("newsletter[settings][background_color]", with: "#7636d2") + expect(page).to have_content("Link color") + expect(page).to have_field("newsletter[settings][link_color]", with: "#7636d2") expect(page).to have_content("Font color over background") expect(page).to have_field("newsletter[settings][font_color_over_bg]", with: "#ffffff") @@ -78,33 +81,12 @@ expect(page).to have_content("Footer event title") expect(page).to have_content("Organization address") + expect(page).to have_content("C/Concepció Arenal 165") expect(page).to have_content("Social links title") - - address = ActionController::Base.helpers.strip_tags(content_block.settings.footer_address_text) - expect(page.html.gsub(/[\n ]+/, " ")).to have_content(address.gsub(/[\n ]+/, " ").strip) - expect(address.lines[1..3]).to all(match(/^\S/)) end end context "when settings from the form" do - let!(:content_block_new) do - content_block = Decidim::ContentBlock.find_by(organization: organization, scope_name: :newsletter_template, scoped_resource_id: newsletter.id, manifest_name: :canodrom_agenda_events) - content_block.destroy! - content_block = create( - :content_block, - :newsletter_template, - organization: organization, - scoped_resource_id: newsletter.id, - manifest_name: :canodrom_agenda_events, - settings: { - intro_title: Decidim::Faker::Localized.word, - intro_text: Decidim::Faker::Localized.word, - body_box_link: I18n.available_locales.index_with { |_locale| Faker::Internet.url } - } - ) - content_block - end - before do fill_in :newsletter_subject_en, with: "Subject" find('input[name="newsletter[settings][intro_title_en]"]').fill_in with: "Intro title" @@ -130,6 +112,7 @@ click_link "Footer" find("input[name='newsletter[settings][footer_title_en]']").fill_in with: "Footer title" + click_link "Mastodon" find("input[name='newsletter[settings][mastodon_handler]']").fill_in with: "super_mastodon" (1..3).each do |i|