简体   繁体   English

更少:按变量值混合和变量名称

[英]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: 看它的一部分代码,表明我想要什么: https://www.dropbox.com/s/vvo6zkt0vxeuurw/codefest-2014-2-80-1024.jpg?dl=0

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. 一步不起作用。

  1. Put svg-icons in github.com/andrey-hohlov/template-mark-up/tree/master/assets/dev/img/svg-icons 将svg-icons放在github.com/andrey-hohlov/template-mark-up/tree/master/assets/dev/img/svg-icons中
  2. Put png-icons in github.com/andrey-hohlov/template-mark-up/tree/master/assets/dev/img/png-icons 将png图标放入github.com/andrey-hohlov/template-mark-up/tree/master/assets/dev/img/png-icons
  3. Use grunt 使用咕unt声
  4. All sprite created in github.com/andrey-hohlov/template-mark-up/tree/master/assets/build/img 所有在github.com/andrey-hohlov/template-mark-up/tree/master/assets/build/img中创建的精灵
  5. .less files create in github.com/andrey-hohlov/template-mark-up/tree/master/assets/dev/css/less/mixins/bg-icon/temp It maked by spritesmith and I can't change anything in it .less文件在github.com/andrey-hohlov/template-mark-up/tree/master/assets/dev/css/less/mixins/bg-icon/temp中创建它由spritesmith制作,我无法更改它

Now about less files. 现在,文件减少了。

  1. github.com/andrey-hohlov/template-mark-up/blob/master/assets/dev/css/less/mixins/bg-icon/temp/datauri.less contain base64 code for svg icons. github.com/andrey-hohlov/template-mark-up/blob/master/assets/dev/css/less/mixins/bg-icon/temp/datauri.less包含svg图标的base64代码。 Class names based on file names, i can only set suffix and prefix 基于文件名的类名,我只能设置后缀和前缀
  2. Files like github.com/andrey-hohlov/template-mark-up/blob/master/assets/dev/css/less/mixins/bg-icon/temp/sprite.datauri.less contain mixins and variables to create sprite css (for png icons). github.com/andrey-hohlov/template-mark-up/blob/master/assets/dev/css/less/mixins/bg-icon/temp/sprite.datauri.less之类的文件包含mixins和创建sprite css的变量(用于png图标)。 I create sprite for svg icons for take from it less width and height (datauri task give only base64). 我为svg图标创建了一个精灵,以减少其宽度和高度(datauri任务仅提供base64)。
  3. Problem in github.com/andrey-hohlov/template-mark-up/blob/master/assets/dev/css/less/mixins/bg-icon/bg-icon.less . github.com/andrey-hohlov/template-mark-up/blob/master/assets/dev/css/less/mixins/bg-icon/bg-icon.less中的问题 There is 2 mixins - for svg and png icons. 有2个mixins-用于svg和png图标。 I need use that with parametr "filename" to create css for icons, but i dont know how! 我需要将其与parametr“ filename”结合使用来为图标创建css,但是我不知道如何! I put there comments. 我在这里发表评论。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM