-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from hsndmr/implement-liquid-template
Implement liquid template
- Loading branch information
Showing
28 changed files
with
721 additions
and
622 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
name: Publish Mailgen Package | ||
|
||
on: | ||
push: | ||
branches: | ||
- '*' | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
dotnet-version: [6.0.x, 8.0.x] | ||
include: | ||
- dotnet-version: 6.0.x | ||
- dotnet-version: 8.0.x | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup .NET | ||
uses: actions/setup-dotnet@v3 | ||
with: | ||
dotnet-version: ${{ matrix.dotnet-version }} | ||
|
||
- name: Install dependencies | ||
run: dotnet restore Mailgen/Mailgen.csproj | ||
|
||
- name: Build | ||
run: dotnet build Mailgen/Mailgen.csproj --configuration Release --no-restore | ||
|
||
- name: Test | ||
run: dotnet test Mailgen/Mailgen.csproj --no-restore --verbosity normal | ||
|
||
publish: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
if: github.ref == 'refs/heads/main' && github.event_name == 'push' | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup .NET | ||
uses: actions/setup-dotnet@v3 | ||
with: | ||
dotnet-version: '8.0.x' | ||
|
||
- name: Install dependencies | ||
run: dotnet restore Mailgen/Mailgen.csproj | ||
|
||
- name: Build | ||
run: dotnet build Mailgen/Mailgen.csproj --configuration Release --no-restore | ||
|
||
- name: Pack | ||
run: dotnet pack Mailgen/Mailgen.csproj --configuration Release --no-restore --output nupkg | ||
|
||
- name: Publish to NuGet | ||
run: dotnet nuget push nupkg/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,134 +1,137 @@ | ||
using Example; | ||
using Mailgen; | ||
using Mailgen.Dtos; | ||
using Mailgen; | ||
using Mailgen.Templates; | ||
using Mailgen.Templates.Models; | ||
|
||
var projectPath = Environment.CurrentDirectory; | ||
await TemplateGenerator.GenerateReceiptTemplate(); | ||
await TemplateGenerator.GenerateResetTemplate(); | ||
|
||
public class Item | ||
{ | ||
public required string Name { get; set; } | ||
public required string Description { get; set; } | ||
public required string Price { get; set; } | ||
} | ||
|
||
var createMailGeneratorDto = new CreateMailGeneratorDto | ||
public static class TemplateGenerator | ||
{ | ||
Options = new TemplateOptionsModel | ||
public static async Task GenerateReceiptTemplate() | ||
{ | ||
Product = new ProductModel | ||
var product = new ProductModel | ||
{ | ||
CopyrightLeft = "© 2024", | ||
CopyrightRight = "All rights reserved.", | ||
Link = "https://github.com/hsndmr", | ||
Name = "Example Product" | ||
} | ||
} | ||
}; | ||
|
||
|
||
// receipt.html | ||
var mailGenerator = new MailGenerator(new HtmlGeneratorFactory(), createMailGeneratorDto); | ||
var generateMailDto = new GenerateMailDto<Item> | ||
{ | ||
Body = new TemplateBodyModel<Item> | ||
{ | ||
Title = "Hi John Appleseed,", | ||
Intros = | ||
[ | ||
"Your order has been processed successfully." | ||
], | ||
Tables = new List<TableModel<Item>> | ||
}; | ||
var mailGenerator = new MailGenerator(product, new DefaultTemplate()); | ||
var body = new BodyModel<Item> | ||
{ | ||
new() | ||
Title = "Hi John Appleseed,", | ||
Intros = | ||
[ | ||
"Your order has been processed successfully." | ||
], | ||
Tables = new List<TableModel<Item>> | ||
{ | ||
Columns = | ||
[ | ||
new TableColumnModel<Item> | ||
{ | ||
Header = "Item", | ||
ValueSelector = item => item.Name, | ||
Width = "20%" | ||
}, | ||
new TableColumnModel<Item> | ||
{ | ||
Header = "Description", | ||
ValueSelector = item => item.Description | ||
}, | ||
new TableColumnModel<Item> | ||
{ | ||
Header = "Price", | ||
ValueSelector = item => item.Price, | ||
Width = "15%", | ||
Align = "right" | ||
} | ||
], | ||
Rows = | ||
[ | ||
new Item | ||
{ | ||
Name = "Node.js", | ||
Description = "Event-driven I/O server-side JavaScript environment based on V8.", | ||
Price = "$10.99" | ||
}, | ||
new Item | ||
new() | ||
{ | ||
Columns = | ||
[ | ||
new TableColumnModel<Item> | ||
{ | ||
Header = "Item", | ||
ValueSelector = item => item.Name, | ||
Width = "20%" | ||
}, | ||
new TableColumnModel<Item> | ||
{ | ||
Header = "Description", | ||
ValueSelector = item => item.Description | ||
}, | ||
new TableColumnModel<Item> | ||
{ | ||
Header = "Price", | ||
ValueSelector = item => item.Price, | ||
Width = "15%", | ||
Align = "right" | ||
} | ||
], | ||
Rows = | ||
[ | ||
new Item | ||
{ | ||
Name = "Node.js", | ||
Description = "Event-driven I/O server-side JavaScript environment based on V8.", | ||
Price = "$10.99" | ||
}, | ||
new Item | ||
{ | ||
Name = "Mailgen", | ||
Description = "A .NET library for generating HTML emails.", | ||
Price = "$1.99" | ||
} | ||
] | ||
} | ||
}, | ||
Actions = | ||
[ | ||
new ActionModel | ||
{ | ||
Instructions = "You can check the status of your order and more in your dashboard:", | ||
Button = new ButtonModel | ||
{ | ||
Name = "Mailgen", | ||
Description = "A .NET library for generating HTML emails.", | ||
Price = "$1.99" | ||
Color = "#22BC66", | ||
Text = "Go to Dashboard", | ||
Link = "https://github.com/hsndmr" | ||
} | ||
] | ||
} | ||
}, | ||
Actions = | ||
[ | ||
new ActionModel | ||
{ | ||
Instructions = "You can check the status of your order and more in your dashboard:", | ||
Button = new ButtonModel | ||
{ | ||
Color = "#22BC66", | ||
Text = "Go to Dashboard", | ||
Link = "https://github.com/hsndmr" | ||
} | ||
} | ||
], | ||
Outro = | ||
[ | ||
"We thank you for your purchase." | ||
], | ||
Signature = "Yours truly" | ||
} | ||
}; | ||
var receipt = await mailGenerator.GenerateMail(generateMailDto); | ||
var mailPath = Path.Combine(projectPath, "receipt.html"); | ||
File.WriteAllText(mailPath, receipt); | ||
|
||
], | ||
Outro = | ||
[ | ||
"We thank you for your purchase." | ||
], | ||
Signature = "Yours truly" | ||
}; | ||
|
||
// reset.html | ||
var html = await mailGenerator.GenerateMail(body); | ||
await File.WriteAllTextAsync(@"GeneratedTemplates/receipt.html", html); | ||
} | ||
|
||
var generateMailForResetDto = new GenerateMailDto<Item> | ||
{ | ||
Body = new TemplateBodyModel<Item> | ||
public static async Task GenerateResetTemplate() | ||
{ | ||
Title = "Hi John Appleseed,", | ||
Intros = | ||
[ | ||
"You have received this email because a password reset request for your account was received." | ||
], | ||
Actions = | ||
[ | ||
new ActionModel | ||
{ | ||
Instructions = "Click the button below to reset your password:", | ||
Button = new ButtonModel | ||
var product = new ProductModel | ||
{ | ||
Link = "https://github.com/hsndmr", | ||
Name = "Example Product" | ||
}; | ||
var mailGenerator = new MailGenerator(product, new DefaultTemplate()); | ||
var body = new BodyModel<Item> | ||
{ | ||
Title = "Hi John Appleseed,", | ||
Intros = | ||
[ | ||
"You have received this email because a password reset request for your account was received." | ||
], | ||
Actions = | ||
[ | ||
new ActionModel | ||
{ | ||
Color = "#DC4D2F", | ||
Text = "Reset your password", | ||
Link = "https://github.com/hsndmr" | ||
Instructions = "Click the button below to reset your password:", | ||
Button = new ButtonModel | ||
{ | ||
Color = "#DC4D2F", | ||
Text = "Reset your password", | ||
Link = "https://github.com/hsndmr" | ||
} | ||
} | ||
} | ||
], | ||
Outro = | ||
[ | ||
"If you did not request a password reset, no further action is required on your part." | ||
] | ||
], | ||
Outro = | ||
[ | ||
"If you did not request a password reset, no further action is required on your part." | ||
] | ||
}; | ||
|
||
var html = await mailGenerator.GenerateMail(body); | ||
await File.WriteAllTextAsync(@"GeneratedTemplates/reset.html", html); | ||
} | ||
}; | ||
var reset = await mailGenerator.GenerateMail(generateMailForResetDto); | ||
var resetMailPath = Path.Combine(projectPath, "reset.html"); | ||
File.WriteAllText(resetMailPath, reset); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.