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