Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch 'grunt'

Conflicts:
  .gitignore
  js/pluginName.coffee
  • Loading branch information...
commit 175db22e6e1c320084920aa353ddb30b916ee4d5 2 parents f3fe641 + 252ba6f
Matthieu Aussaguel matthieua authored
4 .gitignore
... ... @@ -1,5 +1,3 @@
1 1 .DS_Store
2   -Gemfile.lock
3   -.jhw-cache/
4 2 node_modules/
5   -_SpecRunner.html
  3 +_SpecRunner.html
11 .travis.yml
... ... @@ -1,8 +1,3 @@
1   -language: ruby
2   -bundler_args: --without development
3   -rvm:
4   - - 1.9.2
5   -env:
6   - - DISPLAY=:99.0
7   -before_install: sh -e /etc/init.d/xvfb start
8   -script: bundle exec rake jasmine:ci
  1 +language: node_js
  2 +node_js:
  3 + - 0.8
13 Gemfile
... ... @@ -1,13 +0,0 @@
1   -source 'http://rubygems.org'
2   -
3   -gem 'rake'
4   -gem 'jasmine'
5   -
6   -group :development do
7   - gem 'jasmine-headless-webkit'
8   - gem 'guard'
9   - gem 'guard-coffeescript'
10   - gem 'guard-jasmine-headless-webkit'
11   - gem 'growl'
12   - gem 'rb-fsevent'
13   -end
9 Guardfile
... ... @@ -1,9 +0,0 @@
1   -# CoffeeScript compilation
2   -guard 'coffeescript', :input => 'js', :output => 'js'
3   -guard 'coffeescript', :input => 'spec/coffeescripts', :output => 'spec/javascripts'
4   -
5   -# Jasmine tests suite
6   -guard 'jasmine-headless-webkit' do
7   - watch(%r{spec/coffeescripts/.+Spec\.coffee$}) { "spec/javascripts" }
8   - watch(%r{js/(.+)\.coffee$}) { "spec/javascripts" }
9   -end
9 Rakefile
... ... @@ -1,9 +0,0 @@
1   -
2   -begin
3   - require 'jasmine'
4   - load 'jasmine/tasks/jasmine.rake'
5   -rescue LoadError
6   - task :jasmine do
7   - abort "Jasmine is not available. In order to run jasmine, you must: (sudo) gem install jasmine"
8   - end
9   -end
70 grunt.js
... ... @@ -0,0 +1,70 @@
  1 +/*global module:false*/
  2 +module.exports = function(grunt) {
  3 + // Project configuration.
  4 + grunt.initConfig({
  5 + pkg : '<json:package.json>',
  6 + meta : {
  7 + banner : '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
  8 + '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
  9 + '<%= pkg.homepage ? "* " + pkg.homepage + "\n" : "" %>' +
  10 + '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
  11 + ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */'
  12 + },
  13 + coffee : {
  14 + helpers : {
  15 + src : 'spec/coffeescripts/helpers/*.coffee',
  16 + dest : 'spec/javascripts/helpers'
  17 + },
  18 + specs : {
  19 + src : 'spec/coffeescripts/*.coffee',
  20 + dest : 'spec/javascripts'
  21 + },
  22 + plugin : {
  23 + src : 'js/*.coffee',
  24 + dest : 'js'
  25 + }
  26 + },
  27 + jasmine : {
  28 + src : ['js/libs/**/*.js', 'js/*.js', 'spec/javascripts/libs/**/*.js'],
  29 + helpers : 'spec/javascripts/helpers/**/*.js',
  30 + specs : 'spec/javascripts/**/*.js'
  31 + },
  32 + watch : {
  33 + coffee : {
  34 + files: ['<config:coffee.helpers.src>', '<config:coffee.specs.src>', '<config:coffee.plugin.src>'],
  35 + tasks: 'coffee growl:coffee'
  36 + },
  37 + jasmine : {
  38 + files : ['<config:jasmine.src>', '<config:jasmine.specs>'],
  39 + tasks : 'jasmine growl:jasmine'
  40 + }
  41 + },
  42 + growl : {
  43 + coffee : {
  44 + title : 'CoffeeScript',
  45 + message : 'Compiled successfully'
  46 + },
  47 + jasmine : {
  48 + title : 'Jasmine',
  49 + message : 'Tests passed successfully'
  50 + }
  51 + },
  52 + min : {
  53 + dist : {
  54 + src : ['<banner:meta.banner>', 'js/<%= pkg.name %>.js'],
  55 + dest : 'js/<%= pkg.name %>.min.js'
  56 + }
  57 + }
  58 + });
  59 +
  60 + // Lib tasks.
  61 + grunt.loadNpmTasks('grunt-growl');
  62 + grunt.loadNpmTasks('grunt-jasmine-runner');
  63 + grunt.loadNpmTasks('grunt-coffee');
  64 +
  65 + // Default task.
  66 + grunt.registerTask('default', 'growl coffee jasmine');
  67 +
  68 + // Travis CI task.
  69 + grunt.registerTask('travis', 'jasmine');
  70 +};
6 index.html
@@ -3,7 +3,7 @@
3 3 <html lang="en">
4 4 <head>
5 5 <meta charset="utf-8">
6   - <title>Coffeescript jQuery Plugin Boilerplate</title>
  6 + <title>Plugin Name</title>
7 7 <link rel="stylesheet" href="css/site.css">
8 8 <!--[if IE]>
9 9 <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
@@ -14,7 +14,7 @@
14 14
15 15 <div id="container">
16 16 <header>
17   - <h1>Coffeescript jQuery Plugin Boilerplate</h1>
  17 + <h1>Plugin Name</h1>
18 18 </header>
19 19
20 20 <div id="main">
@@ -25,7 +25,7 @@
25 25 </div>
26 26
27 27 <script src="js/libs/jquery.min.js"></script>
28   - <script src="js/plugin.js"></script>
  28 + <script src="js/pluginName.js"></script>
29 29 <script>
30 30 $( function() {
31 31 $( '#main' ).pluginName( {
9,305 js/libs/jquery.min.js
9,301 additions, 4 deletions not shown
46 js/plugin.js
... ... @@ -1,46 +0,0 @@
1   -(function() {
2   -
3   - jQuery(function() {
4   - $.pluginName = function(element, options) {
5   - var setState;
6   - this.state = '';
7   - this.settings = {};
8   - this.$element = $(element);
9   - setState = function(state) {
10   - this.state = state;
11   - };
12   - this.getState = function() {
13   - return state;
14   - };
15   - this.getSetting = function(settingKey) {
16   - return this.settings[settingKey];
17   - };
18   - this.callSettingFunction = function(functionName, args) {
19   - if (args == null) {
20   - args = [];
21   - }
22   - return this.settings[functionName].apply(this, args);
23   - };
24   - this.init = function() {
25   - this.settings = $.extend({}, this.defaults, options);
26   - return this.callSettingFunction('callback', [this.$element, this.getSetting('message')]);
27   - };
28   - this.init();
29   - return this;
30   - };
31   - $.pluginName.prototype.defaults = {
32   - message: 'hello word',
33   - callback: function() {}
34   - };
35   - return $.fn.pluginName = function(options) {
36   - return this.each(function() {
37   - var plugin;
38   - if ($(this).data('pluginName') === void 0) {
39   - plugin = new $.pluginName(this, options);
40   - return $(this).data('pluginName', plugin);
41   - }
42   - });
43   - };
44   - });
45   -
46   -}).call(this);
25 js/plugin.coffee → js/pluginName.coffee
... ... @@ -1,14 +1,15 @@
1 1 #
2   -# CoffeeScript jQuery Plugin Boilerplace
3   -# Author: Matthieu Aussaguel, http://www.mynameismatthieu.com, @mattaussaguel
4   -# Version: 1.0 stable
5   -# Website: http://minijs.github.com/miniBoilerplate/
  2 +# Name : <plugin name>
  3 +# Author : <your name>, <your website url>, <twitter handle>
  4 +# Version : <version number>
  5 +# Repo : <repo url>
  6 +# Website : <website url>
6 7 #
7 8
8 9 jQuery ->
9 10 $.pluginName = ( element, options ) ->
10 11 # current state
11   - @state = ''
  12 + state = ''
12 13
13 14 # plugin settings
14 15 @settings = {}
@@ -17,23 +18,25 @@ jQuery ->
17 18 @$element = $ element
18 19
19 20 # set current state
20   - setState = ( @state ) ->
  21 + @setState = ( _state ) -> state = _state
21 22
22 23 #get current state
23   - @getState = -> @state
  24 + @getState = -> state
24 25
25 26 # get particular plugin setting
26   - @getSetting = ( settingKey ) ->
27   - @settings[settingKey]
  27 + @getSetting = ( key ) ->
  28 + @settings[ key ]
28 29
29 30 # call one of the plugin setting functions
30   - @callSettingFunction = ( functionName, args = [] ) ->
31   - @settings[functionName].apply( this, args )
  31 + @callSettingFunction = ( name, args = [] ) ->
  32 + @settings[name].apply( this, args )
32 33
33 34 @init = ->
34 35 @settings = $.extend( {}, @defaults, options )
35 36 @callSettingFunction( 'callback', [ @$element, @getSetting( 'message' ) ] )
36 37
  38 + @setState 'ready'
  39 +
37 40 # initialise the plugin
38 41 @init()
39 42
44 js/pluginName.js
... ... @@ -0,0 +1,44 @@
  1 +
  2 +jQuery(function() {
  3 + $.pluginName = function(element, options) {
  4 + var state;
  5 + state = '';
  6 + this.settings = {};
  7 + this.$element = $(element);
  8 + this.setState = function(_state) {
  9 + return state = _state;
  10 + };
  11 + this.getState = function() {
  12 + return state;
  13 + };
  14 + this.getSetting = function(key) {
  15 + return this.settings[key];
  16 + };
  17 + this.callSettingFunction = function(name, args) {
  18 + if (args == null) {
  19 + args = [];
  20 + }
  21 + return this.settings[name].apply(this, args);
  22 + };
  23 + this.init = function() {
  24 + this.settings = $.extend({}, this.defaults, options);
  25 + this.callSettingFunction('callback', [this.$element, this.getSetting('message')]);
  26 + return this.setState('ready');
  27 + };
  28 + this.init();
  29 + return this;
  30 + };
  31 + $.pluginName.prototype.defaults = {
  32 + message: 'hello word',
  33 + callback: function() {}
  34 + };
  35 + return $.fn.pluginName = function(options) {
  36 + return this.each(function() {
  37 + var plugin;
  38 + if ($(this).data('pluginName') === void 0) {
  39 + plugin = new $.pluginName(this, options);
  40 + return $(this).data('pluginName', plugin);
  41 + }
  42 + });
  43 + };
  44 +});
34 package.json
... ... @@ -0,0 +1,34 @@
  1 +{
  2 + "name" : "pluginName",
  3 + "title" : "Plugin Name",
  4 + "description" : "Example jQuery plugin using TDD",
  5 + "version" : "1.0.0",
  6 + "homepage" : "http://miniboilerplate.com",
  7 + "author" : {
  8 + "name" : "Matthieu Aussaguel",
  9 + "email" : "matthieu.aussaguel@gmail.com",
  10 + "url" : "http://mynameismatthieu.com"
  11 + },
  12 + "repository" : {
  13 + "type" : "git",
  14 + "url" : "git://github.com/miniJs/miniBoilerplate.git"
  15 + },
  16 + "description" : "Looking to create a jQuery plugin in CoffeeScript using Test-driven development? If so, MiniBoilerplate is what you've been looking for.",
  17 + "keywords": ["development", "workflow", "rapid", "test", "jasmine", "jquery", "plugin", "headless", "javascript", "coffeescript", "guard", "boilerplate", "default", "toolkit", "base"],
  18 + "bugs" : {
  19 + "url" : "https://github.com/miniJs/miniBoilerplate/issues"
  20 + },
  21 + "licenses": [{
  22 + "type": "MIT",
  23 + "url" : "http://matthieuaussaguel.mit-license.org/"
  24 + }],
  25 + "devDependencies" : {
  26 + "grunt" : "0.3.15",
  27 + "grunt-coffee" : "0.0.6",
  28 + "grunt-growl" : "0.1.2",
  29 + "grunt-jasmine-runner" : "0.5.5"
  30 + },
  31 + "scripts": {
  32 + "test": "grunt travis"
  33 + }
  34 +}
16 spec/coffeescripts/PluginSpec.coffee → spec/coffeescripts/PluginNameSpec.coffee
@@ -25,14 +25,26 @@ describe 'PluginName', ->
25 25 expect( plugin.settings.message ).toBe( options.message )
26 26 expect( plugin.settings.callback ).toBe( options.callback )
27 27
  28 + describe 'plugin state', ->
  29 + beforeEach ->
  30 + @plugin = new $.pluginName( @$element )
  31 +
  32 + it 'should have a ready state', ->
  33 + expect( @plugin.getState() ).toBe 'ready'
  34 +
  35 + it 'should be updatable', ->
  36 + @plugin.setState( 'new state' )
  37 +
  38 + expect( @plugin.getState() ).toBe 'new state'
  39 +
28 40 describe 'plugin logic', ->
29   - it 'should execute the callback append the hello world! to the element', ->
  41 + it 'should execute the callback method', ->
30 42 @$element.pluginName( options )
31 43
32 44 expect( @$element ).toHaveText 'Hello World!'
33 45
34 46 describe 'callback', ->
35   - it 'should execute the callback with the right arguments', ->
  47 + it 'should execute the callback with the correct arguments', ->
36 48 options =
37 49 message: options.message
38 50 callback: jasmine.createSpy 'callback'
61 spec/javascripts/PluginNameSpec.js
... ... @@ -0,0 +1,61 @@
  1 +
  2 +describe('PluginName', function() {
  3 + var options;
  4 + options = {
  5 + message: 'Hello World',
  6 + callback: function(element, text) {
  7 + return $(element).append("" + text + "!");
  8 + }
  9 + };
  10 + beforeEach(function() {
  11 + loadFixtures('fragment.html');
  12 + return this.$element = $('#fixtures');
  13 + });
  14 + describe('plugin behavior', function() {
  15 + it('should be available on the jQuery object', function() {
  16 + return expect($.fn.pluginName).toBeDefined();
  17 + });
  18 + it('should be chainable', function() {
  19 + return expect(this.$element.pluginName()).toBe(this.$element);
  20 + });
  21 + it('should offers default values', function() {
  22 + var plugin;
  23 + plugin = new $.pluginName(this.$element);
  24 + return expect(plugin.defaults).toBeDefined();
  25 + });
  26 + return it('should overwrites the settings', function() {
  27 + var plugin;
  28 + plugin = new $.pluginName(this.$element, options);
  29 + expect(plugin.settings.message).toBe(options.message);
  30 + return expect(plugin.settings.callback).toBe(options.callback);
  31 + });
  32 + });
  33 + describe('plugin state', function() {
  34 + beforeEach(function() {
  35 + return this.plugin = new $.pluginName(this.$element);
  36 + });
  37 + it('should have a ready state', function() {
  38 + return expect(this.plugin.getState()).toBe('ready');
  39 + });
  40 + return it('should be updatable', function() {
  41 + this.plugin.setState('new state');
  42 + return expect(this.plugin.getState()).toBe('new state');
  43 + });
  44 + });
  45 + describe('plugin logic', function() {
  46 + return it('should execute the callback method', function() {
  47 + this.$element.pluginName(options);
  48 + return expect(this.$element).toHaveText('Hello World!');
  49 + });
  50 + });
  51 + return describe('callback', function() {
  52 + return it('should execute the callback with the correct arguments', function() {
  53 + options = {
  54 + message: options.message,
  55 + callback: jasmine.createSpy('callback')
  56 + };
  57 + new $.pluginName(this.$element, options);
  58 + return expect(options.callback).toHaveBeenCalledWith(this.$element, "Hello World");
  59 + });
  60 + });
  61 +});
52 spec/javascripts/PluginSpec.js
... ... @@ -1,52 +0,0 @@
1   -(function() {
2   -
3   - describe('PluginName', function() {
4   - var options;
5   - options = {
6   - message: 'Hello World',
7   - callback: function(element, text) {
8   - return $(element).append("" + text + "!");
9   - }
10   - };
11   - beforeEach(function() {
12   - loadFixtures('fragment.html');
13   - return this.$element = $('#fixtures');
14   - });
15   - describe('plugin behavior', function() {
16   - it('should be available on the jQuery object', function() {
17   - return expect($.fn.pluginName).toBeDefined();
18   - });
19   - it('should be chainable', function() {
20   - return expect(this.$element.pluginName()).toBe(this.$element);
21   - });
22   - it('should offers default values', function() {
23   - var plugin;
24   - plugin = new $.pluginName(this.$element);
25   - return expect(plugin.defaults).toBeDefined();
26   - });
27   - return it('should overwrites the settings', function() {
28   - var plugin;
29   - plugin = new $.pluginName(this.$element, options);
30   - expect(plugin.settings.message).toBe(options.message);
31   - return expect(plugin.settings.callback).toBe(options.callback);
32   - });
33   - });
34   - describe('plugin logic', function() {
35   - return it('should execute the callback append the hello world! to the element', function() {
36   - this.$element.pluginName(options);
37   - return expect(this.$element).toHaveText('Hello World!');
38   - });
39   - });
40   - return describe('callback', function() {
41   - return it('should execute the callback with the right arguments', function() {
42   - options = {
43   - message: options.message,
44   - callback: jasmine.createSpy('callback')
45   - };
46   - new $.pluginName(this.$element, options);
47   - return expect(options.callback).toHaveBeenCalledWith(this.$element, "Hello World");
48   - });
49   - });
50   - });
51   -
52   -}).call(this);
6 spec/javascripts/helpers/SpecHelper.js
... ... @@ -1,6 +1,2 @@
1   -// Generated by CoffeeScript 1.3.3
2   -(function() {
3 1
4   - beforeEach(function() {});
5   -
6   -}).call(this);
  2 +beforeEach(function() {});

0 comments on commit 175db22

Please sign in to comment.
Something went wrong with that request. Please try again.