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I,GAGV,IACO,IACT,EAEO,CAER,CApSkB,CAoShB,EACL,CAED,GAAE,KAAK","file":"/npm/docpad-plugin-cms@2.5.6/out/cms.plugin.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/docpad-plugin-cms@2.5.6/out/cms.plugin.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","// Generated by CoffeeScript 1.10.0\n(function() {\n  var extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },\n    hasProp = {}.hasOwnProperty;\n\n  module.exports = function(BasePlugin) {\n    var CmsPlugin, copy, ensurePaths, fs, path, thisPlugin, util, watchr;\n    fs = require('fs');\n    util = require('util');\n    copy = require('fs-extra').copy;\n    path = require('path');\n    ensurePaths = require('./helpers/ensurePaths');\n    watchr = require('watchr');\n    thisPlugin = {\n      name: \"thisPlugin\"\n    };\n    return CmsPlugin = (function(superClass) {\n      extend(CmsPlugin, superClass);\n\n      function CmsPlugin() {\n        return CmsPlugin.__super__.constructor.apply(this, arguments);\n      }\n\n      CmsPlugin.prototype.name = 'cms';\n\n      CmsPlugin.prototype.config = {\n        templateLocation: path.join(__dirname, '..', 'templates', 'bootstrap'),\n        templateFolder: 'cms',\n        postsCollectionName: 'posts',\n        copyTemplates: true,\n        watchTemplates: false\n      };\n\n      CmsPlugin.prototype.layoutsPath = '';\n\n      CmsPlugin.prototype.filesPath = '';\n\n      CmsPlugin.prototype.documentsPath = '';\n\n      CmsPlugin.prototype.tmpllayoutsDir = '';\n\n      CmsPlugin.prototype.tmplfilesDir = '';\n\n      CmsPlugin.prototype.tmpldocsDir = '';\n\n      CmsPlugin.prototype.editURL = '';\n\n      CmsPlugin.prototype.imageURL = '';\n\n      CmsPlugin.prototype.dataURL = '';\n\n      CmsPlugin.prototype.destroy = function() {\n        if (this.watcher) {\n          this.watcher.close();\n          this.watcher = null;\n        }\n        return CmsPlugin.__super__.destroy.apply(this, arguments);\n      };\n\n      CmsPlugin.prototype.setConfig = function() {\n        var cfg, plugin, tplFolder;\n        CmsPlugin.__super__.setConfig.apply(this, arguments);\n        plugin = this;\n        thisPlugin = this;\n        cfg = plugin.getConfig();\n        ensurePaths(plugin.docpad, plugin);\n        tplFolder = cfg.templateFolder;\n        plugin.editURL = '/' + tplFolder + '/edit/*';\n        plugin.imageURL = '/' + tplFolder + '/images';\n        plugin.dataURL = '/' + tplFolder + '/data/:item';\n        if (cfg.watchTemplates) {\n          return plugin.watchTemplates();\n        }\n      };\n\n      CmsPlugin.prototype.watchListener = function(type, pathToFile) {\n        var dirname, filename, outpath;\n        if (type === \"update\") {\n          dirname = path.dirname(pathToFile);\n          outpath = \"\";\n          if (pathToFile.indexOf(thisPlugin.tmpllayoutsDir) > -1) {\n            filename = pathToFile.substr(thisPlugin.tmpllayoutsDir.length);\n            outpath = path.join(thisPlugin.layoutsPath, filename);\n          } else if (pathToFile.indexOf(thisPlugin.tmplfilesDir) > -1) {\n            filename = pathToFile.substr(thisPlugin.tmplfilesDir.length);\n            outpath = path.join(thisPlugin.filesPath, filename);\n          } else if (pathToFile.indexOf(thisPlugin.tmpldocsDir) > -1) {\n            filename = pathToFile.substr(thisPlugin.tmpldocsDir.length);\n            outpath = path.join(thisPlugin.docsPath, filename);\n          }\n          if (outpath) {\n            return copy(pathToFile, outpath);\n          }\n        }\n      };\n\n      CmsPlugin.prototype.watchTemplates = function() {\n        var docpad, opts, plugin;\n        docpad = this.docpad;\n        plugin = this;\n        opts = {\n          path: this.getConfig().templateLocation,\n          listener: this.watchListener\n        };\n        docpad.log(\"info\", \"Watching CMS templates...\");\n        return this.watcher = watchr.watch(opts);\n      };\n\n      CmsPlugin.prototype.requiredPlugins = ['eco', 'authentication', 'cleanurls', 'posteditor'];\n\n      CmsPlugin.prototype.checkPlugins = function() {\n        var docpad, i, len, name, plugins, ref, results;\n        docpad = this.docpad;\n        plugins = docpad.loadedPlugins;\n        ref = this.requiredPlugins;\n        results = [];\n        for (i = 0, len = ref.length; i < len; i++) {\n          name = ref[i];\n          if (!plugins[name]) {\n            results.push(docpad.log(\"warn\", \"cms: \" + name + \" plugin not installed\"));\n          } else {\n            results.push(void 0);\n          }\n        }\n        return results;\n      };\n\n      CmsPlugin.prototype.pagesQry = {\n        relativeOutDirPath: {\n          $nin: ['cms', 'posts']\n        },\n        outExtension: 'html'\n      };\n\n      CmsPlugin.prototype.buildCollections = function() {\n        var docpad, pagesCollection, plugin;\n        plugin = this;\n        docpad = plugin.docpad;\n        pagesCollection = docpad.getCollection('documents').findAllLive(plugin.pagesQry);\n        pagesCollection.options.name = 'pages';\n        return docpad.addCollection(pagesCollection);\n      };\n\n      CmsPlugin.prototype.templateHelpers = {\n        getLatestPosts: function() {\n          var collection, templateData;\n          templateData = this;\n          collection = templateData.getCollection(templateData.postsCollectionName);\n          if (collection) {\n            return collection.findAll({}, {}, {\n              limit: 4\n            }).toJSON();\n          } else {\n            return templateData.getCollection('documents').findAll({}, {}, {\n              limit: 4\n            }).toJSON();\n          }\n        },\n        getPosts: function() {\n          var collection, templateData;\n          templateData = this;\n          collection = templateData.getCollection(templateData.postsCollectionName);\n          if (collection) {\n            return collection.toJSON();\n          } else {\n            return templateData.getCollection('documents').findAllLive().toJSON();\n          }\n        },\n        getPages: function() {\n          var collection, templateData;\n          templateData = this;\n          collection = templateData.getCollection('pages');\n          if (collection) {\n            return collection.toJSON();\n          } else {\n            return null;\n          }\n        },\n        getDocuments: function() {\n          var collection, templateData;\n          templateData = this;\n          collection = templateData.getCollection('documents');\n          if (collection) {\n            return collection.toJSON();\n          } else {\n            return null;\n          }\n        },\n        getSettings: function() {\n          var cfg, settings;\n          settings = {};\n          cfg = this.config;\n          Object.keys(cfg).sort().forEach(function(key) {\n            return settings[key] = cfg[key];\n          });\n          return settings;\n        },\n        getUsers: function() {\n          var auth;\n          auth = this.loadedPlugins[\"authentication\"];\n          if (auth.getUsers) {\n            return auth.getUsers();\n          } else if (auth.simpleMembership) {\n            return auth.simpleMembership.getUsers();\n          } else {\n            return [];\n          }\n        }\n      };\n\n      CmsPlugin.prototype.extendTemplateData = function(opts) {\n        var key, plugin, ref, results, templateData, val;\n        templateData = opts.templateData;\n        plugin = thisPlugin;\n        templateData.postsCollectionName = plugin.getConfig().postsCollectionName;\n        templateData.loadedPlugins = plugin.docpad.loadedPlugins;\n        plugin.buildCollections();\n        plugin.checkPlugins();\n        templateData.config = plugin.docpad.getConfig();\n        ref = plugin.templateHelpers;\n        results = [];\n        for (key in ref) {\n          val = ref[key];\n          if (!templateData[key]) {\n            results.push(templateData[key] = plugin.templateHelpers[key]);\n          } else {\n            results.push(void 0);\n          }\n        }\n        return results;\n      };\n\n      CmsPlugin.prototype.serverExtend = function(opts) {\n        var docpad, plugin, server;\n        server = opts.server;\n        plugin = this;\n        docpad = plugin.docpad;\n        server.get(plugin.imageURL, function(req, res, next) {\n          var coll, err, error, output;\n          try {\n            coll = docpad.getDatabase().findAllLive({\n              relativeOutDirPath: 'images'\n            }).toJSON();\n            output = [];\n            coll.forEach(function(item) {\n              return output.push(item.url);\n            });\n            return res.json(output);\n          } catch (error) {\n            err = error;\n            console.log(err);\n            return res.status(500).json({\n              success: false,\n              msg: \"unable to find images\"\n            });\n          }\n        });\n        server.get(plugin.editURL, function(req, res, next) {\n          var editPage, err, error;\n          try {\n            editPage = docpad.getCollection('documents').findOne({\n              slug: 'cms-edit'\n            });\n            if (editPage) {\n              opts = {\n                document: editPage,\n                err: '',\n                req: req,\n                res: res\n              };\n              return docpad.serveDocument(opts, next);\n            } else {\n              return res.status(500).json({\n                success: false,\n                msg: 'unable to find edit page!'\n              });\n            }\n          } catch (error) {\n            err = error;\n            console.log(\"error getting edit page....\");\n            console.log(err);\n            return res.status(500).json({\n              success: false,\n              msg: err\n            });\n          }\n        });\n        server.get(plugin.dataURL, function(req, res, next) {\n          var id, item, name;\n          item = req.params.item;\n          if (item === \"user\") {\n            name = \"Not logged in\";\n            id = -1;\n            if (req.user && req.user.name) {\n              name = req.user.name;\n              id = req.user.our_id;\n            }\n            return res.json({\n              user: name,\n              id: id\n            });\n          }\n        });\n        return this;\n      };\n\n      return CmsPlugin;\n\n    })(BasePlugin);\n  };\n\n}).call(this);\n"]}