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
2 changes: 1 addition & 1 deletion Functions/Public/blockquote.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Function blockquote {
#>
[Cmdletbinding()]
Param(
[Parameter(Mandatory=$true)]
[Parameter(Mandatory=$false)]
[AllowEmptyString()]
[AllowNull()]
[String]
Expand Down
92 changes: 92 additions & 0 deletions Functions/Public/datalist.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
Function datalist {
<#
.SYNOPSIS
Create a datalist tag in an HTML document.

.DESCRIPTION

The <datalist> tag specifies a list of pre-defined options for an <input> element.

The <datalist> tag is used to provide an "autocomplete" feature on <input> elements. Users will see a drop-down list of pre-defined options as they input data.

Use the <input> element's list attribute to bind it together with a <datalist> element.

.EXAMPLE

datalist {
option -value "Volvo" -Content "Volvo"
option -value Saab -Content "saab"
}


Generates the following code:

<datalist>
<option value="Volvo" >volvo</option>
<option value="Saab" >saab</option>
</datalist>
.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
}
}
76 changes: 76 additions & 0 deletions Tests/datalist.tests.ps1
Original file line number Diff line number Diff line change
@@ -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 '^<datalist.*>' | should be $true
$string -match '.*</datalist>$' | should be $true

}

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

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

it "Testing Attributes parameters"{

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


}

it 'Testing: -Content Parameter should expand child elements' {

$string2 = datalist {option -value "Volvo" -Content "Car" }
$String2 = $string2 -join ""

$string2 -match '^.*>.*<option value="Volvo".*<.*' | should be $true

}


}



}

Pop-Location
2 changes: 1 addition & 1 deletion pshtml.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'pshtml.psm1'

# Version number of this module.
ModuleVersion = '0.5.17'
ModuleVersion = '0.5.18'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down