Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CoffeeScript support #9

Merged
merged 2 commits into from
Jun 1, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules/
.tmp
7 changes: 7 additions & 0 deletions slushfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,19 @@ gulp.task('default', function (done) {
{name: 'LESS', value: 'less'},
{name: 'Sass', value: 'sass'}
]},
{type: 'confirm', name: 'coffee', message: 'Do you want to use CoffeScript in your app?', default: false},
{type: 'confirm', name: 'example', message: 'Do you want to include a Todo List example in your app?', default: true}
],
function (answers) {
answers.nameDashed = _.slugify(answers.name);
answers.modulename = _.camelize(answers.nameDashed);
var files = [__dirname + '/templates/**'];
if (answers.coffee) {
files.push('!' + __dirname + '/templates/src/**/*.js')
}
else {
files.push('!' + __dirname + '/templates/src/**/*.coffee')
}
if (!answers.example) {
files.push('!' + __dirname + '/templates/src/app/todo/**');
}
Expand Down
21 changes: 17 additions & 4 deletions templates/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,18 @@ gulp.task('csslint', ['styles'], function () {
.pipe(g.csslint('./.csslintrc'))
.pipe(g.csslint.reporter());
});

<% if(coffee) { %>
/**
* CoffeeScript
*/
gulp.task('coffee', function () {
return gulp.src([
'./src/app/**/*.coffee'
])
.pipe(g.coffee())
.pipe(gulp.dest('./.tmp/src/app'));
});
<% } %>
/**
* Scripts
*/
Expand Down Expand Up @@ -94,7 +105,7 @@ gulp.task('vendors', function () {
* Index
*/
gulp.task('index', index);
gulp.task('build-all', ['styles', 'templates'], index);
gulp.task('build-all', ['styles', 'templates'<%if(coffee){%>, 'coffee'<%}%>], index);

function index () {
var opt = {read: false};
Expand Down Expand Up @@ -131,7 +142,7 @@ gulp.task('dist', ['vendors', 'assets', 'styles-dist', 'scripts-dist'], function
*/
gulp.task('statics', g.serve({
port: 3000,
root: ['./.tmp', './src/app', './bower_components']
root: ['./.tmp', './.tmp/src/app', './src/app', './bower_components']
}));

/**
Expand Down Expand Up @@ -202,7 +213,7 @@ function testFiles() {
.queue(g.bowerFiles().pipe(g.filter('**/*.js')))
.queue(gulp.src('./bower_components/angular-mocks/angular-mocks.js'))
.queue(appFiles())
.queue(gulp.src('./src/app/**/*_test.js'))
.queue(gulp.src(['./src/app/**/*_test.js', './.tmp/src/app/**/*_test.js']))
.done();
}

Expand All @@ -219,6 +230,8 @@ function cssFiles (opt) {
function appFiles () {
var files = [
'./.tmp/' + bower.name + '-templates.js',
'./.tmp/src/app/**/*.js',
'!./.tmp/src/app/**/*_test.js',
'./src/app/**/*.js',
'!./src/app/**/*_test.js'
];
Expand Down
5 changes: 3 additions & 2 deletions templates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@
"gulp-serve": "~0.1.1",
"gulp-concat": "~2.1.7",
"gulp-clean": "~0.2.4",
"<%= styleData.plugin %>": "<%= styleData.pluginVersion %>",
"gulp-minify-css": "~0.3.0",
"<%= styleData.plugin %>": "<%= styleData.pluginVersion %>",<% if(coffee) {%>
"gulp-coffee": "~1.4.3",
<% } %>"gulp-minify-css": "~0.3.0",
"gulp-csslint": "~0.1.3",
"event-stream": "~3.1.0",
"sort-stream": "~1.0.0",
Expand Down
14 changes: 14 additions & 0 deletions templates/src/app/app.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
angular.module('<%= modulename %>', [
'ngRoute'
<% if (example) { %>'<%= modulename %>.todo'
<% } %>'<%= nameDashed %>-templates'
])<% if (example) { %>
.config ($routeProvider) ->
'use strict'
$routeProvider
.when '/todo',
controller: 'TodoCtrl'
templateUrl: '/<%= nameDashed %>/todo/todo.html'
.otherwise
redirectTo: '/todo'
<% } %>
20 changes: 20 additions & 0 deletions templates/src/app/todo/todo-controller.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
angular
.module '<%= modulename %>.todo'
.controller 'TodoCtrl', ($scope, $window) ->
'use strict'
$scope.todos = JSON.parse($window.localStorage.getItem('todos') or '[]')
$scope.$watch('todos', (newTodos, oldTodos) ->
if (newTodos != oldTodos)
$window.localStorage.setItem 'todos', JSON.stringify(angular.copy($scope.todos))
, true)

$scope.add = ->
todo =
label: $scope.label
isDone: false
$scope.todos.push(todo)
$window.localStorage.setItem 'todos', JSON.stringify(angular.copy($scope.todos))
$scope.label = ''

$scope.check = ->
@todo.isDone = not @todo.isDone
23 changes: 23 additions & 0 deletions templates/src/app/todo/todo-controller_test.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
describe 'TodoCtrl', ->
todoCtrl = null
scope = null

beforeEach module('<%= modulename %>')

beforeEach inject ($injector) ->
scope = $injector.get('$rootScope')

todoCtrl = ->
$injector.get('$controller')('TodoCtrl', $scope:scope)

it 'should add new todos on add()', ->
todo =
label: 'A new todo'
isDone: false
todoCtrl()
scope.label = todo.label
scope.add()
scope.label.length.should.equal(0)
scope.todos.length.should.equal(1)
scope.todos[scope.todos.length - 1].label.should.equal(todo.label)
scope.todos[scope.todos.length - 1].isDone.should.equal(false)
1 change: 1 addition & 0 deletions templates/src/app/todo/todo.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
angular.module '<%= modulename %>.todo', []