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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: f6ac8ab4b77bc4dfe83044ae0d1456f74eb963f9
4
- data.tar.gz: 2bfeb9fd9b87a69548fbf28144afbc42b8bd594d
2
+ SHA256:
3
+ metadata.gz: fb3490f8acb885a84f2bd888720038a49656cccd4340f88f4462d0b410b709b9
4
+ data.tar.gz: 504c1bc66d830b6705d921e39483751cb50d6d732f2db0b984d7b9f9ca8b951e
5
5
  SHA512:
6
- metadata.gz: 3ee9c793467b1c0ae2796946ceeebb440f5b165ec19a6a992e25e0afc745343fa23a391071b47afaeb57aded8949e66726838a066ae9774afe86da1928d3a7aa
7
- data.tar.gz: 03bd57d27dc7ab6dd37f5a5c0493077558811a4b28bb3b20adf6f5cb99a9b4d22624f2b812f0ffe55faba02fbfcc02aa7ab075f21c8983839c1168fd0e4f5294
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("../spec/dummy/Rakefile", __FILE__)
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,5 @@
1
1
  module Picturesque
2
2
  class ApplicationController < ActionController::Base
3
+ protect_from_forgery with: :exception
3
4
  end
4
5
  end
@@ -1,4 +1,4 @@
1
- require_dependency "picturesque/application_controller"
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(size: params[:size], quality: params[:quality], format: params[:format])
9
+ @file = @image.process(params.slice(:size, :quality, :format))
10
10
 
11
- canonical = picturesque.image_url(id: params[:id], slug: params[:slug])
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(/(?<w>\d+)\D(?<h>\d+)/)
6
- w , h = Integer(matches[:w]) , Integer(matches[:h])
5
+ matches = size.match(/(?<width>\d+)\D(?<height>\d+)/)
6
+ width = Integer(matches[:width])
7
+ height = Integer(matches[:height])
7
8
 
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
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 = "inline".freeze
5
+ DISPOSITION = 'inline'.freeze
6
6
 
7
7
  module Format
8
- JPG = "jpg".freeze
9
- PNG = "png".freeze
10
- GIF = "gif".freeze
8
+ JPG = 'jpg'.freeze
9
+ PNG = 'png'.freeze
10
+ GIF = 'gif'.freeze
11
11
  end
12
12
 
13
13
  module Quality
14
- HIGH = 90.freeze
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(self.url).format(format || Format::JPG) do |file|
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
- def self.find(params)
39
- Picturesque.config.find.call(params)
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
@@ -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
- }, defaults: { quality: Picturesque::Image::Quality::HIGH, format: Picturesque::Image::Format::JPG }
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
@@ -1,16 +1,16 @@
1
- require "mini_magick"
1
+ require 'mini_magick'
2
2
 
3
- require "picturesque/engine"
4
- require "picturesque/config"
3
+ require 'picturesque/engine'
4
+ require 'picturesque/config'
5
5
 
6
6
  module Picturesque
7
7
 
8
8
  def self.config
9
- @@config ||= Picturesque::Config.new
9
+ @config ||= Picturesque::Config.new
10
10
  end
11
11
 
12
12
  def self.setup(&block)
13
- block.call(self.config)
13
+ block.call(config)
14
14
  end
15
15
 
16
16
  end
@@ -1,3 +1,3 @@
1
1
  module Picturesque
2
- VERSION = "1.0.1"
2
+ VERSION = '1.0.3'.freeze
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.1
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: 2016-01-27 00:00:00.000000000 Z
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: rspec-rails
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: slim-rails
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: jquery-rails
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
- rubyforge_project:
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
@@ -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.
@@ -1,8 +0,0 @@
1
- class CreatePicturesqueImages < ActiveRecord::Migration
2
- def change
3
- create_table :picturesque_images do |t|
4
-
5
- t.timestamps null: false
6
- end
7
- end
8
- end
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :picturesque do
3
- # # Task goes here
4
- # end