我开始将网站从Singularity 1.1.2升级到1.4.0,并且在同一样式表中使用多个网格时立即碰壁。我在这个网站上有五个不同的网格。以前我能够为每个网格和排水沟设置变量,就像这样......
$copy-grids: 2;
$copy-grids: add-grid(4 at $breakpoint-xs-min, $copy-grids);
$copy-grids: add-grid(6 at $breakpoint-l-min, $copy-grids);
$copy-gutters: $gutter-width;
$front-grids: 1;
$front-grids: add-grid(2 at $breakpoint-2up-min, $front-grids);
$front-grids: add-grid(3 at $breakpoint-3up-min, $front-grids);
$front-grids: add-grid(4 at $breakpoint-4up-min, $front-grids);
$front-gutters: breakpoint-to-base-em($front-gutter-width);
...
然后我能够使用Singularity的layout()
函数将这些变量传递给自定义mixins,就像这样......
// Mixins for the main content body copy.
@mixin copy-layout {
@include layout($copy-grids, $copy-gutters) {
// All the things!
@content;
}
}
@mixin copy-grid-span($span, $location) {
@include copy-layout {
@include grid-span($span, $location);
}
}
// Mixins for the front page.
@mixin front-layout {
@include layout($front-grids, $front-gutters) {
$gutter-styles: 'split' 'fixed';
// All the things!
@content;
}
}
@mixin front-grid-span($span, $location) {
@include front-layout {
@include grid-span($span, $location);
}
}
...
这让我使用我的自定义mixins代替标准grid-span()
mixins来轻松实现我定义的任何网格。例如:
#block-bean-front-page-message {
margin-bottom: $front-gutters;
@include breakpoint-1up() {
width: 100%;
padding: 0 $front-gutters/2;
}
@include breakpoint-2up-to-4up() {
@include front-grid-span(1, 2);
}
@include breakpoint-4up(true) {
@include front-grid-span(3, 2);
}
}
问题在于,在Singularity v1.4中,网格和装订线设置不再保存到普通的sass变量中。相反,它们将作为键控值保存在全局$Singularity-Settings
地图中。用于这些值的密钥在add-grid()
,add-gutter()
和add-gutter-style()
mixins中进行了硬编码,其中没有一个接受自定义变量名称。这似乎有效地阻止我定义多个网格。因此,虽然layout()
mixin仍然存在,但我不再有可以传递给我的网格和装订设置的变量,打破我的自定义布局包装mixins。
我已将此作为issue on Github发布,我了解更多永久性修复可能正在进行中。但与此同时,我希望有一种解决方法,我可以使用当前版本的Singularity来完成多个网格。
答案 0 :(得分:0)
看起来我能够通过重写add-grid(),add-gutter()和add-gutter-style()mixins来实现我所追求的目标:
@mixin add-grid($grid-definition, $grid-key: 'grids') {
$Grid-Map: ();
@if sgs-has($grid-key) {
$Grid-Map: sgs-get($grid-key);
}
@else {
$New-Map: sgs-set($grid-key, $Grid-Map)
}
$Add-Grid: add-grid($grid-definition, $Grid-Map);
$HOLDER: sgs-set($grid-key, $Add-Grid);
}
@mixin add-gutter($gutter-definition, $gutter-key: 'gutters') {
$Gutter-Map: ();
@if sgs-has($gutter-key) {
$Gutter-Map: sgs-get($gutter-key);
}
@else {
$New-Map: sgs-set($gutter-key, $Gutter-Map)
}
$Add-Gutter: add-gutter($gutter-definition, $Gutter-Map);
$HOLDER: sgs-set($gutter-key, $Add-Gutter);
}
@mixin add-gutter-style($gutter-style-definition, $gutter-style-key: 'gutter styles') {
$Gutter-Style-Map: ();
@if sgs-has($gutter-style-key) {
$Gutter-Style-Map: sgs-get($gutter-style-key);
}
@else {
$New-Map: sgs-set($gutter-style-key, $Gutter-Style-Map)
}
$Add-Gutter-Style: add-gutter-style($gutter-style-definition, $Gutter-Style-Map);
$HOLDER: sgs-set($gutter-style-key, $Add-Gutter-Style);
}
然后我可以像这样定义我的网格......
@include add-grid(2, 'copy grids');
@include add-grid(4 at $breakpoint-xs-min, 'copy grids');
@include add-grid(6 at $breakpoint-l-min, 'copy grids');
$copy-grids: sgs-get('copy grids');
@include add-gutter($gutter-width, 'copy gutters');
$copy-gutters: sgs-get('copy gutters');
@include add-grid(2, 'front grids');
@include add-grid(2 at $breakpoint-2up-min, 'front grids');
@include add-grid(3 at $breakpoint-3up-min, 'front grids');
@include add-grid(4 at $breakpoint-4up-min, 'front grids');
$front-grids: sgs-get('front grids');
@include add-gutter($front-gutter-width-em, 'front gutters');
$front-gutters: sgs-get('front gutters');
$front-gutter-styles: 'split' 'fixed';
...给我变量,我可以传递给布局函数。现在一切似乎都在起作用,除了阴沟样式,它们似乎对输出没有任何影响,但这是一个不同的问题。