thumbor_rails 0.0.0 → 0.1.0

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: 822e16c0f961cec7b2f5b8baaa17fcd253eced25
4
- data.tar.gz: 8f156ec653e4e8a69c4be64089ff03caa9f17ee0
3
+ metadata.gz: 5f945ed803b05c9cd5c033721e72c3e5a948ef03
4
+ data.tar.gz: 98812b81213e952bbd2afa9fe7c7b7e5965b7789
5
5
  SHA512:
6
- metadata.gz: faef58844a6ef0c4df25f59439ab60d5ae84c2e005c954f3a231929c127d664dd3b141e0d0f0ccf877326c12613c2211a8c39cc138b93e9f6735899ecfa5f97c
7
- data.tar.gz: 82562544d5ce6e35752e8e4a89644b6cc8a8189cf06bf853c77be0ecf7bd2b225ec0674b7a9caca526d47f42a6fe31e7db98c343af8bc772e56bb62bdfba53e1
6
+ metadata.gz: 3bef58317da733d42ce7271e8340e0570408d984580cbb09cc585cf90c7c9b6cad26709c638b7b218240aa0c00daf19e7ec02fbe1dcf57dad512046ad314a381
7
+ data.tar.gz: 44a48b1e8734047f3f2a2dedae7f5bb5b328a3335a46cf11ccf70a274e5bd9880ee3aff486cef5126ff00f28a73d8359fe8c4c2c52a95a23c8ccaa0a1a4da2b0
data/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # Thumbor Rails [<img src="https://secure.travis-ci.org/rafaelcaricio/thumbor_rails.png?branch=master" alt="Build Status" />](https://travis-ci.org/rafaelcaricio/thumbor_rails)
2
+
3
+ https://github.com/rafaelcaricio/thumbor_rails
4
+
5
+ ## DESCRIPTION
6
+
7
+ thumbor_rails is a client to make easier to use the thumbor imaging service (http://github.com/globocom/thumbor) in Ruby and Rails projects.
8
+
9
+ ## Installation
10
+
11
+ You can use this gem by putting the following inside your Gemfile:
12
+
13
+ ```
14
+ gem "thumbor_rails", "0.1.0"
15
+ ```
16
+
17
+ Now generate the thumbor basic client configuration:
18
+
19
+ ```
20
+ rails g thumbor_rails:install
21
+ ```
22
+
23
+ It will generate the basic configuration in `config/initializers/thumbor_rails.rb` and you have to update the values of `server_url` to point to your thumbor server and the `security_key` to have your security key.
24
+
25
+ That's all.
26
+
27
+ ## Usage
28
+
29
+ There are two basic helpers you can use in your views:
30
+
31
+ ```
32
+ thumbor_url
33
+ thumbor_image_tag
34
+ ```
35
+
36
+ ### thumbor_url
37
+
38
+ The `thumbor_url` helper allows you to to generate a thumbor url, a simple use is:
39
+
40
+ ```ruby
41
+ <%= thumbor_url "http://example.com/awesome_image.jpg" %>
42
+ ```
43
+
44
+ Of course, you can pass various parameters to thumbor as described in the [ruby-thumbor gem](https://github.com/thumbor/ruby-thumbor#usage). An exemple would be:
45
+
46
+ ```ruby
47
+ <%= thumbor_url "http://example.com/awesome_image.jpg", width: 200, height: 300 %>
48
+ ```
49
+
50
+ ### thumbor_image_tag
51
+
52
+ The `thumbor_image_tag` helper allows you to simplify the usage when creating a simple image tag in your views. It returns a complete image tag with the generated thumbor url in the `src` attribute of the `img` tag. Example:
53
+
54
+ ```ruby
55
+ <%= thumbor_image_tag "http://myimage.jpg", unsafe: true, width: 100, height: 100 %>
56
+ ```
57
+
58
+ Will result in something like:
59
+
60
+ ```html
61
+ <img alt="Myimage" src="http://thumbor.example.com/unsafe/100x100/http://myimage.jpg" />
62
+ ```
63
+
64
+ ## Maintainers
65
+
66
+ - Rafael Caricio (@rafaelcaricio)[https://coderwall.com/rafaelcaricio]
67
+
68
+ ## Contributing
69
+
70
+ 1. Fork it
71
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
72
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
73
+ 4. Push to the branch (`git push origin my-new-feature`)
74
+ 5. Create new Pull Request
@@ -0,0 +1,12 @@
1
+ module ThumborRails
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ desc "Copy ThumborRails default configuration files"
5
+ source_root File.expand_path('../templates', __FILE__)
6
+
7
+ def copy_config
8
+ template "config/initializers/thumbor_rails.rb"
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,4 @@
1
+ ThumborRails.setup do |config|
2
+ config.server_url = 'http://thumbor.example.com'
3
+ config.security_key = 'MY_SECURITY_KEY'
4
+ end
@@ -0,0 +1,30 @@
1
+ require 'ruby-thumbor'
2
+
3
+ module ThumborRails
4
+ module Helpers
5
+ include ActionView::Helpers::AssetTagHelper
6
+
7
+ def thumbor_url(image_url, options = {})
8
+ options[:image] = image_url
9
+ thumbor_service = crypto_service
10
+ thumbor_service = unsafe_service if options[:unsafe]
11
+ "#{ThumborRails.server_url}#{thumbor_service.generate(options)}"
12
+ end
13
+
14
+ def thumbor_image_tag(image_url, options = {}, tag_attrs = {})
15
+ image_tag(thumbor_url(image_url, options), tag_attrs)
16
+ end
17
+
18
+ private
19
+
20
+ def crypto_service
21
+ Thumbor::CryptoURL.new(ThumborRails.security_key)
22
+ end
23
+
24
+ def unsafe_service
25
+ Thumbor::CryptoURL.new(nil)
26
+ end
27
+ end
28
+ end
29
+
30
+ ActionView::Base.send :include, ThumborRails::Helpers
@@ -1,3 +1,3 @@
1
1
  module ThumborRails
2
- VERSION = '0.0.0'
2
+ VERSION = '0.1.0'
3
3
  end
data/lib/thumbor_rails.rb CHANGED
@@ -1,7 +1,13 @@
1
+ require 'thumbor_rails/helpers'
2
+
1
3
  module ThumborRails
2
- class Yo
3
- def hey!
4
- puts "ho!"
5
- end
4
+ mattr_accessor :server_url
5
+ @@server_url = 'http://thumbor.example.com'
6
+
7
+ mattr_accessor :security_key
8
+ @@security_key = 'MY_SECURITY_KEY'
9
+
10
+ def self.setup
11
+ yield self
6
12
  end
7
13
  end
@@ -0,0 +1,3 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'action_view'
3
+ require 'thumbor_rails'
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe ThumborRails::Helpers do
4
+ include ThumborRails::Helpers
5
+
6
+ describe "#thumbor_url" do
7
+ it 'should generate a basic encrypted url' do
8
+ expect(thumbor_url('http://test.img')).to eq('http://thumbor.example.com/yPVDsGJsQKjKky_cdbkNuIpc9-A=/http://test.img')
9
+ end
10
+
11
+ it 'should allow unsafe urls' do
12
+ expect(thumbor_url('http://test.img', unsafe: true)).to eq('http://thumbor.example.com/unsafe/http://test.img')
13
+ end
14
+
15
+ it 'should pass arguments to thumbor' do
16
+ expect(thumbor_url('http://test.img', unsafe: true, width: 100, height: 200)).to eq('http://thumbor.example.com/unsafe/100x200/http://test.img')
17
+ end
18
+ end
19
+
20
+ describe '#thumbor_image_tag' do
21
+ it 'should return a simple image' do
22
+ expect(thumbor_image_tag('http://myimg.jpg')).to eq('<img alt="Myimg" src="http://thumbor.example.com/Q-1lWnxlCLnkzXWWM5xTAs1QEBM=/http://myimg.jpg" />')
23
+ end
24
+
25
+ it 'should pass arguments to thumbor' do
26
+ expect(thumbor_image_tag('http://myimg.jpg', unsafe: true)).to eq('<img alt="Myimg" src="http://thumbor.example.com/unsafe/http://myimg.jpg" />')
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe ThumborRails do
4
+ it 'setup block yields self' do
5
+ subject.setup do |config|
6
+ expect(subject).to equal(config)
7
+ end
8
+ end
9
+
10
+ it 'has security_key attibute' do
11
+ expect(subject).to respond_to 'security_key'
12
+ end
13
+
14
+ it 'has server_url attibute' do
15
+ expect(subject).to respond_to 'server_url'
16
+ end
17
+
18
+ describe 'when configured' do
19
+ before do
20
+ subject.setup do |config|
21
+ config.server_url = 'http://thumbor.globo.com'
22
+ end
23
+ end
24
+
25
+ it 'should use the configuration' do
26
+ expect(subject.server_url).to eq('http://thumbor.globo.com')
27
+ end
28
+ end
29
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thumbor_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rafael Caricio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-26 00:00:00.000000000 Z
11
+ date: 2014-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-thumbor
@@ -67,16 +67,22 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  description: thumbor_rails is a client for the thumbor imaging service (http://github.com/globocom/thumbor)
70
- in Ruby and Rails projects.
70
+ for Ruby and Rails projects.
71
71
  email:
72
72
  - rafael@caricio.com
73
73
  executables: []
74
74
  extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
+ - lib/generators/thumbor_rails/install_generator.rb
78
+ - lib/generators/thumbor_rails/templates/config/initializers/thumbor_rails.rb
79
+ - lib/thumbor_rails/helpers.rb
77
80
  - lib/thumbor_rails/version.rb
78
81
  - lib/thumbor_rails.rb
79
- - README.rdoc
82
+ - README.md
83
+ - spec/spec_helper.rb
84
+ - spec/thumbor_rails/helpers_spec.rb
85
+ - spec/thumbor_rails_spec.rb
80
86
  homepage: https://github.com/rafaelcaricio/thumbor_rails
81
87
  licenses:
82
88
  - MIT
@@ -84,7 +90,7 @@ metadata: {}
84
90
  post_install_message:
85
91
  rdoc_options:
86
92
  - --main
87
- - README.rdoc
93
+ - README.md
88
94
  require_paths:
89
95
  - lib
90
96
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -103,5 +109,8 @@ rubygems_version: 2.0.14
103
109
  signing_key:
104
110
  specification_version: 4
105
111
  summary: thumbor_rails is a client to manage and generate urls for the thumbor imaging
106
- service (http://github.com/globocom/thumbor) in Ruby and Rails projects.
107
- test_files: []
112
+ service (http://github.com/globocom/thumbor) for Ruby and Rails projects.
113
+ test_files:
114
+ - spec/spec_helper.rb
115
+ - spec/thumbor_rails/helpers_spec.rb
116
+ - spec/thumbor_rails_spec.rb
data/README.rdoc DELETED
File without changes