Looking to create a jQuery plugin in CoffeeScript using Test-driven development? If so, MiniBoilerplate is what you've been looking for.
As an example, MiniBoilerplate has been used to create the entire suite of MiniJs.com plugins.
Based on Grunt, node.js, CoffeeScript, Jasmine, PhantomJS and jQuery.
Includes default JavaScript, HTML, CSS and Readme file templates
jQuery, Jasmine and Jasmine jQuery libraries included
JavaScript code is written in CoffeeScript
Jasmine test suite, default helper templates provided and Travis-CI compatible
Instant CoffeeScript compilation and test suite status
It takes less than 5 minutes to get started
jQuery ->
$.pluginName = ( element, options ) ->
# current state
state = ''
# plugin settings
@settings = {}
# jQuery version of DOM element attached to the plugin
@$element = $ element
# set current state
@setState = ( _state ) -> state = _state
#get current state
@getState = -> state
# get particular plugin setting
@getSetting = ( key ) ->
@settings[ key ]
# call one of the plugin setting functions
@callSettingFunction = ( name, args = [] ) ->
@settings[name].apply( this, args )
@init = ->
@settings = $.extend( {}, @defaults, options )
@callSettingFunction( 'callback', [ @$element, @getSetting( 'message' ) ] )
@setState 'ready'
# initialise the plugin
@init()
# make the plugin chainable
this
# default plugin settings
$.pluginName::defaults =
message: 'hello word' # option description
callback: -> # callback description
$.fn.pluginName = ( options ) ->
this.each ->
if $( this ).data( 'pluginName' ) is undefined
plugin = new $.pluginName( this, options )
$( this).data( 'pluginName', plugin )
$('#element').pluginName({
message: 'hi',
callback: function() {
alert('bye');
}
});
ruby <(curl -fsSkL raw.github.com/mxcl/homebrew/go)
brew install phantomjs
brew install node
npm install -g grunt
cd path/to/miniboilerplate
npm install
grunt coffee
grunt jasmine
grunt jasmine-server
grunt
grunt watch
grunt min
1. Hook up your GitHub repository to Travis
2. Update plugin name in package.json
3. Update repository name at the very top of the README file (four spots)
4. Push your local Git repository to Github and go to Travis to check your build status
I am a Web Developer currently working at Envato as part of the Marketplace dev team in Melbourne, Australia. I focus mostly on Ruby/Rails technologies but I also enjoy coding in CoffeeScript. Visit my personal website and my Github page for more info about me.
Follow @mattaussaguel