This repository has been archived by the owner on Nov 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from PrisisForks/master
Added more test, remove old functions, fixed some bugs
- Loading branch information
Showing
18 changed files
with
368 additions
and
341 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
// Here are all the functions, helpers, mixins and variables. | ||
@import 'utils/variables'; | ||
@import 'utils/helpers'; | ||
@import 'utils/functions'; | ||
|
||
@import 'helpers/helpers'; | ||
|
||
@import 'functions/functions'; | ||
|
||
@import 'utils/mixins'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Gets a value to/from a configuration path | ||
// | ||
// @function config-get | ||
// | ||
// @param $key {string} The configuration path | ||
// @param $default {bool} Whether the configuration is default | ||
// | ||
// @return {*} The value of the configuration path | ||
@function config-get($key, $default: false) { | ||
@if $default { | ||
@if config-map-has($config-default, $key) { | ||
@return config-map-get($config-default, $key); | ||
} | ||
} @else { | ||
@if config-map-has($config-attr, $key) { | ||
@return config-map-get($config-attr, $key); | ||
} @else if config-map-has($config-default, $key) { | ||
@return config-map-get($config-default, $key); | ||
} | ||
} | ||
|
||
@warn 'The key "#{$key}" doesn\'t exist.'; | ||
|
||
@return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Returns whether a configuration path exists | ||
// | ||
// @function config-has | ||
// | ||
// @param $key {string} The configuration path | ||
// | ||
// @return {bool} True if the configuration path has a value, | ||
// otherwise false | ||
@function config-has($key) { | ||
@if config-map-has($config-attr, $key) or config-map-has($config-default, $key) { | ||
@return true; | ||
} | ||
|
||
@return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Sets a value to/from a configuration path | ||
// | ||
// @function config | ||
// | ||
// @param $key {string} The configuration key | ||
// @param $value {*} The value to set | ||
// @param $default {bool} Whether the configuration is default | ||
// | ||
// @return {*} The value of the configuration path | ||
@function config-set($key, $value, $default: false) { | ||
@if $default { | ||
@if config-map-has($config-default, $key) { | ||
$value: config-map-get($config-default, $key); | ||
} @else { | ||
$config-default: config-map-set($config-default, $key, $value) !global; | ||
} | ||
} @else { | ||
$config-attr: config-map-set($config-attr, $key, $value) !global; | ||
} | ||
|
||
@return $value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@import 'config-set'; | ||
@import 'config-get'; | ||
@import 'config-has'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@import 'list'; | ||
@import 'str'; | ||
@import 'map'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Return list-map from `$list` and ensure input list-map is list-of-lists | ||
// | ||
// @function list-map-check | ||
// | ||
// @access public | ||
// | ||
// @param $list {list} | ||
// | ||
// @return {list-map} | ||
@function list-map-check($list) { | ||
@if length($list) == 2 and length(nth($list, 1)) == 1 { | ||
@return append((), $list, 'comma'); | ||
} | ||
|
||
@return $list; | ||
} | ||
|
||
// Extracts a slice of a list | ||
// | ||
// @function list-slice | ||
// | ||
// @access private | ||
// | ||
// @param $list {list} The list to extract | ||
// @param $start {number} The start index to extract | ||
// @param $end {number} The end index to extract | ||
// | ||
// @return {list} The extracted list | ||
@function list-slice($list, $start: 1, $end: length($list)) { | ||
$output: (); | ||
|
||
@if $start >= 1 and $end >= $start { | ||
@for $i from $start through $end { | ||
$output: append($output, nth($list, $i)); | ||
} | ||
} | ||
|
||
@return $output; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
// Sets a value to a Map by the map path | ||
// | ||
// @function config-map-set | ||
// | ||
// @access private | ||
// | ||
// @param $map {map} The Map | ||
// @param $path {string} The map path | ||
// @param $value {*|null} The value to set | ||
// | ||
// @return {map...} A new Map | ||
@function config-map-set($map, $path, $value) { | ||
$map: list-map-check($map); | ||
$keys: str-split($path, $config-delimiter); | ||
$length: length($keys); | ||
|
||
$result: (nth($keys, $length): $value); | ||
|
||
@if $length > 1 { | ||
@for $i from 1 through $length - 1 { | ||
$path: ''; | ||
$key: nth($keys, 1); | ||
|
||
$j: $length - $i; | ||
$key: nth($keys, $j); | ||
|
||
$path: str-join(list-slice($keys, 1, $j), $config-delimiter); | ||
|
||
@if config-map-has($map, $path) { | ||
$value: config-map-get($map, $path); | ||
|
||
@if type-of($value) == 'map' { | ||
$result: config-map-merge(($key: $value), ($key: $result)); | ||
} @else { | ||
$result: ($key: $result); | ||
} | ||
} @else { | ||
$result: ($key: $result); | ||
} | ||
} | ||
} | ||
|
||
$map: config-map-merge($map, $result); | ||
|
||
@return $map; | ||
} | ||
|
||
// Gets a value from a Map by the map path | ||
// | ||
// @function config-map-get | ||
// | ||
// @access private | ||
// | ||
// @param $map {map...} The Map | ||
// @param $path {string} The map path | ||
// | ||
// @return {*} The value of the map path | ||
@function config-map-get($map, $path) { | ||
$keys: str-split($path, $config-delimiter); | ||
$value: list-map-check($map); | ||
|
||
@each $key in $keys { | ||
@if type-of($value) != 'map' or not map-has-key($value, $key) { | ||
@warn 'The path "#{$path}" doesn\'t exist.'; | ||
|
||
@return null; | ||
} | ||
|
||
$value: map-get($value, $key); | ||
} | ||
|
||
@return $value; | ||
} | ||
|
||
// Returns whether the key of a map path exists in a Map | ||
// | ||
// @function config-map-has | ||
// | ||
// @access private | ||
// | ||
// @param $map {map...} The Map | ||
// @param $key {string} The map path | ||
// | ||
// @return {bool} True if the map path has a value, | ||
// otherwise false | ||
@function config-map-has($map, $key) { | ||
$keys: str-split($key, $config-delimiter); | ||
$value: list-map-check($map); | ||
|
||
@each $key in $keys { | ||
@if type-of($value) != 'map' or not map-has-key($value, $key) { | ||
@return false; | ||
} | ||
|
||
$value: map-get($value, $key); | ||
} | ||
|
||
@return true; | ||
} | ||
|
||
// Recursively merges one or more maps | ||
// | ||
// @function config-map-merge | ||
// | ||
// @access private | ||
// | ||
// @param $maps {map...} The map(s) to merge | ||
// | ||
// @return {map} The merged map | ||
@function config-map-merge($maps...) { | ||
$result: nth($maps, 1); | ||
|
||
@for $i from 1 through length($maps) - 1 { | ||
@each $key, $value in nth($maps, $i + 1) { | ||
@if type-of($result) != 'map' { | ||
$result: ($key: $value); | ||
} | ||
|
||
@if type-of($value) == 'map' { | ||
$value: config-map-merge(map-get($result, $key), $value); | ||
} | ||
|
||
@if $key != null { | ||
$result: map-merge($result, ($key: $value)); | ||
} | ||
} | ||
} | ||
|
||
@return $result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Joins list elements with a string | ||
// | ||
// @function str-join | ||
// | ||
// @access private | ||
// | ||
// @param $list {list} The list to join | ||
// @param $glue {string} The glue string to join list elements | ||
// | ||
// @return {string} The joined string | ||
@function str-join($list, $glue: '') { | ||
$result: ''; | ||
|
||
@if length($list) == 0 { | ||
@return $result; | ||
} | ||
|
||
@if length($list) > 1 { | ||
@for $i from 1 through length($list) - 1 { | ||
$result: $result + nth($list, $i) + $glue; | ||
} | ||
} | ||
|
||
$result: $result + nth($list, length($list)); | ||
|
||
@return $result; | ||
} | ||
|
||
// Splits a string by a delimiter | ||
// | ||
// @function str-split | ||
// | ||
// @access private | ||
// | ||
// @param $string {string} The string to split | ||
// @param $delimiter {string} The boundary string to split the string | ||
// | ||
// @return {list} The splitted list | ||
@function str-split($string, $delimiter: '') { | ||
$result: (); | ||
$length: str-length($string); | ||
|
||
@if str-length($delimiter) == 0 { | ||
@for $i from 1 through $length { | ||
$result: append($result, str-slice($string, $i, $i)); | ||
} | ||
|
||
@return $result; | ||
} | ||
|
||
$break: false; | ||
|
||
@while not $break { | ||
$index: str-index($string, $delimiter); | ||
|
||
@if not $index or $index == 0 { | ||
$break: true; | ||
} @else { | ||
$part: if($index != 1, str-slice($string, 1, $index - 1), ''); | ||
$result: append($result, $part); | ||
$string: str-slice($string, $index + str-length($delimiter)); | ||
} | ||
} | ||
|
||
@return append($result, $string); | ||
} |
Oops, something went wrong.