diff --git a/lib/nib/positions.styl b/lib/nib/positions.styl index 654d4440..098c3ac6 100644 --- a/lib/nib/positions.styl +++ b/lib/nib/positions.styl @@ -1,10 +1,63 @@ // helper +-type(prop) + + type = 'ident' + types = 'auto' 'inherit' + + if prop is a 'unit' + type = 'unit' + + if prop in types + type = 'unit' + + return type + +-keys(props) + + props = arguments if length(arguments) > 1 + keys = () + + for prop in props + if -type(prop) is 'ident' + push(keys, prop) + + return keys + +-vals(props) + + props = arguments if length(arguments) > 1 + vals = () + length = length(props) + + for prop, i in props + + type = -type(prop) + + if type is 'unit' + push(vals, prop) + else + if previous is defined + unless -type(previous) is 'unit' + push(vals,0) + + if (i+1) == length + push(vals,0) + + previous = prop + + return vals + -pos(type, args) - i = 0 + + keys = -keys(args) + vals = -vals(args) + position: unquote(type) - {args[i]}: args[i + 1] is a 'unit' ? args[i += 1] : 0 - {args[i += 1]}: args[i + 1] is a 'unit' ? args[i += 1] : 0 + + for key, i in keys + {key}: vals[i]; + /* * Position utility. @@ -19,7 +72,9 @@ * fixed: top 5px left * fixed: top left 5px * fixed: top 5px left 5px - * + * fixed: top 5px left 5px right auto + * fixed: top 5px left 5px right auto bottom inherit + * */ fixed() diff --git a/test/cases/positions.css b/test/cases/positions.css new file mode 100644 index 00000000..409eac6d --- /dev/null +++ b/test/cases/positions.css @@ -0,0 +1,59 @@ +#fixed-0 { + position: fixed; + bottom: 0; + right: 0; +} +#fixed-1 { + position: fixed; + top: 5px; + left: auto; +} +#fixed-2 { + position: fixed; + bottom: 0; + left: 10px; +} +#fixed-3 { + position: fixed; + bottom: 10px; + right: 0; +} +#fixed-4 { + position: fixed; + bottom: 0; + right: 0; + left: 0; +} +#fixed-5 { + position: fixed; + bottom: 0; + right: 5px; + left: 5px; +} +#fixed-6 { + position: fixed; + bottom: 10px; + right: 5px; + left: 5px; +} +#fixed-7 { + position: fixed; + top: 0; + bottom: 0; + right: 0; + left: 0; +} +#fixed-8 { + position: fixed; + top: 0; + bottom: auto; + right: 0; + left: 5px; +} +#fixed-9 { + position: fixed; + top: auto; + bottom: 10px; + right: inherit; + left: 5px; +} diff --git a/test/cases/positions.styl b/test/cases/positions.styl new file mode 100644 index 00000000..8a700c48 --- /dev/null +++ b/test/cases/positions.styl @@ -0,0 +1,32 @@ + +@import 'nib/positions' + +#fixed-0 + fixed: bottom right + +#fixed-1 + fixed: top 5px left auto + +#fixed-2 + fixed: bottom left 10px + +#fixed-3 + fixed: bottom 10px right + +#fixed-4 + fixed: bottom right left + +#fixed-5 + fixed: bottom right 5px left 5px + +#fixed-6 + fixed: bottom 10px right 5px left 5px + +#fixed-7 + fixed: top bottom right left + +#fixed-8 + fixed: top bottom auto right left 5px + +#fixed-9 + fixed: top auto bottom 10px right inherit left 5px diff --git a/test/runner.js b/test/runner.js index 296acc81..2c9cdfb8 100644 --- a/test/runner.js +++ b/test/runner.js @@ -34,6 +34,6 @@ describe('integration', function(){ if (err) throw err; actual.trim().should.equal(css); }); - }) + }); }); -}) \ No newline at end of file +}); \ No newline at end of file