Module: LibPixel::ViewHelpers
- Defined in:
- lib/libpixel/view_helpers.rb
Instance Method Summary collapse
-
#libpixel_image_tag(source, options = {}) ⇒ Object
libpixel_image_tag(“”, :width=>200, :libpixel=>:dpr=>2, :source=>“images”) => <img width=“200” alt=“image” src=“” />.
Instance Method Details
#libpixel_image_tag(source, options = {}) ⇒ Object
libpixel_image_tag(“”, :width=>200, :libpixel=>:dpr=>2, :source=>“images”)
> <img width=“200” alt=“image” src=“” />
LibPixel.default_source = “source” libpixel_image_tag(“image.jpg”, :libpixel=>:width=>200)
> <img alt=“image” src=“example.libpx.com/source/image.jpg?width=200” />
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/libpixel/view_helpers.rb', line 11 def libpixel_image_tag(source, = {}) = nil if source.respond_to? :fetch libpixel_url = LibPixel.url(source[:libpixel]) = source.reject {|k| k == :libpixel} else source = URI::escape(source) libpixel_url = LibPixel.url(source, .fetch(:libpixel) {{}}) = .reject {|k| k == :libpixel} end uri = URI(libpixel_url) if uri.query query_items = CGI.parse(uri.query) src = query_items["src"].first if src [:alt] = .fetch(:alt) {image_alt(src)} end end image_tag(libpixel_url.html_safe, ) end |