PicklesDoc.Pickles.DocumentationBuilders.Word.WordStepFormatter.GenerateStepParagraph C# (CSharp) Method

GenerateStepParagraph() public static method

public static GenerateStepParagraph ( Step step ) : Paragraph
step PicklesDoc.Pickles.ObjectModel.Step
return Paragraph
        public static Paragraph GenerateStepParagraph(Step step)
        {
            // HACK - We need to generate a custom paragraph here because 2 Run objects are needed to allow for the bolded keyword
            var paragraph = new Paragraph(new ParagraphProperties(new ParagraphStyleId { Val = "Normal" }));

            // Add comments before step
            if (step.Comments.Any(o => o.Type == CommentType.StepComment))
            {
                foreach (var comment in step.Comments.Where(o => o.Type == CommentType.StepComment))
                {
                    paragraph.Append(new Run(new RunProperties(new Italic()), new Text(comment.Text)));
                    paragraph.Append(new Break());
                }
            }

            // Add step
            paragraph.Append(new Run(new RunProperties(new Bold()), new Text(step.NativeKeyword)));
            var nameText = new Text { Space = SpaceProcessingModeValues.Preserve };
            nameText.Text = " " + step.Name;
            paragraph.Append(new Run(nameText));

            // Add comments after step
            if (step.Comments.Any(o => o.Type == CommentType.AfterLastStepComment))
            {
                paragraph.Append(new Break());

                foreach (var comment in step.Comments.Where(o => o.Type == CommentType.AfterLastStepComment))
                {
                    paragraph.Append(new Run(new RunProperties(new Italic()), new Text(comment.Text)));
                    paragraph.Append(new Break());
                }
            }

            return paragraph;
        }
    }

Usage Example

Example #1
0
        public void Format(Body body, Scenario background)
        {
            var headerParagraph = new Paragraph(new ParagraphProperties(new ParagraphStyleId {
                Val = "Heading2"
            }));
            var backgroundKeyword = GetLocalizedBackgroundKeyword();

            headerParagraph.Append(new Run(new RunProperties(new Bold()), new Text(backgroundKeyword)));

            var table = new Table();

            table.Append(GenerateTableProperties());
            var row  = new TableRow();
            var cell = new TableCell();

            cell.Append(headerParagraph);

            foreach (var descriptionSentence in WordDescriptionFormatter.SplitDescription(background.Description))
            {
                cell.Append(CreateNormalParagraph(descriptionSentence));
            }

            foreach (var step in background.Steps)
            {
                cell.Append(WordStepFormatter.GenerateStepParagraph(step));
            }

            cell.Append(CreateNormalParagraph(""));             // Is there a better way to generate a new empty line?
            row.Append(cell);
            table.Append(row);

            body.Append(table);
        }