private async Task <string> AddCofoundryDependenciesAsync(string html, ActionContext context) { const string HEAD_TAG_END = "</head>"; const string BODY_TAG_END = "</body>"; var insertHeadIndex = html.IndexOf(HEAD_TAG_END, StringComparison.OrdinalIgnoreCase) - 1; if (insertHeadIndex > 0) { html = html.Substring(0, insertHeadIndex) + Environment.NewLine + TAB + _staticResourceReferenceRenderer.ScriptTag(_adminRouteLibrary.VisualEditor, "contentpage").ToString() + TAB + _staticResourceReferenceRenderer.CssTag(_adminRouteLibrary.VisualEditor, "site-viewer").ToString() + html.Substring(insertHeadIndex); } var insertBodyIndex = html.IndexOf(BODY_TAG_END, StringComparison.OrdinalIgnoreCase) - 1; // Early return if no data available if (insertBodyIndex < 0) { return(html); } // Response data can be null if this is a 404 page string responseJson = "null"; var pageResponseData = _pageResponseDataCache.Get(); if (pageResponseData != null) { responseJson = CreateResponseJson(pageResponseData); } var toolbarHtml = await _razorViewRenderer.RenderViewAsync(context, _adminRouteLibrary.VisualEditor.VisualEditorToolbarViewPath(), pageResponseData); var svgIcons = await RenderSvgIconsToStringAsync(); html = html.Substring(0, insertBodyIndex) + Environment.NewLine + TAB + "<script>var Cofoundry = { 'PageResponseData': " + responseJson + " }</script>" + TAB + toolbarHtml + string.Format("<!-- SVG ICONS --><div style='{0}'>{1}</div><!-- END SVG ICONS -->", "display:none", svgIcons) + html.Substring(insertBodyIndex); return(html); }
/// <summary> /// Renders a page block by finding the template and applying the specified model to it /// </summary> /// <param name="viewContext">ViewContext is required so we can render the razor view.</param> /// <param name="pageViewModel">The view model for the page being rendered.</param> /// <param name="blockViewModel">The view model for the module being rendered.</param> /// <returns>The rendered module html.</returns> public async Task <string> RenderBlockAsync( ViewContext viewContext, IEditablePageViewModel pageViewModel, IEntityVersionPageBlockRenderDetails blockViewModel ) { var displayData = GetBlockDisplayData(pageViewModel, blockViewModel); string viewPath = GetViewPath(blockViewModel); string html = await _razorViewRenderer.RenderViewAsync(viewContext, viewPath, displayData); if (pageViewModel.IsPageEditMode) { html = ParseBlockHtmlForEditing(html, blockViewModel); } return(html); }
/// <summary> /// Generates any scripts or content that needs to be added /// to the end of the document body. /// </summary> /// <param name="context"> /// The current ActionContext of the exectuing MVC action. /// </param> public async Task <string> CreateBodyScriptAsync(ActionContext context) { string responseJson = "null"; var pageResponseData = _pageResponseDataCache.Get(); if (pageResponseData != null) { responseJson = CreateResponseJson(pageResponseData); } var toolbarHtml = await _razorViewRenderer.RenderViewAsync(context, _adminRouteLibrary.VisualEditor.VisualEditorToolbarViewPath(), pageResponseData); var svgIcons = await RenderSvgIconsToStringAsync(); var script = "<script>var Cofoundry = { 'PageResponseData': " + responseJson + " }</script>" + toolbarHtml + string.Format("<!-- SVG ICONS --><div style='{0}'>{1}</div><!-- END SVG ICONS -->", "display:none", svgIcons); return(script); }