sou пре 7 година
родитељ
комит
5a58819ee4
1 измењених фајлова са 28 додато и 20 уклоњено
  1. 28 20
      lib/routes/page.js

+ 28 - 20
lib/routes/page.js

@@ -316,20 +316,7 @@ module.exports = function(crowi, app) {
 
       return Page.findAllTemplates(pathList)
         .then(templates => {
-          //get local template
-          //@tempate: applicable only to immediate decendants
-          const localTemplate = templateFinder(templates, templateUrl, '@');
-
-          //get global templates
-          //_tempate: applicable to all pages under
-          const globalTemplate = globalTemplateFinder(templates, templateUrl);
-
-          if (localTemplate) {
-            renderVars.template = localTemplate.revision.body;
-          }
-          else if (globalTemplate) {
-            renderVars.template = globalTemplate.revision.body;
-          }
+          renderVars.template = templateFinder(templates, templateUrl);
         });
     })
     // get list pages
@@ -396,8 +383,16 @@ module.exports = function(crowi, app) {
     return findAllAscendantPaths(newPath, pathList);
   };
 
+  const findTemplateByType = (templates, path, type) => {
+    for (let i = 0; i < templates.length; i++) {
+      if (templates[i].path === `${path}/${type}template`) {
+        return templates[i];
+      }
+    }
+  };
+
   const globalTemplateFinder = (globalTemplates, path) => {
-    const globalTemplate = templateFinder(globalTemplates, path, '_');
+    const globalTemplate = findTemplateByType(globalTemplates, path, '_');
     if (globalTemplate) {
       return globalTemplate;
     }
@@ -410,12 +405,25 @@ module.exports = function(crowi, app) {
     return globalTemplateFinder(globalTemplates, newPath);
   };
 
-  const templateFinder = (templates, path, type) => {
-    for (let i = 0; i < templates.length; i++) {
-      if (templates[i].path === `${path}/${type}template`) {
-        return templates[i];
-      }
+  const templateFinder = (templates, templateUrl) => {
+    let templateBody;
+
+    //get local template
+    //@tempate: applicable only to immediate decendants
+    const localTemplate = findTemplateByType(templates, templateUrl, '@');
+
+    //get global templates
+    //_tempate: applicable to all pages under
+    const globalTemplate = globalTemplateFinder(templates, templateUrl);
+
+    if (localTemplate) {
+      templateBody =  localTemplate.revision.body;
     }
+    else if (globalTemplate) {
+      templateBody = globalTemplate.revision.body;
+    }
+
+    return templateBody;
   };
 
   actions.deletedPageListShow = function(req, res) {