【发布时间】:2018-04-04 04:22:40
【问题描述】:
你能帮我写一些代码来通过 gulp spritesmith 在 Less 中创建精灵模板吗?
我有带有 Sass 函数和 mixins 的 sprite.template.mustache:
$icons: (0:0)
{{#items}}
$icons: map-merge($icons,({{name}}: (X: {{px.offset_x}}, Y:{{px.offset_y}}, W: {{px.width}}, H: {{px.height}}, TW: {{px.total_width}}, TH: {{px.total_height}}, IMG: '{{{escaped_image}}}')))
{{/items}}
{{#options.functions}}
// Gets an attribute from the sass map
@function icon-attr($icon, $attr)
$icon: map-get($icons, $icon)
@return map-get($icon, $attr)
@mixin sprite($iconName)
background-image: url(icon-attr($iconName, IMG))
width: icon-attr($iconName, W)
height: icon-attr($iconName, H)
background-position: icon-attr($iconName, X) icon-attr($iconName, Y)
@mixin sprite-position($iconName)
background-position: icon-attr($iconName, X) icon-attr($iconName, Y)
@mixin sprite-retina($iconName)
background-image: url(icon-attr($iconName, IMG))
$width: icon-attr($iconName, W)
$height: icon-attr($iconName, H)
width: $width/2
height: $height/2
$x: icon-attr($iconName, X)
$y: icon-attr($iconName, Y)
background-position: $x/2 $y/2
$tw: icon-attr($iconName, TW)
$th: icon-attr($iconName, TH)
background-size: $tw/2 $th/2
{{/options.functions}}
我在重写函数时遇到了一些麻烦:“map-merge”和“map-get”到 Less。
我知道LESS中没有这样的功能,但我也知道有自己的数组可以配置。
【问题讨论】:
-
从
lists插件开始,然后询问您面临的具体问题(一切皆有可能,但必须从头开始重新考虑给定 sn-p 中的许多概念以适应不太具体的结构)。 -
好的,谢谢,我试试
-
我更深入地研究了这段代码的实际作用,并......请参阅下面的答案。
标签: sass gulp less gulp-less gulp-spritesmith