Skip to content

Commit 54dc4e4

Browse files
authored
Added optional snippets and badges #31 #30 #42 (#44)
* Added optional snippets and badges #31 #30 #42 * Remove quick start config * Get option from root path * Doc improvements based on feedback @vicperdana
1 parent ba8548b commit 54dc4e4

13 files changed

Lines changed: 668 additions & 16 deletions

File tree

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222
"**/.azure-pipelines/jobs/*.yaml": "azure-pipelines"
2323
},
2424
"cSpell.words": [
25-
"cmdlet"
25+
"Concat",
26+
"Quickstart",
27+
"cmdlet",
28+
"cmdlets"
2629
],
2730
"cSpell.enabledLanguageIds": [
2831
"csharp",

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22

33
## Unreleased
44

5+
What's changed since pre-release v0.2.0-B2101002:
6+
7+
- New features:
8+
- Added the ability to disable parameter file snippet. [#31](https://github.com/Azure/PSDocs.Azure/issues/31)
9+
- To disable parameter file snippet set configuration `AZURE_USE_PARAMETER_FILE_SNIPPET`.
10+
- See [about_PSDocs_Azure_Configuration] for details.
11+
- Added the ability to include badges in template document. [#30](https://github.com/Azure/PSDocs.Azure/issues/30)
12+
- Set the `.ps-docs/azure-template-badges.md` file to include badge content.
13+
- See [about_PSDocs_Azure_Badges] for details.
14+
- Engineering:
15+
- Bump PSDocs dependency to v0.8.0. [#42](https://github.com/Azure/PSDocs.Azure/issues/42)
16+
517
## v0.2.0-B2101002 (pre-release)
618

719
What's changed since v0.1.0:
@@ -28,3 +40,6 @@ What's changed since pre-release v0.1.0-B2012006:
2840
## v0.1.0-B2012006 (pre-release)
2941

3042
- Initial pre-release.
43+
44+
[about_PSDocs_Azure_Configuration]: docs/concepts/en-US/about_PSDocs_Azure_Configuration.md
45+
[about_PSDocs_Azure_Badges]: docs/concepts/en-US/about_PSDocs_Azure_Badges.md

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,23 @@ jobs:
266266
source_dir: 'out/docs/*'
267267
```
268268

269+
## Language reference
270+
271+
PSDocs for Azure extends PowerShell with the following cmdlets and concepts.
272+
273+
### Commands
274+
275+
The following commands exist in the `PSDocs.Azure` module:
276+
277+
- [Get-AzDocTemplateFile](docs/commands/en-US/Get-AzDocTemplateFile.md) - Get Azure template files within a directory structure.
278+
279+
### Concepts
280+
281+
The following conceptual topics exist in the `PSDocs.Azure` module:
282+
283+
- [Badges](docs/concepts/en-US/about_PSDocs_Azure_Badges.md)
284+
- [Configuration](docs/concepts/en-US/about_PSDocs_Azure_Configuration.md)
285+
- [AZURE_USE_PARAMETER_FILE_SNIPPET](docs/concepts/en-US/about_PSDocs_Azure_Configuration.md#azure_use_parameter_file_snippet)
269286

270287
## Changes and versioning
271288

docs/commands/en-US/Get-AzDocTemplateFile.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ schema: 2.0.0
99

1010
## SYNOPSIS
1111

12-
Get Azure template files.
12+
Get Azure template files within a directory structure.
1313

1414
## SYNTAX
1515

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# PSDocs_Azure_Badges
2+
3+
## about_PSDocs_Azure_Badges
4+
5+
## SHORT DESCRIPTION
6+
7+
Describes how to insert template badges in to documentation.
8+
9+
## LONG DESCRIPTION
10+
11+
PSDocs allows external files to be included in Azure template documentation.
12+
Commonly this concept is used to include images that represent the validation status of the template.
13+
These images, are commonly referred to as _badges_.
14+
PSDocs can include badges that have been generated by an external validation tool.
15+
16+
To include badge markdown:
17+
18+
- Create a sub-directory called `.ps-docs` in the working path of PSDocs.
19+
This would normally be root directory (`$PWD`) of the repository where your Azure template are stored.
20+
- Create a file named `azure-template-badges.md` within the `.ps-docs` sub-directory.
21+
- When creating all files and folder use lower case names.
22+
23+
The contents of this file is automatically inserted in generated output after the title but before description.
24+
25+
### Include badges
26+
27+
To include badge images use standard markdown syntax within the `azure-template-badges.md` file.
28+
29+
> Markdown uses links to reference images.
30+
> A person viewing the page must have permissions to view the source image.
31+
> If not, the badge may be shown as a broken or placeholder image.
32+
33+
For example:
34+
35+
```markdown
36+
![label](https://image_uri)
37+
```
38+
39+
For example, a Github Actions badge for PSDocs.Azure would be:
40+
41+
```markdown
42+
![Analyze](https://github.com/Azure/PSDocs.Azure/workflows/Analyze/badge.svg)
43+
```
44+
45+
To include badges images with a clickable link use standard markdown syntax:
46+
47+
```markdown
48+
[![label](https://image_uri)](https://link_uri)
49+
```
50+
51+
For example, an Azure Pipelines badge for PSDocs.Azure would be:
52+
53+
```markdown
54+
[![Build Status](https://dev.azure.com/PSDocs/PSDocs.Azure/_apis/build/status/PSDocs.Azure-CI?branchName=refs%2Fpull%2F44%2Fmerge)](https://dev.azure.com/PSDocs/PSDocs.Azure/_build/latest?definitionId=1&branchName=refs%2Fpull%2F44%2Fmerge)
55+
```
56+
57+
### Dynamic links
58+
59+
In additional to inserting static content, some replacement tokens have been defined.
60+
When specified within `azure-template-badges.md` each token will be replaced when the file is included.
61+
The following replacement tokens have been defined:
62+
63+
- `{{ template_path }}` - The relative path of the template directory.
64+
- `{{ template_path_encoded }}` - The relative path of the template directory URL encoded.
65+
66+
For example, if the template path was `.\templates\storage\v1\template.json` the following would be used:
67+
68+
- `{{ template_path }}` = `templates/storage/v1`
69+
- `{{ template_path_encoded }}` = `templates%2fstorage%2fv1`
70+
71+
The follow example shows source markdown for including badges:
72+
73+
```markdown
74+
![Best Practice Check](https://azurequickstartsservice.blob.core.windows.net/badges/{{ template_path }}/BestPracticeResult.svg)
75+
[![Deploy To Azure](https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/1-CONTRIBUTION-GUIDE/images/deploytoazure.svg?sanitize=true)](https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2FAzure%2Fazure-quickstart-templates%2Fmaster%2F{{ template_path_encoded }}%2Fazuredeploy.json)
76+
```
77+
78+
After replacement the following would be the resulting output included in the template document:
79+
80+
```markdown
81+
![Best Practice Check](https://azurequickstartsservice.blob.core.windows.net/badges/templates/storage/v1/BestPracticeResult.svg)
82+
[![Deploy To Azure](https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/1-CONTRIBUTION-GUIDE/images/deploytoazure.svg?sanitize=true)](https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2FAzure%2Fazure-quickstart-templates%2Fmaster%2Ftemplates%2fstorage%2fv1%2Fazuredeploy.json)
83+
```
84+
85+
## NOTE
86+
87+
An online version of this document is available at https://github.com/Azure/PSDocs.Azure/blob/main/docs/concepts/en-US/about_PSDocs_Azure_Badges.md.
88+
89+
## KEYWORDS
90+
91+
- Badge
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# PSDocs_Azure_Configuration
2+
3+
## about_PSDocs_Azure_Configuration
4+
5+
## SHORT DESCRIPTION
6+
7+
Describes PSDocs configuration options specific to `PSDocs.Azure`.
8+
9+
## LONG DESCRIPTION
10+
11+
PSDocs exposes configuration options that can be used to customize execution of document generation.
12+
This topic describes what configuration options are available.
13+
14+
PSDocs configuration options can be specified by setting the configuration option in `ps-docs.yaml`.
15+
Additionally, configuration options can be configured in a baseline or set at runtime.
16+
For details of setting configuration options see [PSDocs options][options]
17+
18+
The following configurations options are available for use:
19+
20+
- [AZURE_USE_PARAMETER_FILE_SNIPPET](#azure_use_parameter_file_snippet)
21+
22+
### AZURE_USE_PARAMETER_FILE_SNIPPET
23+
24+
This configuration option determines if a parameter file snippet is added to documentation.
25+
By default, a snippet is generated.
26+
To prevent a parameter file snippet being generated, set this option to `false`.
27+
28+
Syntax:
29+
30+
```yaml
31+
configuration:
32+
AZURE_USE_PARAMETER_FILE_SNIPPET: bool # Either true or false
33+
```
34+
35+
Default:
36+
37+
```yaml
38+
# YAML: The default AZURE_USE_PARAMETER_FILE_SNIPPET configuration option
39+
configuration:
40+
AZURE_USE_PARAMETER_FILE_SNIPPET: true
41+
```
42+
43+
Example:
44+
45+
```yaml
46+
# YAML: Prevent parameter file snippet from being generated
47+
configuration:
48+
AZURE_USE_PARAMETER_FILE_SNIPPET: false
49+
```
50+
51+
## NOTE
52+
53+
An online version of this document is available at https://github.com/Azure/PSDocs.Azure/blob/main/docs/concepts/en-US/about_PSDocs_Azure_Configuration.md.
54+
55+
## KEYWORDS
56+
57+
- Configuration
58+
- Document
59+
- Snippet
60+
61+
[options]: https://github.com/BernieWhite/PSDocs/blob/main/docs/concepts/PSDocs/en-US/about_PSDocs_Configuration.md

pipeline.build.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ task VersionModule ModuleDependencies, {
108108
$manifest = Test-ModuleManifest -Path $manifestPath;
109109
$requiredModules = $manifest.RequiredModules | ForEach-Object -Process {
110110
if ($_.Name -eq 'PSDocs' -and $Configuration -eq 'Release') {
111-
@{ ModuleName = 'PSDocs'; ModuleVersion = '0.7.0' }
111+
@{ ModuleName = 'PSDocs'; ModuleVersion = '0.8.0' }
112112
}
113113
else {
114114
@{ ModuleName = $_.Name; ModuleVersion = $_.Version }
@@ -155,8 +155,8 @@ task PSScriptAnalyzer NuGet, {
155155

156156
# Synopsis: Install PSRule
157157
task PSRule NuGet, {
158-
if ($Null -eq (Get-InstalledModule -Name PSRule -MinimumVersion 1.0.1 -ErrorAction Ignore)) {
159-
Install-Module -Name PSRule -Repository PSGallery -MinimumVersion 1.0.1 -Scope CurrentUser -Force;
158+
if ($Null -eq (Get-InstalledModule -Name PSRule -MinimumVersion 1.0.3 -ErrorAction Ignore)) {
159+
Install-Module -Name PSRule -Repository PSGallery -MinimumVersion 1.0.3 -Scope CurrentUser -Force;
160160
}
161161
if ($Null -eq (Get-InstalledModule -Name PSRule.Rules.MSFT.OSS -MinimumVersion '0.1.0-B2012007' -AllowPrerelease -ErrorAction Ignore)) {
162162
Install-Module -Name PSRule.Rules.MSFT.OSS -Repository PSGallery -MinimumVersion '0.1.0-B2012007' -AllowPrerelease -Scope CurrentUser -Force;
@@ -166,8 +166,8 @@ task PSRule NuGet, {
166166

167167
# Synopsis: Install PSDocs
168168
task PSDocs NuGet, {
169-
if ($Null -eq (Get-InstalledModule -Name PSDocs -MinimumVersion 0.7.0 -ErrorAction Ignore)) {
170-
Install-Module -Name PSDocs -Repository PSGallery -MinimumVersion 0.7.0 -Scope CurrentUser -Force;
169+
if ($Null -eq (Get-InstalledModule -Name PSDocs -MinimumVersion 0.8.0 -ErrorAction Ignore)) {
170+
Install-Module -Name PSDocs -Repository PSGallery -MinimumVersion 0.8.0 -Scope CurrentUser -Force;
171171
}
172172
Import-Module -Name PSDocs -Verbose:$False;
173173
}

src/PSDocs.Azure/docs/Azure.Template.Doc.ps1

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,7 @@ function global:GetTemplateExample {
4747
$Path = Join-Path -Path $PWD -ChildPath $Path;
4848
}
4949
$template = Get-Content -Path $Path -Raw | ConvertFrom-Json;
50-
$normalPath = $Path;
51-
if ($normalPath.StartsWith($PWD, [System.StringComparison]::InvariantCultureIgnoreCase)) {
52-
$normalPath = $Path.Substring(([String]$PWD).Length);
53-
$normalPath = ($normalPath -replace '\\', '/').TrimStart('/');
54-
}
50+
$normalPath = GetTemplateRelativePath -Path $Path;
5551
$baseContent = [PSCustomObject]@{
5652
'$schema'= "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json`#"
5753
contentVersion = '1.0.0.0'
@@ -68,7 +64,7 @@ function global:GetTemplateExample {
6864
continue;
6965
}
7066

71-
if ($property.Value.type -eq 'securestring') {
67+
if ($property.Value.type -eq 'secureString') {
7268
$param = [PSCustomObject]@{
7369
reference = [PSCustomObject]@{
7470
keyVault = [PSCustomObject]@{
@@ -109,6 +105,27 @@ function global:GetTemplateExample {
109105
}
110106
}
111107

108+
# Synopsis: Function to get the relative path of the template
109+
function global:GetTemplateRelativePath {
110+
[CmdletBinding()]
111+
[OutputType([String])]
112+
param (
113+
[Parameter(Mandatory = $True)]
114+
[String]$Path
115+
)
116+
process {
117+
if (![System.IO.Path]::IsPathRooted($Path)) {
118+
$Path = [System.IO.Path]::Combine($PWD, $Path);
119+
}
120+
$normalPath = [System.IO.Path]::GetFullPath($Path);
121+
if ($normalPath.StartsWith($PWD, [System.StringComparison]::InvariantCultureIgnoreCase)) {
122+
$normalPath = $normalPath.Substring(([String]$PWD).Length);
123+
$normalPath = $normalPath.Replace('\', '/').TrimStart('/')
124+
}
125+
return $normalPath;
126+
}
127+
}
128+
112129
# A function to import metadata
113130
function global:GetTemplateMetadata {
114131
[CmdletBinding()]
@@ -164,6 +181,17 @@ Document 'README' {
164181
Title $LocalizedData.DefaultTitle
165182
}
166183

184+
# Add badges
185+
$relativePath = (Split-Path (GetTemplateRelativePath -Path $templatePath) -Parent).Replace('\', '/').TrimStart('/');
186+
$relativePathEncoded = [System.Web.HttpUtility]::UrlEncode($relativePath);
187+
Include '.ps-docs/azure-template-badges.md' -ErrorAction SilentlyContinue -BaseDirectory $PWD -Replace @{
188+
'{{ template_path }}' = $relativePath
189+
'{{ template_path_encoded }}' = $relativePathEncoded
190+
}
191+
192+
Write-Verbose $relativePath
193+
Write-Verbose $relativePathEncoded
194+
167195
# Write opening line
168196
if ($Null -ne $metadata -and [bool]$metadata.PSObject.Properties['description']) {
169197
$metadata.description
@@ -198,9 +226,15 @@ Document 'README' {
198226
@{ Name = $LocalizedData.Description; Expression = { $_.Description }}
199227
}
200228

201-
# Insert snippet
202-
$example = GetTemplateExample -Path $templatePath;
229+
# Insert snippets
203230
Section $LocalizedData.Snippets {
204-
$example | Code 'json'
231+
232+
# Add parameter file snippet
233+
if ($PSDocs.Configuration.GetBoolOrDefault('AZURE_USE_PARAMETER_FILE_SNIPPET', $True)) {
234+
Section $LocalizedData.ParameterFile {
235+
$example = GetTemplateExample -Path $templatePath;
236+
$example | Code 'json'
237+
}
238+
}
205239
}
206240
}

src/PSDocs.Azure/en/PSDocs-strings.psd1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@
1212
Type = 'Type'
1313
Name = 'Name'
1414
DefaultTitle = 'Azure template'
15+
ParameterFile = 'Parameter file'
1516
}

templates/storage/v1/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ resourceId | string | A unique resource identifier for the storage account.
104104

105105
## Snippets
106106

107+
### Parameter file
108+
107109
```json
108110
{
109111
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",

0 commit comments

Comments
 (0)