Slide 1

Slide 1 text

clean out your junk-drawer! SassConf 2013 NY

Slide 2

Slide 2 text

are you ready to receive the light?

Slide 3

Slide 3 text

For many of us getting started with Sass, at one time or another have created a junk-drawer of files. Fo mi a c

Slide 4

Slide 4 text

ne ed For most, this was a rookie mistake, but for others, this is a continuing issue with our architecture and file management techniques. Sas ru de

Slide 5

Slide 5 text

e s is ur s. Sass doesn't come with any real rules for file management so developers are pretty much left to their own devices.

Slide 6

Slide 6 text

increased complexity

Slide 7

Slide 7 text

the good ‘ol days .selection { ! font-size: 12px; line-height: 13px; ! font-family: Arial, Helvetica, sans-serif; ! text-align: center; ! margin-top: 10px; } .selection ul,li { ! font-size: 12px; line-height: 14px; ! font-family: Arial, Helvetica, sans-serif; ! text-align: left; ! vertical-align: top; ! margin-left: 10px; ! width: auto; ! height: auto; }

Slide 8

Slide 8 text

things got much more complicated /* GLOBALHEADER */ #globalheader { position:relative; display:block; width:980px; height:36px; margin: 18px auto; text-align:left; z-index:9998; background:url(/global/nav/images/ globalheader.png) repeat-x; -khtml-border-radius:4px; -ms-border-radius:4px; -o-border-radius:4px; -moz-border- radius:4px; -webkit-border-radius:4px; border-radius:4px; -khtml-box-shadow:rgba(0,0,0,0.3) 0 1px 2px; -ms-box-shadow:rgba(0,0,0,0.3) 0 1px 2px; -o-box-shadow:rgba(0,0,0,0.3) 0 1px 2px; -moz-box-shadow:rgba(0,0,0,0.3) 0 1px 2px; -webkit-box-shadow:rgba(0,0,0,0.3) 0 1px 2px; box-shadow:rgba(0,0,0,0.3) 0 1px 2px; font:12px/18px "Lucida Grande", "Lucida Sans Unicode", Helvetica, Arial, Verdana, sans-serif; } @media only screen and (max-device-width:768px) { #globalheader { z-index:1; } } #globalheader #globalnav { position:relative; display:block; margin:0; padding:0; zoom:1; z-index:3; } #globalheader #globalnav:after { content:"."; display:block; height:0; clear:both; visibility:hidden; } #globalheader #globalnav li { display:inline; } #globalheader #globalnav li a { float:left; width:102px; height:36px; overflow:hidden; crap ton of CSS

Slide 9

Slide 9 text

things got much more complicated /* GLOBALHEADER */ #globalheader { position:relative; display:block; width:980px; height:36px; margin: 18px auto; text-align:left; z-index:9998; background:url(/global/nav/images/ globalheader.png) repeat-x; -khtml-border-radius:4px; -ms-border-radius:4px; -o-border-radius:4px; -moz-border- radius:4px; -webkit-border-radius:4px; border-radius:4px; -khtml-box-shadow:rgba(0,0,0,0.3) 0 1px 2px; -ms-box-shadow:rgba(0,0,0,0.3) 0 1px 2px; -o-box-shadow:rgba(0,0,0,0.3) 0 1px 2px; -moz-box-shadow:rgba(0,0,0,0.3) 0 1px 2px; -webkit-box-shadow:rgba(0,0,0,0.3) 0 1px 2px; box-shadow:rgba(0,0,0,0.3) 0 1px 2px; font:12px/18px "Lucida Grande", "Lucida Sans Unicode", Helvetica, Arial, Verdana, sans-serif; } @media only screen and (max-device-width:768px) { #globalheader { z-index:1; } } #globalheader #globalnav { position:relative; display:block; margin:0; padding:0; zoom:1; z-index:3; } #globalheader #globalnav:after { content:"."; display:block; height:0; clear:both; visibility:hidden; } #globalheader #globalnav li { display:inline; } #globalheader #globalnav li a { float:left; width:102px; height:36px; overflow:hidden; crap ton of CSS

Slide 10

Slide 10 text

we tried ... but failed @import url(‘path/reset.css’); @import url(‘path/evil.css’); @import url(‘path/more-evil.css’); @import url(‘path/bootstrap-sucks.css’); web performance killer

Slide 11

Slide 11 text

we tried ... but failed @import url(‘path/reset.css’); @import url(‘path/evil.css’); @import url(‘path/more-evil.css’); @import url(‘path/bootstrap-sucks.css’); web performance killer

Slide 12

Slide 12 text

Sass, LESS, etc ...

Slide 13

Slide 13 text

Text Text /* GLOBAL VARIABLES */ $prefix_defaults: -moz- -webkit- -o- -ms- '' !default; $webkit_support: -webkit- '' !default; $moz_support: -moz- '' !default; $ms_support: -ms- '' !default; $moz_webkit_support: -moz- -webkit- '' !default; $moz_ms_support: -moz- -ms- '' !default; $webkit_ms_support: -webkit- -ms- '' !default; $grid-width: 980px; $max-device-width: 768px; $background-position-full: 100%; $background-position-half: 50%; $link-color: #7F7F7F; $text-color: #333; /* Mixins */ @mixin border_radius ($border_radius, $prefixes: $webkit_support) { @each $prefix in $prefixes { #{$prefix}border-radius: $border_radius; } } @mixin box_shadow ($shadow_color: $shadow_color, $shadow: $shadow, $prefixes: $prefix_defaults) { @each $prefix in $prefixes { #{$prefix}box-shadow: $shadow_color $shadow; } } variables mixins

Slide 14

Slide 14 text

/* GLOBALHEADER */ #globalheader { position:relative; display:block; width:$grid-width; height:36px; margin: 18px auto; text-align:left; z-index:9998; background:url(/global/nav/images/ globalheader.png) repeat-x; ! -khtml-border-radius:4px; -ms-border-radius:4px; -o-border-radius:4px; -moz-border- radius:4px; -webkit-border-radius:4px; border-radius:4px; ! -khtml-box-shadow:rgba(0,0,0,0.3) 0 1px 2px; -ms-box-shadow:rgba(0,0,0,0.3) 0 1px 2px; -o-box-shadow:rgba(0,0,0,0.3) 0 1px 2px; -moz-box-shadow:rgba(0,0,0,0.3) 0 1px 2px; - webkit-box-shadow:rgba(0,0,0,0.3) 0 1px 2px; box-shadow:rgba(0,0,0,0.3) 0 1px 2px; ! font:12px/18px "Lucida Grande", "Lucida Sans Unicode", Helvetica, Arial, Verdana, sans-serif; } @media only screen and (max-device-width:$max-device-width) { ! #globalheader { z-index:1; } } #globalheader #globalnav { position:relative; display:block; margin:0; padding:0; zoom:1; z-index:3; } #globalheader #globalnav:after { content:"."; display:block; height:0; clear:both; visibility:hidden; } #globalheader #globalnav li { display:inline; } #globalheader #globalnav li a { float:left; width:102px; height:36px; overflow:hidden; text-indent:-9999px; background:url(/global/nav/images/globalnav.png) no-repeat; cursor:pointer; } /* VML FOR IE */ v\:roundrect, v\:fill { behavior:url(#default#VML); } #globalheader-roundrect, #globalheader-fill { display:block; position:absolute; width:; height:35px; top:0; left:0; z-index:2; } #globalheader-shadow { display:block; position:absolute; width:$grid-width; height:35px; top:-1px; left:-2px; z-index:1; -ms- filter:"progid:DXImageTransform.Microsoft.Blur(pixelRadius=2)"; filter:progid:DXImageTransform.Microsoft.Blur(pixelRadius=2); } /* VARIANTS */

Slide 15

Slide 15 text

/* GLOBALHEADER */ #globalheader { position:relative; display:block; width:$grid-width; height:36px; margin: 18px auto; text-align:left; z-index:9998; background:url(/global/nav/images/ globalheader.png) repeat-x; ! -khtml-border-radius:4px; -ms-border-radius:4px; -o-border-radius:4px; -moz-border- radius:4px; -webkit-border-radius:4px; border-radius:4px; ! -khtml-box-shadow:rgba(0,0,0,0.3) 0 1px 2px; -ms-box-shadow:rgba(0,0,0,0.3) 0 1px 2px; -o-box-shadow:rgba(0,0,0,0.3) 0 1px 2px; -moz-box-shadow:rgba(0,0,0,0.3) 0 1px 2px; - webkit-box-shadow:rgba(0,0,0,0.3) 0 1px 2px; box-shadow:rgba(0,0,0,0.3) 0 1px 2px; ! font:12px/18px "Lucida Grande", "Lucida Sans Unicode", Helvetica, Arial, Verdana, sans-serif; } @media only screen and (max-device-width:$max-device-width) { ! #globalheader { z-index:1; } } #globalheader #globalnav { position:relative; display:block; margin:0; padding:0; zoom:1; z-index:3; } #globalheader #globalnav:after { content:"."; display:block; height:0; clear:both; visibility:hidden; } #globalheader #globalnav li { display:inline; } #globalheader #globalnav li a { float:left; width:102px; height:36px; overflow:hidden; text-indent:-9999px; background:url(/global/nav/images/globalnav.png) no-repeat; cursor:pointer; } /* VML FOR IE */ v\:roundrect, v\:fill { behavior:url(#default#VML); } #globalheader-roundrect, #globalheader-fill { display:block; position:absolute; width:; height:35px; top:0; left:0; z-index:2; } #globalheader-shadow { display:block; position:absolute; width:$grid-width; height:35px; top:-1px; left:-2px; z-index:1; -ms- filter:"progid:DXImageTransform.Microsoft.Blur(pixelRadius=2)"; filter:progid:DXImageTransform.Microsoft.Blur(pixelRadius=2); } /* VARIANTS */ die hard

Slide 16

Slide 16 text

early days of file management style.scss mixins.scss variables.scss typography.scss forms.scss

Slide 17

Slide 17 text

early days of file management style.scss mixins.scss variables.scss typography.scss forms.scss overly simplified

Slide 18

Slide 18 text

early days of file management style.scss mixins.scss variables.scss typography.scss forms.scss overly simplified too much code in one file

Slide 19

Slide 19 text

early days of file management style.scss mixins.scss variables.scss typography.scss forms.scss overly simplified too much code in one file base, elements, modules and layout in the same files

Slide 20

Slide 20 text

early days of file management style.scss mixins.scss variables.scss typography.scss forms.scss overly simplified too much code in one file base, elements, modules and layout in the same files cats and dogs living together, mass hysteria!

Slide 21

Slide 21 text

early days of file management style.scss mixins.scss variables.scss typography.scss forms.scss overly simplified too much code in one file base, elements, modules and layout in the same files cats and dogs living together, mass hysteria!

Slide 22

Slide 22 text

seemed like a good idea

Slide 23

Slide 23 text

file structures of inspiration app/ models/ views/ controllers/ admin/ blog/ shared/

Slide 24

Slide 24 text

file structures of inspiration app/ models/ views/ controllers/ admin/ blog/ shared/ THE MVC IS AWESOME! LET’S USE THIS TO ORGANIZE THE SASS!

Slide 25

Slide 25 text

where do I put the abstracted stuff? style.scss mixins variables forms typography partials views

Slide 26

Slide 26 text

where do I put the abstracted stuff? style.scss mixins variables forms typography partials views attempts to break out mixins and variables == lots of files dumped into folders

Slide 27

Slide 27 text

where do I put the abstracted stuff? style.scss mixins variables forms typography partials views attempts to break out mixins and variables == lots of files dumped into folders UI modules and patterns inevitably ended up within the View styles

Slide 28

Slide 28 text

where do I put the abstracted stuff? style.scss mixins variables forms typography partials views attempts to break out mixins and variables == lots of files dumped into folders UI modules and patterns inevitably ended up within the View styles But code is being duplicated? Oh yeah, make it a partial!

Slide 29

Slide 29 text

where do I put the abstracted stuff? style.scss mixins variables forms typography partials junk-drawer views attempts to break out mixins and variables == lots of files dumped into folders UI modules and patterns inevitably ended up within the View styles But code is being duplicated? Oh yeah, make it a partial!

Slide 30

Slide 30 text

felt so right ... was sooooo wrong html { body { section { header {color: green;} article { header {} } } } } the HTML: the Sass: html body section header {color: green;} the CSS:

Slide 31

Slide 31 text

felt so right ... was sooooo wrong html { body { section { header {color: green;} article { header {} } } } } the HTML: the Sass: html body section header {color: green;} the CSS:

Slide 32

Slide 32 text

learn from ‘doing it wrong’

Slide 33

Slide 33 text

our perspective was all wrong

Slide 34

Slide 34 text

our perspective was all wrong Styles are written based on placement in the view

Slide 35

Slide 35 text

our perspective was all wrong Styles are written based on placement in the view CSS too specific. Very fragile with placement

Slide 36

Slide 36 text

our perspective was all wrong Styles are written based on placement in the view CSS too specific. Very fragile with placement Presentation classes in the markup

Slide 37

Slide 37 text

our perspective was all wrong Styles are written based on placement in the view CSS too specific. Very fragile with placement Presentation classes in the markup Poor code reuse, if any at all. To much ‘⌘C / ⌘V`

Slide 38

Slide 38 text

our perspective was all wrong Styles are written based on placement in the view CSS too specific. Very fragile with placement Presentation classes in the markup Poor code reuse, if any at all. To much ‘⌘C / ⌘V` A major case of the div’itus

Slide 39

Slide 39 text

our perspective was all wrong Styles are written based on placement in the view CSS too specific. Very fragile with placement Presentation classes in the markup Poor code reuse, if any at all. To much ‘⌘C / ⌘V` A major case of the div’itus Using IDs for styling to over-ride the cascade

Slide 40

Slide 40 text

start with the smaller parts

Slide 41

Slide 41 text

start with the smaller parts Buttons Typography Color pallet standard icons borders and line widths

Slide 42

Slide 42 text

start small and build up

Slide 43

Slide 43 text

start small and build up Header module Hero module Nav module Hero copy module Article module List module

Slide 44

Slide 44 text

nature has taught us everything

Slide 45

Slide 45 text

code the element, create the module and assemble the layout buttons/ color/ forms/ layouts/ modules/ typography/ ui_patterns/ _buttons.scss _config.scss _forms.scss _reset.scss _typography.scss style.scss vendor/

Slide 46

Slide 46 text

a powerful weapon in the Sass arsenal // Following sequence will load the necessary Stipe libraries // ---------------------------------------------------------------- @import "compass/css3"; // Including the Compass CSS3 mixins @import "stipe/manifest"; @import "vendor/**/*"; // This where you start building your own styles. // ---------------------------------------------------------------- @import "typography"; @import "forms"; @import "buttons"; @import "design"; @import "ui_patterns/**/*"; // manifest files @import "modules/**/*"; // manifest files @import "layouts/*"; // manifest files

Slide 47

Slide 47 text

a powerful weapon in the Sass arsenal // Following sequence will load the necessary Stipe libraries // ---------------------------------------------------------------- @import "compass/css3"; // Including the Compass CSS3 mixins @import "stipe/manifest"; @import "vendor/**/*"; // This where you start building your own styles. // ---------------------------------------------------------------- @import "typography"; @import "forms"; @import "buttons"; @import "design"; @import "ui_patterns/**/*"; // manifest files @import "modules/**/*"; // manifest files @import "layouts/*"; // manifest files keep sub- directory files nicely organized

Slide 48

Slide 48 text

there is no right or wrong here Text @import "grid/lib/the_grid"; @import "grid/lib/grid_placement"; @import "grid/lib/grid_margin"; @import "grid/lib/push_logic"; @import "grid/mixins"; @import "grid/extends"; manual: @import "grid/lib/*"; @import "grid/mixins"; @import "grid/extends"; glob: }

Slide 49

Slide 49 text

this can really save your bacon

Slide 50

Slide 50 text

! manage the smart defaults for your UI /////// Typography configuration/////// // ----------------------------------------------------------------------------- $font_size: 12; // $heading_1: 46; $heading_2: 32; $heading_3: 28; $heading_4: 18; $heading_5: 18; $heading_6: 18; // $line: $font_size * 1.5; // $small_point_size: 10; $large_point_size: 14; // $primary_font_family: #{"Helvetica Neue", Arial, sans-serif}; $secondary_font_family: #{"Helvetica Neue", Arial, sans-serif}; $heading_font_family: #{"Helvetica Neue", Arial, sans-serif}; $icon_font_alpha: #{'FontAwesome'}; $icon_font_bravo: #{'zocial'}; /////// Default webfont directory/////// // ----------------------------------------------------------------------------- $webfont_directory: "/fonts/"; /////// default image directory ///////

Slide 51

Slide 51 text

! manage the smart defaults for your UI /////// Typography configuration/////// // ----------------------------------------------------------------------------- $font_size: 12; // $heading_1: 46; $heading_2: 32; $heading_3: 28; $heading_4: 18; $heading_5: 18; $heading_6: 18; // $line: $font_size * 1.5; // $small_point_size: 10; $large_point_size: 14; // $primary_font_family: #{"Helvetica Neue", Arial, sans-serif}; $secondary_font_family: #{"Helvetica Neue", Arial, sans-serif}; $heading_font_family: #{"Helvetica Neue", Arial, sans-serif}; $icon_font_alpha: #{'FontAwesome'}; $icon_font_bravo: #{'zocial'}; /////// Default webfont directory/////// // ----------------------------------------------------------------------------- $webfont_directory: "/fonts/"; /////// default image directory /////// all logic NO CSS!

Slide 52

Slide 52 text

where we get to work

Slide 53

Slide 53 text

all CSS, NO LOGIC! Text button { font-size: em(16); @include background-image(linear-gradient(top, #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%)); .no-cssgradients & { background-color: #1e5799; } border: 1px solid $primary_button_border_color; border-radius: em(3); color: $white; padding: em(6) em(10); margin: 0; @media #{$mobile} { width: 100%; }

Slide 54

Slide 54 text

where’z u go?

Slide 55

Slide 55 text

functional vs. presentational buttons/ _mixins.scss _extends.scss _buttons.scss

Slide 56

Slide 56 text

functional vs. presentational buttons/ _mixins.scss _extends.scss _buttons.scss functional presentational

Slide 57

Slide 57 text

organize your thoughts // Custom button extends and mixins // -------------------------------------------------- @import "buttons/mixins"; @import "buttons/extends"; // buttons // -------------------------------------------------- //* toadstool buttons */ button, a.button { @inlcude button($button-color); }

Slide 58

Slide 58 text

organize your thoughts // Custom button extends and mixins // -------------------------------------------------- @import "buttons/mixins"; @import "buttons/extends"; // buttons // -------------------------------------------------- //* toadstool buttons */ button, a.button { @inlcude button($button-color); } functional presentational

Slide 59

Slide 59 text

seeing is believing

Slide 60

Slide 60 text

simplicity in organization Module Sass is exclusive to a particular interaction of the application. Modules will come in all shapes and sizes. Larger modules may also consist of smaller modules or smaller UI patterns.

Slide 61

Slide 61 text

simplicity in organization UI patterns are a gray area and are subject to personal interpretation. In practice ... small UI patterns begin to emerge. It is practical to try and encapsulate these smaller patterns for reuse, but I don't lose sleep over them.

Slide 62

Slide 62 text

simplicity in organization modules/ _extends.scss registration/ _functions.scss _mixins.scss _module_registration.scss _module_personalInfo.scss

Slide 63

Slide 63 text

simplicity in organization modules/ _extends.scss registration/ _functions.scss _mixins.scss _module_registration.scss _module_personalInfo.scss _extends.scss purchase/ _functions.scss _mixins.scss _module_order-summary.scss _module_purchase.scss

Slide 64

Slide 64 text

simplicity in organization modules/ _extends.scss registration/ _functions.scss _mixins.scss _module_registration.scss _module_personalInfo.scss directory name primary module

Slide 65

Slide 65 text

name-space by the module itself %order-summary { .form-header { border-radius: em(5) em(5) 0 0; margin-bottom: 0; } .order-summary-container { @extend %Grid4ThreeSideBox; } .initial-assetListing { @media #{$mobile} { display: none; } } .price { text-align: right; } .total { font-size: em($large_point_size); } footer {

Slide 66

Slide 66 text

bringing the picture into focus

Slide 67

Slide 67 text

make up the view

Slide 68

Slide 68 text

make up the view module module module module module

Slide 69

Slide 69 text

manage your grid .checkout-experience { .customer-checkout { @extend %checkout; @extend %grid_7; @media #{$tablet_portrait} { @include grid(10, $grid_context: 10); } } .order-summary { @extend %order-summary; @extend %grid_5; @media #{$tablet_portrait} { @include grid(10, $grid_context: 10); } @media #{$mobile} { @include grid(4, $grid_context: 4); }

Slide 70

Slide 70 text

manage your grid .checkout-experience { .customer-checkout { @extend %checkout; @extend %grid_7; @media #{$tablet_portrait} { @include grid(10, $grid_context: 10); } } .order-summary { @extend %order-summary; @extend %grid_5; @media #{$tablet_portrait} { @include grid(10, $grid_context: 10); } @media #{$mobile} { @include grid(4, $grid_context: 4); } name-spaced selector placement of elements

Slide 71

Slide 71 text

what have we learned?

Slide 72

Slide 72 text

what have we learned? CSS management has come a long way

Slide 73

Slide 73 text

what have we learned? Vanilla CSS has NO TOOLS for code management CSS management has come a long way

Slide 74

Slide 74 text

what have we learned? Vanilla CSS has NO TOOLS for code management outside-in BAD! inside-out BETTER! CSS management has come a long way

Slide 75

Slide 75 text

what have we learned? Vanilla CSS has NO TOOLS for code management outside-in BAD! inside-out BETTER! modular files with @import system === WINNING! CSS management has come a long way

Slide 76

Slide 76 text

what have we learned? Vanilla CSS has NO TOOLS for code management outside-in BAD! inside-out BETTER! modular files with @import system === WINNING! elements, modules and then the view CSS management has come a long way

Slide 77

Slide 77 text

what have we learned? Vanilla CSS has NO TOOLS for code management outside-in BAD! inside-out BETTER! modular files with @import system === WINNING! elements, modules and then the view Take everything you know AND SET IT ON FIRE! CSS management has come a long way

Slide 78

Slide 78 text

what have we learned? Vanilla CSS has NO TOOLS for code management outside-in BAD! inside-out BETTER! modular files with @import system === WINNING! elements, modules and then the view Take everything you know AND SET IT ON FIRE! CSS management has come a long way Organize your Sass! it will hurt less

Slide 79

Slide 79 text

Sass in Depth Kianosh - @kianoshp Dale - @anotheruiguy

Slide 80

Slide 80 text

Sass in Depth Kianosh - @kianoshp Dale - @anotheruiguy http://www.manning.com/dsande/ promo code - mldsandeau

Slide 81

Slide 81 text

you, in the front ...

Slide 82

Slide 82 text

No content