66
Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

Views with AttitudeIntroducing Sass, Austin on Rails, May 24, 2011

@soopaDesigner & Developer at Gowalla

Page 2: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

I ♥ Sass

Page 3: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

I ♥ SCSS

Page 4: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

// .sassbody background-color: #fff;

// .scssbody { background-color: #fff;}

Page 5: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

Sass is not Haml

X

Page 6: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

Sass is not Compass

X

Page 7: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

Sass 101

Page 8: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

Variables$blue: #39b2e5;$baseline: 20px !default;

hgroup h1 { color: $blue; margin-bottom: $baseline;}

Page 9: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

$baseline: 20px !default;

baseline ||= '20px'

Page 10: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

Math$blue: #39b2e5;$baseline: 20px !default;

hgroup h1 { color: $blue;

margin-bottom: $baseline * 2;}

Page 11: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

Nested Selectorshgroup { font-weight: bold; h1 { color: $blue; font-family: Georgia; font-size: 24px; margin-bottom: $baseline * 2; } h2 { font-family: Helvetica; font-size: 18px; }}

Page 12: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

Nested Ruleshgroup { font-weight: bold; h1 { color: $blue;

font { family: Helvetica; size: 24px; } margin-bottom: $baseline * 2; } h2 { font { family: Helvetica; size: 18px; } }}

Page 13: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

Mixins@mixin heading($size, $family: Helvetica, $weight: bold, $color: inherit) { color: $color; font: $weight $size $family;}

hgroup { h1 { @include heading($size: 24px, $family: Georgia, $color: $blue); margin-bottom: $baseline * 2; } h2 { @include heading(18px); }}

Page 14: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

Extendhgroup { h1 { @include heading($size: 24px, $family: Georgia, $color: $blue); margin-bottom: $baseline * 2; } h2 { @include heading(18px); }

h3:first-child { @extend h1; }}

Page 15: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

Parent Selectorshgroup { h1 { @include heading($size: 24px, $family: Georgia, $color: $blue); margin-bottom: $baseline * 2; } h2 { @include heading(18px); } h3:first-child { @extend h1; // crazy client demands H3’s on the homepage be underlined

body.home & { text-decoration: underline; } }}

Page 16: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

Functionshgroup { h1 { @include heading($size: 24px, $family: Georgia, $color: $blue); margin-bottom: $baseline * 2; } h2 { @include heading(18px); } h3:first-child { @extend h1; // crazy client demands H3’s on the homepage be underlined AND darker!? body.home & { text-decoration: underline;

color: darken($blue, 25%); } }}

Page 17: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

Control Directiveshgroup { h1 { @include heading($size: 24px, $family: Georgia, $color: $blue); margin-bottom: $baseline * 2; } h2 { @include heading(18px); } h3:first-child { @extend h1; // crazy client demands H3’s on the homepage be underlined AND darker!? body.home & { text-decoration: underline; color: darken($blue, 25%); // crazy client wants `-webkit-slightly-escalating-text` too!

@for $i from 1 through 5 { .char#{$i} { top: -$i * 2; } } } }}

Page 18: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

Control Directives$environment: staging;

@if $environment != production { // crazy client demands H3’s on the homepage be underlined AND darker!? body.home & { text-decoration: underline; color: darken($blue, 25%); // now he wants -webkit-slightly-escalating-text too! @for $i from 1 through 5 { .char#{$i} { top: -$i * 2; } } }}

Page 19: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

Template Chaining// main.css.scss.erb

$environment: <%= Rails.env %>;

@if $environment != production { // crazy client demands H3’s on the homepage be underlined AND darker!? body.home & { text-decoration: underline; color: darken($blue, 25%); // now he wants -webkit-slightly-escalating-text too! @for $i from 1 through 5 { .char#{$i} { top: -$i * 2; } } }}

Page 20: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

Interpolation// main.css.scss.erb$environment: <%= Rails.env %>;

@if $environment != production { // crazy client demands H3’s on the homepage be underlined AND darker!? body.home & { text-decoration: underline; color: darken($blue, 25%); // now he wants -webkit-slightly-escalating-text too! @for $i from 1 through 5 {

.char#{$i} { top: -$i * 2; } } }}

Page 21: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

Quiet Comments// main.css.scss.erb$environment: <%= Rails.env %>;

@if $environment != production { // crazy client demands H3’s on the homepage be underlined AND darker!? body.home & { text-decoration: underline; color: darken($blue, 25%); // now he wants -webkit-slightly-escalating-text too! @for $i from 1 through 5 { .char#{$i} { top: -$i * 2; } } }}

Page 22: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

Compiling

Page 23: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

$blue: #39b2e5; $baseline: 20px !default;$environment: <%= Rails.env %>;

@mixin heading($size, $family: Helvetica, $weight: bold, $color: inherit) { color: $color; font: $weight $size $family;}

hgroup { h1 { @include heading($size: 24px, $family: Georgia, $color: $blue); margin-bottom: $baseline * 2; } h2 { @include heading(18px); } h3:first-child { @extend h1; @if $environment != production { // crazy client demands H3’s on the homepage be underlined AND darker!? body.home & { text-decoration: underline; color: darken($blue, 25%); // now he wants -webkit-slightly-escalating-text too! @for $i from 1 through 5 { .char#{$i} { top: -$i * 2; } } } } }}

Page 24: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

hgroup h1, hgroup h3:first-child { color: blue; font: bold 24px Georgia; margin-bottom: 40px; } hgroup h2 { color: inherit; font: bold 18px Helvetica; }body.home hgroup h3:first-child { text-decoration: underline; color: #12688c; }body.home hgroup h3:first-child .char1 { top: 2; }body.home hgroup h3:first-child .char2 { top: 4; }body.home hgroup h3:first-child .char3 { top: 6; }body.home hgroup h3:first-child .char4 { top: 8; }body.home hgroup h3:first-child .char5 { top: 10; }

Page 25: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

Sass::Plugin.options[:never_update] = true

Page 26: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

`sass source:destination --style compressed`

Page 27: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

`sass --watch app/sass:public/css`

Page 28: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

_partial.scss

file.scss

Page 29: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

Sass Tips

Page 30: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

The Inception Ruleheader { nav { height: 40px; ul { margin: 10px 0; li { float: left; a { border-bottom: 1px solid #ccc; display: inline-block; } } } }}

Page 31: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

The Inception Ruleheader { li { float: left; a { border-bottom: 1px solid #ccc; display: inline-block; height: 40px; padding: 10px 0; } }}

Page 32: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

Alphabetize Propertiesinput { color: #666; height: 24px; width: 190px; padding: 0 10px 0 25px; border: none; outline: none; width: 180px!important;}

Page 33: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

Alphabetize Propertiesinput { border: none; color: #666; height: 24px; outline: none; padding: 0 10px 0 25px; width: 190px;}

Page 34: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

Single Line Ruleul { list-style-type: none; }

Page 35: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

Create a Styleguide// Typography

$base-font-size: 16px;$base-line-height: 20px;

$font-size-s: 12px;$font-size-m: 13px;$font-size-l: $base-font-size;$font-size-xl: 18px;$font-size-xxl: 24px;

// Colors

$white: #ffffff;$black: #202020; $light-gray: #b3b3b3;$gray: #838383;$dark-gray: #525252; $orange: #ff920d;$yellow: #ffe573;$green: #339922;

Page 36: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla
Page 37: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

Installation

gem 'compass'

`compass init rails`

Page 38: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

Mixin Library@import "compass/css3";

article { @include box-sizing(border-box); @include border-radius(5px); @include box-shadow($gray, 0, 1px, 0); background-color: $light-gray;}

Page 39: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

CSS Frameworks@import "blueprint/grid";@import "compass/css3";

$blueprint-grid-columns: 12;$blueprint-grid-margin: 20px;$blueprint-grid-width: 60px;

article { @include box-sizing(border-box); @include border-radius(5px); @include box-shadow($gray, 0, 1px, 0); @include column(8); background-color: $light-gray;}

Page 40: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

article { -moz-box-sizing: border-box; -webkit-box-sizing: border-box; -ms-box-sizing: border-box; box-sizing: border-box; -moz-border-radius: 5px; -webkit-border-radius: 5px; -o-border-radius: 5px; -ms-border-radius: 5px; -khtml-border-radius: 5px; border-radius: 5px; -moz-box-shadow: 0 1px 0 #838383; -webkit-box-shadow: 0 1px 0 #838383; -o-box-shadow: 0 1px 0 #838383; box-shadow: 0 1px 0 #838383; display: inline; float: left; margin-right: 20px; width: 300px; background-color: #b3b3b3;}* html article { overflow-x: hidden;}

Page 41: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

public/icons/social/ dribbble.png facebook.png flickr.png twitter.png

Automatic Spriting

Page 42: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

Automatic Spriting@import "icons/social/*.png";

nav a { .dribbble { @include social-sprite(dribbble); } .facebook { @include social-sprite(facebook); } .flickr { @include social-sprite(flickr); } .twitter { @include social-sprite(twitter); }}

Page 43: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

Automatic Spriting.social-sprite, nav a.dribbble, nav a.facebook, nav a.flickr, nav a.twitter { background: url('/images/icons/social.png') no-repeat;}

nav a.dribbble { background-position: 0 0;}nav a.facebook { background-position: 0 -48px;}nav a.flickr { background-position: 0 -96px;}nav a.twitter { background-position: 0 -144px;}

Page 44: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

Automatic Spriting@import "icons/social/*.png";

nav a { .dribbble { @include social-sprite(dribbble); } .facebook { @include social-sprite(facebook); } .flickr { @include social-sprite(flickr); } .twitter { @include social-sprite(twitter); }}

Page 45: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

Automatic Spriting@import "icons/social/*.png";

nav a { @each $file in dribbble, facebook, flickr, twitter { &.#{$file} { @include social-sprite($file); } }}

Page 46: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

Helpersinput[type=search] { background: { image: image-url('icons/spyglass.png'); position: left center; repeat: no-repeat; }}

Page 47: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

Helpersinput[type=search] { background: { image: url('/images/icons/spyglass.png'); position: left center; repeat: no-repeat; }}

Page 48: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

Inline Datainput[type=search] { background: { image: inline-image('icons/spyglass.png'); position: left center; repeat: no-repeat; }}

Page 49: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

Inline Datainput[type=search] { background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAAsTAAALEwEAmpwYAAABS0lEQVQ4EZWSPS9EQRSGd3YjYmu7+wdQaLZAsEGjligU21ESiUqhI1GIXyKi4RewKBQSWiKxIioiIb4auZ537xkZ4ybsSZ45c77euXPvdUmS5Lw55zrZj8MQFOEcGvQ84LNNAiZSo+MEpBjSJJ71fbH3w6M0PdrgPn4ZFmELPkGCC/GwYlkXnIKiNSiEjcTT8AJP0BfWvMAkBQ0fgIsbrGnDelbjep7CCMj2KKbPlMbhumvBYJjUXgJ627L31GWuH5btiKsSOLPkRFwMYn0h2WXqfq7dhHegU6biO5LrgWt4g9qvul17jqLu/wrrMAxVmAcNq3YD5UwBE1mi4dmaNRBya3EDXwpFWp+NZMv4lfvZ1GEA9MIuYAeuYBvG4BBmELnHc4z9yn95WstwpBH4fpJ/C+gATCLH4EUqbQmYSCUQWWlbwERKiGxC7xd6NW0WLGy4BwAAAABJRU5ErkJggg=='); background-position: left center; background-repeat: no-repeat;}

Page 50: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla
Page 51: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

// Config

$environment: <%= Rails.env %>;

// Grid

$blueprint-grid-columns: 12;$blueprint-grid-margin: 20px;$blueprint-grid-width: 60px;

// Typography

$base-font-size: 16px;$baseline: 20px !default;

$font-size-s: 12px;$font-size-m: 13px;$font-size-l: $base-font-size;$font-size-xl: 18px;$font-size-xxl: 24px;

// Colors

$white: #ffffff;$black: #202020;

$light-gray: #b3b3b3;$gray: #838383;$dark-gray: #525252;

$orange: #ff920d;$yellow: #ffe573;$green: #339922;$blue: #39b2e5;

@import "blueprint/grid";@import "compass/css3";

@mixin heading($size, $family: Helvetica, $weight: bold, $color: inherit) { color: $color; font: $weight $size $family;}

hgroup { h1 { @include heading($size: 24px, $family: Georgia, $color: $blue); margin-bottom: $baseline * 2; } h2 { @include heading(18px); } h3:first-child { @extend h1; @if $environment != production { // crazy client demands H3’s on the homepage be underlined AND darker!? body.home & { text-decoration: underline; color: darken($blue, 25%); // now he wants -webkit-slightly-escalating-text too! @for $i from 1 through 5 { .char#{$i} { top: -$i * 2; } } } } }}

article { @include box-sizing(border-box); @include border-radius(5px); @include box-shadow($gray, 0, 1px, 0); @include column(8); background-color: $light-gray;}

@import "icons/social/*.png";

nav a { @each $file in dribbble, facebook, flickr, twitter { &.#{$file} { @include social-sprite($file); } }}

input[type=search] { background: { image: inline-image('icons/spyglass.png'); position: left center; repeat: no-repeat; }}

Page 52: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

hgroup h1, hgroup h3:first-child { color: #39b2e5; font: bold 24px Georgia; margin-bottom: 40px;}hgroup h2 { color: inherit; font: bold 18px Helvetica;}body.home hgroup h3:first-child { text-decoration: underline; color: #12688c; }body.home hgroup h3:first-child .char1 { top: -2;}body.home hgroup h3:first-child .char2 { top: -4;}body.home hgroup h3:first-child .char3 { top: -6;}body.home hgroup h3:first-child .char4 { top: -8;}body.home hgroup h3:first-child .char5 { top: -10;}article { -moz-box-sizing: border-box; -webkit-box-sizing: border-box; -ms-box-sizing: border-box; box-sizing: border-box; -moz-border-radius: 5px; -webkit-border-radius: 5px; -o-border-radius: 5px; -ms-border-radius: 5px; -khtml-border-radius: 5px; border-radius: 5px; -moz-box-shadow: 0 1px 0 #838383; -webkit-box-shadow: 0 1px 0 #838383; -o-box-shadow: 0 1px 0 #838383; box-shadow: 0 1px 0 #838383; display: inline; float: left; margin-right: 20px; width: 620px; background-color: #b3b3b3;}* html article { overflow-x: hidden;}.social-sprite, nav a.dribbble, nav a.facebook, nav a.flickr, nav a.twitter { background: url('/images/icons/social-07817f34f2.png') no-repeat;}nav a.dribbble { background-position: 0 0;}nav a.facebook { background-position: 0 -48px;}nav a.flickr { background-position: 0 -96px;}nav a.twitter { background-position: 0 -144px;}input[type=search] { background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAAsTAAALEwEAmpwYAAABS0lEQVQ4EZWSPS9EQRSGd3YjYmu7+wdQaLZAsEGjligU21ESiUqhI1GIXyKi4RewKBQSWiKxIioiIb4auZ537xkZ4ybsSZ45c77euXPvdUmS5Lw55zrZj8MQFOEcGvQ84LNNAiZSo+MEpBjSJJ71fbH3w6M0PdrgPn4ZFmELPkGCC/GwYlkXnIKiNSiEjcTT8AJP0BfWvMAkBQ0fgIsbrGnDelbjep7CCMj2KKbPlMbhumvBYJjUXgJ627L31GWuH5btiKsSOLPkRFwMYn0h2WXqfq7dhHegU6biO5LrgWt4g9qvul17jqLu/wrrMAxVmAcNq3YD5UwBE1mi4dmaNRBya3EDXwpFWp+NZMv4lfvZ1GEA9MIuYAeuYBvG4BBmELnHc4z9yn95WstwpBH4fpJ/C+gATCLH4EUqbQmYSCUQWWlbwERKiGxC7xd6NW0WLGy4BwAAAABJRU5ErkJggg=='); background-position: left center; background-repeat: no-repeat;}

Page 53: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

Sass in Rails

Page 54: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

Organize

Page 55: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

!"" app #"" assets/    #"" stylesheets/

Page 56: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

!"" stylesheets #"" components #"" config $   #"" _base.scss $   #"" _environment.scss.erb $   !"" _styleguide.scss !"" lib #"" _functions.scss !"" _mixins.scss #"" application.css #"" home.css.scss

Page 57: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

config/_base.scss

@import "environment";@import "styleguide";

@import "../lib/mixins";

Page 58: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

main.scss.erb@import "config/base";

hgroup { h1 { @include heading($size: 24px, $family: Georgia, $color: $blue); margin-bottom: $baseline * 2; } h2 { @include heading(18px); } h3:first-child { @extend h1; @if $environment != production { // crazy client demands H3’s on the homepage be underlined AND darker!? body.home & { text-decoration: underline; color: darken($blue, 25%); // now he wants -webkit-slightly-escalating-text too! @for $i from 1 through 5 { .char#{$i} { top: -$i * 2; } } } } }}article { @include box-sizing(border-box); @include border-radius(5px); @include box-shadow($gray, 0, 1px, 0); @include column(8); background-color: $light-gray;}@import "icons/social/*.png";nav a { @each $file in dribbble, facebook, flickr, twitter { &.#{$file} { @include social-sprite($file); } }}input[type=search] { background: { image: inline-image('icons/spyglass.png'); position: left center; repeat: no-repeat; }}

Page 59: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

application.css

/* *= require_self*= require_directory .*/

Page 60: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

Route Scoping# helperdef classes_for_body body_classes = controller.controller_path.split('/') body_classes << controller.action_name body_classes.join ' 'end

# layout<body id="<%= yield :body_id %>" class="<%= classes_for_body %>">

# renders<body id="" class="users photos show”>

Page 61: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

Nested Layouts!"" layouts #"" _document.html.erb #"" admin.html.erb #"" application.html.erb

Page 62: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

_document.html.erb

<!DOCTYPE html>

<html><head> <title><%= yield :page_title %></title> <%= csrf_meta_tag %> <%= yield :head %></head>

<body id="<%= yield :body_id %>" class="<%= classes_for_body %>"> <%= yield %> </body></html>

Page 63: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

application.html.erb

<%- content_for :head do %> <%= stylesheet_link_tag "application" %> <%= javascript_include_tag "application" %><%- end %>

<%= render :layout => 'layouts/document' do %>

<header> <h1>Site Name</h1> <nav></nav> </header>

<%= yield :layout %> <% end %>

Page 64: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

admin.html.erb

<%- provide :head do %> <%= stylesheet_link_tag "admin" %> <%= javascript_include_tag "admin" %><%- end %>

<%= render :layout => 'layouts/document' do %>

<header> <h1>Admin</h1> <nav></nav> </header> <%= yield :layout %> <% end %>

Page 65: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

admin.html.erb

<%- provide :head do %> <%= stylesheet_link_tag "admin" %> <%= javascript_include_tag "admin" %><%- end %>

<%= render :layout => 'layouts/document' do %>

<header> <h1>Admin</h1> <nav></nav> </header> <%= yield :layout %> <% end %>

Page 66: Views with Attitude104.236.43.209/pdf/Introducing Sass.pdf · Views with Attitude Introducing Sass, Austin on Rails, May 24, 2011 @soopa Designer & Developer at Gowalla

Create at Gowaa

gowalla.com/jobs

say hi @soopa