-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
How to introduce pshtml.document while avoiding a breaking change #293
Comments
Rereading this issue, I feel like the easiest way to to this is to perhaps add changes on the
|
For this to work, we create a new class
(Or perhaps 'object' instead of It should have a method called something like |
So, going further in this monologue, I actually enhanced the existing (and year old prototype) to support But the full prototype is working here tagv3Prototype.ps1 It actually works pretty nicely. We only need to extend the current If((Get-pshtmlOutputPreference) -eq 'dynamic'){
return $tag.getHtml()
}Else{
#Is static
return $tag
}
When the OutputPreference is 'Dynamic' if will rend the HTML text. StaticGet-pshtmlOutputPreference
$b = div -id "test dynamic" -Class "dynamic" -Content {"Plop"}
$b
#outputs
static
TagName id Class Children
------- -- ----- --------
div test dynamic dynamic {Plop} dynamicSame code, this time, $OutputPreference is set to 'dynamic'
Get-pshtmlOutputPreference
$b = div -id "test dynamic" -Class "dynamic" -Content {"Plop"}
$b
#outputs
dynamic
<div id='test dynamic' class='dynamic' >Plop</div>
I have already extended the code in the tagv3 branch branch with the code that creates everything around the $OutputPreference variable (Configuration, function etc...). The next step - if we decide to go further with this - is to try to convert the tag functions with the above |
I have wanted to add a main PSHTML object to be able to parse the HTML tree programmatically.
The base research and prototype as been done in #218.
Additionally, we have also looked into how to parse existing html static documents using the HTMLAgilityPack and parse it into the PSHTM.Document format in #250
In either case, it involved in quite a heavy refactoring (which would be ok to do if we decide to do it) but the bigger problem resides in the fact that we would break how pshtml currently works.
Problem
This is how pshtml currently works:
generates immediatly the following string
The current version of
pshtml.document
prototype:GenerateHtml() becomes mandatory to generate the html tree
It might be not that obvious, but the method
.Generatehtml()
becomes mandatory to actually generate the html structure. If this method is not called, only the objects are sent back.This would be a breaking change. Learning from the experiences of the recent update of the pester module to version 5 where some breaking changes have been introduced, I want to avoid the current users of pshtml to force them to relearn how to use pshtml.
The main objective would be to create the pshtml.document object - without impacting current existing scripts.
By there, I am not saying we won't increment the major version number of pshtml, but I really want to avoid the unpleasnt user experience of people needing to change:
a) Their existing habits when using pshtml
b) Existing scripts that use pshtml.
Proposed Solution / Opening discussions
I have thought this one through, and we have two different ways of how pshtml could potentially work.
pshtml.Document
object - which I would call "static generation". (Because the html tree is generated 'on demand' using the.GenerateHtml()
method.)I think that we need to have both of these methodologies to work in pshtml to:
pshtml.document
which will be the root source of potentially new features / extensions.Since it is an
either / or
type of functionality, I think the end user should have the choice of how pshtml should work.Possible solution 1
Similar to the
$VerbosePreference
global variable, we could introduce a similar type of variable to control the default way pshtml will behave. (something like$PshtmlOutputPreference
perhaps?)Accepted values:
The pshtmlOutputPreference variable would define how pshtml behaves:
If set to
dynamic
pshtml would generate the html tree right away (Just as it is currently working).If set to 'static' pshtml would return the
pshtml.document' object. the html tree can than be generated using the
.GenerateHtml()` method.possible solution 2
Similar to the solution 1, we could control the
PshtmlOutputpreference
via thePshtml.Configuration.json
document.Possible solution 3
Introduce a new cmdlet that will be the only entry point for the pshtml.document. Something like
New-PshtmlObject
perhaps?New-PSHTMLObject would create an object of type
pshtml.document
. The html structure could only be created via methods located on thepshtml.document' (
.AddChild()` for instance).It will offer a new way of generating the pshtml object structure in a standardized way, without breaking the existing user experience. but this way might be a more clumsy way to use it.
possible solution 4
A combination of solution 1 and 2 :)
I am open to to other possible solution on how to offer this double functionality to the current users of pshtml, while still improving the code base to facilitate the developers work to introduce new features.
The text was updated successfully, but these errors were encountered: