How to make the review itself was written?
.className {
some style...
// .className .children (how to write this comments?)
.children {
some style...
}
}
If you want that comment will be visible after LESS compilation as a simple CSS comment, simply replace // (LESS single row comment) with /*...*/ (CSS comment). Probably you have to move it down into the relative rule, to be sure that is placed near it. So:
.className {
some style...
.children {
/* .className .children (how to write this comments?) */
some style...
}
}
Please note that this is the default behaviour if final code will not minified (minification strips all comments, LESS and CSS ones).
Final code:
.className {
some style...
}
.className .children {
/* .className .children (how to write this comments?) */
some style...
}
Related
On the trail of this question by Codesections, I'm trying to add a phaser to a variable using traits. Something like this:
my &doing-good is Block will enter {
.add_phaser: "ENTER",
{
if Backtrace.new.grep: { .subname ~~ /bad/ } {
fail("Not authorized to call this");
}
}
};
This fails with is trait on &-sigil variable not yet implemented. Sorry.
I arrived to this because there seems no way to declare that as a block; by default is a Callable, and add_method does not work on Callables, apparently. Any other way of doing this?
I want to bring unqualified names of functions in a template into my working/local scope. Eg.:
struct St {
int t = 44;
}
template Inter(T) { // the 'base' template/interface/parameterized-module
alias Self = T;
void myfunc(ref self) {
writeln("Inter: ", Self.stringof, " : ", 11);
}
}
template Inter(T: St) {
/+ ^^^^^ the 'specialization' which is really
the implementation for the template-module for type `St`
+/
alias Self = T;
void myfunc(ref Self self) {
writeln("Inter TWO (St)! : ", Self.stringof, " : ", self.t);
}
}
void main(string[] args){
St s;
/+ SOMETHING HERE +/
/+ s.myfunc(s); +/ // <- I want to be able to do this
}
Something like a mixin template would work but at the cost of lots of needless code duplication (I wouldn't be duplicating anything but the compiler would have to work with lots of the same code).
Put another way: Yes, UFCS would probably not even work in this case even if I could bring myfunc(self) into scope of main(). But my question is how do I bring stuff inside a template's scope openly/unqualified into another scope? Or yet another way: Imagine I'm making a nested module (I don't know how to do this) that's inside a mixin template, instantiating the mixin with the type I want, then importing everything in mymodule_templ!MyType into my working scope.
Ask for clarifications in the comments please. My questions are seldom readable on my first formulation of them. Thanks!
You mentioned mixin template so maybe you tried it and it didn't work.... but what you're asking for is exactly what a mixin template does:
import std.stdio;
struct St {
int t = 44;
}
// it needs to be declared as a mixin template
mixin template Inter(T) {
alias Self = T;
void myfunc(ref self) {
writeln("Inter: ", Self.stringof, " : ", 11);
}
}
// the overload is also a mixin template....
mixin template Inter(T: St) {
alias Self = T;
void myfunc(ref Self self) {
writeln("Inter TWO (St)! : ", Self.stringof, " : ", self.t);
}
}
mixin Inter!St; // and this is where you mix it in to the current scope
void main(string[] args){
St s;
s.myfunc(); // boom, this works!
}
You could also mix it in to main, but UFCS won't work there simply because ufcs doesn't consider local symbols, it wouldn't work if you hand-wrote the function either. It only looks at the module level.
So the mixin keyword is the import functionality you're looking for.... unless I misunderstood your question.
I would like to generate CSS using less compiler..
Originally I have a less file and I need to prepend every rule with some class (not a nested selector)
.E{ .F{ color:blue; } }
is going to generate
.E .F{color:blue;}
In my case I don't want it to be nested but should get generated in the following way
.E.F{color:blue;}
.E {
&.F { color:blue; }
}
Lets say I have a LESS file like this...
#myVariable: 5px;
.myRule {
myProperty1: #myVariable;
myProperty2: myOtherValue1;
}
I'll get this outcome when I compile this with LESS.
.myRule {
myProperty1: 5px;
myProperty2: myOtherValue1;
}
However, instead of having #myVariable defined inside this LESS file, I want to reference it from somewhere else. My referenced file, may or may not contain this variable. Currently, if the variable is missing, I'll get a result like this.
.myRule {
myProperty1: ;
myProperty2: myOtherValue1;
}
Is there any LESS functionality that would allow me to remove the property completely if the variable was not provided so that my output was like this.
.myRule {
myProperty2: myOtherValue1;
}
I've looked through the language features of LESS and couldn't find anything that does this. Maybe I'm missing something?
This would be the syntax that I'm imagining, but I'm pretty sure this doesn't exist.
.myRule {
when(exists(#myVariable)) {
myProperty1: #myVariable;
}
myProperty2: myOtherValue1;
}
Set Default and Override
//Load in a master variable file for all LESS
//containing all "possible" variables that may be used
//but set to some default values that "hide" the properties
//if the variable does not exist (such as "false" here)
#myVariable: false;
//Load in your specific variable references from elsewhere
//Individual variable may/may not be defined in this file
//but if one is defiend, this value overrides the previous value
#myVariable: 5px;
//Define a mixin to activate the setting of the property
//only if the value is not the original default hiding value
.setIfValue(myVariable) when not (#myVariable = false) {
myProperty1: #myVariable;
}
//Use the mixin to conditionally set the value into other mixins
.myRule {
.setIfValue(myVariable);
myProperty2: myOtherValue1;
}
Default Output
.myRule {
myProperty2: myOtherValue1;
}
Overridden Output
.myRule {
myProperty1: 5px;
myProperty2: myOtherValue1;
}
I think you made the syntax too complex. It should be something like this:
.myRule {
& when (#myVariable = false) {
myProperty1: #myVariable;
}
myProperty2: myOtherValue1;
}
This feature (apparently) is called CSS Guards.
It seems like you can check if a variable has a specific value, but not whether this allows you to check for defined or not.
So, I guess the other file should always define this variable as a prerequisite, but it can set it to 'false' (or any kind of default) to indicate that this property should not be used at all.
How do i set a parametric mixin output to a variable?
Say i have this custom mixin with these parameters:
.gradient(#555, #333, #777);
I want this to be put into a variable so i can refer to this specific gradient throughout my code.
Wrapping it like this:
#mixin elGradient() {
#include .gradient(#555, #333, #777);
}
for inclusion like this:
.element {
#include elGradient;
}
Yields a parse error.
.elGradient() {
.gradient(#555, #333, #777);
}
.element {
.elGradient();
}
This is the simplest way. Alternatively it would make sense to get use of the extend feature if you really need to include same properties again and again:
.elGradientBase {.gradient(#555, #333, #777)}
.elGradient() {
&:extend(.elGradientBase all);
}
.element-1 {
.elGradient();
}
.element-2 {
.elGradient();
}
// etc.