public static void TryGetPage(this TemplateScopeContext scope, string virtualPath, out TemplatePage page, out TemplateCodePage codePage) { scope.Context.TryGetPage(scope.PageResult.VirtualPath, virtualPath, out page, out codePage); codePage?.Init(); var requiresRequest = codePage as IRequiresRequest; if (requiresRequest != null) { var request = scope.GetValue(TemplateConstants.Request) as IRequest; if (request != null) { requiresRequest.Request = request; } } }
public static async Task WritePageAsync(this TemplateScopeContext scope, TemplatePage page, TemplateCodePage codePage, Dictionary <string, object> pageParams, CancellationToken token = default(CancellationToken)) { await scope.PageResult.WritePageAsync(page, codePage, scope.ScopeWithParams(pageParams), token); }
public void GetPage(string fromVirtualPath, string virtualPath, out TemplatePage page, out TemplateCodePage codePage) { if (!TryGetPage(fromVirtualPath, virtualPath, out page, out codePage)) { throw new FileNotFoundException($"Page at path was not found: '{virtualPath}'"); } }
public void TryGetPage(string fromVirtualPath, string virtualPath, out TemplatePage page, out TemplateCodePage codePage) { var pathMapKey = nameof(TryGetPage) + ">" + fromVirtualPath; var mappedPath = GetPathMapping(pathMapKey, virtualPath); if (mappedPath != null) { var mappedPage = Pages.GetPage(mappedPath); if (mappedPage != null) { page = mappedPage; codePage = null; return; } RemovePathMapping(pathMapKey, mappedPath); } var tryExactMatch = virtualPath.IndexOf('/') >= 0; //if nested path specified, look for an exact match first if (tryExactMatch) { var cp = GetCodePage(virtualPath); if (cp != null) { codePage = cp; page = null; return; } var p = Pages.GetPage(virtualPath); if (p != null) { page = p; codePage = null; return; } } //otherwise find closest match from page.VirtualPath var parentPath = fromVirtualPath.IndexOf('/') >= 0 ? fromVirtualPath.LastLeftPart('/') : ""; do { var seekPath = parentPath.CombineWith(virtualPath); var cp = GetCodePage(seekPath); if (cp != null) { codePage = cp; page = null; return; } var p = Pages.GetPage(seekPath); if (p != null) { page = p; codePage = null; SetPathMapping(pathMapKey, virtualPath, seekPath); return; } if (parentPath == "") { break; } parentPath = parentPath.IndexOf('/') >= 0 ? parentPath.LastLeftPart('/') : ""; } while (true); throw new FileNotFoundException($"Page at path was not found: '{virtualPath}'"); }
public static void TryGetPage(this TemplateScopeContext scope, string virtualPath, out TemplatePage page, out TemplateCodePage codePage) { if (scope.PageResult.Partials.TryGetValue(virtualPath, out page)) { codePage = null; return; } scope.Context.TryGetPage(scope.PageResult.VirtualPath, virtualPath, out page, out codePage); codePage?.Init(); if (codePage is IRequiresRequest requiresRequest) { if (scope.GetValue(TemplateConstants.Request) is IRequest request) { requiresRequest.Request = request; } } }