private void testVars2() { string template = "你的好友 {*actor*} 发表了照片 {*photo*} 在昨天"; List <string> vars = PlatformTemplate.GetVars(template); Assert.AreEqual(2, vars.Count); Assert.AreEqual("actor", vars[0]); Assert.AreEqual("photo", vars[1]); }
private void testVars1() { string template = "{*actor*} 发表了日志 {*blogpost*}"; List <string> vars = PlatformTemplate.GetVars(template); Assert.AreEqual(2, vars.Count); Assert.AreEqual("actor", vars[0]); Assert.AreEqual("blogpost", vars[1]); }
public void testGetVarData() { string tpl = "{*actor*} 发表了日志 {*blogpost*}"; string data = "{actor:\"zhangsan\", blogpost:\"<a href='post/2.aspx'>我的第一篇日志</a>\", content:\"日志内容\"}"; string varData = PlatformTemplate.GetVarData(tpl, data); Assert.AreEqual("{actor:\"zhangsan\", blogpost:\"<a href='post/2.aspx'>我的第一篇日志</a>\"}", varData); string tpl2 = "{*actor*} 上传了{*photoCount*}张 新照片。"; string data2 = "{photoCount:3, photos:\"<a href='post/2.aspx'><img src=/></a>\", content:\"发布于。。。\"}"; string varData2 = PlatformTemplate.GetVarData(tpl2, data2); Assert.AreEqual("{photoCount:\"3\"}", varData2); }
public virtual void publishUserAction(User creator, string dataType, long templateBundleId, string templateData, string bodyGeneral, string ip) { // 模板数据是 json 字符串类型;也就是 key-value 对 // 除了自定义的键外,比如 {*gift*}, {*mood*}, {*score*} // 还有系统保留的4个键:images, flash, mp3, video Feed feed = new Feed(); feed.Creator = creator; feed.DataType = dataType; feed.BodyGeneral = bodyGeneral; TemplateBundle t = getRegisteredTemplateBundleByID(templateBundleId); // 判断是单行模式还是多行模式 List <OneLineStoryTemplate> onelineTemplates = t.GetOneLineStoryTemplates( ); List <ShortStoryTemplate> shortStoryTemplates = t.GetShortStoryTemplates( ); // 如果是单行模式,只解析出标题的模板与数据 if (onelineTemplates.Count > 0) { OneLineStoryTemplate tpl = onelineTemplates[0]; //feed.TitleTemplate = getTitleTemplate( onelineTemplates, templateData, dataKeyCount ); feed.TitleTemplate = tpl.Title; feed.TitleData = templateData; } // 如果是多行模式,除了标题,还要解析出主干部分的模板和数据,以及评论 else if (shortStoryTemplates.Count > 0) { ShortStoryTemplate tpl = shortStoryTemplates[0]; feed.TitleTemplate = tpl.Title; feed.TitleData = PlatformTemplate.GetVarData(tpl.Title, templateData); feed.BodyTemplate = tpl.Body; feed.BodyData = PlatformTemplate.GetVarData(tpl.Body, templateData); } else { throw new NotImplementedException("TemplateBundle(id:" + templateBundleId + ")" + lang.get("exTemplateNotFound")); } db.insert(feed); }