Skip to content

Commit

Permalink
Adding background to features in word
Browse files Browse the repository at this point in the history
  • Loading branch information
jni- committed Aug 9, 2013
1 parent 473675b commit d27c4be
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

using System.Collections.Generic;
using DocumentFormat.OpenXml.Wordprocessing;
using PicklesDoc.Pickles.Extensions;
using PicklesDoc.Pickles.Parser;
using PicklesDoc.Pickles.TestFrameworks;
using Table = DocumentFormat.OpenXml.Wordprocessing.Table;
using TableRow = DocumentFormat.OpenXml.Wordprocessing.TableRow;

namespace PicklesDoc.Pickles.DocumentationBuilders.Word
{
public class WordBackgroundFormatter
{

public void Format(Body body, Scenario background)
{
var headerParagraph = new Paragraph(new ParagraphProperties(new ParagraphStyleId { Val = "Heading2" }));
headerParagraph.Append(new Run(new RunProperties(new Bold()), new Text(background.Name)));

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

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

cell.Append(CreateEmptyLine());
row.Append(cell);
table.Append(row);

body.Append(table);
}

private static TableProperties GenerateTableProperties()
{
var tableProperties1 = new TableProperties();
var tableStyle1 = new TableStyle { Val = "TableGrid" };
var tableWidth1 = new TableWidth { Width = "4900", Type = TableWidthUnitValues.Pct };
var tableLook1 = new TableLook { Val = "04A0" };
var tableJustification = new TableJustification { Val = TableRowAlignmentValues.Center };

tableProperties1.Append(tableStyle1);
tableProperties1.Append(tableWidth1);
tableProperties1.Append(tableLook1);
tableProperties1.Append(tableJustification);
return tableProperties1;
}

private static Paragraph CreateEmptyLine()
{
// Is there a better way to do this?
var emptyLine = new Paragraph(new ParagraphProperties(new ParagraphStyleId { Val = "Normal" }));
emptyLine.Append(new Run(new Text("")));
return emptyLine;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,21 @@ public class WordFeatureFormatter
private readonly WordScenarioOutlineFormatter wordScenarioOutlineFormatter;
private readonly WordStyleApplicator wordStyleApplicator;
private readonly WordDescriptionFormatter wordDescriptionFormatter;
private readonly WordBackgroundFormatter wordBackgroundFormatter;

public WordFeatureFormatter(WordScenarioFormatter wordScenarioFormatter,
WordScenarioOutlineFormatter wordScenarioOutlineFormatter,
WordStyleApplicator wordStyleApplicator,
WordDescriptionFormatter wordDescriptionFormatter,
WordBackgroundFormatter wordBackgroundFormatter,
Configuration configuration,
ITestResults nunitResults)
{
this.wordScenarioFormatter = wordScenarioFormatter;
this.wordScenarioOutlineFormatter = wordScenarioOutlineFormatter;
this.wordStyleApplicator = wordStyleApplicator;
this.wordDescriptionFormatter = wordDescriptionFormatter;
this.wordBackgroundFormatter = wordBackgroundFormatter;
this.configuration = configuration;
this.nunitResults = nunitResults;
}
Expand All @@ -72,6 +75,7 @@ public void Format(Body body, FeatureNode featureNode)

body.GenerateParagraph(feature.Name, "Heading1");
this.wordDescriptionFormatter.Format(body, feature.Description);
this.wordBackgroundFormatter.Format(body, feature.Background);

foreach (IFeatureElement featureElement in feature.FeatureElements)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,12 @@ public WordStepFormatter(WordTableFormatter wordTableFormatter)

public void Format(Body body, 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"}));
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));
var paragraph = GenerateStepParagraph(step);
body.Append(paragraph);

if (!string.IsNullOrEmpty(step.DocStringArgument))
{
string[] lines = step.DocStringArgument.Split(new[] {Environment.NewLine},
string[] lines = step.DocStringArgument.Split(new[] { Environment.NewLine },
StringSplitOptions.RemoveEmptyEntries);
foreach (string line in lines)
{
Expand All @@ -60,5 +55,16 @@ public void Format(Body body, Step step)
this.wordTableFormatter.Format(body, step.TableArgument);
}
}

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" }));
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));
return paragraph;
}
}
}
1 change: 1 addition & 0 deletions src/Pickles/Pickles/Pickles.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@
<Compile Include="DocumentationBuilders\Word\TableOfContentsAdder\PtOpenXmlUtil.cs" />
<Compile Include="DocumentationBuilders\Word\TableOfContentsAdder\PtUtil.cs" />
<Compile Include="DocumentationBuilders\Word\TableOfContentsAdder\TocAdder.cs" />
<Compile Include="DocumentationBuilders\Word\WordBackgroundFormatter.cs" />
<Compile Include="DocumentationBuilders\Word\WordDescriptionFormatter.cs" />
<Compile Include="DocumentationBuilders\Word\WordDocumentationBuilder.cs" />
<Compile Include="DocumentationBuilders\Word\WordFeatureFormatter.cs" />
Expand Down

0 comments on commit d27c4be

Please sign in to comment.