New-School HTML

Introduce new-school HTML to people and make it approachable.

The Current State of the Web

The Problem

The Solution

What is Sass?

Why use Sass?

How to use Sass:

Sass will watch your file for any changes and kick out a new compiled stylesheet whenever you save.

SCSS Syntax

Using Sass with existing CSS

If you’re on a project that doesn’t currently use Sass, you can easily convert existing CSS files to any Sass format.

What is Compass?

Why use Compass?

How to use Compass:

Compass will watch your files for any changes and compile them, just like Sass.

CSS3 Mixins

Compass has a ton of CSS3 mixins for:

… and more. Ready to go.

Box Shadows (handles Webkit, Gecko, and CSS3)

Before:

Compass:

Border Radius (handles Webkit, Mozilla, Gecko, IE9, and CSS3)

Before:

Compass:

Functions

Compass provides a bunch of useful Sass functions, like image-height, which can read in an image and provide the dimensions for you in your stylesheet. No more measuring!

What is Mustache.js?

What is Templating?

A Mustache template …

<div>
  <h1>Hello, {{name}}!</h1>
  <h2>You have {{points}} points.</h2>
</div>

… plus data

var user = { name : 'Larissa', points : 5000 };

… equals some good lookin’ markup:

<div>
  <h1>Hello, Larissa!</h1>
  <h2>You have 5000 points.</h2>
</div>

How would you have done that without Templating?

Probably like this:

var user = { name : 'Larissa', points : 5000 };

var markup = "<div><h1>Hello, "
  + user.name 
  + "!</h1><h2>You have "
  + user.points
  + " points.</h2></div>";

But this puts HTML into your JavaScript as strings, and maintaining that is a real pain.

Why use Mustache.js?

How to use Mustache.js:

Set up a template and a place to put your HTML:

<script id="my-template" type="text/x-mustache-template">
  <h1>{{message}}</h1>
</script>

<div id="target-div"></div>

Then interpolate javascript values into it:

var jsonData = { message: "Hello World!" };

var myTemplate = $( '#my-template' ).text();

$( '#target-div' ).html(Mustache.to_html(myTemplate, jsonData));

Mustache takes the properties from the data and puts it into your template.

<div id="target-div">
  <h1>Hello World!</h1>
</div>

Iterating over collections

Mustache has the ability to implicitly iterate over a collection it parses.

<script id="my-template" type="text/x-mustache-template">
  {{#peeps}}
  <div>Hello, {{name}}!</div>
  {{/peeps}}
</script>

The data model has a peeps field with an array of objects.

var jsonData = { peeps : [
  { name : "Alice" }, 
  { name : "Bob" }, 
  { name : "Candice" }
] };

var myTemplate = $( "#my-template" ).html( );

$( "#target-div" ).html( Mustache.to_html( myTemplate, jsonData ) );

Each object will be passed to the iterator, so we can grab all of the names.

<div id="target-div">
  <div>Hello, Alice!</div>
  <div>Hello, Bob!</div>
  <div>Hello, Candice!</div>
</div>

Conclusion

HTML and CSS were meant to build documents, not applications.

With Sass, Compass, and Mustache, we now have better tools for authoring and managing our static web content.