OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Allow plugins to define global_styles.sass (#9176)
Oliver Günther8c632139e891
diff --git a/frontend/.gitignore b/frontend/.gitignoreindex b02277f4532..d59eb6760c8 100644--- a/frontend/.gitignore+++ b/frontend/.gitignore@@ -17,4 +17,5 @@/generated_typings/src/app/modules/plugins/linked//src/app/modules/plugins/linked-plugins.module.ts+/src/app/modules/plugins/linked-plugins.styles.sass/legacy/app/plugins/*diff --git a/frontend/scripts/link_plugin_placeholder.js b/frontend/scripts/link_plugin_placeholder.jsindex bbe981c6ced..5ca1b6e50b2 100755--- a/frontend/scripts/link_plugin_placeholder.js+++ b/frontend/scripts/link_plugin_placeholder.js@@ -3,31 +3,30 @@const fs = require('fs');const path = require('path');const linked_module_example_path = path.join(__dirname, '..', 'src', 'app', 'modules', 'plugins', 'linked-plugins.module.ts.example');+const linked_style_example_path = path.join(__dirname, '..', 'src', 'app', 'modules', 'plugins', 'linked-plugins.styles.sass.example');const linked_module_path = path.join(__dirname, '..', 'src', 'app', 'modules', 'plugins', 'linked-plugins.module.ts');+const linked_style_path = path.join(__dirname, '..', 'src', 'app', 'modules', 'plugins', 'linked-plugins.styles.sass');-const exists = fs.existsSync(linked_module_path);+if (!fs.existsSync(linked_module_path)) {+ console.log(+ `Linked plugin path (${linked_module_path}) does not exist, using default. ` ++ `If you have active OpenProject plugins, run "rake openproject:plugins:register_frontend" to generate the file with the correct plugins being linked.`,+ );-if (!exists) {- console.log(- `Linked plugin path (${linked_module_path}) does not exist, using default. ` +- `If you have active OpenProject plugins, run "rake openproject:plugins:register_frontend" to generate the file with the correct plugins being linked.`- );+ fs.copyFile(linked_module_example_path, linked_module_path, (err) => {+ if (err) throw err;+ });++}- const rd = fs.createReadStream(linked_module_example_path);- const wr = fs.createWriteStream(linked_module_path);- return new Promise(function(resolve, reject) {- rd.on('error', reject);- wr.on('error', reject);- wr.on('finish', resolve);- rd.pipe(wr);- }).then(function() {- console.log("Done.");- }).catch(function(error) {- rd.destroy();- wr.end();+if (!fs.existsSync(linked_style_path)) {+ console.log(+ `Linked sass path (${linked_style_path}) does not exist, using default. ` ++ `If you have active OpenProject plugins, run "rake openproject:plugins:register_frontend" to generate the file with the correct plugins being linked.`,+ );- console.error("Failed to write file: " + error);- throw error;- });+ fs.copyFile(linked_style_example_path, linked_style_path, (err) => {+ if (err) throw err;+ });}diff --git a/frontend/src/app/modules/plugins/linked-plugins.styles.sass.example b/frontend/src/app/modules/plugins/linked-plugins.styles.sass.examplenew file mode 100644index 00000000000..334c5c39323--- /dev/null+++ b/frontend/src/app/modules/plugins/linked-plugins.styles.sass.example@@ -0,0 +1,30 @@+// -- copyright+// OpenProject is an open source project management software.+// Copyright (C) 2012-2020 the OpenProject GmbH+//+// This program is free software; you can redistribute it and/or+// modify it under the terms of the GNU General Public License version 3.+//+// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+// Copyright (C) 2006-2013 Jean-Philippe Lang+// Copyright (C) 2010-2013 the ChiliProject Team+//+// This program is free software; you can redistribute it and/or+// modify it under the terms of the GNU General Public License+// as published by the Free Software Foundation; either version 2+// of the License, or (at your option) any later version.+//+// This program is distributed in the hope that it will be useful,+// but WITHOUT ANY WARRANTY; without even the implied warranty of+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+// GNU General Public License for more details.+//+// You should have received a copy of the GNU General Public License+// along with this program; if not, write to the Free Software+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+//+// See docs/COPYRIGHT.rdoc for more details.+// ++++// This file is generated by Rails using the rake task+// rake openproject:plugins:register_frontenddiff --git a/frontend/src/global_styles/openproject.sass b/frontend/src/global_styles/openproject.sassindex 71117ab71cc..19b89c8b3c1 100644--- a/frontend/src/global_styles/openproject.sass+++ b/frontend/src/global_styles/openproject.sass@@ -5,4 +5,7 @@@import "content/_index.sass"@import "../app/modules/common/openproject-common.module"-@import "../app/modules/modal/modal.module"\ No newline at end of file+@import "../app/modules/modal/modal.module"++// Dynamically linked plugin styles from Rails plugins+@import "../app/modules/plugins/linked-plugins.styles"diff --git a/lib/open_project/plugins/frontend_linking/generator.rb b/lib/open_project/plugins/frontend_linking/generator.rbindex b72db5718f8..63d4d47e849 100644--- a/lib/open_project/plugins/frontend_linking/generator.rb+++ b/lib/open_project/plugins/frontend_linking/generator.rb@@ -58,7 +58,7 @@ module ::OpenProject::Plugins# Register plugins with an Angular frontend to the CLI build.# For that, search all gems with the group :opf_pluginsdef regenerate_angular_links- all_angular_frontend_plugins.tap do |plugins|+ all_frontend_plugins.tap do |plugins|target_dir = Rails.root.join('frontend', 'src', 'app', 'modules', 'plugins', 'linked')puts "Cleaning linked target directory #{target_dir}"@@ -74,7 +74,15 @@ module ::OpenProject::PluginsFileUtils.ln_sf(source, target)end- generate_plugin_module(plugins)+ generate_plugin_module(all_angular_frontend_plugins)+ generate_plugin_sass(all_plugins_with_global_styles)+ end+ end++ def all_frontend_plugins+ openproject_plugins.select do |_, path|+ frontend_entry = File.join(path, 'frontend', 'module')+ File.directory? frontend_entryendend@@ -85,6 +93,13 @@ module ::OpenProject::Pluginsendend+ def all_plugins_with_global_styles+ openproject_plugins.select do |_, path|+ style_file = File.join(path, 'frontend', 'module', 'global_styles.*')+ !Dir.glob(style_file).empty?+ end+ end+### Regenerate the frontend plugin module orchestrating the linked frontendsdef generate_plugin_module(plugins)@@ -98,6 +113,19 @@ module ::OpenProject::PluginsFile.open(file_register, 'w') { |file| file.write(result) }end+ ##+ # Regenerate the frontend plugin sass files+ def generate_plugin_sass(plugins)+ file_register = Rails.root.join('frontend', 'src', 'app', 'modules', 'plugins', 'linked-plugins.styles.sass')+ template_file = File.read(File.expand_path('linked-plugins.styles.sass.erb', __dir__))+ template = ::ERB.new template_file, trim_mode: '-'++ puts "Regenerating frontend plugin sass #{file_register}."+ context = ::OpenProject::Plugins::FrontendLinking::ErbContext.new plugins+ result = template.result(context.get_binding)+ File.open(file_register, 'w') { |file| file.write(result) }+ end+### Print all gemspecs of registered OP plugins# from the :opf_plugins group.diff --git a/lib/open_project/plugins/frontend_linking/linked-plugins.styles.sass.erb b/lib/open_project/plugins/frontend_linking/linked-plugins.styles.sass.erbnew file mode 100644index 00000000000..adec2e75a04--- /dev/null+++ b/lib/open_project/plugins/frontend_linking/linked-plugins.styles.sass.erb@@ -0,0 +1,34 @@+// -- copyright+// OpenProject is an open source project management software.+// Copyright (C) 2012-2020 the OpenProject GmbH+//+// This program is free software; you can redistribute it and/or+// modify it under the terms of the GNU General Public License version 3.+//+// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+// Copyright (C) 2006-2013 Jean-Philippe Lang+// Copyright (C) 2010-2013 the ChiliProject Team+//+// This program is free software; you can redistribute it and/or+// modify it under the terms of the GNU General Public License+// as published by the Free Software Foundation; either version 2+// of the License, or (at your option) any later version.+//+// This program is distributed in the hope that it will be useful,+// but WITHOUT ANY WARRANTY; without even the implied warranty of+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+// GNU General Public License for more details.+//+// You should have received a copy of the GNU General Public License+// along with this program; if not, write to the Free Software+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+//+// See docs/COPYRIGHT.rdoc for more details.+// ++++// This file is generated by Rails using the rake task+// rake openproject:plugins:register_frontend++<%- frontend_plugins.each do |actual_name, _|-%>+@import "./linked/<%= actual_name %>/global_styles"+<%- end -%>