Working with Rails is nice. Not only is Rails already setting up a nearly complete environment for you, the community has created many great additions. A quite popular example is thoughtbot's suspenders. Well, here's my little template/project/BDD environment that I use for JavaScript projects (often reusable stuff that I move out of my Rails projects).
It includes:
- The BlueRidge testing framework (which in turn includes Screw.Unit, Smoke, Rhino and env.js).
- JsDoc ToolKit for documentation generation.
- Sprockets for dependency management and concatenation.
- JSLint as a code quality tool
Build
To build/bundle your JavaScript source into a single, distributable JavaScript file we use Sprockets which is run from a Rake task:
rake buildWill bundle all JavaScripts in the top-level src/ directory. To require files in subdirectories, you will have to use Sprockets require statements or build:recursive:rake build:recursiveTo only build a single file, you can specify it as follows:rake build FILE="singlefile.js"By default the build task will strip comments, to keep the comments you can userake build:keepcommentsAndrake build:recursive:keepcommentsTests/SpecsTo run all your JavaScript specs/tests (based on blue-ridge's Rake tasks):
rake test(Or just use one of the aliases if it suits you better: `spec`, `examples`, `spec:javascripts`, `examples:javascripts`, ...)To only run an individual test file:
rake test TEST=applicationTo run your tests in the browser, just open the fixture associated with the test. You can userake test:fixturesas a shorthand to open your fixtures directory.To start the Rhino shell (with jQuery and env.js pre-loaded):
rake test:shellDocumentationTo generate JsDoc documentation for your project:
rake doc:buildOnce the task has finished, the generated files will be located in doc/jsdoc relative to your project directory.Code Quality
There is a Rake task to run JSLint on your current build, too:
rake lintJSLint's rhino.js script has been modified to automatically set the option *browser* to *true*, which will predefine the standard global properties that are supplied by web browsers, such as *document* and *alert*.I hope others might find this useful as well. Contribution are obviously welcome.
Labels: JavaScript, Programming
It has been a while since the
Often, I do not feel like agreeing with Linus Torvalds. This is not because he is not right, but because of the very opinionated, sometimes even stubborn way he brings his message(s) across. To me one of his most interesting exploits comes from one of the messages he posted to the Linux kernel mailing list back in 2001 (which is
This post in the