WIP on docs
This commit is contained in:
		
							parent
							
								
									5e28714215
								
							
						
					
					
						commit
						7b5912e5e2
					
				@ -519,23 +519,23 @@ 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 =
 | 
			
		||||
    
 | 
			
		||||
@ -551,59 +551,80 @@ module RenderFragment =
 | 
			
		||||
    let private nodeNotFound (nodeId: string) =
 | 
			
		||||
        $"<em>– ID {nodeId} not found –</em>"
 | 
			
		||||
    
 | 
			
		||||
    /// Find the node with the named ID
 | 
			
		||||
    /// <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
 | 
			
		||||
        /// <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(fun node -> findIdNode nodeId node) with
 | 
			
		||||
            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
 | 
			
		||||
        /// <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(fun node -> findIdNode nodeId node) with
 | 
			
		||||
            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
 | 
			
		||||
        /// <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(fun node -> findIdNode nodeId node) with
 | 
			
		||||
            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