-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b8352fa
commit e158764
Showing
3 changed files
with
97 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
module.exports = (str) -> | ||
|
||
conf = | ||
|
||
divisions: 0 | ||
|
||
hasGutters: no | ||
|
||
gutters: [] | ||
|
||
unless typeof str is 'string' or typeof str is 'number' | ||
|
||
throw Error "divisions must be a string" | ||
|
||
str = String(str).replace /^\s+/, '' | ||
.replace /\s+$/, '' | ||
|
||
nums = str.split /\s+/ | ||
|
||
if nums.length is 0 | ||
|
||
throw Error "Divisions must contain numbers" | ||
|
||
divisions = nums.shift() | ||
|
||
unless divisions.match /^[0-9]+$/ | ||
|
||
throw Error "Divisions must be a number. Given: '#{divisions}'" | ||
|
||
divisions = parseInt divisions | ||
|
||
if divisions is 0 | ||
|
||
throw Error "Divisions cannot be zero" | ||
|
||
conf.divisions = divisions | ||
|
||
for gutter, i in nums | ||
|
||
conf.hasGutters = yes | ||
|
||
if isNaN gutter | ||
|
||
throw Error "gutter '#{gutter}' is not a number" | ||
|
||
gutter = parseFloat gutter | ||
|
||
if gutter <= 0 | ||
|
||
throw Error "Gutters must be bigger than zero" | ||
|
||
conf.gutters.push gutter | ||
|
||
conf |