forked from smsohan/MvcMailer
/
Mailer.ps1
75 lines (64 loc) · 2.42 KB
/
Mailer.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
[T4Scaffolding.Scaffolder(Description = "Scaffold your mailers")][CmdletBinding()]
param(
[parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)][string]$MailerName,
[parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)][string[]]$MailerMethods,
[string]$Project,
[string]$CodeLanguage,
[string[]]$TemplateFolders,
[switch]$Force = $false
)
###########################################################
### ###
### FUNCTIONS ###
### ###
###########################################################
function CreateCSFileFromTemplate
{
param ($MailerTemplate, $outputPath)
$outputFolder = "Mailers"
$templateFile = Find-ScaffolderTemplate cs\$MailerTemplate -TemplateFolders $TemplateFolders -Project $Project -CodeLanguage $CodeLanguage -ErrorIfNotFound
if ($templateFile) {
# Render it, adding the output to the Visual Studio project
$namespace = (Get-Project $Project).Properties.Item("DefaultNamespace").Value
$wroteFile = Invoke-ScaffoldTemplate -Template $templateFile -Model @{
Namespace = $namespace;
MailerName = $MailerName;
MailerMethods = $MailerMethods;
} -Project $Project -OutputPath $outputFolder\$outputPath -Force:$Force
if($wroteFile) {
Write-Host "Added MyScaffolder output '$wroteFile'"
}
}
}
function CreateCSFiles
{
CreateCSFileFromTemplate IMailerTemplate I$MailerName
CreateCSFileFromTemplate MailerTemplate $MailerName
}
function CreateViewFileFromTemplate
{
param ($ViewTemplate, $viewPath, $viewName='')
$templateFile = Find-ScaffolderTemplate view\$ViewTemplate -TemplateFolders $TemplateFolders -Project $Project -CodeLanguage $CodeLanguage -ErrorIfNotFound
$namespace = (Get-Project $Project).Properties.Item("DefaultNamespace").Value
if ($templateFile) {
$wroteFile = Invoke-ScaffoldTemplate -Template $templateFile -Model @{
Namespace = $namespace;
MailerName=$MailerName;
ViewName=$viewName;
} -Project $Project -OutputPath $viewPath -Force:$force
if($wroteFile) {
Write-Host "Added MyScaffolder output '$wroteFile'"
}
}
}
function CreateLayoutAndViews
{
CreateViewFileFromTemplate Layout.cshtml Views\$MailerName\_Layout
foreach ($viewName in $MailerMethods)
{
CreateViewFileFromTemplate Mail.cshtml Views\$MailerName\$viewName $viewName
}
}
######## END FUNCTIONS ####################################
CreateCSFiles
CreateLayoutAndViews