CoffeeMugg is a branch of CoffeeKup. The main difference is that instead of local tag functions, tag functions are bound to
- No magic compilation step: the template code runs as you would expect.
- If you want to create a template dynamically using function closures, you can!
- This makes it easier to create libraries of view-helper routines, in the manner of RoR ActionView.
cm = require 'coffeemugg' cm.render -> @div -> @p "I am a paragraph" @raw "<p> This is unescaped, raw HTML </p>" @text "<< This will be escaped ! >>"
Custom TAG functions (subroutines)
You can add custom @TAG functions to CoffeeMugg with 'plugins'.
Sample plugins are in the 'plugins' directory. The best way to use them is to copy them into your project (which manages your dependencies), and install them via 'install_plugin':
cm = require 'coffeemugg' # Use the 'marked' markdown language. # Your project needs to have 'marked' as a dependency. # Note, './plugins' is a folder in _your_ project. cm.install_plugin require('./plugins/marked') # Use the 'partials' system for templating ease. # Note, './templates' is a folder in your project. cm.install_plugin require('./plugins/partials')(require, './templates') template = -> @p -> @marked "This is using __markdown__" @partial '_mypartial', 'myarg'
npm install coffeemugg
Create static html files in CoffeeMugg syntax. It's adapted from coffeecup.
coffeemugg -h Usage: coffeemugg [options] path/to/template.coffee -w, --watch watch templates for changes, and recompile -o, --output set the directory for compiled html -p, --print print the compiled html to stdout, don't write file -f, --format apply line breaks and indentation to html output -v, --version display coffeemugg version -h, --help display this help message
Please take a look at the excellent CoffeeScript documentation for more information.