Skip to content

Commit aba0c5d

Browse files
author
James Brundage
committed
feat: Lerp README ( Fixes #5 )
1 parent e1a8fc6 commit aba0c5d

2 files changed

Lines changed: 301 additions & 1 deletion

File tree

README.md

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,88 @@
11
# Lerp
2-
Linear Interpolation in PowerShell
2+
[![Lerp](https://img.shields.io/powershellgallery/dt/Lerp)](https://www.powershellgallery.com/packages/Lerp/)
3+
##
4+
5+
## Installing and Importing
6+
7+
You can install Lerp from the [PowerShell gallery](https://powershellgallery.com/)
8+
9+
~~~PowerShell
10+
Install-Module Lerp -Scope CurrentUser -Force
11+
~~~
12+
13+
Once installed, you can import the module with:
14+
15+
~~~PowerShell
16+
Import-Module Lerp -PassThru
17+
~~~
18+
19+
## Functions
20+
Lerp has 2 functions
21+
### Get-Lerp
22+
#### Lerp!
23+
Lerp performs linear interpolation in one, two, three, or four dimensions.
24+
25+
This calculates the point along a straight line between two points.
26+
##### Parameters
27+
28+
|Name|Type|Description|
29+
|-|-|-|
30+
|Start|PSObject|The start point|
31+
|End|PSObject|The end point|
32+
|Amount|Single|The amount of lerp<br/>The percentage of change between two points|
33+
34+
##### Examples
35+
###### Example 1
36+
Lerp in 1D
37+
~~~PowerShell
38+
lerp 1 2 .5
39+
~~~
40+
###### Example 2
41+
Lerp in 2D
42+
~~~PowerShell
43+
lerp 1,2 3,4 .5
44+
~~~
45+
###### Example 3
46+
Lerp in 3D
47+
~~~PowerShell
48+
lerp 1,2,3 4,5,6 .5
49+
~~~
50+
###### Example 4
51+
Lerp in 4D
52+
~~~PowerShell
53+
lerp 1,2,3,4 5,6,7,8 .5
54+
~~~
55+
### Lerp
56+
#### Lerp!
57+
Lerp performs linear interpolation in one, two, three, or four dimensions.
58+
59+
This calculates the point along a straight line between two points.
60+
##### Parameters
61+
62+
|Name|Type|Description|
63+
|-|-|-|
64+
|Start|PSObject|The start point|
65+
|End|PSObject|The end point|
66+
|Amount|Single|The amount of lerp<br/>The percentage of change between two points|
67+
68+
##### Examples
69+
###### Example 1
70+
Lerp in 1D
71+
~~~PowerShell
72+
lerp 1 2 .5
73+
~~~
74+
###### Example 2
75+
Lerp in 2D
76+
~~~PowerShell
77+
lerp 1,2 3,4 .5
78+
~~~
79+
###### Example 3
80+
Lerp in 3D
81+
~~~PowerShell
82+
lerp 1,2,3 4,5,6 .5
83+
~~~
84+
###### Example 4
85+
Lerp in 4D
86+
~~~PowerShell
87+
lerp 1,2,3,4 5,6,7,8 .5
88+
~~~

README.md.ps1

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
<#
2+
.SYNOPSIS
3+
README.md.ps1
4+
.DESCRIPTION
5+
README.md.ps1 makes README.md
6+
7+
This is a simple and helpful scripting convention for writing READMEs.
8+
9+
`./README.md.ps1 > ./README.md`
10+
11+
Feel free to copy and paste this code.
12+
13+
Please document your parameters, and add NOTES.
14+
.NOTES
15+
This README.md.ps1 is used to generate help for a module.
16+
17+
It:
18+
19+
* Outputs the name and description
20+
* Provides installation instructions
21+
* Lists commands
22+
* Lists parameters
23+
* Lists examples
24+
.EXAMPLE
25+
./README.md.ps1 > ./README.md
26+
.EXAMPLE
27+
Get-Help ./README.md.ps1
28+
#>
29+
param(
30+
# The name of the module
31+
[string]$ModuleName = $($PSScriptRoot | Split-Path -Leaf),
32+
33+
# The domains that serve git repositories.
34+
# If the project uri links to this domain,
35+
# installation instructions will show how to import the module locally.
36+
[string[]]
37+
$GitDomains = @(
38+
'github.com', 'tangled.org', 'tangled.sh', 'codeberg.org'
39+
),
40+
41+
# If set, we don't need no badges.
42+
[switch]
43+
$NoBadge,
44+
45+
# If set, will not display gallery instructions or badges
46+
[switch]
47+
$NotOnGallery
48+
)
49+
50+
Push-Location $PSScriptRoot
51+
52+
# Import the module
53+
$module = Import-Module "./$ModuleName.psd1" -PassThru
54+
55+
# And output a header
56+
"# $module"
57+
58+
if (-not $NoBadge) {
59+
# If it is on the gallery, show the downloads badge.
60+
if (-not $NotOnGallery) {
61+
@(
62+
"[!"
63+
"[$ModuleName](https://img.shields.io/powershellgallery/dt/$ModuleName)"
64+
"](https://www.powershellgallery.com/packages/$ModuleName/)"
65+
) -join ''
66+
}
67+
}
68+
69+
# Show the module description
70+
"## $($module.Description)"
71+
72+
# Show any intro section defined in the manifest
73+
$module.PrivateData.PSData.PSIntro
74+
75+
#region Boilerplate installation instructions
76+
if (-not $NotOnGallery) {
77+
@"
78+
79+
## Installing and Importing
80+
81+
You can install $ModuleName from the [PowerShell gallery](https://powershellgallery.com/)
82+
83+
~~~PowerShell
84+
Install-Module $($ModuleName) -Scope CurrentUser -Force
85+
~~~
86+
87+
Once installed, you can import the module with:
88+
89+
~~~PowerShell
90+
Import-Module $ModuleName -PassThru
91+
~~~
92+
93+
"@
94+
}
95+
#endregion Gallery installation instructions
96+
97+
#region Git installation instructions
98+
$projectUri = $module.PrivateData.PSData.ProjectURI -as [uri]
99+
100+
if ($projectUri.DnsSafeHost -in $GitDomains) {
101+
@"
102+
103+
You can also clone the repo and import the module locally:
104+
105+
~~~PowerShell
106+
git clone $projectUri
107+
cd ./$ModuleName
108+
Import-Module ./ -PassThru
109+
~~~
110+
111+
"@
112+
}
113+
#endregion Git installation instructions
114+
115+
#region Exported Functions
116+
$exportedFunctions = $module.ExportedFunctions
117+
if ($exportedFunctions) {
118+
119+
"## Functions"
120+
121+
"$($ModuleName) has $($exportedFunctions.Count) function$(
122+
if ($exportedFunctions.Count -gt 1) { "s"}
123+
)"
124+
125+
foreach ($export in $exportedFunctions.Keys | Sort-Object) {
126+
# Get help if it there is help to get
127+
$help = Get-Help $export
128+
# If the help is a string,
129+
if ($help -is [string]) {
130+
# make it preformatted text
131+
"~~~"
132+
"$export"
133+
"~~~"
134+
} else {
135+
# Otherwise, add list the export
136+
"### $($export)"
137+
138+
# And make it's synopsis a header
139+
"#### $($help.SYNOPSIS)"
140+
141+
# put the description below that
142+
"$($help.Description.text -join [Environment]::NewLine)"
143+
144+
# Make a table of parameters
145+
if ($help.parameters.parameter) {
146+
"##### Parameters"
147+
148+
""
149+
150+
"|Name|Type|Description|"
151+
"|-|-|-|"
152+
foreach ($parameter in $help.Parameters.Parameter) {
153+
"|$($parameter.Name)|$($parameter.type.name)|$(
154+
$parameter.description.text -replace '(?>\r\n|\n)', '<br/>'
155+
)|"
156+
}
157+
158+
""
159+
}
160+
161+
# Show our examples
162+
"##### Examples"
163+
164+
$exampleNumber = 0
165+
foreach ($example in $help.examples.example) {
166+
$markdownLines = @()
167+
$exampleNumber++
168+
$nonCommentLine = $false
169+
"###### Example $exampleNumber"
170+
171+
# Combine the code and remarks
172+
$exampleLines =
173+
@(
174+
$example.Code
175+
foreach ($remark in $example.Remarks.text) {
176+
if (-not $remark) { continue }
177+
$remark
178+
}
179+
) -join ([Environment]::NewLine) -split '(?>\r\n|\n)' # and split into lines
180+
181+
# Go thru each line in the example as part of a loop
182+
$codeBlock = @(foreach ($exampleLine in $exampleLines) {
183+
# Any comments until the first uncommentedLine are markdown
184+
if ($exampleLine -match '^\#' -and -not $nonCommentLine) {
185+
$markdownLines += $exampleLine -replace '^\#\s{0,1}'
186+
} else {
187+
$nonCommentLine = $true
188+
$exampleLine
189+
}
190+
}) -join [Environment]::NewLine
191+
192+
$markdownLines
193+
"~~~PowerShell"
194+
$CodeBlock
195+
"~~~"
196+
}
197+
198+
$relatedUris = foreach ($link in $help.relatedLinks.navigationLink) {
199+
if ($link.uri) {
200+
$link.uri
201+
}
202+
}
203+
if ($relatedUris) {
204+
"#### Links"
205+
foreach ($related in $relatedUris) {
206+
"* [$related]($related)"
207+
}
208+
}
209+
}
210+
}
211+
}
212+
#endregion Exported Functions
213+
214+
Pop-Location

0 commit comments

Comments
 (0)