Building Sassy prototypes with Frank
Better living through Ruby by-products
In order to rapidly build prototypes for new features, we’ve started using a totally new process in Emma’s UX group. Where we would normally spend hours crafting an interface in a wireframe app such as OmniGraffle, we’ve gone straight from paper to the browser.
To avoid feeling constrained by the look of pixels to begin with, we start by drawing ideas on graph paper. After that’s been worked out satisfactorily, we move on to HTML, CSS and JavaScript. We’ve found a really nice routine that’s easy to pass off to the team that will go on to build the feature. It’s called Frank. (Yes, Frank is actually a software and not a person.)
While it’s neat to be able to throw some templates together and reduce the amount of repetitive HTML we use to build out click-able prototypes, the main timesaving feature of Frank is the ability to use Sass (without relying on a TextMate plugin or running sass --watch from the command line). You can also use Haml, which is terse, but the benefit of that is somewhat dubious IMO.
Sass is awesome
Ever wanted to put variables in your CSS? Name your colors so you don’t have to remember hex values or litter your HTML with un-semantic color names? Write your CSS as if you were writing Python? All but that last one? That’s what I thought.
Sass is a system that compiles fancy, indention-based syntax into normal (verbose) CSS. Here’s a taste:
#container
width: 960px
margin: 10px auto
a
font-size: 20px
color: #f00
Which would compile to:
#container {
width: 960px;
margin: 10px auto; }
#container a {
font-size: 20px;
color: #f00; }
The Sass is not much less code versus the CSS in this simple example, but note that the indentation automatically creates nested selectors like #container a. That makes for very specific CSS that’s easy to maintain.
Now, look what else is possible. You can define named variables (technically constants) and assign color values to them.
$pale_blue: #EAF5FC
Then you can use them like this:
#container
background: $pale_blue
Taking that idea a step further, you can do things like:
#container
background: darken($pale_blue, 20%)
Not too shabby, eh?
Now for Mixins. Once you get to the concept of these, you see how Sass gives you CSS superpowers. Observe.
Define a Mixin like so:
@mixin rounded($radius)
-webkit-border-radius: $radius
-moz-border-radius: $radius
border-radius: $radius
Then you can use it like this:
#container
@include rounded(10px)
Bam. You just rounded the #container’s corners without having to triplicate your work by including all the browser-specific prefixes.
Here’s another incredible time-saver:
@mixin clearfix
*display: inline-block
&:after
content: " "
display: block
height: 0
clear: both
visibility: hidden
No more adding non-semantic clearing classes in your markup, or, heaven forbid, extra markup (you don’t really do that anymore, do you?) just to have a container clear its floated content.
#container
@include clearfix
And if there’s ever a new technique needed for a new browser, just add it to this Mixin, and it’s automatically used everywhere you’re calling it.
Here’s what all of that fanciness looks like together:
#container
background: darken($pale_blue, 20%)
@include rounded(10px)
@include clearfix
Frank
So Frank is great because you can use Sass. Frank is also great because you can build site structures with pretty URLs without any configuration.
A folder structure like this…
/about/
index.haml
/mission/
index.haml
/people/
index.haml
… will automatically create URLs like /about/, /about/mission/ and /about/people/ as well as parsing out the dynamic Haml and Sass. And this is all done without having to configure Apache and Virtual Hosts. You’re always just a $frank up away from browsing the site locally. (If you do have a need to mess with Virtual Hosts in general, check out VirtualHostX.)
Using Frank in production
We’re in good company. Our friends over at MailChimp are using Frank to power their marketing site. If you don’t have need for a CMS and all your site contributors are cool with editing source code, I can’t think of a better way to power a website (with the exception, maybe, of Jekyll).

