Source

templ / misc / functions.templ

The default branch has multiple heads

Full commit
{  rem "

This template generates an HTML page containing a list and description of 
every built in executable object (functions, macros, and operators) for
templ.

"
}{syntax html}<html>
    <head>
        <title>templ builtin functions, operators, and macros</title>
        <style type='text/css'>
        /* <![CDATA[ */
            
            h2 \{
                margin: 10px 0 8px 0;
            \}
            h3 \{
                margin: 8px 0 4px 0;
            \}
            h4 \{
                margin: 4px 0 16px 0;
            \}

            li \{
                border-bottom: 1px solid;
            \}

        /* ]]> */
        </style>
    </head>
    <body>
        <h1>templ builtin functions, operators, and macros</h1>

            <ul style='padding: 0; list-item-type: none;'>
{end-syntax html}
{v{:
    % Get the list of vars now, before we add any of our own.
    {set VARS {sort {vars}}}
    {set HTMLESC {lambda {:
        {strrep > &gt;
            {strrep < &lt; {@ 0 {$ :argv}}}
        }
    }}}
    % Iterate over all variable symbols, which includes all available functions
    {for FUNCNAME {$ VARS}
    {:
        % Set FUNC to be the actual value
        {set FUNC {$ {$ FUNCNAME}}}

        %See if it's an executable
        {if {is-exe {$ FUNC}}
        {:
            % Only use the symbols that are the actual name of the function, not all the aliases.
            {if {=== {$ FUNCNAME} {exe-name {$ FUNC}} }
            {:
                %Show the canonical name.
                {spit <<<
            <li class='exe'>
                <a title="{HTMLESC {$ FUNCNAME} }">
                <h2 class='name'>{HTMLESC {$ FUNCNAME }}</h2>
                >>>
                }

                % Show the aliases.
                {set ALIASES {aliases {$ FUNC}}}
                {if {len {$ ALIASES}} {:
                    {spit <<<
                <h3 class='aliases'>aka: {implode ", " {gen
                        ALIAS {$ ALIASES} {implode "" {' "\"<span class='alias'>" {$ ALIAS} "</span>\""}}
                    }}</h3>
                    >>> }
                }}

                %What type of executable.
                {spit <<<
                <h4 class='type'>{if
                        
                        {is-func {$ FUNC}}
                        function

                        {is-oper {$ FUNC}}
                        operator
                
                        {is-macro {$ FUNC}}
                        macro

                    }</h4>
                >>>
                }

                %The doc string
                {spit <<<
                <pre class='doc'>{HTMLESC {doc {$ FUNC }}}</pre>
            </li>
                >>>
                }

            }} %end if it's the name
        }} %end if is-exe
    }} %end for
}}
        </ul>
    </body>
</html>
{ dont
 vim: set syntax=templ:
}