@@ -13,7 +13,8 @@ module.exports = postcss.plugin('lost', function lost(settings) {
1313
1414 settings = assign ( settings , {
1515 gutter : '30px' ,
16- flexbox : 'no-flex'
16+ flexbox : 'no-flex' ,
17+ cycle : 'auto'
1718 } ) ;
1819
1920 return function ( css ) {
@@ -36,6 +37,17 @@ module.exports = postcss.plugin('lost', function lost(settings) {
3637 if ( rule . params [ 0 ] == 'flexbox' ) {
3738 settings . flexbox = rule . params [ 1 ] ;
3839 }
40+ if ( rule . params [ 0 ] == 'cycle' ) {
41+ if ( rule . params [ 1 ] !== 'auto' ) {
42+ if ( rule . params [ 1 ] === 'none' || rule . params [ 1 ] === '0' ) {
43+ settings . cycle = 0 ;
44+ } else {
45+ settings . cycle = rule . params [ 1 ] ;
46+ }
47+ } else {
48+ settings . cycle = 'auto' ;
49+ }
50+ }
3951
4052 rule . removeSelf ( ) ;
4153 } ) ;
@@ -529,9 +541,10 @@ module.exports = postcss.plugin('lost', function lost(settings) {
529541 * element's width.
530542 *
531543 * @param {integer } [cycle] - Lost works by assigning a margin-right to all
532- * elements except the last in the row. It does this by default by using
533- * the denominator of the fraction you pick. To override the default use
534- * this param., e.g.: .foo { lost-column: 2/4 2; }
544+ * elements except the last in the row. If settings.cycle is set to auto
545+ * it will do this by default by using the denominator of the fraction you
546+ * pick. To override the default use this param.,
547+ * e.g.: .foo { lost-column: 2/4 2; }
535548 *
536549 * @param {length } [gutter] - The margin on the right side of the element
537550 * used to create a gutter. Typically this is left alone and
@@ -575,10 +588,16 @@ module.exports = postcss.plugin('lost', function lost(settings) {
575588 } ,
576589 declArr = [ ] ,
577590 lostColumn ,
578- lostColumnCycle = decl . value . split ( '/' ) [ 1 ] ,
591+ lostColumnCycle ,
579592 lostColumnGutter = settings . gutter ,
580593 lostColumnFlexbox = settings . flexbox ;
581594
595+ if ( settings . cycle === 'auto' ) {
596+ lostColumnCycle = decl . value . split ( '/' ) [ 1 ] ;
597+ } else {
598+ lostColumnCycle = settings . cycle ;
599+ }
600+
582601 declArr = decl . value . split ( ' ' ) ;
583602 lostColumn = declArr [ 0 ] ;
584603
@@ -639,11 +658,13 @@ module.exports = postcss.plugin('lost', function lost(settings) {
639658 value : '0 0 auto'
640659 } ) ;
641660
642- newBlock (
643- ':nth-child(' + lostColumnCycle + 'n)' ,
644- [ 'margin-right' ] ,
645- [ 0 ]
646- ) ;
661+ if ( lostColumnCycle !== 0 ) {
662+ newBlock (
663+ ':nth-child(' + lostColumnCycle + 'n)' ,
664+ [ 'margin-right' ] ,
665+ [ 0 ]
666+ ) ;
667+ }
647668
648669 newBlock (
649670 ':last-child' ,
@@ -657,17 +678,20 @@ module.exports = postcss.plugin('lost', function lost(settings) {
657678 [ lostColumnGutter ]
658679 ) ;
659680 } else {
660- newBlock (
661- ':nth-child(' + lostColumnCycle + 'n + 1)' ,
662- [ 'clear' ] ,
663- [ 'left' ]
664- ) ;
665681
666- newBlock (
667- ':nth-child(' + lostColumnCycle + 'n)' ,
668- [ 'float' , 'margin-right' ] ,
669- [ 'right' , 0 ]
670- ) ;
682+ if ( lostColumnCycle !== 0 ) {
683+ newBlock (
684+ ':nth-child(' + lostColumnCycle + 'n + 1)' ,
685+ [ 'clear' ] ,
686+ [ 'left' ]
687+ ) ;
688+
689+ newBlock (
690+ ':nth-child(' + lostColumnCycle + 'n)' ,
691+ [ 'margin-right' ] ,
692+ [ 0 ]
693+ ) ;
694+ }
671695
672696 newBlock (
673697 ':last-child' ,
@@ -879,10 +903,16 @@ module.exports = postcss.plugin('lost', function lost(settings) {
879903 } ,
880904 declArr = [ ] ,
881905 lostWaffle ,
882- lostWaffleCycle = decl . value . split ( '/' ) [ 1 ] ,
906+ lostWaffleCycle ,
883907 lostWaffleGutter = settings . gutter ,
884908 lostWaffleFlexbox = settings . flexbox ;
885909
910+ if ( settings . cycle === 'auto' ) {
911+ lostWaffleCycle = decl . value . split ( '/' ) [ 1 ] ;
912+ } else {
913+ lostWaffleCycle = settings . cycle ;
914+ }
915+
886916 declArr = decl . value . split ( ' ' ) ;
887917 lostWaffle = declArr [ 0 ] ;
888918
@@ -943,17 +973,19 @@ module.exports = postcss.plugin('lost', function lost(settings) {
943973 value : '0 0 auto'
944974 } ) ;
945975
946- newBlock (
947- ':nth-last-child(-n + ' + lostWaffleCycle + ')' ,
948- [ 'margin-bottom' ] ,
949- [ 0 ]
950- ) ;
976+ if ( lostWaffleCycle !== 0 ) {
977+ newBlock (
978+ ':nth-last-child(-n + ' + lostWaffleCycle + ')' ,
979+ [ 'margin-bottom' ] ,
980+ [ 0 ]
981+ ) ;
951982
952- newBlock (
953- ':nth-child(' + lostWaffleCycle + 'n)' ,
954- [ 'margin-right' ] ,
955- [ 0 ]
956- ) ;
983+ newBlock (
984+ ':nth-child(' + lostWaffleCycle + 'n)' ,
985+ [ 'margin-right' ] ,
986+ [ 0 ]
987+ ) ;
988+ }
957989
958990 newBlock (
959991 ':last-child' ,
@@ -967,23 +999,25 @@ module.exports = postcss.plugin('lost', function lost(settings) {
967999 [ lostWaffleGutter , lostWaffleGutter ]
9681000 ) ;
9691001 } else {
970- newBlock (
971- ':nth-last-child(-n + ' + lostWaffleCycle + ')' ,
972- [ 'margin-bottom' ] ,
973- [ 0 ]
974- ) ;
1002+ if ( lostWaffleCycle !== 0 ) {
1003+ newBlock (
1004+ ':nth-last-child(-n + ' + lostWaffleCycle + ')' ,
1005+ [ 'margin-bottom' ] ,
1006+ [ 0 ]
1007+ ) ;
9751008
976- newBlock (
977- ':nth-child(' + lostWaffleCycle + 'n + 1)' ,
978- [ 'clear' ] ,
979- [ 'left' ]
980- ) ;
1009+ newBlock (
1010+ ':nth-child(' + lostWaffleCycle + 'n + 1)' ,
1011+ [ 'clear' ] ,
1012+ [ 'left' ]
1013+ ) ;
9811014
982- newBlock (
983- ':nth-child(' + lostWaffleCycle + 'n)' ,
984- [ 'float' , 'margin-right' ] ,
985- [ 'right' , 0 ]
986- ) ;
1015+ newBlock (
1016+ ':nth-child(' + lostWaffleCycle + 'n)' ,
1017+ [ 'margin-right' ] ,
1018+ [ 0 ]
1019+ ) ;
1020+ }
9871021
9881022 newBlock (
9891023 ':last-child' ,
0 commit comments