public void Process(GetSummaryArgs args) { if (!OnlyWhenRequired || !args.Summary.StartsWith("<" + WrappingTag + ">")) { args.Summary = "<{0}>{1}</{0}>".FormatWith(WrappingTag, args.Summary); } }
public void Test(string input, string expected, int limit, bool stripTags) { var procesor = new AutoGenerate { FieldName = "Text", StripTags = stripTags, MaximumCharacterCount = limit }; using (var db = new Db { new DbItem("item") { new DbField("text") { Value = input } } }) { var args = new GetSummaryArgs { Entry = db.GetItem("/sitecore/content/item") }; procesor.Process(args); Assert.That(args.Summary, Is.EqualTo(expected)); } }
protected override void GetSummary(GetSummaryArgs args) { args.Summary = ""; if (args.Entry == null) return; var doc = new HtmlDocument(); doc.LoadHtml(args.Entry[FieldName]); var blockLimiter = doc.DocumentNode.SelectSingleNode(GetXPath()); if (blockLimiter != null) { var index = blockLimiter.StreamPosition; var content = doc.DocumentNode.OuterHtml; if (index < content.Length) { var trimmedDoc = new HtmlDocument(); trimmedDoc.LoadHtml(content.Substring(0, index)); args.Summary = trimmedDoc.DocumentNode.OuterHtml; } else args.Summary = content; } }
public void Test(string input, string expected, string xpath) { var procesor = new FirstContentBlock { FieldName = "Text", XPath = xpath }; using (var db = new Db { new DbItem("item") { new DbField("text") { Value = input } } }) { var args = new GetSummaryArgs { Entry = db.GetItem("/sitecore/content/item") }; procesor.Process(args); Assert.That(args.Summary, Is.EqualTo(expected)); } }
protected override void GetSummary(GetSummaryArgs args) { var doc = new HtmlDocument(); doc.LoadHtml(args.Entry[FieldName]); var blockLimiter = doc.DocumentNode.SelectSingleNode(GetXPath()); if (blockLimiter != null) { var index = blockLimiter.StreamPosition; var content = doc.DocumentNode.OuterHtml; if (index < content.Length) { var trimmedDoc = new HtmlDocument(); trimmedDoc.LoadHtml(content.Substring(0, index)); args.Summary = trimmedDoc.DocumentNode.OuterHtml; } else { args.Summary = content; } } }
public void Process(GetSummaryArgs args) { // This processor is to compensate for messy markup. It shouldn't be required when editing (and it can break EE) if (Context.PageMode.IsPageEditor) return; if (!OnlyWhenRequired || !args.Summary.StartsWith("<" + WrappingTag + ">")) args.Summary = "<{0}>{1}</{0}>".FormatWith(WrappingTag, args.Summary); }
protected string GetSummary(EntryItem entry) { var args = new GetSummaryArgs(); args.Entry = entry; CorePipeline.Run("weblogGetSummary", args, true); return args.Summary; }
protected override void GetSummary(GetSummaryArgs args) { var renderer = new FieldRenderer(); renderer.Item = args.Entry; renderer.FieldName = FieldName; args.Summary = renderer.Render(); }
public void ContainsNoTag() { var procesor = new FirstContentBlock(); procesor.XPath = "//hr"; var args = new GetSummaryArgs(); args.Entry = m_contentNoTags; procesor.Process(args); Assert.IsNullOrEmpty(args.Summary); }
public void ContainsSelfClosingTag() { var procesor = new FirstContentBlock(); procesor.XPath = "//hr"; var args = new GetSummaryArgs(); args.Entry = m_contentContainsHr; procesor.Process(args); Assert.AreEqual("Lorem ipsum", args.Summary); }
public void ContainsSurroundingTag() { var procesor = new FirstContentBlock(); procesor.XPath = "//span"; var args = new GetSummaryArgs(); args.Entry = m_contentContainsSpan; procesor.Process(args); Assert.AreEqual("Nullam et arcu dui, in pharetra diam. In vitae ante ac orci mollis egestas a ", args.Summary); }
public void ContainsCutTag() { var procesor = new FirstContentBlock(); procesor.XPath = "//hr"; var args = new GetSummaryArgs(); args.Entry = m_contentSurroundingTag; procesor.Process(args); Assert.AreEqual("<div>Lorem ipsum</div>", args.Summary); }
public void EmptySummary() { var processor = new Wrap(); processor.OnlyWhenRequired = true; processor.WrappingTag = "p"; var args = new GetSummaryArgs(); args.Summary = string.Empty; processor.Process(args); Assert.AreEqual("<p></p>", args.Summary); }
public void AlreadyWrapped_AlwaysWrap() { var processor = new Wrap(); processor.OnlyWhenRequired = false; processor.WrappingTag = "span"; var args = new GetSummaryArgs(); args.Summary = "<span>lorem ipsum</span>"; processor.Process(args); Assert.AreEqual("<span><span>lorem ipsum</span></span>", args.Summary); }
protected string GetSummary(EntryItem entry) { var args = new GetSummaryArgs(); args.Entry = entry; #if SC62 || SC64 CorePipeline.Run("weblogGetSummary", args); #else CorePipeline.Run("weblogGetSummary", args, true); #endif return args.Summary; }
public void NullItem() { var procesor = new AutoGenerate(); procesor.StripTags = true; procesor.MaximumCharacterCount = 300; var args = new GetSummaryArgs(); args.Entry = null; procesor.Process(args); Assert.IsNullOrEmpty(args.Summary); }
public void Unwrapped_OnlyRequiredWrap() { var processor = new Wrap(); processor.OnlyWhenRequired = true; processor.WrappingTag = "span"; var args = new GetSummaryArgs(); args.Summary = "lorem ipsum"; processor.Process(args); Assert.AreEqual("<span>lorem ipsum</span>", args.Summary); }
public void StripTagsLimit_OverLimit() { var procesor = new AutoGenerate(); procesor.StripTags = true; procesor.MaximumCharacterCount = 200; var args = new GetSummaryArgs(); args.Entry = m_contentTagsLarge; procesor.Process(args); Assert.AreEqual("HTML Ipsum PresentsPellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu ...", args.Summary); }
public void Process(GetSummaryArgs args) { // This processor is to compensate for messy markup. It shouldn't be required when editing (and it can break EE) if (Context.PageMode.IsExperienceEditor) { return; } if (!OnlyWhenRequired || !args.Summary.StartsWith("<" + WrappingTag + ">")) { args.Summary = "<{0}>{1}</{0}>".FormatWith(WrappingTag, args.Summary); } }
public void StripTags_TagsPresent() { var procesor = new AutoGenerate(); procesor.FieldName = "Text"; procesor.StripTags = true; procesor.MaximumCharacterCount = 300; var args = new GetSummaryArgs(); args.Entry = m_contentTagsSmall; procesor.Process(args); Assert.AreEqual("Lorem ipsum dolor sit amet", args.Summary); }
public void StripTags_NoTags() { var procesor = new AutoGenerate(); procesor.FieldName = "Text"; procesor.StripTags = true; procesor.MaximumCharacterCount = m_contentNoTagsSmall["text"].Length; var args = new GetSummaryArgs(); args.Entry = m_contentNoTagsSmall; procesor.Process(args); Assert.AreEqual(m_contentNoTagsSmall["text"], args.Summary); }
public void EmptyField() { var procesor = new AutoGenerate(); procesor.FieldName = "Text"; procesor.StripTags = true; procesor.MaximumCharacterCount = 300; var args = new GetSummaryArgs(); args.Entry = m_testRoot; procesor.Process(args); Assert.IsNullOrEmpty(args.Summary); }
public void KeepTagsLimit_OverLimit() { var procesor = new AutoGenerate(); procesor.StripTags = false; procesor.MaximumCharacterCount = 41; var args = new GetSummaryArgs(); args.Entry = m_contentTagsLarge; procesor.Process(args); // It doesn't appear HAP is closing the P tag. Assert.AreEqual("<h1>HTML Ipsum Presents</h1><p><strong>Pellentesque habitant ...</strong>", args.Summary); }
protected override void GetSummary(GetSummaryArgs args) { if (args.Entry == null) { args.Summary = string.Empty; return; } var content = args.Entry[FieldName]; if (StripTags) { content = StringUtil.RemoveTags(content); } if (content.Length <= GetMaximumCharacterCount()) { args.Summary = content; } else { if (StripTags) { args.Summary = content.Substring(0, GetMaximumCharacterCount()) + GetMoreString(); } else { var doc = new HtmlDocument(); doc.LoadHtml(content); var count = 0; var limitIndex = FindLimitIndex(doc.DocumentNode, ref count, GetMaximumCharacterCount()); if (limitIndex < content.Length) { var trimmedDoc = new HtmlDocument(); trimmedDoc.LoadHtml(content.Substring(0, limitIndex) + GetMoreString()); args.Summary = trimmedDoc.DocumentNode.OuterHtml; } else { args.Summary = content; } } } }
public void NullItem() { var procesor = new FirstContentBlock { FieldName = "Text", XPath = "//hr" }; var args = new GetSummaryArgs { Entry = null }; procesor.Process(args); Assert.That(args.Summary, Is.Empty); }
public void NullItem() { var procesor = new AutoGenerate { FieldName = "Text", StripTags = true, MaximumCharacterCount = 200 }; var args = new GetSummaryArgs { Entry = null }; procesor.Process(args); Assert.That(args.Summary, Is.Empty); }
protected override void GetSummary(GetSummaryArgs args) { if (args.Entry == null) return; var content = args.Entry[FieldName]; if(StripTags) content = StringUtil.RemoveTags(content); if (content.Length <= GetMaximumCharacterCount()) { args.Summary = content; } else { if (StripTags) { args.Summary = content.Substring(0, GetMaximumCharacterCount()) + GetMoreString(); } else { var doc = new HtmlDocument(); doc.LoadHtml(content); var count = 0; var limitIndex = FindLimitIndex(doc.DocumentNode, ref count, GetMaximumCharacterCount()); if (limitIndex < content.Length) { var trimmedDoc = new HtmlDocument(); trimmedDoc.LoadHtml(content.Substring(0, limitIndex) + GetMoreString()); args.Summary = trimmedDoc.DocumentNode.OuterHtml; } else args.Summary = content; } } }
protected virtual bool ShouldProcess(GetSummaryArgs args) { return string.IsNullOrEmpty(args.Summary); }
public void Process(GetSummaryArgs args) { if (ShouldProcess(args)) GetSummary(args); }
public void Process(GetSummaryArgs args) { if (!OnlyWhenRequired || !args.Summary.StartsWith("<" + WrappingTag + ">")) args.Summary = "<{0}>{1}</{0}>".FormatWith(WrappingTag, args.Summary); }
protected abstract void GetSummary(GetSummaryArgs args);