mirror of
https://github.com/overleaf/overleaf.git
synced 2025-02-17 09:42:07 +00:00
Allow modules to inject parts of views
This commit is contained in:
parent
374c0f3d65
commit
db9632f8f2
5 changed files with 83 additions and 48 deletions
|
@ -164,39 +164,40 @@ module.exports = (grunt) ->
|
|||
moduleUnitTestTasks = []
|
||||
if fs.existsSync "./modules"
|
||||
for module in fs.readdirSync "./modules"
|
||||
config.coffee["module_#{module}_server"] = {
|
||||
expand: true,
|
||||
flatten: false,
|
||||
cwd: "modules/#{module}/app/coffee",
|
||||
src: ['**/*.coffee'],
|
||||
dest: "modules/#{module}/app/js",
|
||||
ext: '.js'
|
||||
}
|
||||
config.coffee["module_#{module}_index"] = {
|
||||
src: "modules/#{module}/index.coffee",
|
||||
dest: "modules/#{module}/index.js"
|
||||
}
|
||||
|
||||
moduleCompileServerTasks.push "coffee:module_#{module}_server"
|
||||
moduleCompileServerTasks.push "coffee:module_#{module}_index"
|
||||
|
||||
config.coffee["module_#{module}_unit_tests"] = {
|
||||
expand: true,
|
||||
flatten: false,
|
||||
cwd: "modules/#{module}/test/unit/coffee",
|
||||
src: ['**/*.coffee'],
|
||||
dest: "modules/#{module}/test/unit/js",
|
||||
ext: '.js'
|
||||
}
|
||||
config.mochaTest["module_#{module}_unit"] = {
|
||||
src: ["modules/#{module}/test/unit/js/*.js"]
|
||||
options:
|
||||
reporter: grunt.option('reporter') or 'spec'
|
||||
grep: grunt.option("grep")
|
||||
}
|
||||
|
||||
moduleCompileUnitTestTasks.push "coffee:module_#{module}_unit_tests"
|
||||
moduleUnitTestTasks.push "mochaTest:module_#{module}_unit"
|
||||
if fs.existsSync "./modules/#{module}/index.coffee"
|
||||
config.coffee["module_#{module}_server"] = {
|
||||
expand: true,
|
||||
flatten: false,
|
||||
cwd: "modules/#{module}/app/coffee",
|
||||
src: ['**/*.coffee'],
|
||||
dest: "modules/#{module}/app/js",
|
||||
ext: '.js'
|
||||
}
|
||||
config.coffee["module_#{module}_index"] = {
|
||||
src: "modules/#{module}/index.coffee",
|
||||
dest: "modules/#{module}/index.js"
|
||||
}
|
||||
|
||||
moduleCompileServerTasks.push "coffee:module_#{module}_server"
|
||||
moduleCompileServerTasks.push "coffee:module_#{module}_index"
|
||||
|
||||
config.coffee["module_#{module}_unit_tests"] = {
|
||||
expand: true,
|
||||
flatten: false,
|
||||
cwd: "modules/#{module}/test/unit/coffee",
|
||||
src: ['**/*.coffee'],
|
||||
dest: "modules/#{module}/test/unit/js",
|
||||
ext: '.js'
|
||||
}
|
||||
config.mochaTest["module_#{module}_unit"] = {
|
||||
src: ["modules/#{module}/test/unit/js/*.js"]
|
||||
options:
|
||||
reporter: grunt.option('reporter') or 'spec'
|
||||
grep: grunt.option("grep")
|
||||
}
|
||||
|
||||
moduleCompileUnitTestTasks.push "coffee:module_#{module}_unit_tests"
|
||||
moduleUnitTestTasks.push "mochaTest:module_#{module}_unit"
|
||||
|
||||
grunt.initConfig config
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ SubscriptionFormatters = require('../Features/Subscription/SubscriptionFormatter
|
|||
querystring = require('querystring')
|
||||
SystemMessageManager = require("../Features/SystemMessages/SystemMessageManager")
|
||||
_ = require("underscore")
|
||||
Modules = require "./Modules"
|
||||
|
||||
fingerprints = {}
|
||||
Path = require 'path'
|
||||
|
@ -146,3 +147,9 @@ module.exports = (app)->
|
|||
res.locals.currentLngCode = req.lng
|
||||
next()
|
||||
|
||||
app.use (req, res, next) ->
|
||||
if !Settings.cacheModuleViewIncludes
|
||||
Modules.loadViewIncludes()
|
||||
res.locals.moduleIncludes = Modules.moduleIncludes
|
||||
next()
|
||||
|
||||
|
|
|
@ -1,13 +1,36 @@
|
|||
fs = require "fs"
|
||||
Path = require "path"
|
||||
jade = require "jade"
|
||||
|
||||
MODULE_BASE_PATH = Path.resolve(__dirname + "/../../../modules")
|
||||
|
||||
modules = []
|
||||
for mod in fs.readdirSync(MODULE_BASE_PATH)
|
||||
modules.push require(Path.join(MODULE_BASE_PATH, mod, "index"))
|
||||
|
||||
module.exports = Modules =
|
||||
modules: []
|
||||
loadModules: () ->
|
||||
for moduleName in fs.readdirSync(MODULE_BASE_PATH)
|
||||
if fs.existsSync(Path.join(MODULE_BASE_PATH, moduleName, "index.js"))
|
||||
loadedModule = require(Path.join(MODULE_BASE_PATH, moduleName, "index"))
|
||||
loadedModule.name = moduleName
|
||||
@modules.push loadedModule
|
||||
|
||||
applyRouter: (app) ->
|
||||
for module in modules
|
||||
module.router?.apply(app)
|
||||
for module in @modules
|
||||
module.router?.apply(app)
|
||||
|
||||
viewIncludes: {}
|
||||
loadViewIncludes: (app) ->
|
||||
@viewIncludes = {}
|
||||
for module in @modules
|
||||
for view, partial of module.viewIncludes or {}
|
||||
@viewIncludes[view] ||= []
|
||||
@viewIncludes[view].push fs.readFileSync(Path.join(MODULE_BASE_PATH, module.name, "app/views", partial + ".jade"))
|
||||
|
||||
moduleIncludes: (view, locals) ->
|
||||
partials = Modules.viewIncludes[view] or []
|
||||
html = ""
|
||||
for partial in partials
|
||||
compiler = jade.compile(partial)
|
||||
html += compiler(locals)
|
||||
return html
|
||||
|
||||
Modules.loadModules()
|
|
@ -19,6 +19,7 @@ ReferalConnect = require('../Features/Referal/ReferalConnect')
|
|||
RedirectManager = require("./RedirectManager")
|
||||
OldAssetProxy = require("./OldAssetProxy")
|
||||
translations = require("translations-sharelatex").setup(Settings.i18n)
|
||||
Modules = require "./Modules"
|
||||
|
||||
metrics.mongodb.monitor(Path.resolve(__dirname + "/../../../node_modules/mongojs/node_modules/mongodb"), logger)
|
||||
metrics.mongodb.monitor(Path.resolve(__dirname + "/../../../node_modules/mongoose/node_modules/mongodb"), logger)
|
||||
|
@ -41,13 +42,13 @@ app.ignoreCsrf = (method, route) ->
|
|||
ignoreCsrfRoutes.push new express.Route(method, route)
|
||||
|
||||
|
||||
|
||||
app.configure () ->
|
||||
if Settings.behindProxy
|
||||
app.enable('trust proxy')
|
||||
app.use express.static(__dirname + '/../../../public', {maxAge: staticCacheAge })
|
||||
app.set 'views', __dirname + '/../../views'
|
||||
app.set 'view engine', 'jade'
|
||||
Modules.loadViewIncludes app
|
||||
app.use express.bodyParser(uploadDir: Settings.path.uploadFolder)
|
||||
app.use express.bodyParser(uploadDir: __dirname + "/../../../data/uploads")
|
||||
app.use translations.expressMiddlewear
|
||||
|
|
|
@ -102,14 +102,17 @@ block content
|
|||
span.small
|
||||
a(href='/help/kb/dropbox-2') (#{translate("learn_more")})
|
||||
- if(!userHasDropboxFeature)
|
||||
.alert.alert-info #{translate("dropbox_is_premium")}
|
||||
a.btn.btn-info(href='/user/subscription/plans') #{translate("upgrade")}
|
||||
- else if(userIsRegisteredWithDropbox)
|
||||
.alert.alert-success #{translate("account_is_linked")}
|
||||
row
|
||||
a(href='/dropbox/unlink').btn #{translate("unlink_dropbox")}
|
||||
- else
|
||||
a.btn.btn-info(href='/dropbox/beginAuth') #{translate("link_to_dropbox")}
|
||||
.alert.alert-info #{translate("dropbox_is_premium")}
|
||||
a.btn.btn-info(href='/user/subscription/plans') #{translate("upgrade")}
|
||||
- else if(userIsRegisteredWithDropbox)
|
||||
.alert.alert-success #{translate("account_is_linked")}
|
||||
row
|
||||
a(href='/dropbox/unlink').btn #{translate("unlink_dropbox")}
|
||||
- else
|
||||
p
|
||||
a.btn.btn-info(href='/dropbox/beginAuth') #{translate("link_to_dropbox")}
|
||||
|
||||
| !{moduleIncludes("userSettings", locals)}
|
||||
|
||||
hr.soften
|
||||
|
||||
|
|
Loading…
Reference in a new issue