From 5ad489335d7cd66f5320425bc020eca1b5493413 Mon Sep 17 00:00:00 2001 From: Arnaud Levy <contact@arnaudlevy.com> Date: Mon, 27 Feb 2023 07:04:53 +0100 Subject: [PATCH] style --- .../communication/extranets_controller.rb | 4 +++- app/controllers/extranet/style_controller.rb | 5 +++++ app/models/communication/extranet.rb | 4 ++++ .../communication/extranet/with_style.rb | 13 +++++++++++++ .../communication/extranets/_form.html.erb | 2 ++ app/views/extranet/application/_head.html.erb | 1 + app/views/extranet/home/index.html.erb | 19 ++++++++++++------- config/initializers/mime_types.rb | 1 + config/routes/extranet.rb | 1 + .../20230227052540_add_look_to_extranets.rb | 7 +++++++ db/schema.rb | 5 ++++- test/fixtures/communication/extranets.yml | 3 +++ test/models/communication/extranet_test.rb | 3 +++ 13 files changed, 59 insertions(+), 9 deletions(-) create mode 100644 app/controllers/extranet/style_controller.rb create mode 100644 app/models/communication/extranet/with_style.rb create mode 100644 db/migrate/20230227052540_add_look_to_extranets.rb diff --git a/app/controllers/admin/communication/extranets_controller.rb b/app/controllers/admin/communication/extranets_controller.rb index 717958ce9..29a4fcffe 100644 --- a/app/controllers/admin/communication/extranets_controller.rb +++ b/app/controllers/admin/communication/extranets_controller.rb @@ -73,11 +73,13 @@ class Admin::Communication::ExtranetsController < Admin::Communication::Applicat :feature_posts, :has_sso, :host, + :home_sentence, :logo, :logo_delete, :name, :privacy_policy, - :registration_contact, + :registration_contact, + :sass, :sso_target_url, :sso_cert, :sso_name_identifier_format, diff --git a/app/controllers/extranet/style_controller.rb b/app/controllers/extranet/style_controller.rb new file mode 100644 index 000000000..dea8f4d4b --- /dev/null +++ b/app/controllers/extranet/style_controller.rb @@ -0,0 +1,5 @@ +class Extranet::StyleController < Extranet::ApplicationController + def index + render body: current_extranet.css, content_type: 'text/css' + end +end \ No newline at end of file diff --git a/app/models/communication/extranet.rb b/app/models/communication/extranet.rb index ae1a93f4b..ab3057119 100644 --- a/app/models/communication/extranet.rb +++ b/app/models/communication/extranet.rb @@ -6,16 +6,19 @@ # about_type :string indexed => [about_id] # color :string # cookies_policy :text +# css :text # feature_alumni :boolean default(FALSE) # feature_assets :boolean default(FALSE) # feature_contacts :boolean default(FALSE) # feature_jobs :boolean default(FALSE) # feature_posts :boolean default(FALSE) # has_sso :boolean default(FALSE) +# home_sentence :text # host :string # name :string # privacy_policy :text # registration_contact :string +# sass :text # sso_button_label :string # sso_cert :text # sso_mapping :jsonb @@ -44,6 +47,7 @@ class Communication::Extranet < ApplicationRecord include WithAbouts include WithFeatures include WithLegal + include WithStyle include WithSso include WithUniversity diff --git a/app/models/communication/extranet/with_style.rb b/app/models/communication/extranet/with_style.rb new file mode 100644 index 000000000..f3d5e22a2 --- /dev/null +++ b/app/models/communication/extranet/with_style.rb @@ -0,0 +1,13 @@ +module Communication::Extranet::WithStyle + extend ActiveSupport::Concern + + included do + before_validation :generate_css + end + + protected + + def generate_css + self.css = SassC::Sass2Scss.convert sass + end +end \ No newline at end of file diff --git a/app/views/admin/communication/extranets/_form.html.erb b/app/views/admin/communication/extranets/_form.html.erb index df19b8c67..62246a4bc 100644 --- a/app/views/admin/communication/extranets/_form.html.erb +++ b/app/views/admin/communication/extranets/_form.html.erb @@ -22,6 +22,8 @@ preview: 100, direct_upload: true %> <%= f.input :color, as: :color %> + <%= f.input :home_sentence %> + <%= f.input :sass %> <% end %> </div> <div class="col-xl-6"> diff --git a/app/views/extranet/application/_head.html.erb b/app/views/extranet/application/_head.html.erb index 8c49787e7..4609cab2b 100644 --- a/app/views/extranet/application/_head.html.erb +++ b/app/views/extranet/application/_head.html.erb @@ -4,6 +4,7 @@ <%= csrf_meta_tags %> <%= csp_meta_tag %> <%= stylesheet_link_tag 'extranet', media: 'all' %> +<link rel="stylesheet" href="<%= extranet_style_path(format: :css) %>" media="all"> <%= javascript_include_tag 'extranet' %> <% if current_extranet.favicon.attached? %> <%= favicon_link_tag url_for(current_extranet.favicon.variant(:thumb)) %> diff --git a/app/views/extranet/home/index.html.erb b/app/views/extranet/home/index.html.erb index 48168a94a..b821aa90d 100644 --- a/app/views/extranet/home/index.html.erb +++ b/app/views/extranet/home/index.html.erb @@ -1,13 +1,18 @@ <% content_for :title, current_context %> <% content_for :header do %> - <h1><%# TODO i18n %> - Bienvenue sur l’extranet <%= current_context %>. - Retrouvez les <%= link_to University::Person::Alumnus.model_name.human(count: 2).downcase, university_persons_path %>, - <% if current_extranet.should_show_years? %> - recherchez par <%= link_to Education::AcademicYear.model_name.human(count: 2).downcase, education_academic_years_path %>, + <h1> + <% if current_extranet.home_sentence.present? %> + <%= current_extranet.home_sentence.html_safe %> + <% else %> + <%# TODO i18n %> + Bienvenue sur l’extranet <%= current_context %>. + Retrouvez les <%= link_to University::Person::Alumnus.model_name.human(count: 2).downcase, university_persons_path %>, + <% if current_extranet.should_show_years? %> + recherchez par <%= link_to Education::AcademicYear.model_name.human(count: 2).downcase, education_academic_years_path %>, + <% end %> + explorez les <%= link_to Education::Cohort.model_name.human(count: 2).downcase, education_cohorts_path %>, + découvrez les <%= link_to University::Organization.model_name.human(count: 2).downcase, university_organizations_path %>. <% end %> - explorez les <%= link_to Education::Cohort.model_name.human(count: 2).downcase, education_cohorts_path %>, - découvrez les <%= link_to University::Organization.model_name.human(count: 2).downcase, university_organizations_path %>. </h1> <% end %> diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb index 1ce3a81f7..e7f0e9b10 100644 --- a/config/initializers/mime_types.rb +++ b/config/initializers/mime_types.rb @@ -2,4 +2,5 @@ # Add new mime types for use in respond_to blocks: # Mime::Type.register "text/richtext", :rtf +# Mime::Type.register "text/css", :css Mime::Type.register "application/xml", :xml, %w( text/xml application/x-xml ) diff --git a/config/routes/extranet.rb b/config/routes/extranet.rb index 7ee4169e1..f7a659b44 100644 --- a/config/routes/extranet.rb +++ b/config/routes/extranet.rb @@ -19,4 +19,5 @@ get 'terms' => 'extranet/pages#terms', as: :terms get 'privacy-policy' => 'extranet/pages#privacy_policy', as: :privacy_policy get 'cookies-policy' => 'extranet/pages#cookies_policy', as: :cookies_policy get 'data' => 'extranet/pages#data', as: :data +get 'extranet' => 'extranet/style#index', as: :extranet_style, constraints: { format: 'css' } root to: 'extranet/home#index' diff --git a/db/migrate/20230227052540_add_look_to_extranets.rb b/db/migrate/20230227052540_add_look_to_extranets.rb new file mode 100644 index 000000000..698556cdf --- /dev/null +++ b/db/migrate/20230227052540_add_look_to_extranets.rb @@ -0,0 +1,7 @@ +class AddLookToExtranets < ActiveRecord::Migration[7.0] + def change + add_column :communication_extranets, :home_sentence, :text + add_column :communication_extranets, :sass, :text + add_column :communication_extranets, :css, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index 6b4d26f99..83c445005 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_02_27_045821) do +ActiveRecord::Schema[7.0].define(version: 2023_02_27_052540) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" @@ -118,6 +118,9 @@ ActiveRecord::Schema[7.0].define(version: 2023_02_27_045821) do t.boolean "feature_assets", default: false t.boolean "feature_posts", default: false t.boolean "feature_jobs", default: false + t.text "home_sentence" + t.text "sass" + t.text "css" t.index ["about_type", "about_id"], name: "index_communication_extranets_on_about" t.index ["university_id"], name: "index_communication_extranets_on_university_id" end diff --git a/test/fixtures/communication/extranets.yml b/test/fixtures/communication/extranets.yml index 927e24449..32d364d3e 100644 --- a/test/fixtures/communication/extranets.yml +++ b/test/fixtures/communication/extranets.yml @@ -6,16 +6,19 @@ # about_type :string indexed => [about_id] # color :string # cookies_policy :text +# css :text # feature_alumni :boolean default(FALSE) # feature_assets :boolean default(FALSE) # feature_contacts :boolean default(FALSE) # feature_jobs :boolean default(FALSE) # feature_posts :boolean default(FALSE) # has_sso :boolean default(FALSE) +# home_sentence :text # host :string # name :string # privacy_policy :text # registration_contact :string +# sass :text # sso_button_label :string # sso_cert :text # sso_mapping :jsonb diff --git a/test/models/communication/extranet_test.rb b/test/models/communication/extranet_test.rb index 4cc7a451f..504f037d0 100644 --- a/test/models/communication/extranet_test.rb +++ b/test/models/communication/extranet_test.rb @@ -6,16 +6,19 @@ # about_type :string indexed => [about_id] # color :string # cookies_policy :text +# css :text # feature_alumni :boolean default(FALSE) # feature_assets :boolean default(FALSE) # feature_contacts :boolean default(FALSE) # feature_jobs :boolean default(FALSE) # feature_posts :boolean default(FALSE) # has_sso :boolean default(FALSE) +# home_sentence :text # host :string # name :string # privacy_policy :text # registration_contact :string +# sass :text # sso_button_label :string # sso_cert :text # sso_mapping :jsonb -- GitLab