I am creating a set of LESS mixins with Visual Studio/Web Essentials.
Is it possible to write XML-type documentation for LESS mixins? Or perhaps have an enum to limit the parameters that are input?
For instance, with this mixin:
.background-clip(@value)
{
-webkit-background-clip: @value;
-moz-background-clip: @value;
background-clip: @value;
}
It would be nice to have some documentation that describes the three possible values, just like when you are creating a normal CSS selector for background-clip -
An "Enum" List of Accepted Values
This would be handled through a parametric mixin call, like this:
This only allows the four values given to be passed in order for it to activate. So this:
Would yield this output (ignoring the second call because it is not valid):
Commented Feedback
If feedback to the user was wanted, then a second parametric mixin could offer that through a comment.
OPTION 1 is pure comment
Then the above test case would have this additional output:
OPTION 2 includes a bogus property value to show what the improper
@value
input was:Which outputs this additional test case CSS:
Browsers would ignore the unrecognized "property" of
invalid-background-clip-input-equals
, but it would alert one viewing the compiled css what invalid the value passed was.OPTION 3 includes a bogus (i.e. undefined) mixin to potentially force a compilation error (different compilers might handle undefined mixins differently):
Which outputs in this compiler this information:
This may be a way to "force" the less programmer to input a valid value by throwing an error. Note how in this case the actual undefined mixin giving the error is the
.background-clip-undefined()
, yet this compiler is actually providing the "calling" information.background-clip(something)
which is really what the error is.One could combine options 2 and 3 so that if an error is not thrown by a compiler, at least the comment feedback is visible.