I’m happy to report that WebMatrix 2 shipped today. WebMatrix is a lightweight (and free!) web development tool. It excels at editing HTML, JavaScript, and CSS, which makes it a natural fit to use with Site44. This latest release also adds first-class support for CoffeeScript and LESS.
Getting started with WebMatrix and Site44
If you’re not already a Site44 user, please give it a try. All you need is a Dropbox account, and creating a free website takes only a minute. To create a site, browse to Site44 and click “Sign in with Dropbox.” Once you’ve signed in, click “Create a new website,” give it a name, and you’re done!
At this point, you should have a new folder in Dropbox. Any changes you make in that folder are directly reflected on your website. (When I did this, I called my website “webmatrix.site44.com,” so my folder is called “Dropbox\Apps\site44\webmatrix.site44.com.”)
When you open up WebMatrix, choose “open folder as a site,” and browse to the folder in Dropbox. That’s all you need to do to edit a Site44 website with WebMatrix.
Using CoffeeScript and LESS
CoffeeScript and LESS are languages that compile to JavaScript and CSS, respectively. WebMatrix 2 supports both right out of the box. When you create a new file, click on “All” to show all supported file types, and you’ll see CoffeeScript and LESS there.
WebMatrix has nice support (including syntax-highlighting and autocomplete) for these languages, but note that browsers don’t understand them natively, so you need to compile them down to JavaScript and CSS for them to work.
WebMatrix can actually do that compilation for us, through an extension called “OrangeBits.” To enable this functionality, you’ll need to click on the “Gallery” button in the ribbon. This opens the extension gallery, and from there you can choose OrangeBits and install it. (This all takes just a few seconds, and you only need to do it once.)
Once you’ve installed OrangeBits, every time you save a .coffee or .less file, it will automatically be compiled to a corresponding .js or .css file. OrangeBits itself is open source, so if you want to learn more about how it works, check it out on GitHub.
An example
When I was playing around with CoffeeScript and LESS in WebMatrix, I built a little site at webmatrix.site44.com. It’s an utterly useless website, but I hope it serves as an example of what you can do when you combine WebMatrix with Site44.
The HTML of the page is simple:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
Notice that I’m referencing clicky.js
and StyleSheet.css
. Those are being automatically generated from CoffeeScript and LESS. The CoffeeScript handles button clicks and uses jQuery to toggle a CSS class on the content part of the page:
1 2 |
|
Here are a few tips to understanding CoffeeScript:
- The arrow operator translates to
function () { ... }
. This saves a lot of typing when writing callbacks and event handlers. - Functions can be called Ruby-style (with a space instead of parentheses).
foo bar, baz
translates tofoo(bar, baz)
.
The stylesheet is created by a similar process. Here’s the source:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
Here are a few things to notice about LESS:
- Those .box-shadow rules are essentially reusable subroutines. These “mixins,” as they’re called, can save a ton of copy/pasting when writing CSS.
- There’s a variable:
@color
, and it’s manipulated in a few places (lighten
,desaturate
, anddarken
). I can change the entire style of the page by just changing that variable, rather than having to update four different colors. - Instead of having to write
#main.reverse h1 { ... }
, I was able to just nest theh1
rule inside the#main.reverse
rule. This nesting makes the styles easier to read and maintain.
“Just save”
WebMatrix’s support for CoffeeScript and LESS (via the OrangeBits extension) shares a common philosophy with Site44, which is that you should be able to just save a file and be done. When you save a .coffee or .less file, WebMatrix automatically compiles it into .js or .css. And when you save anything to your folder in Dropbox, Site44 automatically picks up those changes and reflects them in your website. In this way, WebMatrix makes a great addition to your Site44 workflow.