Skip to content

Commit

Permalink
feat(view sub-generator): add inserting a new view's sass file `@impo…
Browse files Browse the repository at this point in the history
…rt` to at an ordered position in '_views.sass'

Add documentation to '_views.sass'
  • Loading branch information
cueedee committed May 7, 2015
1 parent 2add7f6 commit 1ee475d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
9 changes: 9 additions & 0 deletions generators/app/templates/src/sass/_views.sass
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
//
// Please note that this file is likely to be modified by bat:view sub-generator runs .
//
// You are, however, welcome to edit this file.
//
// When doing so, it will probably be best to stick to a one-`@import`-statement-per-line discipline and not much else.
// Even though the sub-generator will take care not to break things, it likely isn't /f(?:ul|oo)l-proof/.
//
@import "views/_index"
20 changes: 18 additions & 2 deletions generators/view/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,25 @@ var ViewGenerator = generators.Base.extend(
//
this.conflicter.force = true;

var pad = (( views.length && views.slice( -1 ) !== '\n' ) ? '\n' : '' );
// Look for a place to insert, preferably at an alfanumerically ordered position.
//
var insertAt, match, matcher = /^@import.*/mg;

this.write( viewsPath, views + pad + statement + '\n' );
while ( (( match = matcher.exec( views ) )) )
{
if ( statement < match[ 0 ] ) { insertAt = match.index; }
}

if ( insertAt == null )
{
var pad = (( views.length && views.slice( -1 ) !== '\n' ) ? '\n' : '' );

this.write( viewsPath, views + pad + statement + '\n' );
}
else
{
this.write( viewsPath, views.slice( 0, insertAt ) + statement + '\n' + views.slice( insertAt ) );
}
}
}
}
Expand Down

0 comments on commit 1ee475d

Please sign in to comment.