-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #758 from alanlomeli/customize-menu-items
Proposal for custom templating
- Loading branch information
Showing
11 changed files
with
310 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,3 +45,4 @@ version.props | |
src/Common/AssemblyInfo.?s | ||
tests/FSharp.Literate.Tests/output1/ | ||
.vscode/ | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
module FSharp.Formatting.Common.Menu | ||
|
||
open System | ||
open System.IO | ||
open FSharp.Formatting.Templating | ||
|
||
type MenuItem = { Link: string; Content: string } | ||
|
||
let private snakeCase (v: string) = | ||
System | ||
.Text | ||
.RegularExpressions | ||
.Regex | ||
.Replace(v, "[A-Z]", "$0") | ||
.Replace(" ", "_") | ||
.ToLower() | ||
|
||
let createMenu (input: string) (header: string) (items: MenuItem list) : string = | ||
let pwd = Directory.GetCurrentDirectory() | ||
let menuTemplate = File.ReadAllText(Path.Combine(pwd, input, "_menu_template.html")) | ||
let menuItemTemplate = File.ReadAllText(Path.Combine(pwd, input, "_menu-item_template.html")) | ||
|
||
let menuItems = | ||
items | ||
|> List.map (fun (model: MenuItem) -> | ||
let link = model.Link | ||
let title = System.Web.HttpUtility.HtmlEncode model.Content | ||
let id = snakeCase title | ||
|
||
SimpleTemplating.ApplySubstitutionsInText | ||
[| ParamKeys.``fsdocs-menu-item-link``, link | ||
ParamKeys.``fsdocs-menu-item-content``, title | ||
ParamKeys.``fsdocs-menu-item-id``, id |] | ||
menuItemTemplate) | ||
|> String.concat "\n" | ||
|
||
SimpleTemplating.ApplySubstitutionsInText | ||
[| ParamKeys.``fsdocs-menu-header-content``, header | ||
ParamKeys.``fsdocs-menu-header-id``, snakeCase header | ||
ParamKeys.``fsdocs-menu-items``, menuItems |] | ||
menuTemplate | ||
|
||
let isTemplatingAvailable (input: string) : bool = | ||
let pwd = Directory.GetCurrentDirectory() | ||
let menuTemplate = Path.Combine(pwd, input, "_menu_template.html") | ||
let menuItemTemplate = Path.Combine(pwd, input, "_menu-item_template.html") | ||
File.Exists(menuTemplate) && File.Exists(menuItemTemplate) | ||
|
||
let getLastWriteTimes (input: string) : DateTime list = | ||
let pwd = Directory.GetCurrentDirectory() | ||
|
||
let getLastWriteTime f = | ||
Path.Combine(pwd, input, f) |> File.GetLastWriteTime | ||
|
||
[ getLastWriteTime "_menu_template.html"; getLastWriteTime "_menu-item_template.html" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.