Skip to content

Commit

Permalink
Merge pull request #3 from nojaf/menu-unit-test
Browse files Browse the repository at this point in the history
  • Loading branch information
alanlomeli authored Aug 16, 2022
2 parents 930006f + a93b76d commit 8b462ad
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/styling.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ with the existing default template.
## Customizing menu items by template

You can add advanced stylings to the sidebar generated menu items by creating a new template for it.
You can add advanced styling to the sidebar generated menu items by creating a new template for it.
`fsdoc` will look for menu templates in the `--input` folder which defaults to the docs folder.

To customize the generated menu-item headers, use file `_menu_template.html` with starting template:
Expand All @@ -132,7 +132,7 @@ To customize the generated menu-item headers, use file `_menu_template.html` wit
{{fsdocs-menu-items}}
```

Similarly, to customize the individual menu item list, use file `_menu_item_template.html` with starting template:
Similarly, to customize the individual menu item list, use file `_menu-item_template.html` with starting template:

```html
<li class="nav-item"><a href="{{fsdocs-menu-item-link}}" class="nav-link">{{fsdocs-menu-item-content}}</a></li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<Compile Include="GenerateMarkdown.fs" />
<Compile Include="GenerateSearchIndex.fs" />
<Compile Include="ApiDocs.fs" />
<InternalsVisibleTo Include="FSharp.ApiDocs.Tests" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FSharp.Formatting.Common\FSharp.Formatting.Common.fsproj" />
Expand Down
61 changes: 61 additions & 0 deletions tests/FSharp.ApiDocs.Tests/ApiDocsTests.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[<NUnit.Framework.TestFixture>]
module ApiDocs.Tests

open System
open FsUnit
open System.IO
open NUnit.Framework
Expand Down Expand Up @@ -1165,6 +1166,66 @@ let ``Metadata generates cross-type links for Inline Code`` (format: OutputForma
format.ExtensionInUrl
)

[<Test>]
[<TestCaseSource("formats")>]
let ``Phased generation allows a custom menu template folder`` (format: OutputFormat) =
let library = testBin </> "FsLib1.dll" |> fullpath
let inputs = ApiDocInput.FromFile(library)
let output = getOutputDir format "Phased"
let templateFolder = DirectoryInfo(Directory.GetCurrentDirectory() </> "menu")
templateFolder.Create()

File.WriteAllText(
templateFolder.FullName </> "_menu_template.html",
"""
HEADER: {{fsdocs-menu-header-content}}
HEADER ID: {{fsdocs-menu-header-id}}
ITEMS: {{fsdocs-menu-items}}
"""
)

File.WriteAllText(
templateFolder.FullName </> "_menu-item_template.html",
"""
LINK: {{fsdocs-menu-item-link}}
LINK ID: {{fsdocs-menu-item-id}}
CONTENT: {{fsdocs-menu-item-content}}
"""
)

let _, substitutions, _, _ =
match format with
| OutputFormat.Html ->
ApiDocs.GenerateHtmlPhased([ inputs ], output, "Collection", [], menuTemplateFolder = "menu")
| OutputFormat.Markdown ->
ApiDocs.GenerateMarkdownPhased([ inputs ], output, "Collection", [], menuTemplateFolder = "menu")

let listOfNamespaces =
substitutions
|> Seq.choose (function
| key, content ->
if key = ParamKeys.``fsdocs-list-of-namespaces`` then
Some content
else
None)
|> Seq.head
|> fun s ->
s
.Replace("\r", "")
.Split('\n', StringSplitOptions.RemoveEmptyEntries)
|> Array.map (fun s -> s.Trim())
|> String.concat "\n"

Assert.AreEqual(
$"""HEADER: API Reference
HEADER ID: api_reference
ITEMS:
LINK: /reference/index{format.ExtensionInUrl}
LINK ID: all_namespaces
CONTENT: All Namespaces"""
.Replace("\r", ""),
listOfNamespaces
)

let runtest testfn =
try
Expand Down

0 comments on commit 8b462ad

Please sign in to comment.