Просмотр исходного кода

load css from config and inject

Yuki Takei 9 лет назад
Родитель
Сommit
3fa3199981
4 измененных файлов с 29 добавлено и 0 удалено
  1. 19 0
      lib/models/config.js
  2. 4 0
      lib/util/swigFunctions.js
  3. 2 0
      lib/views/admin/customize.html
  4. 4 0
      lib/views/layout/layout.html

+ 19 - 0
lib/models/config.js

@@ -176,6 +176,10 @@ module.exports = function(crowi) {
         });
 
         debug('Config loaded', config);
+
+        // uglify and store
+        Config.generateUglifiedCustomCss(config);
+
         return callback(null, config);
       });
   };
@@ -231,6 +235,21 @@ module.exports = function(crowi) {
     return config.markdown['markdown:isEnabledLinebreaksInComments'];
   };
 
+  /**
+   * uglify store custom css strings
+   */
+  configSchema.statics.generateUglifiedCustomCss = function(config)
+  {
+    var rawCss = config.crowi['customize:css'] || getArrayForInstalling()['customize:css'];
+    // TODO uglify
+    this.uglifiedCustomCss = rawCss;
+  }
+
+  configSchema.statics.customCss = function(config)
+  {
+    return this.uglifiedCustomCss;
+  }
+
   configSchema.statics.hasSlackConfig = function(config)
   {
     if (!config.notification) {

+ 4 - 0
lib/util/swigFunctions.js

@@ -37,6 +37,10 @@ module.exports = function(crowi, app, req, locals) {
     return Config.isEnabledLinebreaksInComments(config);
   }
 
+  locals.customCss = function() {
+    return Config.customCss();
+  }
+
   locals.slackConfigured = function() {
     var config = crowi.getConfig()
     if (Config.hasSlackToken(config)) {

+ 2 - 0
lib/views/admin/customize.html

@@ -36,6 +36,8 @@
       <fieldset>
         <legend>カスタムCSS</legend>
 
+        <p class="help-block">システム全体に適用されるCSSを記述できます。</p>
+
         <div class="form-group">
           <div class="col-xs-12">
             <textarea class="form-control" type="textarea" name="settingForm[customize:css]" rows="20">{{ settingForm['customize:css'] }}</textarea>

+ 4 - 0
lib/views/layout/layout.html

@@ -44,6 +44,10 @@
   <link href='//cdn.jsdelivr.net/fontawesome/4.7.0/css/font-awesome.min.css' rel='stylesheet' type='text/css'>
 
   {% block html_additional_headers %}{% endblock %}
+
+  <style>
+    {{ customCss() }}
+  </style>
 </head>
 {% endblock %}