public void TestCompileFunction() { var temp = @" $lang(home) $navigator() ${archive.data(视频)} <div> $categories('prod\,uct',{ <div class=""col-md-3 col-lg-2 col-sm-4""> {name} </div> }) </div> "; IDataContainer dc = new NormalDataContainer(); TemplatePage tp = new TemplatePage(dc); tp.TemplateHandleObject = new TemplateMock(); tp.OnPreInit += TemplateMock.CompliedTemplate; tp.OnBeforeCompile += (TemplatePage page, ref String content) => { var pageArchive = new PageArchive(new ArchiveDto()); page.AddVariable("archive", pageArchive); }; tp.SetTemplateContent(temp); var content = tp.Compile(); Console.WriteLine(content); }
public TemplatePage GetTemplatePage(string filePath, PluginPackAttribute attr) { string pluginDirPath = attr.WorkSpace; string cacheId = String.Concat("plugin", "_tpl_", attr.WorkIndent, filePath); string html = WebCtx.Current.Cache.Get(cacheId) as string; if (html == null) { //模板文件放在/plugins/com.spdepository/pages/下 string tplFilePath = pluginDirPath + filePath; try { using (TextReader tr = new StreamReader(tplFilePath)) { html = tr.ReadToEnd(); tr.Dispose(); } WebCtx.Current.Cache.Insert(cacheId, html, tplFilePath); } catch (Exception exc) { throw new Exception(exc.Message + ", File:" + tplFilePath); } } TemplatePage tpl = new TemplatePage(this.dc); tpl.SetTemplateContent(html); string pluginPath = this._pluginPath + attr.WorkIndent; tpl.AddVariable("os", new { version = FwCtx.Version.GetVersion(), domain = WebCtx.Current.Domain, ppath = pluginPath, fpath = this._fpath, mjs = this._shareJs, sjs = this._shareJs, scss = this._shareCss, mcss = this._shareCss }); tpl.AddVariable("plugin", new { path = pluginPath, indent = attr.WorkIndent, name = attr.Name }); return(tpl); }
private void Main() { IDataContainer dc = new BasicDataContainer(null); TemplatePage tp = new TemplatePage(dc); tp.SetTemplateContent("$m=item KEY:${item.key} Note:${item.note}<br />${m.key}"); tp.AddVariable("item", new { Key = "Key", Note = "Note" }); //var x = System.Web.HttpContext.Current.Items; string y = tp.ToString(); // return y; }
public void TestCompileFunction() { var temp = @" <div> $categories('prod\,uct',{ <div class=""col-md-3 col-lg-2 col-sm-4""> {name} </div> <div style=""background-image:url('{name}')""></div> }) </div> "; TemplatePage tp = new TemplatePage(null); tp.TemplateHandleObject = new TemplateMock(); tp.OnPreInit += TemplateMock.CompliedTemplate; tp.SetTemplateContent(temp); var content = tp.Compile(); Console.WriteLine(content); }