picturesque 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b8a5c98f1b75feb62c9031b691cd99d8e2171677
4
- data.tar.gz: c9b08b1c89bf406181c2e3e6d7f42a433a9dbd23
3
+ metadata.gz: f6ac8ab4b77bc4dfe83044ae0d1456f74eb963f9
4
+ data.tar.gz: 2bfeb9fd9b87a69548fbf28144afbc42b8bd594d
5
5
  SHA512:
6
- metadata.gz: 8a43dd0921bb16f07cd06c0492403f2af7fad87f817b27ab787b63626b75c76f9feb308cfd1cb5618660e76b4993632b89a7a31203d7fe93dafbd3baef8abb22
7
- data.tar.gz: 7217bf12941fe331a9090c6d4590c50d55b5f918d54d4904bdc5410e7304646f4778654f0d90590a57a9de176cb71fa74468c71bfa4bc4471efa5dfb91132937
6
+ metadata.gz: 3ee9c793467b1c0ae2796946ceeebb440f5b165ec19a6a992e25e0afc745343fa23a391071b47afaeb57aded8949e66726838a066ae9774afe86da1928d3a7aa
7
+ data.tar.gz: 03bd57d27dc7ab6dd37f5a5c0493077558811a4b28bb3b20adf6f5cb99a9b4d22624f2b812f0ffe55faba02fbfcc02aa7ab075f21c8983839c1168fd0e4f5294
data/README.rdoc CHANGED
@@ -1,14 +1,22 @@
1
1
  = Picturesque
2
2
 
3
- Picturesque is an engine for resizing and formatting images on the fly.
3
+ Picturesque is an engine for resizing and formatting images on the fly. It makes generating responsive images a snap:
4
+
5
+ <%= picturesque_image_tag(image, slug: image.slug, alt: image.name, size: '160x160') %>
6
+
7
+ <img alt="Steve Jobs and Bill Gates" height=160 width=160
8
+ src="https://.../picturesque/1/160x160/steve-jobs-and-bill-gates.jpg"
9
+ srcset="https://.../picturesque/1/160x160/steve-jobs-and-bill-gates.jpg 1x,
10
+ https://.../picturesque/1/320x320/steve-jobs-and-bill-gates.jpg 2x,
11
+ https://.../picturesque/1/480x480/steve-jobs-and-bill-gates.jpg 3x" />
4
12
 
5
13
  == Requirements
6
14
 
7
15
  The gem is tested with:
8
16
 
9
- * Ruby on Rails 4.2.3
10
- * Ruby 2.2.2
11
- * JRuby 9.0.0.0
17
+ * Ruby on Rails 4.2.5.1
18
+ * Ruby 2.3.0
19
+ * JRuby 9.0.4.0
12
20
 
13
21
  == Installation
14
22
 
@@ -22,39 +30,45 @@ The gem is tested with:
22
30
 
23
31
  # config/initializers/picturesque.rb
24
32
  Picturesque.setup do |config|
25
- config.url -> (id) { Photo.find(id).url }
33
+ config.find = -> (params) { Picturesque::Image.new(Image.find(params[:id]).url) }
26
34
  end
27
35
 
28
36
  == Examples
29
37
 
30
- Migration:
38
+ === Migration
31
39
 
32
- rails g model photo url:string
40
+ rails g model image url:string name:string
33
41
 
34
- class CreatePhoto < ActiveRecord::Migration
42
+ class CreateImage < ActiveRecord::Migration
35
43
  def self.up
36
- create_table :videos do |t|
37
- t.string :url
44
+ create_table :images do |t|
45
+ t.string :url, presence: true, index: { unique: true }
46
+ t.string :name, presence: true, index: { unique: true }
38
47
 
39
48
  t.timestamps
40
49
  end
41
50
  end
42
51
 
43
52
  def self.down
44
- drop_table :videos
53
+ drop_table :images
45
54
  end
46
55
  end
47
56
 
48
- Model:
57
+ === Model
49
58
 
50
- class Photo < ActiveRecord::Base
51
- validates_presence_of :url
59
+ class Image < ActiveRecord::Base
60
+ validates :name, presence: true, uniqueness: true
61
+ validates :url, presence: true, uniqueness: true
62
+
63
+ def slug
64
+ name.parameterize if name
65
+ end
52
66
  end
53
67
 
54
- View:
68
+ === View
55
69
 
56
- <%- @photos.each do |photo| -%>
57
- <%= image_tag(picturesque_image_url(photo, size: '64x64'), size: '64x64') %>
70
+ <%- @images.each do |image| -%>
71
+ <%= picturesque_image_tag(image, slug: image.slug, alt: image.name, size: '160x160') %>
58
72
  <%- end -%>
59
73
 
60
74
  == Status
@@ -66,4 +80,4 @@ View:
66
80
 
67
81
  == Copyright
68
82
 
69
- Copyright (c) 2014 - 2015 Kevin Sylvestre. See LICENSE for details.
83
+ Copyright (c) 2014 - 2016 Kevin Sylvestre. See LICENSE for details.
@@ -3,11 +3,14 @@ require_dependency "picturesque/application_controller"
3
3
  module Picturesque
4
4
  class ImagesController < ApplicationController
5
5
 
6
- # GET /:id/(:size)/(:quality)/(*slug).(:format)
6
+ # GET /:id/(:size)(/:quality)(/:slug).(:format)
7
7
  def show
8
- @image = Picturesque::Image.find(params[:id])
8
+ @image = Picturesque::Image.find(params)
9
9
  @file = @image.process(size: params[:size], quality: params[:quality], format: params[:format])
10
10
 
11
+ canonical = picturesque.image_url(id: params[:id], slug: params[:slug])
12
+ response.header['Link'] = "<#{canonical}>; rel=\"canonical\""
13
+
11
14
  expires_in 3.years, public: @file
12
15
  send_file @file.path, disposition: Picturesque::Image::DISPOSITION
13
16
  end
@@ -1,4 +1,14 @@
1
1
  module Picturesque
2
2
  module ApplicationHelper
3
+
4
+ def picturesque_image_tag(image, size:, slug:, alt:, scales: (1..3))
5
+ matches = size.match(/(?<w>\d+)\D(?<h>\d+)/)
6
+ w , h = Integer(matches[:w]) , Integer(matches[:h])
7
+
8
+ image_tag picturesque.image_url(image, size: "#{w}x#{h}", slug: image.slug),
9
+ srcset: scales.map { |s| "#{picturesque.image_url(image, size: "#{w * s}x#{h * s}", slug: slug)} #{s}x" }.join(','),
10
+ size: "#{w}×#{h}", alt: alt
11
+ end
12
+
3
13
  end
4
14
  end
@@ -12,7 +12,6 @@ module Picturesque
12
12
 
13
13
  module Quality
14
14
  HIGH = 90.freeze
15
- WEAK = 10.freeze
16
15
  end
17
16
 
18
17
  attr_accessor :url
@@ -36,8 +35,8 @@ module Picturesque
36
35
  end
37
36
  end
38
37
 
39
- def self.find(id)
40
- new(Picturesque.config.url.call(id))
38
+ def self.find(params)
39
+ Picturesque.config.find.call(params)
41
40
  end
42
41
 
43
42
  end
data/config/routes.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  Picturesque::Engine.routes.draw do
2
2
 
3
- get ':id(/:size)(/:quality)(/*slug)(.:format)', to: 'images#show', as: :image, constraints: {
3
+ get ':id(/:size)(/:quality)(/:slug).:format', to: 'images#show', as: :image, constraints: {
4
4
  size: /\d+x\d+/,
5
5
  quality: /\d{2}/,
6
6
  format: /(bmp|bpg|gif|jpg|jpe|jpeg|png|webp)/
@@ -2,7 +2,7 @@ class CreatePicturesqueImages < ActiveRecord::Migration
2
2
  def change
3
3
  create_table :picturesque_images do |t|
4
4
 
5
- t.timestamps
5
+ t.timestamps null: false
6
6
  end
7
7
  end
8
8
  end
@@ -1,5 +1,5 @@
1
1
  module Picturesque
2
2
  class Config
3
- attr_accessor :url
3
+ attr_accessor :find
4
4
  end
5
5
  end
@@ -1,3 +1,3 @@
1
1
  module Picturesque
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: picturesque
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-15 00:00:00.000000000 Z
11
+ date: 2016-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -152,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
152
  version: '0'
153
153
  requirements: []
154
154
  rubyforge_project:
155
- rubygems_version: 2.4.5
155
+ rubygems_version: 2.5.1
156
156
  signing_key:
157
157
  specification_version: 4
158
158
  summary: Picturesque makes image resizing simple