diff --git a/Functions/Public/em.ps1 b/Functions/Public/em.ps1 new file mode 100644 index 00000000..9a1a0ab4 --- /dev/null +++ b/Functions/Public/em.ps1 @@ -0,0 +1,83 @@ +Function em { + <# + .SYNOPSIS + Generates em HTML tag. + + .Description + This tag is a phrase tag. It renders as emphasized text. + + .EXAMPLE + p{ + "This is";em {"cool"} + } + + Will generate the following code + +

+ This is + + cool + +

+ + .Notes + Author: Andrew Wickham + Version: 2.0.0 + History: + 2018.10.04;@awickham10; Creation + + .LINK + https://github.com/Stephanevg/PSHTML + #> + [CmdletBinding()] + Param( + + [Parameter( + ValueFromPipeline = $true, + Position = 0 + )] + [object]$Content, + + [Parameter(Position = 1)] + [String]$Class, + + [Parameter(Position = 2)] + [String]$Id, + + [Parameter(Position = 3)] + [String]$Style, + + [Parameter(Position = 4)] + [Hashtable]$Attributes + + ) + $CommonParameters = "tagname" + [System.Management.Automation.PSCmdlet]::CommonParameters + [System.Management.Automation.PSCmdlet]::OptionalCommonParameters + $CustomParameters = $PSBoundParameters.Keys | Where-Object -FilterScript { $_ -notin $CommonParameters } + + + $htmltagparams = @{} + $tagname = "em" + if($CustomParameters){ + + foreach ($entry in $CustomParameters){ + + if($entry -eq "content"){ + + + $htmltagparams.$entry = $PSBoundParameters[$entry] + }else{ + $htmltagparams.$entry = "{0}" -f $PSBoundParameters[$entry] + } + + + } + + if($Attributes){ + $htmltagparams += $Attributes + } + + Set-HtmlTag -TagName $tagname -Attributes $htmltagparams -TagType nonVoid + } + + +} \ No newline at end of file diff --git a/Tests/em.Tests.ps1 b/Tests/em.Tests.ps1 new file mode 100644 index 00000000..ed15025d --- /dev/null +++ b/Tests/em.Tests.ps1 @@ -0,0 +1,66 @@ +$TestsPath = Split-Path $MyInvocation.MyCommand.Path + +#$FunctionsPath = join-Path -Path (get-item $TestsPath).Parent -ChildPath "Functions" + +$RootFolder = (get-item $TestsPath).Parent + +Push-Location -Path $RootFolder.FullName + +set-location -Path $RootFolder.FullName + +Write-Verbose "Importing module" + +import-module .\PSHTML -Force + +Context "Testing PSHTML"{ + Describe "Testing em" { + + + $Class = "MyClass" + $Id = "MyID" + $Style = "Background:green" + $CustomAtt = @{"MyAttribute1"='MyValue1';"MyAttribute2"="MyValue2"} + $string = em {"woop"} -Attributes $CustomAtt -Style $Style -Class $class -id $id + + if($string -is [array]){ + $string = $String -join "" + } + + it "Should contain opening and closing tags" { + $string -match '^' | should be $true + $string -match '.*$' | should be $true + + } + + it "Testing content in child element"{ + $string -match "^.*>woop<.*" | should be $true + } + + it "Testing common parameters: Class"{ + $string -match '^' | should be $true + } + it "Testing common parameters: ID"{ + $string -match '^' | should be $true + } + it "Testing common parameters: Style"{ + $string -match '^' | should be $true + } + + + it "Testing Attributes parameters"{ + + foreach($at in $CustomAtt.Keys){ + $val = $null + $val = $CustomAtt[$at] + $string -match "^" | should be $true + } + + + } + + + } + +} + +Pop-Location \ No newline at end of file