picturesque 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f8dfcc2b8efb76cf156862232d2aafc737c28008
4
+ data.tar.gz: d7021d8ecfa9fe36587f790d9e82b2e70361d3cf
5
+ SHA512:
6
+ metadata.gz: eedc16bc960d2a2f680c4a9853d323a0563922c4ea8322e07be5e7031c3fe779ea03382b9f742cb5a74076f267ecd46285fdea3fa979b573b1deeef3492044e7
7
+ data.tar.gz: c0fa9f478c3533e156afc0fe62acf7ca734780c83a28e58bb87ad265dfa1b1397455aad05f417c22ee3121e25bcd35f84b2b560a87c48cf3325721cb54f8199f
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 Kevin Sylvestre
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,69 @@
1
+ = Picturesque
2
+
3
+ Picturesque is an engine for resizing and formatting images on the fly.
4
+
5
+ == Requirements
6
+
7
+ The gem is tested with:
8
+
9
+ * Ruby on Rails 4.2.2
10
+ * Ruby 2.2.2
11
+ * JRuby 9.0.0.0
12
+
13
+ == Installation
14
+
15
+ gem install picturesque
16
+
17
+ == Additional
18
+
19
+ brew install imagemagick
20
+
21
+ == Configuration
22
+
23
+ # config/initializers/picturesque.rb
24
+ Picturesque.setup do |config|
25
+ config.url -> (id) { Photo.find(id).url }
26
+ end
27
+
28
+ == Examples
29
+
30
+ Migration:
31
+
32
+ rails g model photo url:string
33
+
34
+ class CreatePhoto < ActiveRecord::Migration
35
+ def self.up
36
+ create_table :videos do |t|
37
+ t.string :url
38
+
39
+ t.timestamps
40
+ end
41
+ end
42
+
43
+ def self.down
44
+ drop_table :videos
45
+ end
46
+ end
47
+
48
+ Model:
49
+
50
+ class Photo < ActiveRecord::Base
51
+ validates_presence_of :url
52
+ end
53
+
54
+ View:
55
+
56
+ <%- @photos.each do |photo| -%>
57
+ <%= image_tag(picturesque_image_url(photo, size: '64x64'), size: '64x64') %>
58
+ <%- end -%>
59
+
60
+ == Status
61
+
62
+ {<img src="https://img.shields.io/gemnasium/ksylvest/picturesque.svg" />}[https://gemnasium.com/ksylvest/picturesque]
63
+ {<img src="https://img.shields.io/travis/ksylvest/picturesque.svg" />}[https://travis-ci.org/ksylvest/picturesque]
64
+ {<img src="https://img.shields.io/coveralls/ksylvest/picturesque.svg" />}[https://coveralls.io/r/ksylvest/picturesque]
65
+ {<img src="https://img.shields.io/codeclimate/github/ksylvest/picturesque.svg" />}[https://codeclimate.com/github/ksylvest/picturesque]
66
+
67
+ == Copyright
68
+
69
+ Copyright (c) 2014 - 2015 Kevin Sylvestre. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Picturesque'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
@@ -0,0 +1 @@
1
+ //= require_tree .
@@ -0,0 +1,3 @@
1
+ /*
2
+ *= require_tree .
3
+ */
@@ -0,0 +1,4 @@
1
+ module Picturesque
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,16 @@
1
+ require_dependency "picturesque/application_controller"
2
+
3
+ module Picturesque
4
+ class ImagesController < ApplicationController
5
+
6
+ # GET /:id/(:size)/(:quality)/(*slug).(:format)
7
+ def show
8
+ @image = Picturesque::Image.find(params[:id])
9
+ @file = @image.process(size: params[:size], quality: params[:quality], format: params[:format])
10
+
11
+ expires_in 3.years, public: @file
12
+ send_file @file.path, disposition: Picturesque::Image::DISPOSITION
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,4 @@
1
+ module Picturesque
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,44 @@
1
+ module Picturesque
2
+ class Image
3
+ include ActiveModel::Model
4
+
5
+ DISPOSITION = "inline".freeze
6
+
7
+ module Format
8
+ JPG = "jpg".freeze
9
+ PNG = "png".freeze
10
+ GIF = "gif".freeze
11
+ end
12
+
13
+ module Quality
14
+ HIGH = 90.freeze
15
+ WEAK = 10.freeze
16
+ end
17
+
18
+ attr_accessor :url
19
+
20
+ def initialize(url)
21
+ self.url = url
22
+ end
23
+
24
+ def process(size: nil, quality: nil, format: nil)
25
+ MiniMagick::Image.open(self.url).format(format || Format::JPG) do |file|
26
+ file.quality(quality || Quality::HIGH)
27
+
28
+ if size
29
+ w,h = size.split("x")
30
+ if w && Integer(w) > 0 && h && Integer(h) > 0
31
+ file.resize("#{w}x#{h}^")
32
+ file.gravity "center"
33
+ file.extent "#{w}x#{h}"
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ def self.find(id)
40
+ new(Picturesque.config.url.call(id))
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Picturesque</title>
5
+ <%= stylesheet_link_tag "picturesque/application", media: "all" %>
6
+ <%= javascript_include_tag "picturesque/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,9 @@
1
+ Picturesque::Engine.routes.draw do
2
+
3
+ get ':id(/:size)(/:quality)(/*slug)(.:format)', to: 'images#show', as: :image, constraints: {
4
+ size: /\d+x\d+/,
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 }
8
+
9
+ end
@@ -0,0 +1,8 @@
1
+ class CreatePicturesqueImages < ActiveRecord::Migration
2
+ def change
3
+ create_table :picturesque_images do |t|
4
+
5
+ t.timestamps
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module Picturesque
2
+ class Config
3
+ attr_accessor :url
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Picturesque
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Picturesque
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module Picturesque
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,16 @@
1
+ require "mini_magick"
2
+
3
+ require "picturesque/engine"
4
+ require "picturesque/config"
5
+
6
+ module Picturesque
7
+
8
+ def self.config
9
+ @@config ||= Picturesque::Config.new
10
+ end
11
+
12
+ def self.setup(&block)
13
+ block.call(self.config)
14
+ end
15
+
16
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :picturesque do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: picturesque
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kevin Sylvestre
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mini_magick
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pg
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: fabrication
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-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: slim-rails
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: sass-rails
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: jquery-rails
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Picturesque exposes a simple API for resizing images
126
+ email:
127
+ - kevin@ksylvest.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - LICENSE
133
+ - README.rdoc
134
+ - Rakefile
135
+ - app/assets/javascripts/picturesque/application.js
136
+ - app/assets/stylesheets/picturesque/application.css
137
+ - app/controllers/picturesque/application_controller.rb
138
+ - app/controllers/picturesque/images_controller.rb
139
+ - app/helpers/picturesque/application_helper.rb
140
+ - app/models/picturesque/image.rb
141
+ - app/views/layouts/picturesque/application.html.erb
142
+ - config/routes.rb
143
+ - db/migrate/20141218101647_create_picturesque_images.rb
144
+ - lib/picturesque.rb
145
+ - lib/picturesque/config.rb
146
+ - lib/picturesque/engine.rb
147
+ - lib/picturesque/version.rb
148
+ - lib/tasks/picturesque_tasks.rake
149
+ homepage: https://github.com/ksylvest/picturesque
150
+ licenses:
151
+ - MIT
152
+ metadata: {}
153
+ post_install_message:
154
+ rdoc_options: []
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ requirements: []
168
+ rubyforge_project:
169
+ rubygems_version: 2.4.5
170
+ signing_key:
171
+ specification_version: 4
172
+ summary: Picturesque makes image resizing simple
173
+ test_files: []