Class [Color] is not available when using import-module
Stephanevg opened this issue ยท 13 comments
It is impossible to use the static method [Class]::Red (green etc..) when the module is loaded using import-module.
On a higher note, it would make sense to perhaps have a function, that would return the color type
Get-PSHTMLColor -Type RGB -Color Red
Returns -> rgb(220,20,60)
Add more types
Hi Stephane,
I've been looking at this bug/feature request.
It appears that classes can't be accessed from a module without using 'Using module ', unless you wrap them in a function.
I've done a fairly major overhaul to the Color class, setting up a generic way of dealing with colors and adding the ability to output them in hex "#FFFFFF" format. The class has got support for the 140+ W3 color names (instead of those originally part of the module) but it does add 290+ lines to the module.
I've also created a Get-PSTMLColor function that generates rgb, rgba or hex format values based on a color name.
Regards,
Stuart.
Hi @wightsci
Well that sounds like a pretty cool PR actually!
Any chance you submit your changes back to the module? that would be really awesome!
Hi @wightsci Did you manage to do something on this one?
I am close to ship a new version, and adding Get-PSHTMLColor
cmdlet would be a very nice addition.
Really cool PR @wightsci ! Thank you so much for participating in this project!!!
I do have two small remarks (Actually a question and a remark) before I merge your PR:
-
I noticed you pushed to the wrong branch (you pushed directly to the master branch), could you please change it to the 'dev' branch please? that be great!
-
Also, I don't think I saw any pester tests for your code. are you planning to add some?
I've rebased the PR to the dev branch as requested. Unfortunately I haven't created Pester tests. It would probably take another day or so. Would that be OK?
Thanks @wightsci ! Yeah, that would be ok.
(You don't need to write a test for every color. One test that generates a color for each of the values from the [ValidateSet("hex","hsl","hsla","rgb","rgba")]
should be enough
Also, I see the $type
parameter is mandatory. Do you think it would make sense to set it as mandator= $false, and propose a default value ( RGB perhaps, as it is the most common one?)
It would make it easier for the users that don't know what they actually want. don't you think?
One last thing, could you also add a short comment based help section to your function?
it helps to auto generate the end-users documentation. You can find an example here --> https://github.com/Stephanevg/PSHTML/blob/master/Code/Functions/Public/New-PSHTMLChartBarDataSet.ps1
Hi,
There's already comment-based help for Get-PSHTMLColor (lines 1696 to 1739). I'm happy to change $type to default to rgb.
Apologies, put the comment-based help in the wrong part of the function.
Added new commit to PR with Pester tests and a fixed hsl calculation that was identified by the Pester tests!