如何在手写笔中生成占位符

时间:2014-08-19 03:00:48

标签: css code-generation stylus

我希望生成可根据配置的比例更改的占位符和变量,例如:

  • $small-margin-top
  • $large-margin-top
  • $small-padding-bottom

每个占位符将相应的生成变量应用于规则:

$small-margin-top
    margin-top $marginsmall

$large-margin-top
    margin-top $marginLarge

$small-padding-bottom
    margin-bottom $marginSmall

我现在已经静态定义了变量:

/* Margin */
$margin = 1rem
$marginsmall = $margin / $multiplier
$marginlarge = $margin * $multiplierLarge
$marginmini = $marginSmall / $multiplierLarge

但是我收到了一个错误:

  

TypeError:expected" name"成为一个字符串,但得到了ident:marginmini

properties = margin padding

proportions = mini small medium large

directions = top left bottom right

for property in properties
    for proportion in proportions
            for direction in directions
                ${property}-{direction}-{proportion}
                    {property}-{direction} lookup(property + proportion)

如何为proportions变量生成占位符,以便生成的占位符可以稍后扩展(@extend $margin-large)?


编辑:here is the working solution

1 个答案:

答案 0 :(得分:2)

lookup bif接受一个字符串,并且你传递一个ident(边距,填充等,没有引号)。您可以使用串联将它们转换为字符串。此外,您错过了$标志:

properties = margin padding

proportions = mini small medium large

directions = top left bottom right

for property in properties
    for proportion in proportions
        for direction in directions
            ${proportion}-{property}-{direction}
                {property}-{direction} lookup('$' + property + proportion)