Upgrade to Pro — share decks privately, control downloads, hide ads and more …

SVG Meets CSS Meets Rails

SVG Meets CSS Meets Rails

No clear process to manage image assets in a Ruby on Rails projects? You heard about the benefits of using SVGs but never got the hang of it?

This presentation proposes and explains a workflow to start using SVG images efficiently in web applications. The techniques and workflows can also be applied to non-Ruby based applications.

Presented at Bangkok Ruby Tuesday #7

Olivier Robert

August 28, 2018
Tweet

More Decks by Olivier Robert

Other Decks in Programming

Transcript

  1. Questions • How do you manage UI images for your

    application? • SVG? PNG? JPEG? BITMAP? TIFF? RAW? • How do you name images? • How do you organize images? • Do you even care?
  2. But if you look under the hood... tons of generated

    and unnecessary code. No thank you!
  3. Prepare SVG Images Enforce fixed width / height for all

    icons ⇒ 32px is a good default • 2x default font size (16px) ⇒ Can be anything e.g. 16px, 48px
  4. Prepare SVG Images Enforce default color for all images Black

    is a good default ⇒ It does not matter which color as it will be replaced
  5. Generating an SVG sprite Image: Ruby gem Using the gem

    `svgeez` ⇒ https://github.com/jgarber623/svgeez
  6. Generating an SVG sprite Image: JS Package Using SVGSpritemapPlugin via

    Webpack ⇒ Requires Webpacker in the Rails application
  7. Using the SVG sprite image: Sprite Setup • Insert the

    sprite image a the stop of the body ⇒ Needs to be defined first • Use HTML attribute “hidden” to hide it
  8. Using the SVG sprite image: Inside Views • icon_id matches

    the svg image filename and symbol ID in the sprite image • Add all other attributes to the SVG image
  9. Things to know • Inline SVG allow access to any

    part of the SVG as CSS selectors: ⇒ Great for animation • Sprite image can be used as background image in CSS too • Older version of IE still requires a polyfill: SVG4everybody ⇒ There is a Webpack plugin
  10. Thanks! Contact Nimbl3 [email protected] 399 Sukhumvit Road, Interchange 21 Klongtoey

    nua, Wattana Bangkok 10110 28C Stanley St, Singapore 068737 20th Floor, Central Tower 28 Queen's Road Central, Hong Kong nimbl3.com