예제 #1
0
        protected virtual void RenderContent(CoconaHelpRenderingContext ctx, ICoconaHelpContent content)
        {
            switch (content)
            {
            case ICoconaHelpSectioningContent section:
                RenderSectioningContent(ctx, section);
                break;

            case HelpHeading heading:
                RenderHeading(ctx, heading);
                break;

            case HelpParagraph paragraph:
                RenderParagraph(ctx, paragraph);
                break;

            case HelpLabelDescriptionList labelDescriptionList:
                RenderLabelDescriptionList(ctx, labelDescriptionList);
                break;

            case HelpPreformattedText preformattedText:
                RenderPreformattedText(ctx, preformattedText);
                break;
            }
        }
예제 #2
0
        public string Render(HelpMessage message)
        {
            var ctx = new CoconaHelpRenderingContext();

            RenderContent(ctx, message);
            return(ctx.StringBuilder.ToString());
        }
예제 #3
0
        protected virtual void RenderParagraph(CoconaHelpRenderingContext ctx, HelpParagraph paragraph)
        {
            var depth = ctx.CurrentDepth - 1;

            ctx.StringBuilder
            .AppendPadding(depth)
            .AppendLine(paragraph.Content);
        }
예제 #4
0
        protected virtual void RenderHeading(CoconaHelpRenderingContext ctx, HelpHeading heading)
        {
            var depth = ctx.CurrentDepth - 1;

            ctx.StringBuilder
            .AppendPadding(depth)
            .AppendLine(heading.Content);
        }
예제 #5
0
                public SectionStackItem(CoconaHelpRenderingContext ctx, ICoconaHelpSectioningContent section)
                {
                    _ctx = ctx;
                    _ctx.Sections.Push(this);
                    _ctx.CurrentSection = this;

                    Section       = section;
                    ChildPosition = 0;
                }
예제 #6
0
        protected virtual void RenderPreformattedText(CoconaHelpRenderingContext ctx, HelpPreformattedText pre)
        {
            var depth = ctx.CurrentDepth - 1;

            foreach (var line in pre.Content.Split('\n'))
            {
                ctx.StringBuilder
                .AppendPadding(depth)
                .AppendLine(line.TrimEnd());
            }
        }
예제 #7
0
        protected virtual void RenderLabelDescriptionList(CoconaHelpRenderingContext ctx, HelpLabelDescriptionList labelDescriptionList)
        {
            var depth       = ctx.CurrentDepth - 1;
            var maxLabelLen = labelDescriptionList.Items.Max(x => x.Label.Length);

            foreach (var labelAndDesc in labelDescriptionList.Items)
            {
                ctx.StringBuilder
                .AppendPadding(depth)
                .Append(labelAndDesc.Label)
                .AppendPadding(maxLabelLen - labelAndDesc.Label.Length, " ")
                .Append("    ")
                .AppendLine(labelAndDesc.Description);
            }
        }
예제 #8
0
        protected virtual void RenderSectioningContent(CoconaHelpRenderingContext ctx, ICoconaHelpSectioningContent section)
        {
            using (new CoconaHelpRenderingContext.SectionStackItem(ctx, section))
            {
                var prevContentIsSection = false;
                foreach (var child in section.Children)
                {
                    if (prevContentIsSection)
                    {
                        ctx.StringBuilder.AppendLine();
                    }

                    RenderContent(ctx, child);
                    ctx.CurrentSection !.Advance();

                    if (child is ICoconaHelpSectioningContent)
                    {
                        prevContentIsSection = true;
                    }
                }
            }
        }