3 ways-to-create-sprites-in-rails

Nico Hagenburger
Nico HagenburgerRails developer, Web designer, Haml and Sass fan at home
3 Ways to Create
  CSS Sprites
   With Rails
What Are Image
Sprites?
A great way to save
  HTTP requests.
In other words:

 Something that
makes your website
     faster. awes om
                     e!
3 ways-to-create-sprites-in-rails
Rails 3.1 > Integrated Spriting
CSS_Sprite > better <img>
Lemonade > Full CSS sprites
Finding Information




  http://www.drdobbs.com/blog/archives/2010/06/preparing_for_r.html
Few Information




http://blog.endpoint.com/2010/06/rails-3-at-railsconf-2010-code-goodness.html
A Piece of Code




   http://twitter.com/jsiarto/status/15861245321
Finally!


   http://www.rubyinside.com/dhhs-railsconf-2010-keynote-video-a-justification-of-rails-3-0-3325.html
Generation Sprites
<%= sprite_css("icons") %>



★   Combines all images of a folder
★   Generates CSS
Using Images
<%= sprite_tag("icons/trash") %>



★   Adds a HTML tag with the class
                (I guess it works this way.)
Questions
★   Is it possible to pack CSS files?
★   Why “icons/trash” if image_tag requires
    “icons/trash.png”?
★   When will it be available?
Rails 3.1 > Integrated Spriting
CSS_Sprite > better <img>
Lemonade > Full CSS sprites
gem install
css_sprite
Features
★   Creates sprite images
★   Creates classes for each file
★   Sass compatible
★   Rake Task for generation
From Image to CCS
images under css_sprite directory                             class name in css_sprite css

twitter_icon.png                                              .twitter_icon

facebook_icon.png                                             .facebook_icon

hotmail-logo.png                                              .hotmail-logo

gmail-logo.png                                                .gmail-logo

icons/twitter_icon.png                                        .icons .twitter_icon

widget/icons/twitter_icon.png                                 .widget .icons .twitter_icon

twitter_icon_hover.png                                        .twitter_icon:hover

twitter-icon-hover.png                                        .twitter-icon:hover

logos_hover/gmail_logo.png                                    .logos:hover .gmail_logo

logos-hover/gmail-logo.png                                    .logos:hover .gmail-logo

…                                                             …




                                    full table at http://github.com/flyerhzm/css_sprite
Built Sprites (1)
rake css_sprite:build
Built Sprites (2)
rake css_sprite:start
Pros
★   Easy for HTML developers
★   Easy if you’re handling <img> tag
Cons
★   A lot of CSS generated (sizes, …)
★   Additional non-semantic tags
★   Additional classes
★   Positioned background images difficult
★   RMagick
★   Rake task
Alternatives
★   http://github.com/gistinc/sprite
    based on css_sprite
★   http://github.com/sblackstone/auto_sprite
    image_tag extention + CSS classes
★   http://github.com/setepo/css-sprites
    image_tag extention + inline CSS
Rails 3.1 > Integrated Spriting
CSS_Sprite > better <img>
Lemonade > Easy Sprites
3 ways-to-create-sprites-in-rails
gem install
 lemonade
Simple Sprites
.add {
  background:
    sprite-image("icons/pl.png");
}

.remove {
  background:
    sprite-image("icons/rm.png");
}
               all icons by p.yusukekamiyamane.com (CC by 3.0)
Output
.add {
  background:
    url("icons.png");
}

.remove {
  background:
    url("icons.png") 0 -16px;
}
Right Aligned
.something {
  background:
    sprite-image("i/wide.png");
}
a.next {
  background: yellow no-repeat
    sprite-image("i/n.png", 100%);
  padding-right: 20px;
}
Result
.something {
  background:
    url("i.png");
}
                  Example link
a.next {
  background: yellow no-repeat
    url("i.png") 100% -20px;
  padding-right: 20px;
}
Empty Space
.add {
  background:
    sprite-image("icons/pl.png");
}
.remove {
  background: yellow no-repeat
    sprite-image("icons/rm.png");
  padding: 20px;
}
Could be Better
.add {
  background:
    url("icons.png");
}
.remove {             Example link
  background:
    url("icons.png") 0 -16px;
  padding: 20px;
}
Empty Space
.add {
  background:
    sprite-image("icons/pl.png");
}
.remove {
  background: yellow no-repeat
    sprite-image("icons/rm.png",
       0, 0, 20px);
  padding: 20px; }
Just Perfect
.add {
  background:
    url("icons.png");
}
.remove {             Example link
  background:
    url("icons.png") 0 -36px;
  padding: 20px;
}
Sprite Generation
★   Sprite image named by directory:
    “icons/*.png” > “icons.png”

★   Background position added only if needed

★   Add “no-repeat” by yourself:
    background:
      sprite-image("…") no-repeat;
Any questions?
Happy forking:
http://github.com/flyerhzm/css_sprite
http://github.com/hagenburger/lemonade
last name
first name


             nico@hagenburger.net
    e-mail
              twitter
                        blog
1 of 37

Recommended

3 Steps to Make Better & Faster Frontends by
3 Steps to Make Better & Faster Frontends3 Steps to Make Better & Faster Frontends
3 Steps to Make Better & Faster FrontendsNico Hagenburger
4K views37 slides
Big Frontends Made Simple by
Big Frontends Made SimpleBig Frontends Made Simple
Big Frontends Made SimpleNico Hagenburger
3.3K views51 slides
Rapid Prototyping FTW!!! by
Rapid Prototyping FTW!!!Rapid Prototyping FTW!!!
Rapid Prototyping FTW!!!cloudbring
991 views63 slides
Revolver by
RevolverRevolver
RevolverMichelle Lim
106 views11 slides
CSS Preprocessors: LESS is more or look SASS-y trying by
CSS Preprocessors: LESS is more or look SASS-y tryingCSS Preprocessors: LESS is more or look SASS-y trying
CSS Preprocessors: LESS is more or look SASS-y tryingJames Cryer
1.9K views19 slides
Scaling Rails Sites by default by
Scaling Rails Sites by defaultScaling Rails Sites by default
Scaling Rails Sites by defaultYi-Ting Cheng
1K views46 slides

More Related Content

What's hot

Write LESS. DO more. by
Write LESS. DO more.Write LESS. DO more.
Write LESS. DO more.Eugene Nor
658 views30 slides
Variations on a Theme by
Variations on a ThemeVariations on a Theme
Variations on a ThemeCommercial Progression
1.2K views54 slides
CSS Grid Layout by
CSS Grid LayoutCSS Grid Layout
CSS Grid LayoutRachel Andrew
128.2K views120 slides
Big Design Conference: CSS3 by
Big Design Conference: CSS3 Big Design Conference: CSS3
Big Design Conference: CSS3 Wynn Netherland
1.7K views141 slides
Traceur - Javascript.next - Now! RheinmainJS April 14th by
Traceur - Javascript.next - Now! RheinmainJS April 14thTraceur - Javascript.next - Now! RheinmainJS April 14th
Traceur - Javascript.next - Now! RheinmainJS April 14thCarsten Sandtner
2.1K views21 slides
Intro to CouchDB by
Intro to CouchDBIntro to CouchDB
Intro to CouchDBbenaldred
591 views38 slides

What's hot(20)

Write LESS. DO more. by Eugene Nor
Write LESS. DO more.Write LESS. DO more.
Write LESS. DO more.
Eugene Nor658 views
CSS Grid Layout by Rachel Andrew
CSS Grid LayoutCSS Grid Layout
CSS Grid Layout
Rachel Andrew128.2K views
Big Design Conference: CSS3 by Wynn Netherland
Big Design Conference: CSS3 Big Design Conference: CSS3
Big Design Conference: CSS3
Wynn Netherland1.7K views
Traceur - Javascript.next - Now! RheinmainJS April 14th by Carsten Sandtner
Traceur - Javascript.next - Now! RheinmainJS April 14thTraceur - Javascript.next - Now! RheinmainJS April 14th
Traceur - Javascript.next - Now! RheinmainJS April 14th
Carsten Sandtner2.1K views
Intro to CouchDB by benaldred
Intro to CouchDBIntro to CouchDB
Intro to CouchDB
benaldred591 views
Accelerated Native Mobile Development with the Ti gem by Wynn Netherland
Accelerated Native Mobile Development with the Ti gemAccelerated Native Mobile Development with the Ti gem
Accelerated Native Mobile Development with the Ti gem
Wynn Netherland954 views
LESS by Joe Seifi
LESSLESS
LESS
Joe Seifi13.4K views
Capybara by Mona Soni
CapybaraCapybara
Capybara
Mona Soni1.9K views
Introducing grunt, npm and sass by priyanka1452
Introducing grunt, npm and sassIntroducing grunt, npm and sass
Introducing grunt, npm and sass
priyanka1452274 views
Obscure Wordpress Functions That Are Actually Quite Useful by Graham Armfield
Obscure Wordpress Functions That Are Actually Quite UsefulObscure Wordpress Functions That Are Actually Quite Useful
Obscure Wordpress Functions That Are Actually Quite Useful
Graham Armfield801 views
Perch, Patterns and Old Browsers by Rachel Andrew
Perch, Patterns and Old BrowsersPerch, Patterns and Old Browsers
Perch, Patterns and Old Browsers
Rachel Andrew1.8K views
LESS(CSS preprocessor) by VIPIN KUMAR
LESS(CSS preprocessor)LESS(CSS preprocessor)
LESS(CSS preprocessor)
VIPIN KUMAR696 views
Getting Started with Sass & Compass by Rob Davarnia
Getting Started with Sass & CompassGetting Started with Sass & Compass
Getting Started with Sass & Compass
Rob Davarnia1.8K views
Confoo: You can use CSS for that! by Rachel Andrew
Confoo: You can use CSS for that!Confoo: You can use CSS for that!
Confoo: You can use CSS for that!
Rachel Andrew1.5K views
Sass, Compass and the new tools - Open Web Camp IV by Dirk Ginader
Sass, Compass and the new tools - Open Web Camp IVSass, Compass and the new tools - Open Web Camp IV
Sass, Compass and the new tools - Open Web Camp IV
Dirk Ginader3.1K views
Locarise,reagent and JavaScript Libraries by Ikuru Kanuma
Locarise,reagent and JavaScript LibrariesLocarise,reagent and JavaScript Libraries
Locarise,reagent and JavaScript Libraries
Ikuru Kanuma479 views
Brian Hoke: WordCamp Toronto 2014 Presentation "Sass & WordPress" by bentleyhoke
Brian Hoke: WordCamp Toronto 2014 Presentation "Sass & WordPress"Brian Hoke: WordCamp Toronto 2014 Presentation "Sass & WordPress"
Brian Hoke: WordCamp Toronto 2014 Presentation "Sass & WordPress"
bentleyhoke604 views
Distributed caching for your next node.js project cf summit - 06-15-2017 by Viktor Gamov
Distributed caching for your next node.js project   cf summit - 06-15-2017Distributed caching for your next node.js project   cf summit - 06-15-2017
Distributed caching for your next node.js project cf summit - 06-15-2017
Viktor Gamov295 views

Similar to 3 ways-to-create-sprites-in-rails

Css sprite best practices by
Css sprite best practicesCss sprite best practices
Css sprite best practicesRichard Huang
3.1K views17 slides
Css sprite_maker-1 by
Css  sprite_maker-1Css  sprite_maker-1
Css sprite_maker-1lokku
1.9K views26 slides
Adobe MAX 2008: HTML/CSS + Fireworks by
Adobe MAX 2008: HTML/CSS + FireworksAdobe MAX 2008: HTML/CSS + Fireworks
Adobe MAX 2008: HTML/CSS + FireworksNathan Smith
2K views63 slides
High Performance Webdesign by
High Performance WebdesignHigh Performance Webdesign
High Performance Webdesign拓樹 谷
3.9K views120 slides
Make Your Animations Perform Well - JS Conf Budapest 2017 by
Make Your Animations Perform Well - JS Conf Budapest 2017 Make Your Animations Perform Well - JS Conf Budapest 2017
Make Your Animations Perform Well - JS Conf Budapest 2017 Anna Migas
736 views86 slides
Death of a Themer by
Death of a ThemerDeath of a Themer
Death of a ThemerJames Panton
4.3K views90 slides

Similar to 3 ways-to-create-sprites-in-rails(20)

Css sprite best practices by Richard Huang
Css sprite best practicesCss sprite best practices
Css sprite best practices
Richard Huang3.1K views
Css sprite_maker-1 by lokku
Css  sprite_maker-1Css  sprite_maker-1
Css sprite_maker-1
lokku1.9K views
Adobe MAX 2008: HTML/CSS + Fireworks by Nathan Smith
Adobe MAX 2008: HTML/CSS + FireworksAdobe MAX 2008: HTML/CSS + Fireworks
Adobe MAX 2008: HTML/CSS + Fireworks
Nathan Smith2K views
High Performance Webdesign by 拓樹 谷
High Performance WebdesignHigh Performance Webdesign
High Performance Webdesign
拓樹 谷3.9K views
Make Your Animations Perform Well - JS Conf Budapest 2017 by Anna Migas
Make Your Animations Perform Well - JS Conf Budapest 2017 Make Your Animations Perform Well - JS Conf Budapest 2017
Make Your Animations Perform Well - JS Conf Budapest 2017
Anna Migas736 views
Death of a Themer by James Panton
Death of a ThemerDeath of a Themer
Death of a Themer
James Panton4.3K views
Progressive Downloads and Rendering by Stoyan Stefanov
Progressive Downloads and RenderingProgressive Downloads and Rendering
Progressive Downloads and Rendering
Stoyan Stefanov6K views
Make your animations perform well - Anna Migas - Codemotion Rome 2017 by Codemotion
Make your animations perform well - Anna Migas - Codemotion Rome 2017Make your animations perform well - Anna Migas - Codemotion Rome 2017
Make your animations perform well - Anna Migas - Codemotion Rome 2017
Codemotion740 views
Font End Development + Automation with Django by Evan Reiser
Font End Development + Automation with DjangoFont End Development + Automation with Django
Font End Development + Automation with Django
Evan Reiser1.9K views
Even faster web sites by Felipe Lavín
Even faster web sitesEven faster web sites
Even faster web sites
Felipe Lavín1.2K views
create-netflix-clone-06-client-ui_transcript.pdf by ShaiAlmog1
create-netflix-clone-06-client-ui_transcript.pdfcreate-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdf
ShaiAlmog1239 views
Make your animations perform well by Anna Migas
Make your animations perform wellMake your animations perform well
Make your animations perform well
Anna Migas131 views
CreateJSの概要 + Animate CC 2018の新機能 by Yasunobu Ikeda
CreateJSの概要 + Animate CC 2018の新機能CreateJSの概要 + Animate CC 2018の新機能
CreateJSの概要 + Animate CC 2018の新機能
Yasunobu Ikeda1.9K views
分层语义化模板实践 ---- 张克军 by 裕波 周
分层语义化模板实践 ---- 张克军分层语义化模板实践 ---- 张克军
分层语义化模板实践 ---- 张克军
裕波 周1.1K views
Keeping the frontend under control with Symfony and Webpack by Ignacio Martín
Keeping the frontend under control with Symfony and WebpackKeeping the frontend under control with Symfony and Webpack
Keeping the frontend under control with Symfony and Webpack
Ignacio Martín6.4K views
Progressive downloads and rendering (Stoyan Stefanov) by Ontico
Progressive downloads and rendering (Stoyan Stefanov)Progressive downloads and rendering (Stoyan Stefanov)
Progressive downloads and rendering (Stoyan Stefanov)
Ontico1.4K views

Recently uploaded

Serverless computing with Google Cloud (2023-24) by
Serverless computing with Google Cloud (2023-24)Serverless computing with Google Cloud (2023-24)
Serverless computing with Google Cloud (2023-24)wesley chun
11 views33 slides
HTTP headers that make your website go faster - devs.gent November 2023 by
HTTP headers that make your website go faster - devs.gent November 2023HTTP headers that make your website go faster - devs.gent November 2023
HTTP headers that make your website go faster - devs.gent November 2023Thijs Feryn
22 views151 slides
Future of Indian ConsumerTech by
Future of Indian ConsumerTechFuture of Indian ConsumerTech
Future of Indian ConsumerTechKapil Khandelwal (KK)
22 views68 slides
Ransomware is Knocking your Door_Final.pdf by
Ransomware is Knocking your Door_Final.pdfRansomware is Knocking your Door_Final.pdf
Ransomware is Knocking your Door_Final.pdfSecurity Bootcamp
59 views46 slides
Info Session November 2023.pdf by
Info Session November 2023.pdfInfo Session November 2023.pdf
Info Session November 2023.pdfAleksandraKoprivica4
13 views15 slides
Voice Logger - Telephony Integration Solution at Aegis by
Voice Logger - Telephony Integration Solution at AegisVoice Logger - Telephony Integration Solution at Aegis
Voice Logger - Telephony Integration Solution at AegisNirmal Sharma
39 views1 slide

Recently uploaded(20)

Serverless computing with Google Cloud (2023-24) by wesley chun
Serverless computing with Google Cloud (2023-24)Serverless computing with Google Cloud (2023-24)
Serverless computing with Google Cloud (2023-24)
wesley chun11 views
HTTP headers that make your website go faster - devs.gent November 2023 by Thijs Feryn
HTTP headers that make your website go faster - devs.gent November 2023HTTP headers that make your website go faster - devs.gent November 2023
HTTP headers that make your website go faster - devs.gent November 2023
Thijs Feryn22 views
Voice Logger - Telephony Integration Solution at Aegis by Nirmal Sharma
Voice Logger - Telephony Integration Solution at AegisVoice Logger - Telephony Integration Solution at Aegis
Voice Logger - Telephony Integration Solution at Aegis
Nirmal Sharma39 views
Future of AR - Facebook Presentation by ssuserb54b561
Future of AR - Facebook PresentationFuture of AR - Facebook Presentation
Future of AR - Facebook Presentation
ssuserb54b56115 views
PharoJS - Zürich Smalltalk Group Meetup November 2023 by Noury Bouraqadi
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023
Noury Bouraqadi132 views
"Running students' code in isolation. The hard way", Yurii Holiuk by Fwdays
"Running students' code in isolation. The hard way", Yurii Holiuk "Running students' code in isolation. The hard way", Yurii Holiuk
"Running students' code in isolation. The hard way", Yurii Holiuk
Fwdays17 views
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f... by TrustArc
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc11 views
6g - REPORT.pdf by Liveplex
6g - REPORT.pdf6g - REPORT.pdf
6g - REPORT.pdf
Liveplex10 views
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院 by IttrainingIttraining
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
Piloting & Scaling Successfully With Microsoft Viva by Richard Harbridge
Piloting & Scaling Successfully With Microsoft VivaPiloting & Scaling Successfully With Microsoft Viva
Piloting & Scaling Successfully With Microsoft Viva
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... by Bernd Ruecker
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
Bernd Ruecker40 views
Igniting Next Level Productivity with AI-Infused Data Integration Workflows by Safe Software
Igniting Next Level Productivity with AI-Infused Data Integration Workflows Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Safe Software280 views

3 ways-to-create-sprites-in-rails

  • 1. 3 Ways to Create CSS Sprites With Rails
  • 3. A great way to save HTTP requests.
  • 4. In other words: Something that makes your website faster. awes om e!
  • 6. Rails 3.1 > Integrated Spriting CSS_Sprite > better <img> Lemonade > Full CSS sprites
  • 7. Finding Information http://www.drdobbs.com/blog/archives/2010/06/preparing_for_r.html
  • 9. A Piece of Code http://twitter.com/jsiarto/status/15861245321
  • 10. Finally! http://www.rubyinside.com/dhhs-railsconf-2010-keynote-video-a-justification-of-rails-3-0-3325.html
  • 11. Generation Sprites <%= sprite_css("icons") %> ★ Combines all images of a folder ★ Generates CSS
  • 12. Using Images <%= sprite_tag("icons/trash") %> ★ Adds a HTML tag with the class (I guess it works this way.)
  • 13. Questions ★ Is it possible to pack CSS files? ★ Why “icons/trash” if image_tag requires “icons/trash.png”? ★ When will it be available?
  • 14. Rails 3.1 > Integrated Spriting CSS_Sprite > better <img> Lemonade > Full CSS sprites
  • 16. Features ★ Creates sprite images ★ Creates classes for each file ★ Sass compatible ★ Rake Task for generation
  • 17. From Image to CCS images under css_sprite directory class name in css_sprite css twitter_icon.png .twitter_icon facebook_icon.png .facebook_icon hotmail-logo.png .hotmail-logo gmail-logo.png .gmail-logo icons/twitter_icon.png .icons .twitter_icon widget/icons/twitter_icon.png .widget .icons .twitter_icon twitter_icon_hover.png .twitter_icon:hover twitter-icon-hover.png .twitter-icon:hover logos_hover/gmail_logo.png .logos:hover .gmail_logo logos-hover/gmail-logo.png .logos:hover .gmail-logo … … full table at http://github.com/flyerhzm/css_sprite
  • 18. Built Sprites (1) rake css_sprite:build
  • 19. Built Sprites (2) rake css_sprite:start
  • 20. Pros ★ Easy for HTML developers ★ Easy if you’re handling <img> tag
  • 21. Cons ★ A lot of CSS generated (sizes, …) ★ Additional non-semantic tags ★ Additional classes ★ Positioned background images difficult ★ RMagick ★ Rake task
  • 22. Alternatives ★ http://github.com/gistinc/sprite based on css_sprite ★ http://github.com/sblackstone/auto_sprite image_tag extention + CSS classes ★ http://github.com/setepo/css-sprites image_tag extention + inline CSS
  • 23. Rails 3.1 > Integrated Spriting CSS_Sprite > better <img> Lemonade > Easy Sprites
  • 26. Simple Sprites .add { background: sprite-image("icons/pl.png"); } .remove { background: sprite-image("icons/rm.png"); } all icons by p.yusukekamiyamane.com (CC by 3.0)
  • 27. Output .add { background: url("icons.png"); } .remove { background: url("icons.png") 0 -16px; }
  • 28. Right Aligned .something { background: sprite-image("i/wide.png"); } a.next { background: yellow no-repeat sprite-image("i/n.png", 100%); padding-right: 20px; }
  • 29. Result .something { background: url("i.png"); } Example link a.next { background: yellow no-repeat url("i.png") 100% -20px; padding-right: 20px; }
  • 30. Empty Space .add { background: sprite-image("icons/pl.png"); } .remove { background: yellow no-repeat sprite-image("icons/rm.png"); padding: 20px; }
  • 31. Could be Better .add { background: url("icons.png"); } .remove { Example link background: url("icons.png") 0 -16px; padding: 20px; }
  • 32. Empty Space .add { background: sprite-image("icons/pl.png"); } .remove { background: yellow no-repeat sprite-image("icons/rm.png", 0, 0, 20px); padding: 20px; }
  • 33. Just Perfect .add { background: url("icons.png"); } .remove { Example link background: url("icons.png") 0 -36px; padding: 20px; }
  • 34. Sprite Generation ★ Sprite image named by directory: “icons/*.png” > “icons.png” ★ Background position added only if needed ★ Add “no-repeat” by yourself: background: sprite-image("…") no-repeat;
  • 37. last name first name nico@hagenburger.net e-mail twitter blog