public StringBuilder AppendHtml(StringBuilder stringBuilder, PageContentProjection projection) { var content = projection.GetHtml(htmlHelper); var childrenContents = projection.GetChildProjections() ?? new List<ChildContentProjection>(); var parsedWidgets = ParseWidgetsFromHtml(content).Distinct(); var availableWidgets = childrenContents.Where(cc => parsedWidgets.Any(id => id.AssignmentIdentifier == cc.AssignmentIdentifier)); foreach (var childProjection in availableWidgets) { var model = parsedWidgets.First(w => w.AssignmentIdentifier == childProjection.AssignmentIdentifier); var replaceWhat = model.Match.Value; var replaceWith = AppendHtml(new StringBuilder(), childProjection).ToString(); content = content.Replace(replaceWhat, replaceWith); } // Widgets, which has no access (e.g. widgets with draft status for public users) var invisibleWidgets = parsedWidgets.Where(id => childrenContents.All(cc => cc.AssignmentIdentifier != id.AssignmentIdentifier)); foreach (var model in invisibleWidgets) { var replaceWhat = model.Match.Value; var replaceWith = string.Empty; content = content.Replace(replaceWhat, replaceWith); } stringBuilder.Append(content); return stringBuilder; }
public void Should_By_Xml_And_Binary_Serializable() { var pageContent = TestDataProvider.CreateNewPageContent(); pageContent.Content = TestDataProvider.CreateNewHtmlContent(); pageContent.Options = new[] { TestDataProvider.CreateNewPageContentOption(pageContent), TestDataProvider.CreateNewPageContentOption(pageContent), TestDataProvider.CreateNewPageContentOption(pageContent) }; var cmsConfiguration = new Mock<ICmsConfiguration>(); var optionService = new DefaultOptionService(null, new HttpRuntimeCacheService(), cmsConfiguration.Object); var optionValues = optionService.GetMergedOptionValues(pageContent.Options, null); PageContentProjection original = new PageContentProjection( pageContent, pageContent.Content, new HtmlContentAccessor((HtmlContent)pageContent.Content, optionValues)); RunSerializationAndDeserialization(original, projection => { Assert.AreEqual(original.ContentId, projection.ContentId); Assert.AreEqual(original.Order, projection.Order); Assert.AreEqual(original.RegionId, projection.RegionId); }); }
public PageContentProjection Create(PageContent pageContent) { IContentAccessor contentAccessor = null; Type contentType; if (pageContent.Content is IProxy) { contentType = pageContent.Content.GetType().BaseType; } else { contentType = pageContent.Content.GetType(); } string key = "CONTENTRENDERER-" + contentType.Name.ToUpperInvariant(); if (containerProvider.CurrentScope.IsRegisteredWithKey<IContentAccessor>(key)) { contentAccessor = containerProvider.CurrentScope .ResolveKeyed<IContentAccessor>(key, new Parameter[] { new PositionalParameter(0, pageContent.Content), new PositionalParameter(1, pageContent.PageContentOptions.Cast<IPageContentOption>().ToList()) }); } if (contentAccessor == null) { throw new CmsException(string.Format("No content accessor found for the content type {0}.", pageContent.Content.GetType().FullName)); } PageContentProjection pageContentProjection = new PageContentProjection(pageContent, contentAccessor); return pageContentProjection; }
/// <summary> /// Initializes a new instance of the <see cref="RegionContentWrapper" /> class. /// </summary> /// <param name="sb">The string builder.</param> /// <param name="content">The region content.</param> /// <param name="allowContentManagement">if set to <c>true</c> allows content management.</param> public RegionContentWrapper(StringBuilder sb, PageContentProjection content, bool allowContentManagement) { this.sb = sb; this.content = content; this.allowContentManagement = allowContentManagement; RenderOpeningTags(); }
/// <summary> /// Initializes a new instance of the <see cref="RegionContentWrapper" /> class. /// </summary> /// <param name="sb">The string builder.</param> /// <param name="content">The region content.</param> /// <param name="allowContentManagement">if set to <c>true</c> allows content management.</param> public RegionContentWrapper(StringBuilder sb, PageContentProjection content, bool allowContentManagement) { this.sb = sb; this.content = content; this.allowContentManagement = allowContentManagement; clearFixClassName = CmsContext.Config.ContentEndingDivCssClassName; renderClearFixDiv = CmsContext.Config.RenderContentEndingDiv; RenderOpeningTags(); }
/// <summary> /// Initializes a new instance of the <see cref="RegionContentWrapper" /> class. /// </summary> /// <param name="sb">The string builder.</param> /// <param name="content">The region content.</param> /// <param name="allowContentManagement">if set to <c>true</c> allows content management.</param> public RegionContentWrapper(StringBuilder sb, HtmlHelper html, PageContentProjection content, bool allowContentManagement) { this.html = html; this.sb = sb; this.content = content; this.allowContentManagement = allowContentManagement; if (allowContentManagement) { RenderOpeningTags(); } }
/// <summary> /// Appends the HTML with HTML, rendered by content projection. /// </summary> /// <param name="stringBuilder">The string builder.</param> /// <param name="projection">The projection.</param> /// <param name="pageModel">The page model.</param> /// <returns></returns> public StringBuilder AppendHtml(StringBuilder stringBuilder, PageContentProjection projection, RenderPageViewModel pageModel) { var renderingPageModel = pageModel.RenderingPage ?? pageModel; var content = projection.GetHtml(htmlHelper); if (!renderingPageModel.RenderedPageContents.Contains(projection.PageContentId)) { renderingPageModel.RenderedPageContents.Add(projection.PageContentId); } var childrenContents = projection.GetChildProjections() ?? new List<ChildContentProjection>(); var parsedWidgets = ParseWidgetsFromHtml(content).Distinct(); var availableWidgets = childrenContents.Where(cc => parsedWidgets.Any(id => id.AssignmentIdentifier == cc.AssignmentIdentifier)); foreach (var childProjection in availableWidgets) { var model = parsedWidgets.First(w => w.AssignmentIdentifier == childProjection.AssignmentIdentifier); var replaceWhat = model.Match.Value; var replaceWith = AppendHtml(new StringBuilder(), childProjection, renderingPageModel).ToString(); content = content.Replace(replaceWhat, replaceWith); } // Widgets, which has no access (e.g. widgets with draft status for public users) var invisibleWidgets = parsedWidgets.Where(id => childrenContents.All(cc => cc.AssignmentIdentifier != id.AssignmentIdentifier)); foreach (var model in invisibleWidgets) { var replaceWhat = model.Match.Value; var replaceWith = string.Empty; content = content.Replace(replaceWhat, replaceWith); } // Add child contents in the master page to child region is possible only if content is widget. // If content is regular HTML content, it works as master page contents, and contents may be added only in the child page // If page is for preview, doesn't rendering children regions if ((!renderingPageModel.IsMasterPage || projection.Content is IChildRegionContainer) && !pageModel.IsPreviewing) { content = AppendHtmlWithChildRegionContens(content, projection, renderingPageModel); } stringBuilder.Append(content); return stringBuilder; }
public void Should_By_Xml_And_Binary_Serializable() { var pageContent = TestDataProvider.CreateNewPageContent(); pageContent.Content = TestDataProvider.CreateNewHtmlContent(); pageContent.Options = new[] { TestDataProvider.CreateNewPageContentOption(pageContent), TestDataProvider.CreateNewPageContentOption(pageContent), TestDataProvider.CreateNewPageContentOption(pageContent) }; PageContentProjection original = new PageContentProjection( pageContent, pageContent.Content, new HtmlContentAccessor((HtmlContent)pageContent.Content, pageContent.Options.Cast<IOption>().ToList())); RunSerializationAndDeserialization(original, projection => { Assert.AreEqual(original.ContentId, projection.ContentId); Assert.AreEqual(original.Order, projection.Order); Assert.AreEqual(original.RegionId, projection.RegionId); }); }
public PageContentProjection Create(IPageContent pageContent, IContent content, IList <IOptionValue> options) { IContentAccessor contentAccessor = null; Type contentType; if (content is IProxy) { contentType = content.GetType().BaseType; } else { contentType = content.GetType(); } string key = "CONTENTRENDERER-" + contentType.Name.ToUpperInvariant(); if (containerProvider.CurrentScope.IsRegisteredWithKey <IContentAccessor>(key)) { contentAccessor = containerProvider.CurrentScope .ResolveKeyed <IContentAccessor>(key, new Parameter[] { new PositionalParameter(0, content), new PositionalParameter(1, options) }); } if (contentAccessor == null) { Log.Error(string.Format("A content accessor was not found for the content type {0} with id={1}.", content.GetType().FullName, content.Id)); contentAccessor = new EmptyContentAccessor(string.Format("<i style=\"color:red;\">{0}</i>", RootGlobalization.Message_FailedToRenderContent)); } PageContentProjection pageContentProjection = new PageContentProjection(pageContent, content, contentAccessor); return(pageContentProjection); }
public PageContentProjection Create(IPageContent pageContent, IContent content, IList<IOption> options) { IContentAccessor contentAccessor = null; Type contentType; if (content is IProxy) { contentType = content.GetType().BaseType; } else { contentType = content.GetType(); } string key = "CONTENTRENDERER-" + contentType.Name.ToUpperInvariant(); if (containerProvider.CurrentScope.IsRegisteredWithKey<IContentAccessor>(key)) { contentAccessor = containerProvider.CurrentScope .ResolveKeyed<IContentAccessor>(key, new Parameter[] { new PositionalParameter(0, content), new PositionalParameter(1, options) }); } if (contentAccessor == null) { Log.Error(string.Format("A content accessor was not found for the content type {0} with id={1}.", content.GetType().FullName, content.Id)); contentAccessor = new EmptyContentAccessor(string.Format("<i style=\"color:red;\">{0}</i>", RootGlobalization.Message_FailedToRenderContent)); } PageContentProjection pageContentProjection = new PageContentProjection(pageContent, content, contentAccessor); return pageContentProjection; }
private string AppendHtmlWithChildRegionContens(string html, PageContentProjection projection, RenderPageViewModel pageModel) { // Render contents from children regions var childRegionContents = projection.GetChildRegionContentProjections() ?? new List<PageContentProjection>(); if (projection.Content is IChildRegionContainer && projection.Content.ContentRegions != null && projection.Content.ContentRegions.Any()) { var stringBuilder = new StringBuilder(html); var pageHtmlHelper = new PageHtmlRenderer(stringBuilder, pageModel); foreach (var region in projection.Content.ContentRegions.Distinct()) { var contentsBuilder = new StringBuilder(); var regionModel = new PageRegionViewModel { RegionId = region.Region.Id, RegionIdentifier = region.Region.RegionIdentifier }; var childRegionContentProjections = childRegionContents.Where(c => c.RegionId == regionModel.RegionId).OrderBy(c => c.Order).ToList(); var canEditRegion = projection.PageId == pageModel.Id && pageModel.AreRegionsEditable; using (new LayoutRegionWrapper(contentsBuilder, regionModel, canEditRegion)) { foreach (var childRegionContentProjection in childRegionContentProjections) { // Add Html using (new RegionContentWrapper(contentsBuilder, childRegionContentProjection, pageModel.CanManageContent && canEditRegion)) { // Pass current model as view data model var modelBefore = htmlHelper.ViewData.Model; htmlHelper.ViewData.Model = pageModel; contentsBuilder = AppendHtml(contentsBuilder, childRegionContentProjection, pageModel); // Restore model, which was before changes htmlHelper.ViewData.Model = modelBefore; } } } // Insert region to master page var regionHtml = contentsBuilder.ToString(); pageHtmlHelper.ReplaceRegionHtml(regionModel.RegionIdentifier, regionHtml); } return pageHtmlHelper.GetReplacedHtml().ToString(); } return html; }