public Func <object, string> GetRenderView(string path) { if (File.Exists(path)) { return(_handlebars.CompileView(path)); } else { return(_handlebars.Compile(path)); } var partials = Path.GetFileNameWithoutExtension(path); _dict.TryGetValue(partials, out var renderView); #if DEBUG if (renderView == null) { Debug.WriteLine($"[ExpressionCache] Require file: {path}, cache status: NOT HIT"); } else { Debug.WriteLine($"[ExpressionCache] Require file: {path}, cache status: HIT"); } #endif if (renderView == null) { renderView = _handlebars.CompileView(path); _dict.Add(partials, renderView); } return(renderView); }
public bool TryRegisterPartial(IHandlebars env, string partialName, string templatePath) { if (env == null) { throw new ArgumentNullException(nameof(env)); } var handlebarsTemplateRegistrations = env.Configuration as IHandlebarsTemplateRegistrations ?? env.As <ICompiledHandlebars>().CompiledConfiguration; if (handlebarsTemplateRegistrations?.FileSystem == null || templatePath == null || partialName == null) { return(false); } var partialPath = handlebarsTemplateRegistrations.FileSystem.Closest(templatePath, "partials/" + partialName + ".hbs"); if (partialPath != null) { var compiled = env .CompileView(partialPath); handlebarsTemplateRegistrations.RegisteredTemplates.Add(partialName, (writer, o, data) => { writer.Write(compiled(o, data)); }); return(true); } else { // Failed to find partial in filesystem return(false); } }
/// <inheritdoc /> public bool TryRegisterPartial(IHandlebars env, string partialName, string templatePath) { if (env == null) { throw new ArgumentNullException(nameof(env)); } if (env.Configuration?.FileSystem == null || templatePath == null || partialName == null) { return(false); } var partialPath = env.Configuration.FileSystem.Closest(templatePath, "partials/" + partialName + ".hbs"); if (partialPath != null) { var compiled = env .CompileView(partialPath); env.Configuration.RegisteredTemplates.Add(partialName, (writer, o) => { writer.Write(compiled(o)); }); return(true); } // Failed to find partial in filesystem return(false); }
public HandlebarsMvcView(string physicalpath, IHandlebars handlebars) { var templatePath = physicalpath; var version = HostingEnvironment.VirtualPathProvider.GetCacheKey(templatePath); var key = templatePath + "_" + version; render = compiledViews.GetOrAdd(key, (k) => { var compiledView = handlebars.CompileView(templatePath); return compiledView; }); }
public HandlebarsMvcView(string physicalpath, IHandlebars handlebars) { var templatePath = physicalpath; var version = HostingEnvironment.VirtualPathProvider.GetCacheKey(templatePath); var key = templatePath + "_" + version; render = compiledViews.GetOrAdd(key, (k) => { var compiledView = handlebars.CompileView(templatePath); return(compiledView); }); }
public static Func <object, string> CompileView(string templatePath) { return(Instance.CompileView(templatePath)); }
private string Render <TModel>(string templatePath, TModel model) { var template = _templateCache.GetOrCreate(templatePath, _ => _handlebars.CompileView(templatePath)); return(template(model).Trim()); }