就需要修改的文件数量而言,我有哪些选择。
在不了解您的代码及其依赖关系的情况下很难做出决定。
但我建议仔细查看jade conditionals、jade includes 和jade extends。我使用 express 应用程序中的翡翠预处理器来准备翡翠模板,并且对该解决方案非常满意。
如果您生成的 HTML 页面没有任何进一步的动态内容,请考虑使用 express 的静态功能。
如果您必须对翡翠输出进行一些非常特殊的处理,您可以在存储/交付文件之前在回调中进行。
一个片段:
jade.compile('./templates/jade/remotecontrol.jade',
{title:'Remotecontrol',
copt:customoptions,
key:project.key,
objects:JSON.stringify(project.objects),
buttons:{login:true},
controls:{joystick:true},
forms:{login:true}},
{callback:storeTo,
storeTo:__dirname+'/projects/'+project.key+'/stk/index.html',
pretty:true})
对于像这样的模板(请识别“包含 ../../../”,因为路径必须与模板相对,而不是节点应用)
doctype html
html(lang="de")
head
title #{title}
meta(charset="UTF-8")
include ../../../templates/jade/favicon.jade
meta(name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no")
link(rel="stylesheet" type="text/css" href="styles/client.css")
script.
var objectsToInject=!{objects};
var key='#{key}';
...
body
include ../../../templates/jade/loading.jade
div.bodycontainer()
button.beforebgr(name="fullscreen" id="fullscreen" class="fullscreen") Fullscreen
if controls.joystick
div.draggable(id="divjoystick" class="draggable ui-widget-content")
include ../../../templates/jade/joystickbase-svg.jade
include ../../../templates/jade/joystick-svg.jade
...
- var scriptname="'libs/js/remotecontrol.js'"
include ../../../templates/jade/loadscript.jade