diff --git a/scripts/test.ps1 b/scripts/test.ps1
index 27665ae..5d323a5 100644
--- a/scripts/test.ps1
+++ b/scripts/test.ps1
@@ -1,3 +1,3 @@
$ErrorActionPreference = "Stop"
-dotnet test --no-build --logger "console;verbosity=detailed"
+dotnet test --logger "console;verbosity=detailed"
diff --git a/src/TextForge.Core/Documents/DocumentContent.cs b/src/TextForge.Core/Documents/DocumentContent.cs
new file mode 100644
index 0000000..3fcabd0
--- /dev/null
+++ b/src/TextForge.Core/Documents/DocumentContent.cs
@@ -0,0 +1,3 @@
+namespace TextForge.Core.Documents;
+
+public record DocumentContent(string Text);
diff --git a/src/TextForge.Core/Documents/TextTemplate.cs b/src/TextForge.Core/Documents/TextTemplate.cs
new file mode 100644
index 0000000..9544660
--- /dev/null
+++ b/src/TextForge.Core/Documents/TextTemplate.cs
@@ -0,0 +1,6 @@
+namespace TextForge.Core.Documents;
+
+public class TextTemplate
+{
+ public string Title { get; } = "TextForge";
+}
diff --git a/src/TextForge.Core/PdfService.cs b/src/TextForge.Core/PdfService.cs
index 92a8b79..0c02ac2 100644
--- a/src/TextForge.Core/PdfService.cs
+++ b/src/TextForge.Core/PdfService.cs
@@ -1,12 +1,13 @@
using QuestPDF.Fluent;
using QuestPDF.Helpers;
using QuestPDF.Infrastructure;
+using TextForge.Core.Documents;
namespace TextForge.Core;
public static class PdfService
{
- public static void CreatePdf(string text, string path)
+ public static void CreatePdf(DocumentContent document, TextTemplate template, string path)
{
QuestPDF.Settings.License = LicenseType.Community;
@@ -14,9 +15,13 @@ public static void CreatePdf(string text, string path)
{
container.Page(page =>
{
- page.Content().Text(text);
+ page.Content().Column(column =>
+ {
+ column.Item().Text(template.Title);
+ column.Item().Text(document.Text);
+ });
});
})
.GeneratePdf(path);
}
-}
\ No newline at end of file
+}
diff --git a/src/TextForge.Core/Preview/PreviewRenderer.cs b/src/TextForge.Core/Preview/PreviewRenderer.cs
new file mode 100644
index 0000000..c093c83
--- /dev/null
+++ b/src/TextForge.Core/Preview/PreviewRenderer.cs
@@ -0,0 +1,5 @@
+namespace TextForge.Core.Preview;
+
+public record PreviewDocument(
+ string Title,
+ string Text);
diff --git a/src/TextForge.Desktop/Views/MainWindow.axaml b/src/TextForge.Desktop/Views/MainWindow.axaml
index 33acff4..4fbad88 100644
--- a/src/TextForge.Desktop/Views/MainWindow.axaml
+++ b/src/TextForge.Desktop/Views/MainWindow.axaml
@@ -15,16 +15,54 @@
-
-
+
-
+
+
diff --git a/src/TextForge.Desktop/Views/MainWindow.axaml.cs b/src/TextForge.Desktop/Views/MainWindow.axaml.cs
index c873996..47bc869 100644
--- a/src/TextForge.Desktop/Views/MainWindow.axaml.cs
+++ b/src/TextForge.Desktop/Views/MainWindow.axaml.cs
@@ -1,8 +1,8 @@
using Avalonia.Controls;
using TextForge.Core;
-
namespace TextForge.Desktop.Views;
-
+using TextForge.Core.Preview;
+using TextForge.Core.Documents;
public partial class MainWindow : Window
{
public MainWindow()
@@ -10,10 +10,23 @@ public MainWindow()
InitializeComponent();
}
- private void ConvertButton_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
+ private void ConvertButton_Click(
+ object? sender,
+ Avalonia.Interactivity.RoutedEventArgs e)
{
var textBox = this.FindControl("InputText");
- PdfService.CreatePdf(textBox!.Text ?? "", "output.pdf");
+ var document = new DocumentContent(textBox!.Text ?? "");
+ var template = new TextTemplate();
+
+ var preview = new PreviewDocument(
+ template.Title,
+ document.Text);
+
+ var previewText = this.FindControl("PreviewText");
+
+ previewText!.Text = preview.Text;
+
+ PdfService.CreatePdf(document, template, "output.pdf");
}
-}
\ No newline at end of file
+}
diff --git a/tests/TextForge.Tests/PdfServiceTests.cs b/tests/TextForge.Tests/PdfServiceTests.cs
index 45fab6c..349080a 100644
--- a/tests/TextForge.Tests/PdfServiceTests.cs
+++ b/tests/TextForge.Tests/PdfServiceTests.cs
@@ -2,6 +2,7 @@
namespace TextForge.Tests;
+using TextForge.Core.Documents;
using UglyToad.PdfPig;
public class PdfServiceTests
@@ -15,7 +16,9 @@ public void CreatePdf_CreatesFile()
$"{Guid.NewGuid()}.pdf");
// Act
- PdfService.CreatePdf("Hello World", path);
+ DocumentContent document = new DocumentContent("Hello World");
+ TextTemplate template = new TextTemplate();
+ PdfService.CreatePdf(document, template, path);
// Assert
Assert.True(File.Exists(path));
@@ -32,15 +35,18 @@ public void CreatePdf_ContentIsCorrect()
Path.GetTempPath(),
$"{Guid.NewGuid()}.pdf");
- PdfService.CreatePdf(text, path);
+ DocumentContent document = new DocumentContent(text);
+ TextTemplate template = new TextTemplate();
+ PdfService.CreatePdf(document, template, path);
- using var document = PdfDocument.Open(path);
+ using var pdfDocument = PdfDocument.Open(path);
- var page = document.GetPage(1);
+ var page = pdfDocument.GetPage(1);
- Assert.Equal(text, page.Text);
+ Assert.Contains(text, page.Text);
+ Assert.Contains(template.Title, page.Text);
// Cleanup
File.Delete(path);
}
-
+
}