Giter VIP home page Giter VIP logo

picture_tag's Introduction

PictureTag

Build Status Gem Version Coverage Status

Rails helper for <picture> tag integrated with Picturefill.

Installation

Add this to your application's Gemfile:

  gem 'picture_tag'

And then execute:

$ bundle

Or install it yourself as:

$ gem install picture_tag

In case you would like to add a picture polyfill:

  source 'https://rails-assets.org' do
    gem 'rails-assets-picturefill'
  end

And add to your application.js:

//= require picture_tag

Usage

= picture_tag '/images/fallback.jpg', image: { alt: 'Your smart alt attribute' } do
  = source_tag srcset: '/images/large.jpg', media: '(min-width: 2000px)', sizes: '100vw'
  = source_tag srcset: '/images/large_retina.jpg 2x', media: '(min-width: 2000px)', sizes: '100vw'
  = source_tag srcset: '/images/medium.jpg', media: '(min-width: 1000px)', sizes: '100vw'
  = source_tag srcset: '/images/medium_retina.jpg 2x', media: '(min-width: 1000px)', sizes: '100vw'
  = source_tag srcset: '/images/small.jpg', sizes: '100vw'
  = source_tag srcset: '/images/small_retina.jpg 2x', sizes: '100vw'

produces

<picture>
  <source srcset="/images/large.jpg" media="(min-width: 2000px)" sizes="100vw">
  <source srcset="/images/large_retina.jpg 2x" media="(min-width: 2000px)" sizes="100vw">
  <source srcset="/images/medium.jpg" media="(min-width: 1000px)" sizes="100vw" >
  <source srcset="/images/medium_retina.jpg 2x" media="(min-width: 1000px)" sizes="100vw" >
  <source srcset="/images/small.jpg" sizes="100vw">
  <source srcset="/images/small_retina.jpg 2x" sizes="100vw">
  <img alt="Your smart alt attribute" srcset="/images/fallback.jpg">
</picture>

Note that the mandatory img tag is automatically generated based on the arguments passed to the picture_tag.

More information

Contributing

  1. Fork it ( https://github.com/tomasc/picture_tag/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

picture_tag's People

Contributors

mschiller avatar tomasc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

picture_tag's Issues

cannot load such file -- rails-assets-picturefill (LoadError)

Hello,
picture_tag.rb requires rails-assets-picturefill, and in my case it will fail if I do not add this to the gemfile:

source 'https://rails-assets.org' do
  gem 'rails-assets-picturefill'
end

So I guess the docs should mention it in the installation chapter ?

Thanks for sharing your efforts!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.