Inheritance: PipelineArgs
Beispiel #1
0
 public void Process(GetSummaryArgs args)
 {
     if (!OnlyWhenRequired || !args.Summary.StartsWith("<" + WrappingTag + ">"))
     {
         args.Summary = "<{0}>{1}</{0}>".FormatWith(WrappingTag, args.Summary);
     }
 }
Beispiel #2
0
        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));
            }
        }
Beispiel #3
0
        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;
            }
        }
Beispiel #4
0
        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));
            }
        }
Beispiel #5
0
        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;
                }
            }
        }
Beispiel #6
0
        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);
        }
Beispiel #7
0
        protected string GetSummary(EntryItem entry)
        {
            var args = new GetSummaryArgs();
            args.Entry = entry;

            CorePipeline.Run("weblogGetSummary", args, true);

            return args.Summary;
        }
Beispiel #8
0
        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);
        }
Beispiel #10
0
        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);
        }
Beispiel #11
0
        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);
        }
Beispiel #12
0
        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);
        }
Beispiel #13
0
        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);
        }
Beispiel #14
0
        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);
        }
Beispiel #15
0
        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;
        }
Beispiel #16
0
        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);
        }
Beispiel #17
0
        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);
        }
Beispiel #18
0
        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);
        }
Beispiel #19
0
        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);
            }
        }
Beispiel #20
0
        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);
        }
Beispiel #21
0
        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);
        }
Beispiel #22
0
        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);
        }
Beispiel #23
0
        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);
        }
Beispiel #24
0
        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;
                    }
                }
            }
        }
Beispiel #25
0
        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);
        }
Beispiel #26
0
        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);
        }
Beispiel #27
0
        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);
 }
Beispiel #30
0
 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);
Beispiel #32
-1
        protected override void GetSummary(GetSummaryArgs args)
        {
            var renderer = new FieldRenderer();
            renderer.Item = args.Entry;
            renderer.FieldName = FieldName;

            args.Summary = renderer.Render();
        }