picturesque 1.0.1 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Rakefile +1 -4
- data/app/controllers/picturesque/application_controller.rb +1 -0
- data/app/controllers/picturesque/images_controller.rb +10 -4
- data/app/helpers/picturesque/application_helper.rb +21 -5
- data/app/models/picturesque/image.rb +19 -17
- data/config/routes.rb +2 -2
- data/lib/picturesque.rb +5 -5
- data/lib/picturesque/version.rb +1 -1
- metadata +6 -24
- data/README.rdoc +0 -83
- data/db/migrate/20141218101647_create_picturesque_images.rb +0 -8
- data/lib/tasks/picturesque_tasks.rake +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fb3490f8acb885a84f2bd888720038a49656cccd4340f88f4462d0b410b709b9
|
4
|
+
data.tar.gz: 504c1bc66d830b6705d921e39483751cb50d6d732f2db0b984d7b9f9ca8b951e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b9f1612f2484eaa14054808248c8876f762aa88319cda265c92f01b23bea7cfc77923903f5b46fafab180a265ef0c681a2ab4ad7761f0d84fa81f248bfe7d56
|
7
|
+
data.tar.gz: 2abafc716e2cc484222ec2cb48ec9bf330e0ec3c67f734ddeb642e9cab6ad0fcb24b9cfb4cb62334b1aeb02db259ad128a8781f789486734c075a3efaf378578
|
data/Rakefile
CHANGED
@@ -14,11 +14,9 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
14
14
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
15
|
end
|
16
16
|
|
17
|
-
APP_RAKEFILE = File.expand_path(
|
17
|
+
APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
|
18
18
|
load 'rails/tasks/engine.rake'
|
19
19
|
|
20
|
-
|
21
|
-
|
22
20
|
Bundler::GemHelper.install_tasks
|
23
21
|
|
24
22
|
require 'rake/testtask'
|
@@ -30,5 +28,4 @@ Rake::TestTask.new(:test) do |t|
|
|
30
28
|
t.verbose = false
|
31
29
|
end
|
32
30
|
|
33
|
-
|
34
31
|
task default: :test
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require_dependency
|
1
|
+
require_dependency 'picturesque/application_controller'
|
2
2
|
|
3
3
|
module Picturesque
|
4
4
|
class ImagesController < ApplicationController
|
@@ -6,14 +6,20 @@ module Picturesque
|
|
6
6
|
# GET /:id/(:size)(/:quality)(/:slug).(:format)
|
7
7
|
def show
|
8
8
|
@image = Picturesque::Image.find(params)
|
9
|
-
@file = @image.process(
|
9
|
+
@file = @image.process(params.slice(:size, :quality, :format))
|
10
10
|
|
11
|
-
|
12
|
-
response.header['Link'] = "<#{canonical}>; rel=\"canonical\""
|
11
|
+
setup_canonical_link
|
13
12
|
|
14
13
|
expires_in 3.years, public: @file
|
15
14
|
send_file @file.path, disposition: Picturesque::Image::DISPOSITION
|
16
15
|
end
|
17
16
|
|
17
|
+
private
|
18
|
+
|
19
|
+
def setup_canonical_link
|
20
|
+
canonical = picturesque.image_url(params.slice(:id, :slug))
|
21
|
+
response.header['Link'] = %(<#{canonical}>; rel="canonical")
|
22
|
+
end
|
23
|
+
|
18
24
|
end
|
19
25
|
end
|
@@ -2,13 +2,29 @@ module Picturesque
|
|
2
2
|
module ApplicationHelper
|
3
3
|
|
4
4
|
def picturesque_image_tag(image, size:, slug:, alt:, scales: (1..3))
|
5
|
-
matches = size.match(/(?<
|
6
|
-
|
5
|
+
matches = size.match(/(?<width>\d+)\D(?<height>\d+)/)
|
6
|
+
width = Integer(matches[:width])
|
7
|
+
height = Integer(matches[:height])
|
7
8
|
|
8
|
-
image_tag
|
9
|
-
|
10
|
-
|
9
|
+
image_tag(
|
10
|
+
picturesque_src(image, width: width, height: height, slug: slug),
|
11
|
+
srcset: picturesque_srcset(image, scales: scales, width: width, height: height, slug: slug),
|
12
|
+
size: "#{width}×#{height}", alt: alt
|
13
|
+
)
|
11
14
|
end
|
12
15
|
|
16
|
+
def picturesque_srcset(image, scales:, width:, height:, slug:)
|
17
|
+
picturesque_srcs(image, scales: scales, width: width, height: height, slug: slug).join(',')
|
18
|
+
end
|
19
|
+
|
20
|
+
def picturesque_srcs(image, scales:, width:, height:, slug:)
|
21
|
+
scales.map do |scale|
|
22
|
+
"#{picturesque_src(image, width: width * scale, height: height * scale, slug: slug)} #{scale}x"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def picturesque_src(image, width:, height:, slug:)
|
27
|
+
picturesque.image_url(image, size: "#{width}×#{height}", slug: slug)
|
28
|
+
end
|
13
29
|
end
|
14
30
|
end
|
@@ -2,41 +2,43 @@ module Picturesque
|
|
2
2
|
class Image
|
3
3
|
include ActiveModel::Model
|
4
4
|
|
5
|
-
DISPOSITION =
|
5
|
+
DISPOSITION = 'inline'.freeze
|
6
6
|
|
7
7
|
module Format
|
8
|
-
JPG =
|
9
|
-
PNG =
|
10
|
-
GIF =
|
8
|
+
JPG = 'jpg'.freeze
|
9
|
+
PNG = 'png'.freeze
|
10
|
+
GIF = 'gif'.freeze
|
11
11
|
end
|
12
12
|
|
13
13
|
module Quality
|
14
|
-
HIGH = 90
|
14
|
+
HIGH = 90
|
15
15
|
end
|
16
16
|
|
17
17
|
attr_accessor :url
|
18
18
|
|
19
|
+
def self.find(params)
|
20
|
+
Picturesque.config.find.call(params)
|
21
|
+
end
|
22
|
+
|
19
23
|
def initialize(url)
|
20
24
|
self.url = url
|
21
25
|
end
|
22
26
|
|
23
27
|
def process(size: nil, quality: nil, format: nil)
|
24
|
-
MiniMagick::Image.open(
|
28
|
+
MiniMagick::Image.open(url).format(format || Format::JPG) do |file|
|
25
29
|
file.quality(quality || Quality::HIGH)
|
26
|
-
|
27
|
-
if size
|
28
|
-
w,h = size.split("x")
|
29
|
-
if w && Integer(w) > 0 && h && Integer(h) > 0
|
30
|
-
file.resize("#{w}x#{h}^")
|
31
|
-
file.gravity "center"
|
32
|
-
file.extent "#{w}x#{h}"
|
33
|
-
end
|
34
|
-
end
|
30
|
+
resize(file: file, size: size) if size
|
35
31
|
end
|
36
32
|
end
|
37
33
|
|
38
|
-
|
39
|
-
|
34
|
+
private
|
35
|
+
|
36
|
+
def resize(file:, size:)
|
37
|
+
width, height = size.split('x')
|
38
|
+
return unless width && Integer(width).positive? && height && Integer(height).positive?
|
39
|
+
file.resize("#{width}x#{height}^")
|
40
|
+
file.gravity 'center'
|
41
|
+
file.extent "#{width}x#{height}"
|
40
42
|
end
|
41
43
|
|
42
44
|
end
|
data/config/routes.rb
CHANGED
@@ -3,7 +3,7 @@ Picturesque::Engine.routes.draw do
|
|
3
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
|
-
format: /(bmp|bpg|gif|jpg|jpe|jpeg|png|webp)
|
7
|
-
|
6
|
+
format: /(bmp|bpg|gif|jpg|jpe|jpeg|png|webp)/,
|
7
|
+
}, defaults: { quality: Picturesque::Image::Quality::HIGH, format: Picturesque::Image::Format::JPG }
|
8
8
|
|
9
9
|
end
|
data/lib/picturesque.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
require
|
1
|
+
require 'mini_magick'
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'picturesque/engine'
|
4
|
+
require 'picturesque/config'
|
5
5
|
|
6
6
|
module Picturesque
|
7
7
|
|
8
8
|
def self.config
|
9
|
-
|
9
|
+
@config ||= Picturesque::Config.new
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.setup(&block)
|
13
|
-
block.call(
|
13
|
+
block.call(config)
|
14
14
|
end
|
15
15
|
|
16
16
|
end
|
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.3
|
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: 2020-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rspec_junit_formatter
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -67,21 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: sass-rails
|
70
|
+
name: rspec-rails
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
86
72
|
requirements:
|
87
73
|
- - ">="
|
@@ -95,7 +81,7 @@ dependencies:
|
|
95
81
|
- !ruby/object:Gem::Version
|
96
82
|
version: '0'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
84
|
+
name: slim-rails
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
100
86
|
requirements:
|
101
87
|
- - ">="
|
@@ -116,7 +102,6 @@ extensions: []
|
|
116
102
|
extra_rdoc_files: []
|
117
103
|
files:
|
118
104
|
- LICENSE
|
119
|
-
- README.rdoc
|
120
105
|
- Rakefile
|
121
106
|
- app/assets/javascripts/picturesque/application.js
|
122
107
|
- app/assets/stylesheets/picturesque/application.css
|
@@ -126,12 +111,10 @@ files:
|
|
126
111
|
- app/models/picturesque/image.rb
|
127
112
|
- app/views/layouts/picturesque/application.html.erb
|
128
113
|
- config/routes.rb
|
129
|
-
- db/migrate/20141218101647_create_picturesque_images.rb
|
130
114
|
- lib/picturesque.rb
|
131
115
|
- lib/picturesque/config.rb
|
132
116
|
- lib/picturesque/engine.rb
|
133
117
|
- lib/picturesque/version.rb
|
134
|
-
- lib/tasks/picturesque_tasks.rake
|
135
118
|
homepage: https://github.com/ksylvest/picturesque
|
136
119
|
licenses:
|
137
120
|
- MIT
|
@@ -151,8 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
134
|
- !ruby/object:Gem::Version
|
152
135
|
version: '0'
|
153
136
|
requirements: []
|
154
|
-
|
155
|
-
rubygems_version: 2.5.1
|
137
|
+
rubygems_version: 3.1.2
|
156
138
|
signing_key:
|
157
139
|
specification_version: 4
|
158
140
|
summary: Picturesque makes image resizing simple
|
data/README.rdoc
DELETED
@@ -1,83 +0,0 @@
|
|
1
|
-
= Picturesque
|
2
|
-
|
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" />
|
12
|
-
|
13
|
-
== Requirements
|
14
|
-
|
15
|
-
The gem is tested with:
|
16
|
-
|
17
|
-
* Ruby on Rails 4.2.5.1
|
18
|
-
* Ruby 2.3.0
|
19
|
-
* JRuby 9.0.4.0
|
20
|
-
|
21
|
-
== Installation
|
22
|
-
|
23
|
-
gem install picturesque
|
24
|
-
|
25
|
-
== Additional
|
26
|
-
|
27
|
-
brew install imagemagick
|
28
|
-
|
29
|
-
== Configuration
|
30
|
-
|
31
|
-
# config/initializers/picturesque.rb
|
32
|
-
Picturesque.setup do |config|
|
33
|
-
config.find = -> (params) { Picturesque::Image.new(Image.find(params[:id]).url) }
|
34
|
-
end
|
35
|
-
|
36
|
-
== Examples
|
37
|
-
|
38
|
-
=== Migration
|
39
|
-
|
40
|
-
rails g model image url:string name:string
|
41
|
-
|
42
|
-
class CreateImage < ActiveRecord::Migration
|
43
|
-
def self.up
|
44
|
-
create_table :images do |t|
|
45
|
-
t.string :url, presence: true, index: { unique: true }
|
46
|
-
t.string :name, presence: true, index: { unique: true }
|
47
|
-
|
48
|
-
t.timestamps
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def self.down
|
53
|
-
drop_table :images
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
=== Model
|
58
|
-
|
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
|
66
|
-
end
|
67
|
-
|
68
|
-
=== View
|
69
|
-
|
70
|
-
<%- @images.each do |image| -%>
|
71
|
-
<%= picturesque_image_tag(image, slug: image.slug, alt: image.name, size: '160x160') %>
|
72
|
-
<%- end -%>
|
73
|
-
|
74
|
-
== Status
|
75
|
-
|
76
|
-
{<img src="https://img.shields.io/gemnasium/ksylvest/picturesque.svg" />}[https://gemnasium.com/ksylvest/picturesque]
|
77
|
-
{<img src="https://img.shields.io/travis/ksylvest/picturesque.svg" />}[https://travis-ci.org/ksylvest/picturesque]
|
78
|
-
{<img src="https://img.shields.io/coveralls/ksylvest/picturesque.svg" />}[https://coveralls.io/r/ksylvest/picturesque]
|
79
|
-
{<img src="https://img.shields.io/codeclimate/github/ksylvest/picturesque.svg" />}[https://codeclimate.com/github/ksylvest/picturesque]
|
80
|
-
|
81
|
-
== Copyright
|
82
|
-
|
83
|
-
Copyright (c) 2014 - 2016 Kevin Sylvestre. See LICENSE for details.
|