From 5ffcbd87497087fa09a6282c0cae555fa7a99f9f Mon Sep 17 00:00:00 2001 From: Joseph Fenly Date: Wed, 17 Oct 2018 09:29:44 +0100 Subject: [PATCH] Added VSCode snippets and function to install them --- .../Public/Install-PSHTMLVSCodeSnippets.ps1 | 27 +++++++++ ...tml_BoilerPlate_full.Snippet.code-snippets | 57 +++++++++++++++++++ ...l_BoilerPlate_medium.Snippet.code-snippets | 57 +++++++++++++++++++ ...ml_BoilerPlate_small.Snippet.code-snippets | 17 ++++++ Tests/Install-PSHTMLVSCodeSnippets.tests.ps1 | 13 +++++ 5 files changed, 171 insertions(+) create mode 100644 PSHTML/Functions/Public/Install-PSHTMLVSCodeSnippets.ps1 create mode 100644 PSHTML/Snippets/PsHtml_BoilerPlate_full.Snippet.code-snippets create mode 100644 PSHTML/Snippets/PsHtml_BoilerPlate_medium.Snippet.code-snippets create mode 100644 PSHTML/Snippets/PsHtml_BoilerPlate_small.Snippet.code-snippets create mode 100644 Tests/Install-PSHTMLVSCodeSnippets.tests.ps1 diff --git a/PSHTML/Functions/Public/Install-PSHTMLVSCodeSnippets.ps1 b/PSHTML/Functions/Public/Install-PSHTMLVSCodeSnippets.ps1 new file mode 100644 index 00000000..dce362b9 --- /dev/null +++ b/PSHTML/Functions/Public/Install-PSHTMLVSCodeSnippets.ps1 @@ -0,0 +1,27 @@ +function Install-PSHTMLVSCodeSnippets { +<# +.SYNOPSIS + Copy the PSHTML VSCode Snippets to the right location +.DESCRIPTION + Gets the PSHTML VSCode snippet files and copies them to users appdata folder +.NOTES + Current version 0.1 + History: + 2018.10.16;FishFenly;Creation. +#> + + $callstack = Get-PSCallStack | Select-Object -ExpandProperty scriptname + + $path = Split-path -path ( + Split-path -Path ( + Split-Path -path $callstack -Parent) -Parent) -Parent + + $snippetsfolder = join-path $path -ChildPath "Snippets" + + + foreach ($snippet in (Get-Item $snippetsfolder\*.code-snippets | Select-Object -ExpandProperty FullName)) { + Write-Verbose "Copying $snippet to $($env:APPDATA)\Code\User\snippets" + Copy-Item -Path $snippet ` + -Destination "$($env:APPDATA)\Code\User\snippets" -Force + } +} \ No newline at end of file diff --git a/PSHTML/Snippets/PsHtml_BoilerPlate_full.Snippet.code-snippets b/PSHTML/Snippets/PsHtml_BoilerPlate_full.Snippet.code-snippets new file mode 100644 index 00000000..1bcaae1d --- /dev/null +++ b/PSHTML/Snippets/PsHtml_BoilerPlate_full.Snippet.code-snippets @@ -0,0 +1,57 @@ +{ + "PsHtml_full": { + "prefix": "pshtml", + "body": [ + "# The following example called 'tribute to Snover' grasps information for the 'shellfather' from around the internet, and generates a html page with the information.", + "html {", + "\thead {", + "\t\ttitle 'Tribute to snover'", + "\t\tlink -href 'mystylesheet' -rel 'stylesheet'", + "\t}", + "\tbody {", + "\t\th1 'Tribute to Jeffery Snover' -class 'Title'", + "\t\tdiv -class 'Photo' {", + "\t\t\timg -src 'https://pbs.twimg.com/profile_images/618804166631145473/2q6yharL_400x400.jpg' -alt 'Jeffrey Snover photo' -height '400' -width '400' -Class 'Photo'", + "\t\t}", + "\t\tdiv -id 'Bio' {", + "\t\t\t$wikirootsite = 'https://en.wikipedia.org'", + "\t\t\t$source = a {'Wikipedia'} -href $wikirootsite", + "\t\t\th2 'Biography'", + "\t\t\th4 'Source -->' $source", + "\t\t\t$wiki = Invoke-WebRequest -Uri ($wikirootsite + '/wiki/Jeffrey_Snover')", + "\t\t\t$output = $wiki.ParsedHtml.getElementById('mw-content-text').children | Where-Object -FilterScript {$_.ClassName -eq 'mw-parser-output'}", + "\t\t\t$bio = $output.Children | Where-Object -FilterScript {$_.TagName -eq 'p'} | Select-Object -Property Tagname,InnerHtml", + "\t\t\tforeach ($p in $bio) {", + "\t\t\t\tif($p.InnerHtml -ne $null) {", + "\t\t\t\t\t$corrected = $p.innerHTML.Replace('/wiki/','$wikirootsite/wiki/')", + "\t\t\t\t\tp {", + "\t\t\t\t\t\t$corrected", + "\t\t\t\t\t}", + "\t\t\t\t}", + "\t\t\t}", + "\t\t}", + "\t\tdiv -id 'Snoverisms' {", + "\t\t\t$snoverismssite = 'http://snoverisms.com/'", + "\t\t\th2 'Snoverisms'", + "\t\t\th4 'Source --> $snoverismssite'", + "\t\t\t$Page = Invoke-WebRequest -Uri $SnoverismsSite", + "\t\t\t$Snoverisms = $Page.ParsedHtml.getElementsByTagName('p') | Where-Object -FilterScript {$_.ClassName -ne 'site-description'} | Select-Object -Property innerhtml", + "\t\t\t$Snoverisms += (Invoke-WebRequest -uri 'http://snoverisms.com/page/2/').ParsedHtml.getElementsByTagName('p') | Where-Object -FilterScript {$_.ClassName -ne 'site-description'} | Select-Object -Property innerhtml", + "\t\t\tul -id 'snoverism-list' -Content {", + "\t\t\t\tForeach ($snov in $Snoverisms) {", + "\t\t\t\t\tli -Class 'snoverism' -content {", + "\t\t\t\t\t\t$snov.innerHTML", + "\t\t\t\t\t}", + "\t\t\t\t}", + "\t\t\t}", + "\t\t}", + "\t\tfooter {", + "\t\t\t$PSHTMLlink = a {'PSHTML'} -href 'https://github.com/Stephanevg/PSHTML'", + "\t\t\th6 'Generated with' + $PSHTMLlink", + "\t\t}", + "\t}", + "}" + ], + "description": "PsHtml Full Snippet" + } +} \ No newline at end of file diff --git a/PSHTML/Snippets/PsHtml_BoilerPlate_medium.Snippet.code-snippets b/PSHTML/Snippets/PsHtml_BoilerPlate_medium.Snippet.code-snippets new file mode 100644 index 00000000..2a8d666e --- /dev/null +++ b/PSHTML/Snippets/PsHtml_BoilerPlate_medium.Snippet.code-snippets @@ -0,0 +1,57 @@ +{ + "PsHtml_medium": { + "prefix": "pshtml", + "body": [ + "html {", + "\thead {", + "\t\ttitle 'woop title'", + "\t\tlink -href 'assets/home.css' -rel 'stylesheet'", + "\t}", + "\tbody {", + "\t\tHeader {", + "\t\t\timg 'https://i0.wp.com/powershelldistrict.com/wp-content/uploads/2016/01/logo_pd_quadri.png' 'logo powershell' -height 100 -width 400", + "\t\t\th1 'This is a h1 Title in a header'", + "\t\t\tdiv {", + "\t\t\t\tp {", + "\t\t\t\t\t'This is a paragraph in a div'", + "\t\t\t\t}", + "\t\t\t}", + "\t\t}", + "\t\ttable {", + "\t\t\tcaption 'A table generated with PSHTML'", + "\t\t\tthead {", + "\t\t\t\ttr {", + "\t\t\t\t\tth 'head 1'", + "\t\t\t\t\tth 'head 2'", + "\t\t\t\t\tth 'head 3'", + "\t\t\t\t}", + "\t\t\t}", + "\t\t\ttbody {", + "\t\t\t\ttr {", + "\t\t\t\t\ttd 'row 1.1'", + "\t\t\t\t\tth 'row 2.1'", + "\t\t\t\t\tth 'row 3.1'", + "\t\t\t\t}", + "\t\t\t\ttr {", + "\t\t\t\t\ttd 'row 1.2'", + "\t\t\t\t\tth 'row 2.2'", + "\t\t\t\t\tth 'row 3.2'", + "\t\t\t\t}", + "\t\t\t}", + "\t\t\ttfoot {", + "\t\t\t\ttr {", + "\t\t\t\t\ttd 'Table footer'", + "\t\t\t\t}", + "\t\t\t}", + "\t\t\tdiv {", + "\t\t\t\ta {", + "\t\t\t\t\t'This points to PowershellDistrict'", + "\t\t\t\t} -href 'http://powershellDistrict.com'", + "\t\t\t}", + "\t\t}", + "\t}", + "}" + ], + "description": "PsHtml Medium Snippet" + } +} \ No newline at end of file diff --git a/PSHTML/Snippets/PsHtml_BoilerPlate_small.Snippet.code-snippets b/PSHTML/Snippets/PsHtml_BoilerPlate_small.Snippet.code-snippets new file mode 100644 index 00000000..d8258a78 --- /dev/null +++ b/PSHTML/Snippets/PsHtml_BoilerPlate_small.Snippet.code-snippets @@ -0,0 +1,17 @@ +{ + "PsHtml_small": { + "prefix": "pshtml", + "body": [ + "html {", + "\thead {", + "\t\ttitle 'iPortal Home Page'", + "\t\tlink -href 'assets/home.css' -rel 'stylesheet'", + "\t}", + "\tbody {", + "\t\t h1 'iPortal'", + "\t}", + "}" + ], + "description": "PsHtml Small Snippet" + } +} \ No newline at end of file diff --git a/Tests/Install-PSHTMLVSCodeSnippets.tests.ps1 b/Tests/Install-PSHTMLVSCodeSnippets.tests.ps1 new file mode 100644 index 00000000..8fbf7984 --- /dev/null +++ b/Tests/Install-PSHTMLVSCodeSnippets.tests.ps1 @@ -0,0 +1,13 @@ +Describe "VSCode Snippets store with PSHTML Snippets" { + Context "Testing PSHTML Snippets exist" { + It "has the Small snippet" { + Test-Path "$($env:APPDATA)\Code\User\snippets\PsHtml_BoilerPlate_small.Snippet.code-snippets" | Should Be $true + } + It "has the Medium snippet" { + Test-Path "$($env:APPDATA)\Code\User\snippets\PsHtml_BoilerPlate_small.Snippet.code-snippets" | Should Be $true + } + It "has the Full snippet" { + Test-Path "$($env:APPDATA)\Code\User\snippets\PsHtml_BoilerPlate_small.Snippet.code-snippets" | Should Be $true + } + } +}