From 85ff7666f3b995a3884d507a00b2b075155e1057 Mon Sep 17 00:00:00 2001 From: Naouak Date: Sat, 15 Apr 2017 22:47:48 +0200 Subject: [PATCH] Check for a custom css file to help customization of instances (#1368) * User can create a custom.scss to customize their instance without modifying gitted files. * Add documentation for customization. * Forgot the helper file * Fix Style to pass codeclimate * Requests from maintainer. --- app/assets/stylesheets/variables.scss | 16 ++++++++-------- app/helpers/style_helper.rb | 19 +++++++++++++++++++ app/views/layouts/application.html.haml | 2 +- config/initializers/assets.rb | 3 ++- 4 files changed, 30 insertions(+), 10 deletions(-) mode change 100644 => 100755 app/assets/stylesheets/variables.scss create mode 100755 app/helpers/style_helper.rb mode change 100644 => 100755 app/views/layouts/application.html.haml mode change 100644 => 100755 config/initializers/assets.rb diff --git a/app/assets/stylesheets/variables.scss b/app/assets/stylesheets/variables.scss old mode 100644 new mode 100755 index cdf81c8186..0dded90b07 --- a/app/assets/stylesheets/variables.scss +++ b/app/assets/stylesheets/variables.scss @@ -1,8 +1,8 @@ -$color1: #282c37; // darkest -$color2: #d9e1e8; // lightest -$color3: #9baec8; // lighter -$color4: #2b90d9; // vibrant -$color5: #ffffff; // white -$color6: #df405a; // error red -$color7: #79bd9a; // succ green -$color8: #000000; // black +$color1: #282c37 !default; // darkest +$color2: #d9e1e8 !default; // lightest +$color3: #9baec8 !default; // lighter +$color4: #2b90d9 !default; // vibrant +$color5: #ffffff !default; // white +$color6: #df405a !default; // error red +$color7: #79bd9a !default; // succ green +$color8: #000000 !default; // black diff --git a/app/helpers/style_helper.rb b/app/helpers/style_helper.rb new file mode 100755 index 0000000000..774407b7fe --- /dev/null +++ b/app/helpers/style_helper.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module StyleHelper + def stylesheet_for_layout + if asset_exist? 'custom.css' + 'custom' + else + 'application' + end + end + + def asset_exist?(path) + if Rails.configuration.assets.compile + Rails.application.precompiled_assets.include? path + else + Rails.application.assets_manifest.assets[path].present? + end + end +end diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml old mode 100644 new mode 100755 index e8253bd6f9..a27c3de956 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -17,7 +17,7 @@ = ' - ' = site_title - = stylesheet_link_tag 'application', media: 'all' + = stylesheet_link_tag stylesheet_for_layout, media: 'all' = csrf_meta_tags = yield :header_tags diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb old mode 100644 new mode 100755 index 43f7860cb0..e6bd8a015b --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -8,5 +8,6 @@ Rails.application.config.assets.version = '1.0' # Precompile additional assets. # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. -Rails.application.config.assets.precompile += %w(application_public.js) +Rails.application.config.assets.precompile += %w(application_public.js custom.css) + Rails.application.config.assets.initialize_on_precompile = true