Stephanevg / PSHTML

Cross platform Powershell module to generate HTML markup language
https://pshtml.readthedocs.io/en/latest/
Other
165 stars 43 forks source link

PSHTML clutters general namespace #292

Closed yecril71pl closed 2 years ago

yecril71pl commented 4 years ago

Subject of the issue

The commands published are not PowerShell commands. PowerShell commands should conform to the convention Verb-Object.

Steps to reproduce

Tell us how to reproduce this issue. What is A?

Expected behaviour

A should be an alias for command FORMAT-HTMLANCHOR.

Actual behaviour

A is a command in module PSHTML.

yecril71pl commented 4 years ago
  1. This must be the reason why you have SELECTTAG instead of SELECT.
  2. The attached code is a proof of concept that you can avoid this problem altogether by using a passive DSL:
    FUNCTION OUT-HTML { 
    $ARGS. AST. ENDBLOCK | % { IF ($_) {
    OUT-HTML $_
    }
    }
    $ARGS. STATEMENTS. PIPELINEELEMENTS | % { $_. EXPRESSION. VALUE
    (,$_. COMMANDELEMENTS) | % {} { $_ | % { 
    IF ($_. STRINGCONSTANTTYPE) { 
    -JOIN ('<', $_. VALUE)
    } 
    IF ($_. EXPRESSION) 
    { $_. EXPRESSION
    } 
    IF ($_. PARAMETERNAME) { -JOIN (' ', $_. PARAMETERNAME, '=', $_. ARGUMENT) }
    }
    } { IF ($_) {
    '>' } 
    $_. SCRIPTBLOCK. ENDBLOCK | SELECT -LAST 1 | % { OUT-HTML $_
    }
    IF ($_. SCRIPTBLOCK) {
    -JOIN (
    '</',
    $_. VALUE,
    '>')
    }
    } {}
    }
    }

    Here is how I use it:

    OUT-HTML { 
    HTML -LANG:EN { 
    META -HTTP-EQUIV:CONTENT-TYPE -CONTENT: 'TEXT/HTML; CHARSET=US-ASCII'
    TITLE {
    'Some title'
    }
    P {
    'Yadda yadda yadda'
    } 
    }
    }

    Note: Empty elements like META do not have a block parameter.

Stephanevg commented 4 years ago

Thanks for opening an issue @yecril71pl I actually don't see this as a problem. The nature of the HTML syntax forces us to use another type of naming convention for the functions than the 'recommended (but not required)' verb-noun specification.

Also, there is already 'kind of' a similar private function which does the same as your 'out-html' called 'Set-pshtmltag' (If I recall correctly).

'IF' we would go with adding aliases, we should point them to that function. Nevertheless, I actually don't think it is needed, and I think it is totally ok to have functions called 'a' or 'br' when a module such as pshtml is loaded.