Skip to content

Commit

Permalink
fix config application when core is used multiple times, update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Harte committed Aug 14, 2017
1 parent 61ea3c6 commit d2bf0f0
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 37 deletions.
4 changes: 2 additions & 2 deletions Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ to generate even more flexible grids, see [Viewport Dependent Configurations](#v
This will define the core variables and mixins and generate selectors and styles needed for any grid setup,
i.e. clearing on the container, floating of cells etc. Generally has to be called only once for any grid setup.

> Note that once the namespace is defined either with this mixin or `grid-unlock()` it cannot be changed anymore.
[Read about namespacing](#namespace)
> Note that the namespace can also be set with `grid-unlock` but once it's set/overwritten through this mixin, it can **only** be
overwritten again with this mixin. [Read about namespacing](#namespace)

**Generates styles for:**

Expand Down
64 changes: 34 additions & 30 deletions src/04-config-mixins.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
@mixin _update-spartan-config($settings, $force: false) {
@if map_has_key($settings, 'namespace') and not $force {
$settings: map_remove($settings, 'namespace');
}

$spartan-config: map-merge($spartan-config, $settings) !global;
}

@mixin grid-config-set($setting, $value: false) {
@if type_of($setting) != map {
$setting: ($setting: $value);
}

@include _update-spartan-config($setting);

// always try to recalculate singleCell value
@if map_has_key($spartan-config, 'width') and map_has_key($spartan-config, 'cells') {
@include _update-spartan-config((singleCell: (map-get($spartan-config, 'width') / map-get($spartan-config, 'cells'))));
}
}

@mixin _set-config-namespace($namespace) {
@if $namespace != '' {
$namespace: #{$namespace}-;
}

$settings: (namespace: $namespace);

@include _update-spartan-config($settings, true);
}

@mixin grid-unlock($width: 100%, $gutter: 0, $cells: 12, $namespace: 'g') {
$config: $width;
$base-config: (width: 100%, gutter: 0, cells: 12, namespace: 'g');
Expand All @@ -16,13 +47,10 @@
$target-config: map-merge($target-config, ($keyword: nth($config, $index)));
}
}

} @else if $config-type == map {
$target-config: map-merge($target-config, $config);

} @else if $config-type == number {
$target-config: map-merge($target-config, (width: $width, gutter: $gutter, cells: $cells, namespace: $namespace));

}

// add fallback notices
Expand All @@ -39,25 +67,14 @@
@warn 'No cells amount given, falling back to default (#{map-get($base-config, 'cells')})';
}
} @else {
@warn 'No configuration parameters given. falling back to default (#{map-remove($base-config, 'namespace')})';
@warn 'No configuration parameters given. falling back to defaults (#{map-remove($base-config, 'namespace')})';
}

$target-config: map-merge($base-config, $target-config);

$width: map-get($target-config, 'width');
$cells: map-get($target-config, 'cells');

// if the namespace has already been set, don't update it
@if map_has_key($spartan-config, 'namespace') {
$namespace: map-get($spartan-config, 'namespace');
} @else if map_has_key($target-config, 'namespace') {
$namespace: map-get($target-config, 'namespace');

@if $namespace != '' {
$namespace: #{$namespace}-;
}
}

// check final settings types
@if type_of($width) != number {
@error 'Maximum grid width is not a number'
Expand All @@ -73,20 +90,7 @@

$single-cell: $width / $cells;

$target-config: map-merge($target-config, (namespace: $namespace, singleCell: ($width / $cells)));

$spartan-config: map-merge($spartan-config, $target-config) !global;
}

@mixin grid-config-set($setting, $value) {
@if type_of($setting) != map {
$setting: ($setting: $value);
}
$target-config: map-merge($target-config, (singleCell: ($width / $cells)));

$spartan-config: map_merge($spartan-config, $setting) !global;

// always try to recalculate singleCell value
@if map_has_key($spartan-config, 'width') and map_has_key($spartan-config, 'cells') {
$spartan-config: map-merge($spartan-config, (singleCell: (map-get($spartan-config, 'width') / map-get($spartan-config, 'cells')))) !global;
}
@include grid-config-set($target-config);
}
14 changes: 9 additions & 5 deletions src/05-usage-mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,18 @@
}

@mixin grid-core($namespace: 'g') {
@if not map_has_key($spartan-config, 'namespace') {
@if $namespace != '' {
$namespace: #{$namespace}-;
}
$config: ();

$spartan-config: map-merge($spartan-config, (namespace: $namespace));
@if type_of($namespace) == map {
$config: $namespace;
} @else {
$config: map-merge($spartan-config, (namespace: $namespace));
}

@include _set-config-namespace(map-get($config, 'namespace'));

@include grid-config-set($config);

@include _spartan-core-selectors;
}

Expand Down

0 comments on commit d2bf0f0

Please sign in to comment.