Tag: dust.js

如何基于服务器和客户端将上下文助手添加到Dust.js中

我正在使用Dust.js和Node / Express。 Dust.jslogging上下文助手函数,帮助器作为一个函数embedded到模型数据中。 我在服务器的JSON数据模型中添加了这样一个函数,但对浏览器的JSON响应没有函数属性(即从下面的模型中返回prop1和prop2,但是helper属性不是。 /* JSON data */ model: { prop1: "somestring", prop2: "someotherstring", helper: function (chunk, context, bodies) { /* I help, then return a chunk */ } /* more JSON data */ 我看到JSON.stringify(从response.json()调用)是删除函数属性。 不知道我可以避免使用JSON.stringify,所以将需要在服务器/客户端之间共享此辅助function的替代方法。 可能有一种方法可以将辅助函数添加到服务器和客户机上的灰尘基础上。 这就是我要找的。 由于“灰尘”文档很less,因此没有logging。 此外,我找不到任何代码片段,certificate这一点。 谢谢你的帮助。

DustJS扩展布局?

在Jade JS中,扩展布局非常简单。 假设一个有layout.jade,而index.jade只是: extend layout block content // content comes here 那就够了。 我搜查官方指南,但没有find如何做。 最相似的似乎是这样的: {>partials} 但是这仍然不能扩展布局。 如何在DustJS中实现类似的事情? 非常感谢。

Dust.js在同一页面上多次使用相同的部分

我有一个父模板接收以下上下文: { users: [ { userId: "18288128", group: "User 1 Group Name", userVideos: [{ id: 1, name: "Video1"}, { id: 2, name: "Video2"}, { id: 3, name: "Video3"}] }, { userId: "1232412", group: "User 2 Group Name", userVideos: [{ id: 4, name: "Video93"}, { id: 5, name: "Video384"}, { id: 6, name: "Video483"}] }, { […]

如何编译防尘js服务器端为IE7渲染

我有一个使用了很多灰尘模板的应用程序。 IE8 +和其他现代浏览器(如Chrome)在客户端渲染方面没有问题,但在IE7和以下版本中无法正常工作。 有没有办法在服务器上运行dust.js并返回一个编译模板?

dust.js是随机的用户上传模板安全地执行服务器端?

我想让我的用户上传他们自己的防尘模板。 现在我编译并将它们存储在一个数据库中。 然后我从数据库中加载它们并根据需要执行它们。 我的平台服务器端是node.js. 用户是否可以在模板中插入恶意数据来阻止我正在运行的node.js进程? 无限循环? 代码注入? 谢谢

Dust.js使用Mongoosestream式传输视图

我有一个简单的应用程序,使用快递和霍夫曼视图引擎,以stream我的看法。 我目前正在试图扩展由官方Dust.js仓库提供的一个例子 。 不幸的是,我不能使用Mongoose进行数据检索。 app.js var app = express(); app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'dust'); app.engine('dust', hoffman.__express()); app.use(hoffman.stream); app.get('/', function (req, res) { res.stream("hello", { "test": function(chunk, context, bodies, params) { //This works as expected //return [{name:"This is a name"},{name:"This is another name"}]; return model.find().lean().exec(function(err, docs) { return docs; }); }, "test1": function(chunk, context, bodies, […]

Dust.js partails新手

我有一些代码,我想用在一些灰尘模板,所以我打算使用partials。 我不确定以下是最好的方法。 请帮忙。 1)我从基本模板中提取通用代码到名为userinfo.html的模板文件中 2)我编译userinfo.html创builduserinfo.dust 3)我添加{>“userinfo.dust”/}代码到所有模板,我想查看用户信息。 4)现在,当我用以下命令呈现模板。 我得到“模板找不到:userinfo.dust”错误。 dust.render("moduleTemplate", templateData, function(err, out) { $main.html(out); }); 做,我需要发送userinfo.dust与templateData同时呈现? 我尝试阅读谷歌可以给我的所有部分相关的信息,但不能够如何实现partials。

合并目录中的javascript文件与节点uglify +手表?

目标: 我正在尝试为客户端模板开发构build一个毫不费力的工作stream程。 文件根目录: /views/uncompiled/ /static/js/compiled/ 我们从/views/uncompiled/ 这是我可以build立东西的地方,比如/views/uncompiled/index.html 。 我构builddust.js模板,所以我使用dusterjs监听my /views/uncompiled/目录中的更改,并自动在我的/static/js/compiled/目录中呈现编译的*.js对应。 所以/views/uncompiled/index.html在保存更改时随时显示/static/js/compiled/index.js 。 问题: 我的layout.html越来越大。 每次添加另一个模板时,我需要包含一个新的*.js脚本: <head> <script src='/static/js/compiled/index.js'></script> <script src='/static/js/compiled/header.js'></script> <script src='/static/js/compiled/footer.js'></script> <script src='/static/js/compiled/baconstrips.js'></script> … </head> 解: 在/static/js/compiled/文件夹中自动将concat *.js另一只手表放在一个app.js文件中,该文件夹的内容随时会被包含在<head> : <head> <script src='/static/js/app.js'></script> </head> 题: 我想使用像Uglify.js这样的concatonation工具也可以压缩。 有没有任何节点包可以自动解决上述问题? 有没有Uglify.js的本地函数已经这样做?

如何将浏览器端的客户端值传递给node.js控制器

我正在构build一个简单的nodejs应用程序,并在客户端使用灰尘。 我正在尝试从用户位置获取lat,lng,并且想要使用节点js express框架进行API调用。 所以我从地理位置api得到客户端的lat,lng。 现在我想将lat,lng传递给控制器​​,这样我就可以查询API来显示用户内容。 对不起,如果这是非常基本的。 我对nodejs和灰尘都很陌生。 我到目前为止尝试了什么? 1.我尝试使用jquery提交表单2.设置一些dom值等 $(document).ready( function() { var options = { enableHighAccuracy: true, timeout: 5000, maximumAge: 0 }; function success(pos) { var crd = pos.coords; document.querySelector("[name='latitude']").value = crd.latitude; document.querySelector("[name='longitude']").value = crd.longitude; console.log('Latitude : ' + crd.latitude); console.log('Longitude: ' + crd.longitude); }; function error(err) { console.warn('ERROR(' + err.code + '): ' […]

在node.js中加载已编译的Dust.js模板

我正在尝试创build一个采用模板名称的函数,并能够将呈现的模板作为string返回。 我正在使用linkedin的粉尘版本。 我预编译模板(使用grunt-dustjs任务)到一个单一的文件,看起来像这样: (function(){dust.register("collections-nav",body_0);function body_0(chk,ctx){return chk.write("\t<div id=\"collection-loop\"><div class=\"section-title lines desktop-12\"><h2>Shop by Collection</h2></div>").section(ctx.getPath(false, ["bigMutha","TopNavigation"]),ctx,{"block":body_1},{}).write("</div>");}function body_1(chk,ctx){return chk.write("<div class=\"collection-index desktop-3 tablet-2 mobile-3 first\" data-alpha=\"").reference(ctx.get(["Title"], false),ctx,"h").write("\"> <div class=\"collection-image\"><a href=\"").reference(ctx.get(["Url"], false),ctx,"h").write("\" title=\"").reference(ctx.get(["Title"], false),ctx,"h").write("\"><img src=\"//cdn.shopify.com/s/files/1/0352/5133/collections/d_cb_20140312_m_handpicked_grande.jpg?v=1394885208\" alt=\"").reference(ctx.get(["Title"], false),ctx,"h").write("\" /></a> </div><div class=\"collection-info\"><a href=\"/collections/mens-designer-clothing\" title=\"Browse our ").reference(ctx.get(["Title"], false),ctx,"h").write(" collection\"><h3>").reference(ctx.get(["Title"], false),ctx,"h").write("</h3><p>16 items</p></a></div></div>");}return body_0;})() (function(){dust.register("index",body_0);var blocks={"body":body_1};function body_0(chk,ctx){ctx=ctx.shiftBlocks(blocks);return chk.partial("layouts/mainfull",ctx,{});}function body_1(chk,ctx){ctx=ctx.shiftBlocks(blocks);return chk.write("<ul>").section(ctx.get(["TopNavigation"], false),ctx,{"block":body_2},{}).write("</ul>").section(ctx.get(["Products"], false),ctx,{"block":body_3},{});}function body_2(chk,ctx){ctx=ctx.shiftBlocks(blocks);return chk.write("<li>").reference(ctx.get(["Title"], false),ctx,"h").write("</li>");}function body_3(chk,ctx){ctx=ctx.shiftBlocks(blocks);return […]