Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions Functions/Public/em.ps1
Original file line number Diff line number Diff line change
@@ -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

<p>
This is
<em>
cool
</em>
</p>

.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
}


}
66 changes: 66 additions & 0 deletions Tests/em.Tests.ps1
Original file line number Diff line number Diff line change
@@ -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 '^<em.*>' | should be $true
$string -match '.*</em>$' | should be $true

}

it "Testing content in child element"{
$string -match "^.*>woop<.*" | should be $true
}

it "Testing common parameters: Class"{
$string -match '^<em.*class="myclass".*>' | should be $true
}
it "Testing common parameters: ID"{
$string -match '^<em.*id="myid".*>' | should be $true
}
it "Testing common parameters: Style"{
$string -match '^<em.*style=".+".*>' | should be $true
}


it "Testing Attributes parameters"{

foreach($at in $CustomAtt.Keys){
$val = $null
$val = $CustomAtt[$at]
$string -match "^<em.*$at=`"$val`".*>" | should be $true
}


}


}

}

Pop-Location