Relax. Don’t fret over taking notes.
Download the presentation slides here:
http://j.mp/drupal-compass
Note: It’s okay if ...
Design & User Experience
Using Sass & Compass
in Drupal Theming
Nathan Smith & Matt Farina
Hello :)
We like Drupal, Sass & Compass.
We hope you do too, or will soon.
Let us introduce ourselves...
Nathan Smith is
a UX designer at
Matt Farina is a
web developer at
HP Cloud Services
http://projekt202.com
http://hpcloud....
Sass & Compass are made possible by...
http://hamptoncatlin.com
He is no longer active
in working on Sass.
http://nex-3.co...
Part 1:
Why Sass?
“The backdrop to this debate is that CSS is absolutely
the worst, least productive part of the web platform.
Apps teams at...
So what’s to be done about CSS?
The answer has actually been staring us in the face
for awhile now, but it’s only been in ...
http://thingsorganizedneatly.tumblr.com/post/9494864300/submission-the-compulsively-tidy-ursus-wehrli
CSS served to browse...
“Years ago, we wrote static HTML. Now, we
almost never do. Our HTML is virtually always
preprocessed, be it by PHP, Python...
Noteworthy CSS preprocessors
• LESS
http://lesscss.org
• Sass & Compass
http://sass-lang.com
http://compass-style.org
• St...
CSS Sass Compass
http://sonspring.com/journal/sass-for-designers
Compass extends the functionality of
Sass by offering a plugin architecture.
It also handles vendor prefixes like a
champ. ...
Oversimplification, FTW!
Compass is to Sass
as
jQuery is to JavaScript
Sass & SCSS are functionally equivalent
We prefer using Sass instead of
SCSS because hey, less typing!
Anti-pattern of nested selectors in Sass
Compass makes vendor prefixes easy...
Compass brings sanity to gradients...
Text editors and IDE’s that support Sass/SCSS syntax
Aptana
http://aptana.org
BBEdit
http://barebones.com/bbedit
Chocolat
...
GUI to compile Sass & Compass
• Compass.app
http://compass.handlino.com
• Scout
http://mhs.github.com/scout-app
• CodeKit
...
Impression of Sass...
Great for CSS, in Ruby on Rails projects.
Great for CSS, in Ruby on Rails projects.
Great for CSS, in Ruby projects.
Impression of Sass...
Great for CSS, in Ruby on Rails projects.
Great for CSS, in Ruby projects.
Great for CSS, in any project!
Impression of Sa...
What if I want to use Sass for something
that wasn’t written in Ruby... impossible?
But, wait...
When I think about not having Sass...
http://en.wikipedia.org/wiki/The_Incredible_Hulk_(TV_series)
Yes, but the amount of Ruby knowledge
it takes to use Sass is basically zero.
Nathan is not a hardcore programmer,
but he ...
Part 2:
Whither a
module?
Why use a Drupal Module?
Possibly  Bad  Reasons...
— You don’t want to install Sass/Compass gems.
— You want Drupal to do ...
Sass/SCSS module
http://drupal.org/project/sass
• Depends on “phamlp”
http://code.google.com/p/phamlp
Last updated in Sept...
Compass stylesheet tool module
http://drupal.org/project/compass
• Ruby (Compass) does the heavy lifting
This means you ne...
Sassy module
http://drupal.org/project/sassy
• Several dependencies
http://github.com/richthegeek/phpsass — and three othe...
Jeff Croft, quoted previously, programs in Python and
uses Django. He also makes use of Sass, via Ruby.
We advocate trying...
ACHIEVEMENT UNLOCKED!
Presuppositions Challenged
Note: I don’t think this photo is necessarily relevant, but I
think we ca...
Part 3:
How to use
For the sake of brevity, we are going to assume in
this talk that your environment already has Ruby set
up. If not, then f...
Setting up Compass & Sass
gem install compass
From the command-line (Terminal.app, iTerm, etc)...
This will also automatic...
Take a hybrid PHP + Ruby approach
Add config.rb to your theme directory
“cd” to your theme directory,
then run “compass watch”
If you just want to flush cache and compile, run
“compass clean && c...
application.css is compiled
and (optionally) minified
via “compass watch”
Serving as a aggregate,
application.sass is built...
Theme *.info file – before Sass
stylesheets[all][] = assets/css/reset.css
stylesheets[all][] = assets/css/override/system.b...
Theme *.info file – before Sass
stylesheets[all][] = assets/css/reset.css
stylesheets[all][] = assets/css/override/system.b...
stylesheets[all][] = assets/css/application.css
; KILL THESE DEFAULT STYLESHEETS:
stylesheets[all][] = ctools.css
styleshe...
stylesheets[all][] = assets/css/application.css
Theme *.info file – after Sass
ACHIEVEMENT UNLOCKED
Only one CSS HTTP reque...
This is still worth
doing. I’ll explain
why in a second.
Even if using “compass watch” with:
output_style = :compressed
You should still use Drupal’s CSS
compression under Perform...
Benefits of using Drupal’s CSS
compression, not just Compass:
1. Cache-busting. File name is changed to...
“css_VvtjvgJd9tI...
Compass output, before Drupal compression
Compass output, after Drupal compression
Achievement Unlocked!
You have now attained CSS bliss.
Don’t forget to rate this as the best
talk you’ve ever heard in you...
Stop the presses!
What  about  debugging?
How do I see what styles
are coming from which
*_file.sass partial?
Part 4:
Debugging
& Demos
Cryptic error
messages are
never helpful.
^ I believe debugging this way stinks.
When things don’t go as planned...
http://autos.yahoo.com/blogs/motoramic/porsche-stuck-wet-cement-proves-karma-exists-210...
Just a one-line change in config.rb
Emits *.sass “stack trace” for each style
A quick tip on source control
While you can track your *.css files via
source control, the ones you really care
about are y...
Now time for some
demonstrations :)
Note: If you’re viewing these slides, but missed our
session, we showed “compass watch...
“Luck, be a lady...” (live demo = dice roll)
http://kloucksphoto.blogspot.com/2011/06/guys-and-dolls-witty-wry-wonderful.h...
If you want to tinker with Haml & Sass...
“We keep thinking we can write better CSS if we just
try harder, that the next site will be clean and stay
that way. [Her]...
Feel free to say hi on Twitter, and/or check out our personal sites for more of our work.
http://twitter.com/NathanSmith
P...
Questions? We (might) have answers.
Feel free to share the link with friends, enemies, etc.
Download the presentation slid...
What did you think?
Locate this session on the
DrupalCon Denver website
http://denver2012.drupal.org/program
Click the “Ta...
Drupal & Compass
Drupal & Compass
Drupal & Compass
Upcoming SlideShare
Loading in...5
×

Drupal & Compass

11,970

Published on

Slides for my talk at DrupalCon Denver, on using Sass and Compass in Drupal themes.

http://denver2012.drupal.org/program/sessions/using-sass-compass-drupal-theming

Published in: Design, Technology
1 Comment
14 Likes
Statistics
Notes
No Downloads
Views
Total Views
11,970
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
125
Comments
1
Likes
14
Embeds 0
No embeds

No notes for slide

Drupal & Compass

  1. 1. Relax. Don’t fret over taking notes. Download the presentation slides here: http://j.mp/drupal-compass Note: It’s okay if you read ahead. We don’t mind. :)
  2. 2. Design & User Experience Using Sass & Compass in Drupal Theming Nathan Smith & Matt Farina
  3. 3. Hello :) We like Drupal, Sass & Compass. We hope you do too, or will soon. Let us introduce ourselves...
  4. 4. Nathan Smith is a UX designer at Matt Farina is a web developer at HP Cloud Services http://projekt202.com http://hpcloud.com yay,  books! Note: We co-authored these books, respectively. We’re not taking all the credit.
  5. 5. Sass & Compass are made possible by... http://hamptoncatlin.com He is no longer active in working on Sass. http://nex-3.com Still works on Sass, in his “20% time.” http://chriseppstein.github.com Also, member of Sass core team. Nathan Weizenbaum Google Chrome (Dart) Hampton Catlin created Haml & Sass Chris Eppstein created Compass ...and other community contributors.
  6. 6. Part 1: Why Sass?
  7. 7. “The backdrop to this debate is that CSS is absolutely the worst, least productive part of the web platform. Apps teams at Google are fond of citing the meme that ‘CSS is good for documents, but not for apps.’ I push back on this, noting the myriad of ways in which CSS is abysmal for documents [as well].” On -webkit vendor prefix drama http://infrequently.org/2012/02/misdirection Alex Russell @slightlylate Google Chrome team / Dojo Toolkit co-creator
  8. 8. So what’s to be done about CSS? The answer has actually been staring us in the face for awhile now, but it’s only been in recent years that CSS has become a first-class citizen. CSS is now being approached with an architectural mindset. PHP is a (recursive) acronym for “PHP: Hypertext Preprocessor.” So, preprocessing is a considered a Good Thing™ for HTML. How does it work for CSS?
  9. 9. http://thingsorganizedneatly.tumblr.com/post/9494864300/submission-the-compulsively-tidy-ursus-wehrli CSS served to browserNeatly organized *.sass
  10. 10. “Years ago, we wrote static HTML. Now, we almost never do. Our HTML is virtually always preprocessed, be it by PHP, Python, Ruby, Perl, .NET, Java, or something else. Today, we almost never write and serve straight HTML.” Jeff Croft @jcroft Chief “Designerd” at nGen Works http://jeffcroft.com/blog/2012/jan/31/on-css-preprocessors
  11. 11. Noteworthy CSS preprocessors • LESS http://lesscss.org • Sass & Compass http://sass-lang.com http://compass-style.org • Stylus & Nib http://learnboost.github.com/stylus http://visionmedia.github.com/nib Note: Obviously, today we will only be covering Sass and Compass.
  12. 12. CSS Sass Compass http://sonspring.com/journal/sass-for-designers
  13. 13. Compass extends the functionality of Sass by offering a plugin architecture. It also handles vendor prefixes like a champ. Today, when you hear us say “Sass,” we may blur the lines between Compass and Sass. Hope that’s okay. Compass is essentially Sass’ extra-awesome secret-sauce.
  14. 14. Oversimplification, FTW! Compass is to Sass as jQuery is to JavaScript
  15. 15. Sass & SCSS are functionally equivalent We prefer using Sass instead of SCSS because hey, less typing!
  16. 16. Anti-pattern of nested selectors in Sass
  17. 17. Compass makes vendor prefixes easy...
  18. 18. Compass brings sanity to gradients...
  19. 19. Text editors and IDE’s that support Sass/SCSS syntax Aptana http://aptana.org BBEdit http://barebones.com/bbedit Chocolat http://chocolatapp.com Coda http://panic.com/coda E Text Editor http://e-texteditor.com Eclipse http://eclipse.org Emacs http://gnu.org/software/emacs Espresso http://macrabbit.com/espresso GEdit http://projects.gnome.org/gedit Komodo http://activestate.com/komodo-ide Netbeans http://netbeans.org PhpStorm http://jetbrains.com/phpstorm PyCharm http://jetbrains.com/pycharm RubyMine http://jetbrains.com/ruby SubEthaEdit http://codingmonkeys.de/subethaedit Sublime Text http://sublimetext.com/dev TextMate http://macromates.com Vim http://vim.org Visual Studio http://microsoft.com/visualstudio http://sass-lang.com/editors.html ^We  recommend
  20. 20. GUI to compile Sass & Compass • Compass.app http://compass.handlino.com • Scout http://mhs.github.com/scout-app • CodeKit http://incident57.com/codekit Note: Personally, we prefer to run command-line “compass watch”
  21. 21. Impression of Sass... Great for CSS, in Ruby on Rails projects.
  22. 22. Great for CSS, in Ruby on Rails projects. Great for CSS, in Ruby projects. Impression of Sass...
  23. 23. Great for CSS, in Ruby on Rails projects. Great for CSS, in Ruby projects. Great for CSS, in any project! Impression of Sass...
  24. 24. What if I want to use Sass for something that wasn’t written in Ruby... impossible? But, wait...
  25. 25. When I think about not having Sass... http://en.wikipedia.org/wiki/The_Incredible_Hulk_(TV_series)
  26. 26. Yes, but the amount of Ruby knowledge it takes to use Sass is basically zero. Nathan is not a hardcore programmer, but he manages to use Sass just fine. Matt explained to Nathan how to use *.sass files in Drupal. Matt is the man. So, does Sass require Ruby?
  27. 27. Part 2: Whither a module?
  28. 28. Why use a Drupal Module? Possibly  Bad  Reasons... — You don’t want to install Sass/Compass gems. — You want Drupal to do everything, end-to-end. Possibly  Good  Reasons... — To use base-theme mixins/variables in sub-theme. — So that modules can supply mixins/variables.
  29. 29. Sass/SCSS module http://drupal.org/project/sass • Depends on “phamlp” http://code.google.com/p/phamlp Last updated in September 2010. • PHP needs code write access to theme This can lead to bad security practices. • Despite the name, only handles SCSS files #sadpanda
  30. 30. Compass stylesheet tool module http://drupal.org/project/compass • Ruby (Compass) does the heavy lifting This means you need Ruby and PHP on your server. • Can compile CSS using devel or cron This is similar to “compass compile” but using Drupal. • Compass location across environments Compass location set it config. Needs to be managed. • Version and permissions can be an issue • Module admin page is hidden (a bug)
  31. 31. Sassy module http://drupal.org/project/sassy • Several dependencies http://github.com/richthegeek/phpsass — and three other modules. • Hooks for namespaces/implementations Incomplete (PHP) implementation of Compass, Bootstrap, Foundation. • Sass & SCSS files in .info file styles[] • Stores generated files in public files
  32. 32. Jeff Croft, quoted previously, programs in Python and uses Django. He also makes use of Sass, via Ruby. We advocate trying to move beyond a “not invented here” mindset, and adopting a more hybrid workflow. Just as it wouldn’t make much sense to port Drupal out of PHP, we think it’s most logical to use first-party releases of Sass and Compass directly, if possible. TL;DR — Stick “close to the metal” if you want to stay on the cutting-edge. “Best tool for the job”
  33. 33. ACHIEVEMENT UNLOCKED! Presuppositions Challenged Note: I don’t think this photo is necessarily relevant, but I think we can all agree that raw electricity looks awesome. https://en.wikipedia.org/wiki/The_Prestige_(film)
  34. 34. Part 3: How to use
  35. 35. For the sake of brevity, we are going to assume in this talk that your environment already has Ruby set up. If not, then follow the instructions here... http://sonspring.com/journal/sass-for-designers Prerequisite: Ruby
  36. 36. Setting up Compass & Sass gem install compass From the command-line (Terminal.app, iTerm, etc)... This will also automatically download the Sass gem, a dependency of Compass. There’s no need to install separately. They’re typically used in tandem anyway.
  37. 37. Take a hybrid PHP + Ruby approach
  38. 38. Add config.rb to your theme directory
  39. 39. “cd” to your theme directory, then run “compass watch” If you just want to flush cache and compile, run “compass clean && compass compile”
  40. 40. application.css is compiled and (optionally) minified via “compass watch” Serving as a aggregate, application.sass is built from “_file.sass” partials. I bring over what I do like from default Drupal CSS as SCSS files, to import: _search.scss _system.base.scss _system.theme.scss Compass outputs the resulting compiled file as “application.css” Sass partials begin with an underscore, aren’t compiled to *.css files individually.
  41. 41. Theme *.info file – before Sass stylesheets[all][] = assets/css/reset.css stylesheets[all][] = assets/css/override/system.base.css stylesheets[all][] = assets/css/override/system.theme.css stylesheets[all][] = assets/css/override/search.css stylesheets[all][] = assets/css/960_12_col.css stylesheets[all][] = assets/css/text.css stylesheets[all][] = assets/css/formalize.css stylesheets[all][] = assets/css/site.css ; KILL THESE DEFAULT STYLESHEETS: stylesheets[all][] = ctools.css stylesheets[all][] = field.css stylesheets[all][] = node.css stylesheets[all][] = system.messages.css stylesheets[all][] = system.menus.css stylesheets[all][] = user.css stylesheets[all][] = views.css For  brevity,  only  CSS  files  shown Files  in  orange   are  listed  to   prevent  Drupal   from  adding  ‘em   automatically.
  42. 42. Theme *.info file – before Sass stylesheets[all][] = assets/css/reset.css stylesheets[all][] = assets/css/override/system.base.css stylesheets[all][] = assets/css/override/system.theme.css stylesheets[all][] = assets/css/override/search.css stylesheets[all][] = assets/css/960_12_col.css stylesheets[all][] = assets/css/text.css stylesheets[all][] = assets/css/formalize.css stylesheets[all][] = assets/css/site.css For  brevity,  only  CSS  files  shown Minus the nonexistent files, to ward off Drupal defaults... This compresses down to a single CSS file, in the Performance cache setting in Drupal.
  43. 43. stylesheets[all][] = assets/css/application.css ; KILL THESE DEFAULT STYLESHEETS: stylesheets[all][] = ctools.css stylesheets[all][] = field.css stylesheets[all][] = node.css stylesheets[all][] = search.css stylesheets[all][] = system.base.css stylesheets[all][] = system.theme.css stylesheets[all][] = system.menus.css stylesheets[all][] = system.messages.css stylesheets[all][] = user.css stylesheets[all][] = views.css Theme *.info file – after Sass For  brevity,  only  CSS  files  shown Files  in  orange   are  listed  to   prevent  Drupal   from  adding  ‘em   automatically.
  44. 44. stylesheets[all][] = assets/css/application.css Theme *.info file – after Sass ACHIEVEMENT UNLOCKED Only one CSS HTTP request! With (or without) cached CSS compression in Performance. Minus the nonexistent files, to ward off Drupal defaults...
  45. 45. This is still worth doing. I’ll explain why in a second.
  46. 46. Even if using “compass watch” with: output_style = :compressed You should still use Drupal’s CSS compression under Performance. Why? Well, let’s flip to the next slide...
  47. 47. Benefits of using Drupal’s CSS compression, not just Compass: 1. Cache-busting. File name is changed to... “css_VvtjvgJd9tI4sfrbHdy7Yvyc5fm9jVFoHRnrEBsJlQs.css” 2. <link /> instead of <style>@import</style> (older IE versions are slower at the latter) 3. Drupal replaces url(../images/file.png) with url(/full/path/to/images/file.png) — Useful if you have assets on a CDN or subdomain.
  48. 48. Compass output, before Drupal compression
  49. 49. Compass output, after Drupal compression
  50. 50. Achievement Unlocked! You have now attained CSS bliss. Don’t forget to rate this as the best talk you’ve ever heard in your life. Or, maybe we forgot something...
  51. 51. Stop the presses! What  about  debugging? How do I see what styles are coming from which *_file.sass partial?
  52. 52. Part 4: Debugging & Demos
  53. 53. Cryptic error messages are never helpful.
  54. 54. ^ I believe debugging this way stinks.
  55. 55. When things don’t go as planned... http://autos.yahoo.com/blogs/motoramic/porsche-stuck-wet-cement-proves-karma-exists-210302568.html
  56. 56. Just a one-line change in config.rb
  57. 57. Emits *.sass “stack trace” for each style
  58. 58. A quick tip on source control While you can track your *.css files via source control, the ones you really care about are your *.sass files, which are the canonical “source of truth.” Educate peer developers not to edit *.css, but instead tweak *.sass files when making changes.
  59. 59. Now time for some demonstrations :) Note: If you’re viewing these slides, but missed our session, we showed “compass watch” in action.
  60. 60. “Luck, be a lady...” (live demo = dice roll) http://kloucksphoto.blogspot.com/2011/06/guys-and-dolls-witty-wry-wonderful.html
  61. 61. If you want to tinker with Haml & Sass...
  62. 62. “We keep thinking we can write better CSS if we just try harder, that the next site will be clean and stay that way. [Her] presentation shows that in fact, messy CSS is the direct result of our worst best-practices. We need to re-examine those assumptions with an eye to practicality and scalability — as well as accessibility, standards, and fabulous design.” Nicole Sullivan @stubbornella CSS Ninja & Front-end Performance Engineer http://stubbornella.org/content/2011/04/28/our-best-practices-are-killing-us (Nicole helped make Yahoo & Facebook more efficient)
  63. 63. Feel free to say hi on Twitter, and/or check out our personal sites for more of our work. http://twitter.com/NathanSmith Personal site — http://sonspring.com http://twitter.com/MattFarina Personal site — http://mattfarina.com Thanks for coming. Keep in touch!
  64. 64. Questions? We (might) have answers. Feel free to share the link with friends, enemies, etc. Download the presentation slides here: http://j.mp/drupal-compass
  65. 65. What did you think? Locate this session on the DrupalCon Denver website http://denver2012.drupal.org/program Click the “Take the Survey” link. Thank You!
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×