From f0457f57492805e4ef7f22291a4bfc1db57636f4 Mon Sep 17 00:00:00 2001 From: stephanevg Date: Fri, 5 Oct 2018 00:08:31 +0200 Subject: [PATCH 1/3] fixed content mandatory $tre to false --- Functions/Public/blockquote.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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] From 1f805e9d66abd75b973550aef7f20dfd6bed97d4 Mon Sep 17 00:00:00 2001 From: stephanevg Date: Fri, 5 Oct 2018 00:18:05 +0200 Subject: [PATCH 2/3] v0.5.18: Added Datalist and tests. --- Functions/Public/datalist.ps1 | 83 +++++++++++++++++++++++++++++++++++ Tests/datalist.tests.ps1 | 65 +++++++++++++++++++++++++++ pshtml.psd1 | 2 +- 3 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 Functions/Public/datalist.ps1 create mode 100644 Tests/datalist.tests.ps1 diff --git a/Functions/Public/datalist.ps1 b/Functions/Public/datalist.ps1 new file mode 100644 index 00000000..b2558090 --- /dev/null +++ b/Functions/Public/datalist.ps1 @@ -0,0 +1,83 @@ +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 + + .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()] + [String] + $Content, + + [string]$cite, + + [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 + } + } +} \ No newline at end of file diff --git a/Tests/datalist.tests.ps1 b/Tests/datalist.tests.ps1 new file mode 100644 index 00000000..345e464f --- /dev/null +++ b/Tests/datalist.tests.ps1 @@ -0,0 +1,65 @@ +$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 + } + + + } + + + } + +} + +Pop-Location \ No newline at end of file diff --git a/pshtml.psd1 b/pshtml.psd1 index cf0bf4e5..9fb1d460 100644 --- a/pshtml.psd1 +++ b/pshtml.psd1 @@ -12,7 +12,7 @@ RootModule = 'pshtml.psm1' # Version number of this module. -ModuleVersion = '0.5.17' +ModuleVersion = '0.5.18' # Supported PSEditions # CompatiblePSEditions = @() From ec4c227476bce3f59773493b2d715b95bf451185 Mon Sep 17 00:00:00 2001 From: stephanevg Date: Fri, 5 Oct 2018 02:09:33 +0200 Subject: [PATCH 3/3] added test and example. Fixed content hardocded type to string. --- Functions/Public/datalist.ps1 | 19 ++++++++++++++----- Tests/datalist.tests.ps1 | 13 ++++++++++++- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Functions/Public/datalist.ps1 b/Functions/Public/datalist.ps1 index b2558090..33359fd5 100644 --- a/Functions/Public/datalist.ps1 +++ b/Functions/Public/datalist.ps1 @@ -13,6 +13,18 @@ Function datalist { .EXAMPLE + datalist { + option -value "Volvo" -Content "Volvo" + option -value Saab -Content "saab" + } + + + Generates the following code: + + + + + .EXAMPLE @@ -28,11 +40,8 @@ Function datalist { [Parameter(Mandatory=$false)] [AllowEmptyString()] [AllowNull()] - [String] $Content, - [string]$cite, - [AllowEmptyString()] [AllowNull()] [String]$Class="", @@ -77,7 +86,7 @@ Function datalist { } - Set-HtmlTag -TagName $tagname -Attributes $htmltagparams -TagType NonVoid } + Set-HtmlTag -TagName $tagname -Attributes $htmltagparams -TagType NonVoid } -} \ No newline at end of file +} diff --git a/Tests/datalist.tests.ps1 b/Tests/datalist.tests.ps1 index 345e464f..e9d5cbf2 100644 --- a/Tests/datalist.tests.ps1 +++ b/Tests/datalist.tests.ps1 @@ -20,7 +20,7 @@ Context "Testing PSHTML"{ $Id = "MyID" $Style = "Background:green" $CustomAtt = @{"MyAttribute1"='MyValue1';"MyAttribute2"="MyValue2"} - $string = datalist {woop} -Attributes $CustomAtt -Style $Style -Class $class -id $id + $string = datalist {"woop"} -Attributes $CustomAtt -Style $Style -Class $class -id $id if($string -is [array]){ $string = $String -join "" @@ -57,9 +57,20 @@ Context "Testing PSHTML"{ } + it 'Testing: -Content Parameter should expand child elements' { + + $string2 = datalist {option -value "Volvo" -Content "Car" } + $String2 = $string2 -join "" + + $string2 -match '^.*>.*