SlideShare a Scribd company logo
OOScss architecture for Rails apps.
My proposition.
Dawid Woźniak
netguru
front-end / rails dev
@dawidwu
dawid@plaind.pl / dawid.wozniak@netguru.pl
We've been struggling to find a best way to
bootsrap an application
and
redesign it in further phase.
How many of you write front-end code?
How many of you use Bootstrap for that?
//application.scss
/*
*=require_self
*=require_tree
*/
@import "bootstrap";
...
Looks familiar?
|- stylesheets
|-application.scss
+-controllers
| +-/admin/*
| |- main.scss
| +- controller.scss
|
...
How many of you use it for a client work?
Is it bad?
NO*
*if you're OK with it's look and feel.
*if you're not tired of the whole Internet looking the same (or at least 90% of open source projects)
*if you do it for prototyping.
*if you do it for fast bootstraping project for a client
*you have a well explained documentation (more less)
...
Have you ever tried to build a custom
design/framework on top of a Bootstrap?
Let me show you some numbers:
bootstrap: 266 KB and ~6700 lines of css
+ responsive: 320 KB and ~8200 lines of css
+ overrides: 362 KB and ~9200 lines of css
+ custom comp.: 445 KB and ~11000 lines of code
+ site specific: 556 KB and ~13780 lines of code
556KB for a production css
NOT BAD AT ALL.
so we're good right?
NO!*
*have you seen the markup?
*have you seen how much overriding you have to do?
*are you sure your devs understand Bootstrap?
*we haven't styled 100screens (I won't tell you how many of them we covered ;-)
So what should I do when the designs come from
the creative agency?
Bootstrap
Example 1. - what's wrong with this code?
Example 1. - what's wrong with this code?
.span9 { width: 740px; }
My reaction was like:
WHY!?
let's correct this code.
Example 2. - what's wrong with this code?
Example 2. - what's wrong with this code?
- it won't fit into the row because of the .well class
Example 2. - what's wrong with this code?
- it won't fit into the row because of the .well class
- that's why the dev overrided span9 for that view
and used span2 for the sidebar previously
Example 2. - what's wrong with this code?
- it won't fit into the row because of the .well class
- that's why the dev overrided span9 for that view
and used span2 for the sidebar previously
- do you know what's the purpose of the row class?
Fun Fun Fun
Example 3. - what's wrong with this code?
Example 3. - what's wrong with this code?
- we dropped the well class to fit into the grid
- that's not what we want
Example 4. - what's wrong with this code?
.well { box-sizing: border-box; }
Example 4. - what's wrong with this code?
.well { box-sizing: border-box; }
- we have to override default .well box-model
Example 4. - what's wrong with this code?
.well { box-sizing: border-box; }
- we have to override default .well box-model
- aaaand we haven't even reached the fluid grid yet
Do you really think you know how to use Bootstrap?
Do you really think you know how to use Bootstrap?
Are you sure it enforces some conventions?
Do you really think you know how to use Bootstrap?
Are you sure it enforces some conventions?
Do you really think you know it that good to build
something on top of it?
Do you really think you know how to use Bootstrap?
Are you sure it enforces some conventions?
Do you really think you know it that good to build
something on top of it?
Are you sure it's easy for your devs to understand it?
Do you really think you know how to use Bootstrap?
Are you sure it enforces some conventions?
Do you really think you know it that good to build
something on top of it?
Are you sure it's easy for your devs to understand it?
Are you sure it's easy for your devs to understand
components build on top of it?
OOScss Architecture For Rails Apps
How this markup should look like?
Have you ever seen something like this in ror app?
.users {
&.show {
padding-top: 0;
header {
position: fixed;
z-index: 10;
width: 100%;
}
nav {
background: #fff;
box-shadow: 0px 2px 15px 2px rgba(80, 80, 80, 1);
position: relative;
height: 20px;
ul {
padding-top: 10px;
}
}
.top_container {
background: image-url("controllers/preview/upper_bar_bg.png")
background-size: cover;
height: 6%;
Have you ever seen something like this?
.logo_container {
float: left;
position:relative;
text-indent: -99999px;
z-index: 10;
top: 0px;
height: 10%;
padding-top: 5px;
a {
h1 {
background: image-url("controllers/preview/Logo_white.png")
no-repeat top center;
height: 86px;
width: 95px;
margin: 5px 26px 0px 2px;
}
}
}
Why this is bad?
- it's nested to the infinity
- it's styled by the elements selectors
- sizes mixed with theme
...
OOCSS principles:
- identify reusable objects
- be semantic w/HTML
- minimize selectors (you know how browser reads selectors?)
- extend classes
- 'style' separate from content
- 'content' separate from container
https://speakerdeck.com/anotheruiguy/module-design-ui-dev-patterns
How to achieve that?
That's kinda impossible with pure CSS so...
SCSS to the rescue!
How to achieve that?
OOScss
+
BEM
How to achieve that?
OOscss
+
BEM
=
SMACSS
(scalable and modular architecture for css)
BEM (block element modifier)
.component-name {}
.component-name--modifier-name {}
.component-name__sub-object {}
.component-name__sub-object--modifier-name {}
.person{} .person__hand > .animal__hand
.person--woman{}
.person__hand{}
.person__hand--left{}
.person__hand--right{} TIPS:
- don't nest to infinity
- indent to reflect html structure
/* Layout Rules */
.l-layout-method
/* State Rules */
.is-state-type
/* Non-styled JavaScript Hooks */
.js-action-name
Introduce naming conventions
OOScss
divide your design into:
- (reusable) components
- (reusable) modules
OOScss ( probably ) the best way:
Abstract class selector A.K.A. SASS %placeholder (since SASS 3.2)
Placeholders are selectors that output nothing unless they are extended.
Example:
%separator
border-top: 1px solid black
hr
@extend %separator
.separator
@extend %separator
hr,
.separator {
border-top: 1px solid black
}
OOScss ( probably ) the best way:
Placeholders don’t have the code bloat problems that mixins or regular
@extend calls have.
That makes placeholders perfect for creating non-semantic CSS modules.
http://ianstormtaylor.com/oocss-plus-sass-is-the-best-way-to-css/
File structure:
- settings
- reset
- variables
- grid-settings
- type
...
- bourbon (useful set of mixins)
- neat (grid library)
- utilities (i.e. custom mixins)
- components
- modules
- layout
- base-view
- views/
Explained
you can add themes/ here
Real life example:
https://github.com/dawidw/cssattempt
- http://bourbon.io/docs
- http://neat.bourbon.io/docs/
- https://speakerdeck.com/anotheruiguy/sass-32-silent-classes
- http://philipwalton.com/articles/the-future-of-oocss-a-proposal/
- http://ianstormtaylor.com/oocss-plus-sass-is-the-best-way-to-css/
- http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#placeholders
- http://blog.teamtreehouse.com/extending-placeholder-selectors-with-sass
- https://speakerdeck.com/anotheruiguy/module-design-ui-dev-patterns
- https://github.com/csswizardry/CSS-Guidelines
- http://bem.info/
pictures from http://frontenddevreactions.tumblr.com/
Further reading

More Related Content

Similar to OOScss Architecture For Rails Apps (20)

PDF
Introduction to Responsive Web Development
Nikhil Baby
 
PPTX
Bootstrap SLIDES for web development course
dreamy678
 
PDF
Scalable front-end architecture with Bootstrap 3 + Atomic CSS
Hayden Bleasel
 
PDF
CSS: a rapidly changing world
Russ Weakley
 
PDF
Bootstrap Tutorial
Luan Nguyen
 
PPTX
Bootstrap [part 1]
Ghanshyam Patel
 
PPT
Bootstrap Part - 1
EPAM Systems
 
PDF
Things To Keep In Mind When Working In The World Of Responsive Design
FITC
 
PDF
Bootstrap Workout 2015
Rob Davarnia
 
PDF
Responsive web design
Netcetera
 
PDF
CSS - OOCSS, SMACSS and more
Russ Weakley
 
PDF
CSMess to OOCSS: Refactoring CSS with Object Oriented Design
Kate Travers
 
PPTX
Rapid and Responsive - UX to Prototype with Bootstrap
Josh Jeffryes
 
PPTX
Create Responsive Website Design with Bootstrap 3
Wahyu Putra
 
PPTX
Lecture-10.pptx
vishal choudhary
 
PDF
Introduction to Bootstrap
Ron Reiter
 
PPTX
An introduction to bootstrap
Mind IT Systems
 
PPT
Cssbestpracticesjstyleguidejandtips 150830184202-lva1-app6892
Deepak Sharma
 
PPT
Css best practices style guide and tips
Chris Love
 
PPTX
Module 3 - Intro to Bootstrap
Katherine McCurdy-Lapierre, R.G.D.
 
Introduction to Responsive Web Development
Nikhil Baby
 
Bootstrap SLIDES for web development course
dreamy678
 
Scalable front-end architecture with Bootstrap 3 + Atomic CSS
Hayden Bleasel
 
CSS: a rapidly changing world
Russ Weakley
 
Bootstrap Tutorial
Luan Nguyen
 
Bootstrap [part 1]
Ghanshyam Patel
 
Bootstrap Part - 1
EPAM Systems
 
Things To Keep In Mind When Working In The World Of Responsive Design
FITC
 
Bootstrap Workout 2015
Rob Davarnia
 
Responsive web design
Netcetera
 
CSS - OOCSS, SMACSS and more
Russ Weakley
 
CSMess to OOCSS: Refactoring CSS with Object Oriented Design
Kate Travers
 
Rapid and Responsive - UX to Prototype with Bootstrap
Josh Jeffryes
 
Create Responsive Website Design with Bootstrap 3
Wahyu Putra
 
Lecture-10.pptx
vishal choudhary
 
Introduction to Bootstrap
Ron Reiter
 
An introduction to bootstrap
Mind IT Systems
 
Cssbestpracticesjstyleguidejandtips 150830184202-lva1-app6892
Deepak Sharma
 
Css best practices style guide and tips
Chris Love
 
Module 3 - Intro to Bootstrap
Katherine McCurdy-Lapierre, R.G.D.
 

More from Netguru (20)

PDF
Payments integration: Stripe & Taxamo
Netguru
 
PDF
Hidden Gems in Swift
Netguru
 
PDF
KISS Augmented Reality
Netguru
 
PDF
Why Would A Programmer Fall In Love With SPA?
Netguru
 
PDF
Defining DSL (Domain Specific Language) using Ruby
Netguru
 
PDF
How To Build Great Relationships With Your Clients
Netguru
 
PDF
Agile Retrospectives
Netguru
 
PDF
Ruby Rails Overview
Netguru
 
PDF
From Birds To Bugs: Testowanie Z Pasją
Netguru
 
PDF
Communication With Clients Throughout The Project
Netguru
 
PDF
Everyday Rails
Netguru
 
PDF
Estimation myths debunked
Netguru
 
PDF
Programming Paradigms Which One Is The Best?
Netguru
 
PDF
Z 50 do 100 w ciągu roku Jak rekrutować w IT?
Netguru
 
PDF
Paradygmaty Programowania: Czy Istnieje Najlepszy?
Netguru
 
PDF
Czy Project Manger Musi Być Osobą Techniczną?
Netguru
 
PDF
CSS architecture: How To Write Clean & Scalable Code
Netguru
 
PDF
Ruby On Rails Intro
Netguru
 
PDF
Perfect Project Read Me (in a few steps)
Netguru
 
PDF
The Git Basics
Netguru
 
Payments integration: Stripe & Taxamo
Netguru
 
Hidden Gems in Swift
Netguru
 
KISS Augmented Reality
Netguru
 
Why Would A Programmer Fall In Love With SPA?
Netguru
 
Defining DSL (Domain Specific Language) using Ruby
Netguru
 
How To Build Great Relationships With Your Clients
Netguru
 
Agile Retrospectives
Netguru
 
Ruby Rails Overview
Netguru
 
From Birds To Bugs: Testowanie Z Pasją
Netguru
 
Communication With Clients Throughout The Project
Netguru
 
Everyday Rails
Netguru
 
Estimation myths debunked
Netguru
 
Programming Paradigms Which One Is The Best?
Netguru
 
Z 50 do 100 w ciągu roku Jak rekrutować w IT?
Netguru
 
Paradygmaty Programowania: Czy Istnieje Najlepszy?
Netguru
 
Czy Project Manger Musi Być Osobą Techniczną?
Netguru
 
CSS architecture: How To Write Clean & Scalable Code
Netguru
 
Ruby On Rails Intro
Netguru
 
Perfect Project Read Me (in a few steps)
Netguru
 
The Git Basics
Netguru
 
Ad

Recently uploaded (20)

PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
July Patch Tuesday
Ivanti
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
Biography of Daniel Podor.pdf
Daniel Podor
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
July Patch Tuesday
Ivanti
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Biography of Daniel Podor.pdf
Daniel Podor
 
Ad

OOScss Architecture For Rails Apps

  • 1. OOScss architecture for Rails apps. My proposition.
  • 3. We've been struggling to find a best way to bootsrap an application and redesign it in further phase.
  • 4. How many of you write front-end code?
  • 5. How many of you use Bootstrap for that?
  • 6. //application.scss /* *=require_self *=require_tree */ @import "bootstrap"; ... Looks familiar? |- stylesheets |-application.scss +-controllers | +-/admin/* | |- main.scss | +- controller.scss | ...
  • 7. How many of you use it for a client work?
  • 9. NO* *if you're OK with it's look and feel. *if you're not tired of the whole Internet looking the same (or at least 90% of open source projects) *if you do it for prototyping. *if you do it for fast bootstraping project for a client *you have a well explained documentation (more less) ...
  • 10. Have you ever tried to build a custom design/framework on top of a Bootstrap?
  • 11. Let me show you some numbers: bootstrap: 266 KB and ~6700 lines of css + responsive: 320 KB and ~8200 lines of css + overrides: 362 KB and ~9200 lines of css + custom comp.: 445 KB and ~11000 lines of code + site specific: 556 KB and ~13780 lines of code
  • 12. 556KB for a production css NOT BAD AT ALL. so we're good right?
  • 13. NO!* *have you seen the markup? *have you seen how much overriding you have to do? *are you sure your devs understand Bootstrap? *we haven't styled 100screens (I won't tell you how many of them we covered ;-)
  • 14. So what should I do when the designs come from the creative agency?
  • 16. Example 1. - what's wrong with this code?
  • 17. Example 1. - what's wrong with this code? .span9 { width: 740px; }
  • 20. Example 2. - what's wrong with this code?
  • 21. Example 2. - what's wrong with this code? - it won't fit into the row because of the .well class
  • 22. Example 2. - what's wrong with this code? - it won't fit into the row because of the .well class - that's why the dev overrided span9 for that view and used span2 for the sidebar previously
  • 23. Example 2. - what's wrong with this code? - it won't fit into the row because of the .well class - that's why the dev overrided span9 for that view and used span2 for the sidebar previously - do you know what's the purpose of the row class?
  • 25. Example 3. - what's wrong with this code?
  • 26. Example 3. - what's wrong with this code? - we dropped the well class to fit into the grid - that's not what we want
  • 27. Example 4. - what's wrong with this code? .well { box-sizing: border-box; }
  • 28. Example 4. - what's wrong with this code? .well { box-sizing: border-box; } - we have to override default .well box-model
  • 29. Example 4. - what's wrong with this code? .well { box-sizing: border-box; } - we have to override default .well box-model - aaaand we haven't even reached the fluid grid yet
  • 30. Do you really think you know how to use Bootstrap?
  • 31. Do you really think you know how to use Bootstrap? Are you sure it enforces some conventions?
  • 32. Do you really think you know how to use Bootstrap? Are you sure it enforces some conventions? Do you really think you know it that good to build something on top of it?
  • 33. Do you really think you know how to use Bootstrap? Are you sure it enforces some conventions? Do you really think you know it that good to build something on top of it? Are you sure it's easy for your devs to understand it?
  • 34. Do you really think you know how to use Bootstrap? Are you sure it enforces some conventions? Do you really think you know it that good to build something on top of it? Are you sure it's easy for your devs to understand it? Are you sure it's easy for your devs to understand components build on top of it?
  • 36. How this markup should look like?
  • 37. Have you ever seen something like this in ror app? .users { &.show { padding-top: 0; header { position: fixed; z-index: 10; width: 100%; } nav { background: #fff; box-shadow: 0px 2px 15px 2px rgba(80, 80, 80, 1); position: relative; height: 20px; ul { padding-top: 10px; } } .top_container { background: image-url("controllers/preview/upper_bar_bg.png") background-size: cover; height: 6%;
  • 38. Have you ever seen something like this? .logo_container { float: left; position:relative; text-indent: -99999px; z-index: 10; top: 0px; height: 10%; padding-top: 5px; a { h1 { background: image-url("controllers/preview/Logo_white.png") no-repeat top center; height: 86px; width: 95px; margin: 5px 26px 0px 2px; } } }
  • 39. Why this is bad? - it's nested to the infinity - it's styled by the elements selectors - sizes mixed with theme ...
  • 40. OOCSS principles: - identify reusable objects - be semantic w/HTML - minimize selectors (you know how browser reads selectors?) - extend classes - 'style' separate from content - 'content' separate from container https://speakerdeck.com/anotheruiguy/module-design-ui-dev-patterns
  • 41. How to achieve that? That's kinda impossible with pure CSS so... SCSS to the rescue!
  • 42. How to achieve that? OOScss + BEM
  • 43. How to achieve that? OOscss + BEM = SMACSS (scalable and modular architecture for css)
  • 44. BEM (block element modifier) .component-name {} .component-name--modifier-name {} .component-name__sub-object {} .component-name__sub-object--modifier-name {} .person{} .person__hand > .animal__hand .person--woman{} .person__hand{} .person__hand--left{} .person__hand--right{} TIPS: - don't nest to infinity - indent to reflect html structure
  • 45. /* Layout Rules */ .l-layout-method /* State Rules */ .is-state-type /* Non-styled JavaScript Hooks */ .js-action-name Introduce naming conventions
  • 46. OOScss divide your design into: - (reusable) components - (reusable) modules
  • 47. OOScss ( probably ) the best way: Abstract class selector A.K.A. SASS %placeholder (since SASS 3.2) Placeholders are selectors that output nothing unless they are extended. Example: %separator border-top: 1px solid black hr @extend %separator .separator @extend %separator hr, .separator { border-top: 1px solid black }
  • 48. OOScss ( probably ) the best way: Placeholders don’t have the code bloat problems that mixins or regular @extend calls have. That makes placeholders perfect for creating non-semantic CSS modules. http://ianstormtaylor.com/oocss-plus-sass-is-the-best-way-to-css/
  • 50. - settings - reset - variables - grid-settings - type ... - bourbon (useful set of mixins) - neat (grid library) - utilities (i.e. custom mixins) - components - modules - layout - base-view - views/ Explained you can add themes/ here
  • 52. - http://bourbon.io/docs - http://neat.bourbon.io/docs/ - https://speakerdeck.com/anotheruiguy/sass-32-silent-classes - http://philipwalton.com/articles/the-future-of-oocss-a-proposal/ - http://ianstormtaylor.com/oocss-plus-sass-is-the-best-way-to-css/ - http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#placeholders - http://blog.teamtreehouse.com/extending-placeholder-selectors-with-sass - https://speakerdeck.com/anotheruiguy/module-design-ui-dev-patterns - https://github.com/csswizardry/CSS-Guidelines - http://bem.info/ pictures from http://frontenddevreactions.tumblr.com/ Further reading