WIP on docs
This commit is contained in:
parent
5e28714215
commit
7b5912e5e2
@ -519,28 +519,28 @@ module HtmxAttrs =
|
||||
let _sseConnect = attr "sse-connect"
|
||||
|
||||
|
||||
/// Script tags to pull htmx into a web page
|
||||
/// <summary>Script tags to pull htmx into a web page</summary>
|
||||
module Script =
|
||||
|
||||
/// Script tag to load the minified version from unpkg.com
|
||||
/// <summary>Script tag to load the minified version from unpkg.com</summary>
|
||||
let minified =
|
||||
script [ _src "https://unpkg.com/htmx.org@2.0.4"
|
||||
_integrity "sha384-HGfztofotfshcF7+8n44JQL2oJmowVChPTg48S+jvZoztPfvwD79OC/LTtG6dMp+"
|
||||
_crossorigin "anonymous" ] []
|
||||
|
||||
/// Script tag to load the unminified version from unpkg.com
|
||||
/// <summary>Script tag to load the unminified version from unpkg.com</summary>
|
||||
let unminified =
|
||||
script [ _src "https://unpkg.com/htmx.org@2.0.4/dist/htmx.js"
|
||||
_integrity "sha384-oeUn82QNXPuVkGCkcrInrS1twIxKhkZiFfr2TdiuObZ3n3yIeMiqcRzkIcguaof1"
|
||||
_crossorigin "anonymous" ] []
|
||||
|
||||
|
||||
/// Functions to extract and render an HTML fragment from a document
|
||||
/// <summary>Functions to extract and render an HTML fragment from a document</summary>
|
||||
[<RequireQualifiedAccess>]
|
||||
module RenderFragment =
|
||||
|
||||
/// Does this element have an ID matching the requested ID name?
|
||||
let private isIdElement nodeId (elt : XmlElement) =
|
||||
let private isIdElement nodeId (elt: XmlElement) =
|
||||
snd elt
|
||||
|> Array.exists (fun attr ->
|
||||
match attr with
|
||||
@ -548,62 +548,83 @@ module RenderFragment =
|
||||
| Boolean _ -> false)
|
||||
|
||||
/// Generate a message if the requested ID node is not found
|
||||
let private nodeNotFound (nodeId : string) =
|
||||
let private nodeNotFound (nodeId: string) =
|
||||
$"<em>– ID {nodeId} not found –</em>"
|
||||
|
||||
/// Find the node with the named ID
|
||||
let rec findIdNode nodeId (node : XmlNode) : XmlNode option =
|
||||
/// <summary>Find the node with the named ID</summary>
|
||||
/// <param name="nodeId">The <tt>id</tt> attribute to find</param>
|
||||
/// <param name="node">The node tree to search</param>
|
||||
/// <returns>The node with the requested <tt>id</tt> attribute, or <tt>None</tt> if it was not found</returns>
|
||||
let rec findIdNode nodeId (node: XmlNode) : XmlNode option =
|
||||
match node with
|
||||
| Text _ -> None
|
||||
| VoidElement elt -> if isIdElement nodeId elt then Some node else None
|
||||
| ParentNode (elt, children) ->
|
||||
if isIdElement nodeId elt then Some node else children |> List.tryPick (fun c -> findIdNode nodeId c)
|
||||
if isIdElement nodeId elt then Some node else children |> List.tryPick (findIdNode nodeId)
|
||||
|
||||
/// Functions to render a fragment as a string
|
||||
/// <summary>Functions to render a fragment as a string</summary>
|
||||
[<RequireQualifiedAccess>]
|
||||
module AsString =
|
||||
|
||||
/// Render to HTML for the given ID
|
||||
let htmlFromNodes nodeId (nodes : XmlNode list) =
|
||||
match nodes |> List.tryPick(fun node -> findIdNode nodeId node) with
|
||||
/// <summary>Render to HTML for the given ID</summary>
|
||||
/// <param name="nodeId">The <tt>id</tt> attribute for the node to be rendered</param>
|
||||
/// <param name="nodes">The node trees to search</param>
|
||||
/// <returns>The HTML for the given <tt>id</tt> node, or an error message if it was not found</returns>
|
||||
let htmlFromNodes nodeId (nodes: XmlNode list) =
|
||||
match nodes |> List.tryPick (findIdNode nodeId) with
|
||||
| Some idNode -> RenderView.AsString.htmlNode idNode
|
||||
| None -> nodeNotFound nodeId
|
||||
|
||||
/// Render to HTML for the given ID
|
||||
/// <summary>Render to HTML for the given ID</summary>
|
||||
/// <param name="nodeId">The <tt>id</tt> attribute for the node to be rendered</param>
|
||||
/// <param name="node">The node tree to search</param>
|
||||
/// <returns>The HTML for the given <tt>id</tt> node, or an error message if it was not found</returns>
|
||||
let htmlFromNode nodeId node =
|
||||
match findIdNode nodeId node with
|
||||
| Some idNode -> RenderView.AsString.htmlNode idNode
|
||||
| None -> nodeNotFound nodeId
|
||||
|
||||
/// Functions to render a fragment as bytes
|
||||
/// <summary>Functions to render a fragment as bytes</summary>
|
||||
[<RequireQualifiedAccess>]
|
||||
module AsBytes =
|
||||
|
||||
let private utf8 = System.Text.Encoding.UTF8
|
||||
|
||||
/// Render to HTML for the given ID
|
||||
let htmlFromNodes nodeId (nodes : XmlNode list) =
|
||||
match nodes |> List.tryPick(fun node -> findIdNode nodeId node) with
|
||||
/// <summary>Render to bytes for the given ID</summary>
|
||||
/// <param name="nodeId">The <tt>id</tt> attribute for the node to be rendered</param>
|
||||
/// <param name="nodes">The node trees to search</param>
|
||||
/// <returns>The bytes for the given <tt>id</tt> node, or an error message if it was not found</returns>
|
||||
let htmlFromNodes nodeId (nodes: XmlNode list) =
|
||||
match nodes |> List.tryPick (findIdNode nodeId) with
|
||||
| Some idNode -> RenderView.AsBytes.htmlNode idNode
|
||||
| None -> nodeNotFound nodeId |> utf8.GetBytes
|
||||
|
||||
/// Render to HTML for the given ID
|
||||
/// <summary>Render to bytes for the given ID</summary>
|
||||
/// <param name="nodeId">The <tt>id</tt> attribute for the node to be rendered</param>
|
||||
/// <param name="node">The node tree to search</param>
|
||||
/// <returns>The bytes for the given <tt>id</tt> node, or an error message if it was not found</returns>
|
||||
let htmlFromNode nodeId node =
|
||||
match findIdNode nodeId node with
|
||||
| Some idNode -> RenderView.AsBytes.htmlNode idNode
|
||||
| None -> nodeNotFound nodeId |> utf8.GetBytes
|
||||
|
||||
/// Functions to render a fragment into a StringBuilder
|
||||
/// <summary>Functions to render a fragment into a StringBuilder</summary>
|
||||
[<RequireQualifiedAccess>]
|
||||
module IntoStringBuilder =
|
||||
|
||||
/// Render to HTML for the given ID
|
||||
let htmlFromNodes sb nodeId (nodes : XmlNode list) =
|
||||
match nodes |> List.tryPick(fun node -> findIdNode nodeId node) with
|
||||
/// <summary>Render HTML into a <tt>StringBuilder</tt> for the given ID</summary>
|
||||
/// <param name="sb">The <tt>StringBuilder</tt> into which the bytes will be rendered</param>
|
||||
/// <param name="nodeId">The <tt>id</tt> attribute for the node to be rendered</param>
|
||||
/// <param name="nodes">The node trees to search</param>
|
||||
let htmlFromNodes sb nodeId (nodes: XmlNode list) =
|
||||
match nodes |> List.tryPick (findIdNode nodeId) with
|
||||
| Some idNode -> RenderView.IntoStringBuilder.htmlNode sb idNode
|
||||
| None -> nodeNotFound nodeId |> sb.Append |> ignore
|
||||
|
||||
/// Render to HTML for the given ID
|
||||
/// <summary>Render HTML into a <tt>StringBuilder</tt> for the given ID</summary>
|
||||
/// <param name="sb">The <tt>StringBuilder</tt> into which the bytes will be rendered</param>
|
||||
/// <param name="nodeId">The <tt>id</tt> attribute for the node to be rendered</param>
|
||||
/// <param name="node">The node tree to search</param>
|
||||
let htmlFromNode sb nodeId node =
|
||||
match findIdNode nodeId node with
|
||||
| Some idNode -> RenderView.IntoStringBuilder.htmlNode sb idNode
|
||||
|
Loading…
x
Reference in New Issue
Block a user