Skip to content

Commit 7be7d13

Browse files
committed
Added support for coffeescript and jade
1 parent fe826cb commit 7be7d13

File tree

10 files changed

+322
-188
lines changed

10 files changed

+322
-188
lines changed

Gruntfile.js

Lines changed: 84 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ module.exports = function (grunt) {
1919
clean: {
2020
files: ['dist']
2121
},
22+
23+
// Automatically inject Bower components into the HTML file
24+
bowerInstall: {
25+
src: ['src/index.jade'],
26+
ignorePath: 'test/'
27+
},
28+
2229
concat: {
2330
options: {
2431
banner: '<%= banner %>',
@@ -29,6 +36,7 @@ module.exports = function (grunt) {
2936
dest: 'dist/jquery.<%= pkg.name %>.js'
3037
}
3138
},
39+
3240
uglify: {
3341
options: {
3442
banner: '<%= banner %>'
@@ -38,13 +46,42 @@ module.exports = function (grunt) {
3846
dest: 'dist/jquery.<%= pkg.name %>.min.js'
3947
}
4048
},
49+
4150
qunit: {
4251
all: {
4352
options: {
4453
urls: ['http://localhost:9000/test/<%= pkg.name %>.html']
4554
}
4655
}
4756
},
57+
58+
jade: {
59+
options: {
60+
pretty: true
61+
},
62+
dist: {
63+
files: [{
64+
expand: true,
65+
cwd: 'src',
66+
dest: 'test/',
67+
src: 'index.jade',
68+
ext: '.html'
69+
}]
70+
},
71+
},
72+
73+
coffee: {
74+
dist: {
75+
files: [{
76+
expand: true,
77+
cwd: 'src',
78+
src: '{,*/}*.coffee',
79+
dest: 'test/',
80+
ext: '.js'
81+
}]
82+
}
83+
},
84+
4885
jshint: {
4986
options: {
5087
reporter: require('jshint-stylish')
@@ -68,36 +105,78 @@ module.exports = function (grunt) {
68105
src: ['test/**/*.js']
69106
}
70107
},
108+
71109
watch: {
72110
gruntfile: {
73111
files: '<%= jshint.gruntfile.src %>',
74112
tasks: ['jshint:gruntfile']
75113
},
114+
jade: {
115+
files: ['src/index.jade'],
116+
tasks: ['jade']
117+
},
118+
bower: {
119+
files: ['bower.json'],
120+
tasks: ['bowerInstall']
121+
},
122+
coffee: {
123+
files: ['src/{,*/}*.coffee'],
124+
tasks: ['coffee']
125+
},
76126
src: {
77127
files: '<%= jshint.src.src %>',
78128
tasks: ['jshint:src', 'qunit']
79129
},
80130
test: {
81131
files: '<%= jshint.test.src %>',
82132
tasks: ['jshint:test', 'qunit']
83-
}
133+
},
84134
},
135+
85136
connect: {
86137
server: {
87138
options: {
88-
hostname: '*',
139+
hostname: '0.0.0.0',
89140
port: 9000
90141
}
91142
}
92143
}
93144
});
94145

95146
// Default task.
96-
grunt.registerTask('default', ['jshint', 'connect', 'qunit', 'clean', 'concat', 'uglify']);
147+
grunt.registerTask('default', [
148+
'clean',
149+
'test', // jade, coffeescript, jshint, qunit
150+
'concat',
151+
'uglify',
152+
]);
153+
154+
// Compile Jade and CoffeeScript
155+
grunt.registerTask('compile', [
156+
'newer:coffee',
157+
'newer:jade'
158+
]);
159+
160+
// Install Bower components
161+
grunt.registerTask('bowerInstall', [
162+
'bower'
163+
]);
164+
165+
// Server task
97166
grunt.registerTask('server', function () {
98167
grunt.log.warn('The `server` task has been deprecated. Use `grunt serve` to start a server.');
99168
grunt.task.run(['serve']);
100169
});
101-
grunt.registerTask('serve', ['connect', 'watch']);
102-
grunt.registerTask('test', ['jshint', 'connect', 'qunit']);
170+
171+
grunt.registerTask('serve', [
172+
'compile', // jade, coffeescript
173+
'connect',
174+
'watch'
175+
]);
176+
177+
grunt.registerTask('test', [
178+
'compile', // jade, coffeescript
179+
'jshint',
180+
'qunit'
181+
]);
103182
};

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,17 @@
2222
}
2323
],
2424
"devDependencies": {
25+
"grunt-contrib-coffee": "~0.7.0",
26+
"grunt-contrib-jade": "~0.11.0",
2527
"grunt-contrib-jshint": "~0.7.2",
2628
"grunt-contrib-qunit": "~0.3.0",
2729
"grunt-contrib-concat": "~0.3.0",
2830
"grunt-contrib-uglify": "~0.2.7",
2931
"grunt-contrib-watch": "~0.5.3",
3032
"grunt-contrib-clean": "~0.5.0",
3133
"grunt-contrib-connect": "~0.5.0",
34+
"grunt-bower-install": "~1.0.0",
35+
"grunt-newer": "~0.6.0",
3236
"time-grunt": "~0.2.3",
3337
"load-grunt-tasks": "~0.2.0",
3438
"jshint-stylish": "~0.1.3",

src/.jshintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
"boss": true,
1212
"eqnull": true,
1313
"browser": true,
14+
"devel" : true,
1415
"predef": ["jQuery"]
1516
}

src/animatecss.coffee

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# (function ($, window, document, undefined) {
2+
#
3+
# // Function-level strict mode syntax
4+
# 'use strict';
5+
#
6+
# $.fn.animateCSS = function (effect, delay, callback) {
7+
#
8+
# // Return this to maintain chainability
9+
# return this.each(function () {
10+
#
11+
# // Cache $(this) for speed and compression
12+
# var $this = $(this),
13+
# transitionEnd = "webkitAnimationEnd oanimationend msAnimationEnd animationend",
14+
# animated = "animated",
15+
# visibility = "visibility",
16+
# visible = "visible",
17+
# hidden = "hidden";
18+
#
19+
# // Create a function we can call later
20+
# function run() {
21+
#
22+
# // Add the animation effect with classes
23+
# $this.addClass( animated + " " + effect);
24+
#
25+
# // Check if the elemenr has been hidden to start with
26+
# if ($this.css( visibility ) === hidden) {
27+
#
28+
# // If it has, show it (after the class has been added)
29+
# $this.css( visibility, visible);
30+
#
31+
# }
32+
#
33+
# // If the element is hidden
34+
# if ($this.is(":" + hidden)) {
35+
#
36+
# // Show it
37+
# $this.show();
38+
#
39+
# }
40+
#
41+
# // Event triggered when the animation has finished
42+
# $this.bind( transitionEnd, function () {
43+
#
44+
# // Remove the classes so they can be added again later
45+
# $this.removeClass(animated + " " + effect);
46+
#
47+
# // Add a callback event
48+
# if (typeof callback === "function") {
49+
#
50+
# // Execute the callback
51+
# callback.call(this);
52+
#
53+
# // Unbind the event handlers
54+
# $this.unbind( transitionEnd );
55+
#
56+
# }
57+
#
58+
# });
59+
#
60+
# }
61+
#
62+
# // Check if delay exists or if it"s a callback
63+
# if (!delay || typeof delay === "function") {
64+
#
65+
# // If it"s a callback, move it to callback so we can call it later
66+
# callback = delay;
67+
#
68+
# // Run the animation (without delay)
69+
# run();
70+
#
71+
# } else {
72+
#
73+
# // Start a counter so we can delay the animation if required
74+
# setTimeout( run, delay );
75+
#
76+
# }
77+
#
78+
# });
79+
#
80+
# };
81+
#
82+
# })(jQuery, window, document);
83+
84+
85+
# Reference jQuery
86+
$ = jQuery
87+
88+
# Adds plugin object to jQuery
89+
$.fn.extend
90+
# Change pluginName to your plugin's name.
91+
pluginName: (options) ->
92+
# Default settings
93+
settings =
94+
option1: true
95+
option2: false
96+
debug: false
97+
98+
# Merge default settings with options.
99+
settings = $.extend settings, options
100+
101+
# Simple logger.
102+
log = (msg) ->
103+
console?.log msg if settings.debug
104+
105+
# _Insert magic here._
106+
return @each ()->
107+
log "Preparing magic show."
108+
# You can use your settings in here now.
109+
log "Option 1 value: #{settings.option1}"

src/animatecss.jade

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
doctype
2+
3+
html
4+
head
5+
meta(charset="utf-8")
6+
title Animate CSS jQuery Plugin Test Suite
7+
8+
//- bower:css
9+
link(rel="stylesheet", href="../bower_components/qunit/qunit/qunit.css", media="screen")
10+
//- endbower
11+
12+
body
13+
#qunit
14+
#qunit-fixture
15+
span lame test markup
16+
span normal test markup
17+
span awesome test markup
18+
19+
//- bower:js
20+
script(src="../bower_components/jquery/dist/jquery.js")
21+
script(src="../bower_components/qunit/qunit/qunit.js")
22+
//- endbower
23+
24+
//- Load local lib and tests
25+
script(src="../src/animatecss.js")
26+
script(src="animatecss_test.js")
27+
28+
//- Removing access to jQuery and $. But it'll still be available as _$, if you REALLY want to mess around with jQuery in the console. REMEMBER WE ARE TESTING A PLUGIN HERE, THIS HELPS ENSURE BEST PRACTICES. REALLY.
29+
30+
script.
31+
window._$ = jQuery.noConflict(true)

0 commit comments

Comments
 (0)