Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Organizing multiple CoffeeScript files

I am working on an implementation of a web service where we are writing our front end code in CoffeeScript. The problem I have stumbled on is while the project is growing functionality has to be separated in different files. What I really need is a simple structure where in the utils.coffee file I will have the general functions which are required from every page and on each separate file I will have page_foo.coffee page_bar.coffee the specific functions. How can I structure it properly so I also make sure utils.coffee loads first and is accessible from everyone?

like image 899
topless Avatar asked Jan 07 '12 12:01

topless


1 Answers

With CoffeeToaster you have the ability to include files that you'll need at the top of them, making sure your final ".js" file (that will be also a merge of all your CoffeeScript files) have everything in the proper order, for use inside the browser.

Take a look on the docs:
http://github.com/serpentem/coffee-toaster

It comes also with a packaging system that when enabled will use your folder's hierarchy as namespaces declarations to your classes if you want so, then you can extends classes from multiple files, do imports and son, such as like:

#<< another/package/myclass
class SomeClass extends another.package.MyClass

The build configuration is extremely minimalist:

# => SRC FOLDER
toast 'src_folder'
    # => VENDORS (optional)
    # vendors: ['vendors/x.js', 'vendors/y.js', ... ]

    # => OPTIONS (optional, default values listed)
    # bare: false
    # packaging: true
    # expose: ''
    # minify: false

    # => HTTPFOLDER (optional), RELEASE / DEBUG (required)
    httpfolder: 'js'
    release: 'www/js/app.js'
    debug: 'www/js/app-debug.js'

There's even a debug option that compile files individually for ease the debugging processes and another useful features.

like image 54
Anderson Arboleya Avatar answered Oct 05 '22 14:10

Anderson Arboleya