Movatterモバイル変換


[0]ホーム

URL:


Netguru, profile picture
Uploaded byNetguru
763 views

OOScss Architecture For Rails Apps

This document discusses using OOScss architecture for Rails applications. It proposes dividing CSS into components, modules, and layouts. Placeholder selectors from Sass can be used to create reusable CSS modules without code bloat. Examples show issues with directly using Bootstrap for complex designs. Following OOScss principles like identifying reusable objects, using semantic HTML, and separating styles from content can help build custom designs on top of frameworks like Bootstrap more effectively.

Embed presentation

Download to read offline
OOScss architecture for Rails apps.My proposition.
Dawid Woźniaknetgurufront-end / rails dev@dawidwudawid@plaind.pl / dawid.wozniak@netguru.pl
We've been struggling to find a best way tobootsrap an applicationandredesign 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 customdesign/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 cssNOT 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 fromthe 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 viewand 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 viewand 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 buildsomething 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 buildsomething 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 buildsomething 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 understandcomponents build on top of it?
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 containerhttps://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-nameIntroduce naming conventions
OOScssdivide 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:%separatorborder-top: 1px solid blackhr@extend %separator.separator@extend %separatorhr,.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/Explainedyou 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

Recommended

PDF
Atomic Design - An Event Apart San Diego
PDF
Brad frost: Atomic design (Webdagene 2014)
PPT
WordPress Development Confoo 2010
PDF
Bridging the gap between designers and developers at the Guardian
PDF
Tooling, theming, made easy
PDF
Use atomic design ftw
PDF
Atomic Design - BDConf Nashville, 2013
PDF
Twitter bootstrap入門 #twtr_hack
PPTX
Bootstrap SLIDES for web development course
PPTX
Create Responsive Website Design with Bootstrap 3
PPTX
Bootstrap [part 1]
PPTX
An introduction to bootstrap
PDF
CSS: a rapidly changing world
PPTX
Module 3 - Intro to Bootstrap
PDF
CSS - OOCSS, SMACSS and more
PPT
Bootstrap Part - 1
PDF
Introduction to Bootstrap
PDF
Scalable front-end architecture with Bootstrap 3 + Atomic CSS
PDF
Bootstrap Workout 2015
PPTX
Rapid and Responsive - UX to Prototype with Bootstrap
PDF
Bootstrap Tutorial
PDF
CSMess to OOCSS: Refactoring CSS with Object Oriented Design
PPT
Cssbestpracticesjstyleguidejandtips 150830184202-lva1-app6892
PPT
Css best practices style guide and tips
PPTX
Lecture-10.pptx
PDF
Things To Keep In Mind When Working In The World Of Responsive Design
 
PDF
Introduction to Responsive Web Development
PDF
Responsive web design
PDF
Perfect Project Read Me (in a few steps)
PDF
Everyday Rails

More Related Content

PDF
Atomic Design - An Event Apart San Diego
PDF
Brad frost: Atomic design (Webdagene 2014)
PPT
WordPress Development Confoo 2010
PDF
Bridging the gap between designers and developers at the Guardian
PDF
Tooling, theming, made easy
PDF
Use atomic design ftw
PDF
Atomic Design - BDConf Nashville, 2013
PDF
Twitter bootstrap入門 #twtr_hack
Atomic Design - An Event Apart San Diego
Brad frost: Atomic design (Webdagene 2014)
WordPress Development Confoo 2010
Bridging the gap between designers and developers at the Guardian
Tooling, theming, made easy
Use atomic design ftw
Atomic Design - BDConf Nashville, 2013
Twitter bootstrap入門 #twtr_hack

Similar to OOScss Architecture For Rails Apps

PPTX
Bootstrap SLIDES for web development course
PPTX
Create Responsive Website Design with Bootstrap 3
PPTX
Bootstrap [part 1]
PPTX
An introduction to bootstrap
PDF
CSS: a rapidly changing world
PPTX
Module 3 - Intro to Bootstrap
PDF
CSS - OOCSS, SMACSS and more
PPT
Bootstrap Part - 1
PDF
Introduction to Bootstrap
PDF
Scalable front-end architecture with Bootstrap 3 + Atomic CSS
PDF
Bootstrap Workout 2015
PPTX
Rapid and Responsive - UX to Prototype with Bootstrap
PDF
Bootstrap Tutorial
PDF
CSMess to OOCSS: Refactoring CSS with Object Oriented Design
PPT
Cssbestpracticesjstyleguidejandtips 150830184202-lva1-app6892
PPT
Css best practices style guide and tips
PPTX
Lecture-10.pptx
PDF
Things To Keep In Mind When Working In The World Of Responsive Design
 
PDF
Introduction to Responsive Web Development
PDF
Responsive web design
Bootstrap SLIDES for web development course
Create Responsive Website Design with Bootstrap 3
Bootstrap [part 1]
An introduction to bootstrap
CSS: a rapidly changing world
Module 3 - Intro to Bootstrap
CSS - OOCSS, SMACSS and more
Bootstrap Part - 1
Introduction to Bootstrap
Scalable front-end architecture with Bootstrap 3 + Atomic CSS
Bootstrap Workout 2015
Rapid and Responsive - UX to Prototype with Bootstrap
Bootstrap Tutorial
CSMess to OOCSS: Refactoring CSS with Object Oriented Design
Cssbestpracticesjstyleguidejandtips 150830184202-lva1-app6892
Css best practices style guide and tips
Lecture-10.pptx
Things To Keep In Mind When Working In The World Of Responsive Design
 
Introduction to Responsive Web Development
Responsive web design

More from Netguru

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

Recently uploaded

PDF
Day 1 - Cloud Security Strategy and Planning ~ 2nd Sight Lab ~ Cloud Security...
PDF
Digit Expo 2025 - EICC Edinburgh 27th November
PDF
Day 5 - Red Team + Blue Team in the Cloud - 2nd Sight Lab Cloud Security Class
PDF
December Patch Tuesday
 
PPTX
wob-report.pptxwob-report.pptxwob-report.pptx
PDF
Our Digital Tribe_ Cultivating Connection and Growth in Our Slack Community 🌿...
PDF
DevFest El Jadida 2025 - Product Thinking
PDF
ElyriaSoftware — Powering the Future with Blockchain Innovation
PDF
Security Forum Sessions from Houston 2025 Event
PDF
Session 1 - Solving Semi-Structured Documents with Document Understanding
PDF
Eredità digitale sugli smartphone: cosa resta di noi nei dispositivi mobili
PPT
software-security-intro in information security.ppt
PDF
The major tech developments for 2026 by Pluralsight, a research and training ...
PDF
Usage Control for Process Discovery through a Trusted Execution Environment
PDF
Internet_of_Things_IoT_for_Next_Generation_Smart_Systems_Utilizing.pdf
PPTX
Building Cyber Resilience for 2026: Best Practices for a Secure, AI-Driven Bu...
PPTX
AI in Cybersecurity: Digital Defense by Yasir Naveed Riaz
PPTX
Protecting Data in an AI Driven World - Cybersecurity in 2026
PDF
TrustArc Webinar - Looking Ahead: The 2026 Privacy Landscape
PDF
Energy Storage Landscape Clean Energy Ministerial
Day 1 - Cloud Security Strategy and Planning ~ 2nd Sight Lab ~ Cloud Security...
Digit Expo 2025 - EICC Edinburgh 27th November
Day 5 - Red Team + Blue Team in the Cloud - 2nd Sight Lab Cloud Security Class
December Patch Tuesday
 
wob-report.pptxwob-report.pptxwob-report.pptx
Our Digital Tribe_ Cultivating Connection and Growth in Our Slack Community 🌿...
DevFest El Jadida 2025 - Product Thinking
ElyriaSoftware — Powering the Future with Blockchain Innovation
Security Forum Sessions from Houston 2025 Event
Session 1 - Solving Semi-Structured Documents with Document Understanding
Eredità digitale sugli smartphone: cosa resta di noi nei dispositivi mobili
software-security-intro in information security.ppt
The major tech developments for 2026 by Pluralsight, a research and training ...
Usage Control for Process Discovery through a Trusted Execution Environment
Internet_of_Things_IoT_for_Next_Generation_Smart_Systems_Utilizing.pdf
Building Cyber Resilience for 2026: Best Practices for a Secure, AI-Driven Bu...
AI in Cybersecurity: Digital Defense by Yasir Naveed Riaz
Protecting Data in an AI Driven World - Cybersecurity in 2026
TrustArc Webinar - Looking Ahead: The 2026 Privacy Landscape
Energy Storage Landscape Clean Energy Ministerial

OOScss Architecture For Rails Apps

  • 1.
    OOScss architecture forRails apps.My proposition.
  • 2.
    Dawid Woźniaknetgurufront-end /rails dev@dawidwudawid@plaind.pl / dawid.wozniak@netguru.pl
  • 3.
    We've been strugglingto find a best way tobootsrap an applicationandredesign it in further phase.
  • 4.
    How many ofyou write front-end code?
  • 5.
    How many ofyou 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 ofyou use it for a client work?
  • 8.
  • 9.
    NO**if you're OKwith 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 evertried to build a customdesign/framework on top of a Bootstrap?
  • 11.
    Let me showyou 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 aproduction cssNOT BAD AT ALL.so we're good right?
  • 13.
    NO!**have you seenthe 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 shouldI do when the designs come fromthe creative agency?
  • 15.
  • 16.
    Example 1. -what's wrong with this code?
  • 17.
    Example 1. -what's wrong with this code?.span9 { width: 740px; }
  • 18.
  • 19.
  • 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 viewand 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 viewand used span2 for the sidebar previously- do you know what's the purpose of the row class?
  • 24.
  • 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 reallythink you know how to use Bootstrap?
  • 31.
    Do you reallythink you know how to use Bootstrap?Are you sure it enforces some conventions?
  • 32.
    Do you reallythink you know how to use Bootstrap?Are you sure it enforces some conventions?Do you really think you know it that good to buildsomething on top of it?
  • 33.
    Do you reallythink you know how to use Bootstrap?Are you sure it enforces some conventions?Do you really think you know it that good to buildsomething on top of it?Are you sure it's easy for your devs to understand it?
  • 34.
    Do you reallythink you know how to use Bootstrap?Are you sure it enforces some conventions?Do you really think you know it that good to buildsomething 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 understandcomponents build on top of it?
  • 36.
    How this markupshould look like?
  • 37.
    Have you everseen 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 everseen 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 isbad?- it's nested to the infinity- it's styled by the elements selectors- sizes mixed with theme...
  • 40.
    OOCSS principles:- identifyreusable objects- be semantic w/HTML- minimize selectors (you know how browser reads selectors?)- extend classes- 'style' separate from content- 'content' separate from containerhttps://speakerdeck.com/anotheruiguy/module-design-ui-dev-patterns
  • 41.
    How to achievethat?That's kinda impossible with pure CSS so...SCSS to the rescue!
  • 42.
    How to achievethat?OOScss+BEM
  • 43.
    How to achievethat?OOscss+BEM=SMACSS(scalable and modular architecture for css)
  • 44.
    BEM (block elementmodifier).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-nameIntroduce naming conventions
  • 46.
    OOScssdivide your designinto:- (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:%separatorborder-top: 1px solid blackhr@extend %separator.separator@extend %separatorhr,.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/
  • 49.
  • 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/Explainedyou can add themes/ here
  • 51.
  • 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

[8]ページ先頭

©2009-2025 Movatter.jp