[英]LESS: Mixin and variable names by variable value
I'm trying to do generating icons from svg-files easier. 我试图做更容易从svg文件生成图标。 (And also generate png-sprite fallback to support ie8). (并且还会生成png精灵后备广告以支持ie8)。 Use grunt.js and less. 使用grunt.js及更少。
That's idea realized bu 2gis.ru: http://www.slideshare.net/codefest/codefest-2014-2 (russian), but i have only this slides and name of technologies thay use: node.js, npm, grunt,js, less. 这个想法在bu 2gis.ru中得以实现: http ://www.slideshare.net/codefest/codefest-2014-2(俄语),但我只有这张幻灯片和使用的技术名称:node.js,npm,grunt, js,更少。
look it part of code, that show what i want: 看它的一部分代码,表明我想要什么:
Now i make this template: https://github.com/andrey-hohlov/template-mark-up (if you clone you need to use 'npm install') 现在,我制作此模板: https : //github.com/andrey-hohlov/template-mark-up (如果要克隆,则需要使用“ npm install”)
One step not working. 一步不起作用。
Now about less files. 现在,文件减少了。
PS I removed url becouse need more reputation to post it. PS我删除了url,因为需要更多信誉才能发布。 PPS I'm very sorry for my english :( PPS我很抱歉我的英语:(
OK then. 好吧。
how can i use mixin name and variable names by another variable value 我如何通过另一个变量值使用混合名称和变量名称
So: 所以:
(1). (1)。 To refer to a variable by its name stored in another variable use "Variable Referencing" syntax, eg: 要使用存储在另一个变量中的名称来引用变量,请使用“变量引用”语法,例如:
#example {
@banana: 22px;
@potato: "banana";
width: @@potato; // -> 22px
}
(2). (2)。 You can't call a mixin by name set in a variable, so to selectively invoke a mixin depending on a variable value use "Pattern Matching" , eg 您不能通过变量中设置的名称来调用mixin,因此要使用变量“ Pattern Matching”根据变量值有选择地调用mixin,例如
.mixin("banana", @values...) {
color: @values;
}
.mixin("potato", @values...) {
background-color: @values;
}
#usage {
.mixin("banana", tomato); // -> color: #ff6347
.mixin("potato", wheat); // -> background-color: #f5deb3
}
If you can't modify those mixins - generate wrappers: 如果您不能修改这些混合-生成包装器:
.mixin(peach) {.mixin-peach()}
#usage {
@variable: peach;
.mixin(@variable); // invokes .mixin-peach
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.