diff --git a/Functions/Public/blockquote.ps1 b/Functions/Public/blockquote.ps1 index 651b3975..86bfcf10 100644 --- a/Functions/Public/blockquote.ps1 +++ b/Functions/Public/blockquote.ps1 @@ -28,7 +28,7 @@ Function blockquote { #> [Cmdletbinding()] Param( - [Parameter(Mandatory=$true)] + [Parameter(Mandatory=$false)] [AllowEmptyString()] [AllowNull()] [String] diff --git a/Functions/Public/datalist.ps1 b/Functions/Public/datalist.ps1 new file mode 100644 index 00000000..33359fd5 --- /dev/null +++ b/Functions/Public/datalist.ps1 @@ -0,0 +1,92 @@ +Function datalist { + <# + .SYNOPSIS + Create a datalist tag in an HTML document. + + .DESCRIPTION + + The tag specifies a list of pre-defined options for an element. + + The tag is used to provide an "autocomplete" feature on elements. Users will see a drop-down list of pre-defined options as they input data. + + Use the element's list attribute to bind it together with a element. + + .EXAMPLE + + datalist { + option -value "Volvo" -Content "Volvo" + option -value Saab -Content "saab" + } + + + Generates the following code: + + + + + + .EXAMPLE + + + .NOTES + Current version 2.0 + History: + 2018.10.05;@stephanevg;Creation. + .LINK + https://github.com/Stephanevg/PSHTML + #> + [Cmdletbinding()] + Param( + [Parameter(Mandatory=$false)] + [AllowEmptyString()] + [AllowNull()] + $Content, + + [AllowEmptyString()] + [AllowNull()] + [String]$Class="", + + [String]$Id, + + [AllowEmptyString()] + [AllowNull()] + [String]$Style, + + [String]$title, + + [Hashtable]$Attributes + ) + + Process { + + $CommonParameters = "tagname" + [System.Management.Automation.PSCmdlet]::CommonParameters + [System.Management.Automation.PSCmdlet]::OptionalCommonParameters + $CustomParameters = $PSBoundParameters.Keys | ? { $_ -notin $CommonParameters } + + $htmltagparams = @{} + $tagname = "datalist" + + 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 + } +} diff --git a/Tests/datalist.tests.ps1 b/Tests/datalist.tests.ps1 new file mode 100644 index 00000000..e9d5cbf2 --- /dev/null +++ b/Tests/datalist.tests.ps1 @@ -0,0 +1,76 @@ +$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 datalist" { + + + $Class = "MyClass" + $Id = "MyID" + $Style = "Background:green" + $CustomAtt = @{"MyAttribute1"='MyValue1';"MyAttribute2"="MyValue2"} + $string = datalist {"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 + } + + + } + + it 'Testing: -Content Parameter should expand child elements' { + + $string2 = datalist {option -value "Volvo" -Content "Car" } + $String2 = $string2 -join "" + + $string2 -match '^.*>.*