public void GetCacheKey() { var widget = new TemplateWidget("__test"); Assert.Equals(widget.GetCacheKey(), "__test"); widget = new TemplateWidget("__test", new { a = 1 }); Assert.Equals(widget.GetCacheKey(), "__test{\"a\":1}"); }
/// <summary> /// 获取前Html /// </summary> protected override string GetBeforeHtml(Context context, TemplateWidget widget) { var firstScope = context.Scopes[0]; var cacheKey = widget.GetCacheKey(); var cssClass = HttpUtils.HtmlEncode(firstScope[CssClassKey]); var style = HttpUtils.HtmlEncode(firstScope[InlineCssKey]); var html = $"<div class='template_widget {cssClass}' data-widget='{cacheKey}' style='{style}'>"; var beforeHtml = firstScope[BeforeHtmlKey] as string; if (!string.IsNullOrEmpty(beforeHtml)) { html += beforeHtml; } return(html); }