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 +4 -4
- data/README.rdoc +32 -18
- data/app/controllers/picturesque/images_controller.rb +5 -2
- data/app/helpers/picturesque/application_helper.rb +10 -0
- data/app/models/picturesque/image.rb +2 -3
- data/config/routes.rb +1 -1
- data/db/migrate/20141218101647_create_picturesque_images.rb +1 -1
- data/lib/picturesque/config.rb +1 -1
- data/lib/picturesque/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6ac8ab4b77bc4dfe83044ae0d1456f74eb963f9
|
4
|
+
data.tar.gz: 2bfeb9fd9b87a69548fbf28144afbc42b8bd594d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
10
|
-
* Ruby 2.
|
11
|
-
* JRuby 9.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.
|
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
|
40
|
+
rails g model image url:string name:string
|
33
41
|
|
34
|
-
class
|
42
|
+
class CreateImage < ActiveRecord::Migration
|
35
43
|
def self.up
|
36
|
-
create_table :
|
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 :
|
53
|
+
drop_table :images
|
45
54
|
end
|
46
55
|
end
|
47
56
|
|
48
|
-
Model
|
57
|
+
=== Model
|
49
58
|
|
50
|
-
class
|
51
|
-
|
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
|
-
<%- @
|
57
|
-
<%=
|
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 -
|
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)
|
6
|
+
# GET /:id/(:size)(/:quality)(/:slug).(:format)
|
7
7
|
def show
|
8
|
-
@image = Picturesque::Image.find(params
|
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(
|
40
|
-
|
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)(
|
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)/
|
data/lib/picturesque/config.rb
CHANGED
data/lib/picturesque/version.rb
CHANGED
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.
|
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:
|
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.
|
155
|
+
rubygems_version: 2.5.1
|
156
156
|
signing_key:
|
157
157
|
specification_version: 4
|
158
158
|
summary: Picturesque makes image resizing simple
|