Slide 1

Slide 1 text

Scalable Stylesheets Theming with Modular CSS John Ferris @pixel_whip 

Slide 2

Slide 2 text

CSS ARCHITECTURE

Slide 3

Slide 3 text

A systematic approach to styling with CSS. CSS ARCHITECTURE

Slide 4

Slide 4 text

OOCSS Object-oriented CSS http://bit.ly/NUkX7Q

Slide 5

Slide 5 text

SMACSS Scalable Modular Architecture for CSS http://smacss.com

Slide 6

Slide 6 text

BEM Block, Element, Modifier http://bit.ly/NzThqF

Slide 7

Slide 7 text

MVCSS Model-View-Controller Stylesheets http://bit.ly/NJRHCl

Slide 8

Slide 8 text

COMMON PRINCIPLES

Slide 9

Slide 9 text

Don’t repeat yourself. Create patterns. CSS ARCHITECTURE

Slide 10

Slide 10 text

Separation of concerns. Don’t mix layout and style. CSS ARCHITECTURE

Slide 11

Slide 11 text

Reduce specificity. Target classes. CSS ARCHITECTURE

Slide 12

Slide 12 text

Consistency and clarity. Define naming conventions. CSS ARCHITECTURE

Slide 13

Slide 13 text

AVOID DCSS ⚠ ( Drupal CSS )

Slide 14

Slide 14 text

Progression of Style Top Left ‑ Bottom Right ‑ ☹

Slide 15

Slide 15 text

Progression of Style Default Tags ‑ Elements ‑ Components ‑ Layout ‑ ☺

Slide 16

Slide 16 text

Contextual Styling CSS Pseudo Logic by exploiting the cascade .not-­‐front  #sidebar-­‐first  .block  h2  {    ... }

Slide 17

Slide 17 text

Contextual Styling PHP logic to apply classes where needed .block-­‐fancy-­‐title  {    ... }

Slide 18

Slide 18 text

Naming Conventions What you have .item-­‐list, .views-­‐row  {    ... } .menu,   .leaf, .leaf  a  {    ... } .resource-­‐list, .resource-­‐item  {    ... } .nav, .nav-­‐item, .nav-­‐link  {    ... } What you want

Slide 19

Slide 19 text

Applying Classes Through the UI • Views • Semantic Fields • Display Suite • Block Class • Skinr • Fusion Accelerator

Slide 20

Slide 20 text

Applying Classes Through the UI Directly to template files block.tpl.php block-­‐-­‐footer.tpl.php block-­‐-­‐header.tpl.php block-­‐-­‐search.tpl.php block-­‐-­‐navigation-­‐-­‐menu.tpl.php block-­‐-­‐navigation-­‐-­‐arghh.tpl.php block-­‐-­‐this-­‐-­‐sucks.tpl.php block-­‐-­‐wtf.tpl.php block-­‐-­‐i-­‐need-­‐a-­‐drink.tpl.php

Slide 21

Slide 21 text

Applying Classes Through the UI Directly to template files With Preprocess Functions

Slide 22

Slide 22 text

Applying Classes Through the UI Directly to template files With Preprocess Functions ☺

Slide 23

Slide 23 text

LET’S DO THIS! https://gist.github.com/3111975

Slide 24

Slide 24 text

Theme Functions 43 Template Files 142 DRUPAL CORE

Slide 25

Slide 25 text

Choose your battles

Slide 26

Slide 26 text

Choose your battles Blocks Fields Menus Forms

Slide 27

Slide 27 text

BLOCKS

Slide 28

Slide 28 text

BLOCKS MARKUP
   

...

   
       ...    

Slide 29

Slide 29 text

BLOCKS block.tpl.php
>        subject):  ?>        >subject  ?>            
>            

Slide 30

Slide 30 text

BLOCKS block.tpl.php
>        subject):  ?>        >subject  ?>            
>            

Slide 31

Slide 31 text

Attributes Array          ‑                         ‑ class="input-­‐search  input-­‐inline"  placeholder="Enter  a  search  term…"   title="Enter  the  terms  you  wish  to  search  for." $vars['#attributes']

Slide 32

Slide 32 text

Opportunities to Alter Block Markup hook_block_view_alter() ‑ hook_preprocess_block() ‑ hook_process_block() ⬋                ⬊ block.tpl.php        block-­‐-­‐module.tpl.php

Slide 33

Slide 33 text

BLOCKS hook_preprocess_block() function  [theme]_preprocess_block(&$vars)  {    //  Set  shortcut  variables.    ...    //  Set  global  classes  for  all  blocks.    ...    //  Add  specific  classes  and/or    //  theme_hook_suggestions  to  targeted  blocks.    ... }

Slide 34

Slide 34 text

hook_preprocess_block() BLOCKS

Slide 35

Slide 35 text

hook_preprocess_block() BLOCKS

Slide 36

Slide 36 text

hook_preprocess_block() BLOCKS

Slide 37

Slide 37 text

hook_preprocess_block() BLOCKS

Slide 38

Slide 38 text

FIELDS

Slide 39

Slide 39 text

FIELDS MARKUP
   
...
   
       
           ...        
   

Slide 40

Slide 40 text

FIELDS theme_field() function  theme_field($variables)  {    $output  =  ''; ...    //  Render  the  label,  if  it's  not  hidden.    if  (!$variables['label_hidden'])  {        $output  .=  '
'  .  $variables['label']  .  ': 
';    }        ...    return  $output; }

Slide 41

Slide 41 text

FIELDS theme_field() function  theme_field($variables)  {    $output  =  ''; ...    //  Render  the  label,  if  it's  not  hidden.    if  (!$variables['label_hidden'])  {        $output  .=  ''  .  $variables['label']  .  ': ';    }        ...    return  $output; }

Slide 42

Slide 42 text

hook_preprocess_field() FIELDS

Slide 43

Slide 43 text

hook_preprocess_field() FIELDS

Slide 44

Slide 44 text

hook_preprocess_field() FIELDS

Slide 45

Slide 45 text

hook_preprocess_field() FIELDS

Slide 46

Slide 46 text

hook_preprocess_field() FIELDS

Slide 47

Slide 47 text

MENUS

Slide 48

Slide 48 text

Standardize around the Menu Block module. MENUS

Slide 49

Slide 49 text

MENUS MARKUP
       
  •        ...    
  •    
  • ...
  •    
  • ...
  •  
theme_menu_tree() theme_menu_link()

Slide 50

Slide 50 text

MENUS theme_menu_link() CORE function  modularstyle_menu_link(array  $variables)  {    $element  =  $variables['element'];    $sub_menu  =  '';    if  ($element['#below'])  {        $sub_menu  =  drupal_render($element['#below']);    }    $output  =  l($element['#title'],                              $element['#href'],                            $element['#localized_options']);        return  ''                          .  $output  .  $sub_menu  .  "\n"; }

Slide 51

Slide 51 text

hook_preprocess_menu_link() MENUS

Slide 52

Slide 52 text

MENUS theme_menu_tree() CORE function  theme_menu_tree($variables)  {    return  '
    '  .  $variables['tree']  .  '
'; }

Slide 53

Slide 53 text

MENUS theme_menu_tree() PREPROCESS NOT WORKING!!! NO CONTEXT!!!

Slide 54

Slide 54 text

MENUS theme_menu_tree() PLAN B

Slide 55

Slide 55 text

theme_menu_tree() MENUS

Slide 56

Slide 56 text

theme_menu_tree() MENUS

Slide 57

Slide 57 text

theme_menu_tree() MENUS

Slide 58

Slide 58 text

I ♥ it, when a plan comes together.

Slide 59

Slide 59 text

Thank You. John Ferris @pixel_whip 