imgix-rails 0.3.2 → 1.0.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: 306dac4865fab9184761f142d5daf2b9d25997d7
4
- data.tar.gz: b92a0db152ef14569cc5740afa68e5fcaef2bf47
3
+ metadata.gz: 36823acfaa06b6d8dd2ce8bcebfc2cb55f4b97f0
4
+ data.tar.gz: 27cb575d84e29fa8d76fec5aaf47f81a82d283f3
5
5
  SHA512:
6
- metadata.gz: 9d6386bd51b1f8bbedea03ca2d397b115b74fea3cc7d8273c114bb3790557011a17526d462e6d2c48d7f71a1575c8a4ad97b02460e187e627a792351ac67994d
7
- data.tar.gz: 66ced9282a5136977b30be7ad62dc39e6c492293a4d5b68d43905b5a05237d0c12afcd8e7916015bc3931a063a1175ac9ab560e5a4db1230267847fb46462e44
6
+ metadata.gz: b3a6719de13260cb1c411f203382ddaf55733f62ee7b6305b85c038636eb20506c47441c72a9318ae790d6f4823d23f9aee9182b9e9052054d5e9857a9631761
7
+ data.tar.gz: e6e45549cac2f1738c5930936e224673b4786acd402bce23960d7554798ffbbe909361d49dbcd70368da1bb526b569aa56a4a769d4a5cb7c225890e4832935d8
data/README.md CHANGED
@@ -38,7 +38,7 @@ end
38
38
 
39
39
  The following configuration flags will be respected:
40
40
 
41
- - `:secure:` toggles the use of HTTPS. Defaults to `true`
41
+ - `:use_https` toggles the use of HTTPS. Defaults to `true`
42
42
  - `:source` a String or Array that specifies the imgix Source address. Should be in the form of `"assets.imgix.net"`.
43
43
  - `:secure_url_token` a optional secure URL token found in your dashboard (https://webapp.imgix.com) used for signing requests
44
44
  - `:hostnames_to_replace` an Array of hostnames to replace with the value(s) specified by `:source`. This is useful if you store full-qualified S3 URLs in your database, but want to serve images through imgix.
@@ -129,6 +129,15 @@ Will generate the following URL:
129
129
  https://assets.imgix.net/users/1/avatar.png?w=400&h=300
130
130
  ```
131
131
 
132
+ Since `ix_image_url` lives inside `UrlHelper`, it can also be used in places other than your views quite easily. This is useful for things such as including imgix URLs in JSON output from a serializer class.
133
+
134
+ ```ruby
135
+ include Imgix::Rails::UrlHelper
136
+
137
+ puts ix_image_url('/users/1/avatar.png', { w: 400, h: 300 })
138
+ # => https://assets.imgix.net/users/1/avatar.png?w=400&h=300
139
+ ```
140
+
132
141
  ### Hostname Removal
133
142
 
134
143
  You can also configure imgix-rails to disregard given hostnames and only use the path component from given URLs. This is useful if you have [a Web Folder or an Amazon S3 imgix Source configured](https://www.imgix.com/docs/tutorials/creating-sources) but store the fully-qualified URLs for those resources in your database.
data/imgix-rails.gemspec CHANGED
@@ -6,9 +6,9 @@ require 'imgix/rails/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "imgix-rails"
8
8
  spec.version = Imgix::Rails::VERSION
9
- spec.authors = ["Kelly Sutton"]
10
- spec.email = ["kelly@imgix.com"]
11
- spec.licenses = ['MIT']
9
+ spec.authors = ["Kelly Sutton", "Paul Straw"]
10
+ spec.email = ["kelly@imgix.com", "ixemail"]
11
+ spec.licenses = ["MIT"]
12
12
 
13
13
  spec.summary = %q{Makes integrating imgix into your Rails app easier. It builds on imgix-rb to offer a few Rails-specific interfaces.}
14
14
  spec.description = %q{Makes integrating imgix into your Rails app easier. It builds on imgix-rb to offer a few Rails-specific interfaces. Please see https://github.com/imgix/imgix-rails for more details.}
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
17
17
  # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
18
  # delete this section to allow pushing this gem to any host.
19
19
  if spec.respond_to?(:metadata)
20
- spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
21
  else
22
22
  raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
23
  end
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
28
  spec.require_paths = ["lib"]
29
29
 
30
- spec.add_runtime_dependency "imgix", '~> 0.3', '>= 0.3.5'
30
+ spec.add_runtime_dependency "imgix", "~> 1.0", ">= 1.0.0"
31
31
 
32
32
  spec.add_development_dependency "bundler", "~> 1.9"
33
33
  spec.add_development_dependency "rake", "~> 10.0"
@@ -0,0 +1,68 @@
1
+ module Imgix
2
+ module Rails
3
+ class ConfigurationError < StandardError; end
4
+
5
+ module UrlHelper
6
+ def ix_image_url(source, options={})
7
+ validate_configuration!
8
+
9
+ source = replace_hostname(source)
10
+
11
+ client.path(source).to_url(options).html_safe
12
+ end
13
+
14
+ private
15
+
16
+ def validate_configuration!
17
+ imgix = ::Imgix::Rails.config.imgix
18
+ unless imgix.try(:[], :source)
19
+ raise ConfigurationError.new("imgix source is not configured. Please set config.imgix[:source].")
20
+ end
21
+
22
+ unless imgix[:source].is_a?(Array) || imgix[:source].is_a?(String)
23
+ raise ConfigurationError.new("imgix source must be a String or an Array.")
24
+ end
25
+ end
26
+
27
+ def replace_hostname(source)
28
+ new_source = source.dup
29
+
30
+ # Replace any hostnames configured to trim things down just to their paths.
31
+ # We use split to remove the protocol in the process.
32
+ hostnames_to_remove.each do |hostname|
33
+ splits = source.split(hostname)
34
+ new_source = splits.last if splits.size > 1
35
+ end
36
+
37
+ new_source
38
+ end
39
+
40
+ def hostnames_to_remove
41
+ Array(::Imgix::Rails.config.imgix[:hostname_to_replace] || ::Imgix::Rails.config.imgix[:hostnames_to_replace])
42
+ end
43
+
44
+ def client
45
+ return @imgix_client if @imgix_client
46
+ imgix = ::Imgix::Rails.config.imgix
47
+
48
+ opts = {
49
+ host: imgix[:source],
50
+ library_param: "rails",
51
+ library_version: Imgix::Rails::VERSION,
52
+ use_https: true,
53
+ secure_url_token: imgix[:secure_url_token]
54
+ }
55
+
56
+ if imgix.has_key?(:include_library_param)
57
+ opts[:include_library_param] = imgix[:include_library_param]
58
+ end
59
+
60
+ if imgix.has_key?(:use_https)
61
+ opts[:use_https] = imgix[:use_https]
62
+ end
63
+
64
+ @imgix_client = ::Imgix::Client.new(opts)
65
+ end
66
+ end
67
+ end
68
+ end
@@ -1,5 +1,5 @@
1
1
  module Imgix
2
2
  module Rails
3
- VERSION = "0.3.2"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
@@ -1,17 +1,10 @@
1
1
  require "imgix"
2
+ require "imgix/rails/url_helper"
2
3
 
3
4
  module Imgix
4
5
  module Rails
5
- class ConfigurationError < StandardError; end
6
-
7
- module ViewHelper
8
- def ix_image_url(source, options={})
9
- validate_configuration!
10
-
11
- source = replace_hostname(source)
12
-
13
- client.path(source).to_url(options).html_safe
14
- end
6
+ module ViewHelper
7
+ include UrlHelper
15
8
 
16
9
  def ix_image_tag(source, options={})
17
10
  source = replace_hostname(source)
@@ -37,56 +30,6 @@ module Imgix
37
30
 
38
31
  private
39
32
 
40
- def validate_configuration!
41
- imgix = ::Imgix::Rails.config.imgix
42
- unless imgix.try(:[], :source)
43
- raise ConfigurationError.new("imgix source is not configured. Please set config.imgix[:source].")
44
- end
45
-
46
- unless imgix[:source].is_a?(Array) || imgix[:source].is_a?(String)
47
- raise ConfigurationError.new("imgix source must be a String or an Array.")
48
- end
49
- end
50
-
51
- def replace_hostname(source)
52
- new_source = source.dup
53
-
54
- # Replace any hostnames configured to trim things down just to their paths.
55
- # We use split to remove the protocol in the process.
56
- hostnames_to_remove.each do |hostname|
57
- splits = source.split(hostname)
58
- new_source = splits.last if splits.size > 1
59
- end
60
-
61
- new_source
62
- end
63
-
64
- def client
65
- return @imgix_client if @imgix_client
66
- imgix = ::Imgix::Rails.config.imgix
67
-
68
- opts = {
69
- host: imgix[:source],
70
- library_param: "rails",
71
- library_version: Imgix::Rails::VERSION,
72
- secure: true
73
- }
74
-
75
- if imgix[:secure_url_token].present?
76
- opts[:token] = imgix[:secure_url_token]
77
- end
78
-
79
- if imgix.has_key?(:include_library_param)
80
- opts[:include_library_param] = imgix[:include_library_param]
81
- end
82
-
83
- if imgix.has_key?(:secure)
84
- opts[:secure] = imgix[:secure]
85
- end
86
-
87
- @imgix_client = ::Imgix::Client.new(opts)
88
- end
89
-
90
33
  def available_parameters
91
34
  @available_parameters ||= parameters.keys
92
35
  end
@@ -108,10 +51,6 @@ module Imgix
108
51
  def configured_resolutions
109
52
  ::Imgix::Rails.config.imgix[:responsive_resolutions] || [1, 2]
110
53
  end
111
-
112
- def hostnames_to_remove
113
- Array(::Imgix::Rails.config.imgix[:hostname_to_replace] || ::Imgix::Rails.config.imgix[:hostnames_to_replace])
114
- end
115
54
  end
116
55
  end
117
56
  end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imgix-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelly Sutton
8
+ - Paul Straw
8
9
  autorequire:
9
10
  bindir: exe
10
11
  cert_chain: []
11
- date: 2015-11-03 00:00:00.000000000 Z
12
+ date: 2015-12-11 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: imgix
@@ -16,20 +17,20 @@ dependencies:
16
17
  requirements:
17
18
  - - "~>"
18
19
  - !ruby/object:Gem::Version
19
- version: '0.3'
20
+ version: '1.0'
20
21
  - - ">="
21
22
  - !ruby/object:Gem::Version
22
- version: 0.3.5
23
+ version: 1.0.0
23
24
  type: :runtime
24
25
  prerelease: false
25
26
  version_requirements: !ruby/object:Gem::Requirement
26
27
  requirements:
27
28
  - - "~>"
28
29
  - !ruby/object:Gem::Version
29
- version: '0.3'
30
+ version: '1.0'
30
31
  - - ">="
31
32
  - !ruby/object:Gem::Version
32
- version: 0.3.5
33
+ version: 1.0.0
33
34
  - !ruby/object:Gem::Dependency
34
35
  name: bundler
35
36
  requirement: !ruby/object:Gem::Requirement
@@ -91,6 +92,7 @@ description: Makes integrating imgix into your Rails app easier. It builds on im
91
92
  for more details.
92
93
  email:
93
94
  - kelly@imgix.com
95
+ - ixemail
94
96
  executables: []
95
97
  extensions: []
96
98
  extra_rdoc_files: []
@@ -105,6 +107,7 @@ files:
105
107
  - bin/setup
106
108
  - imgix-rails.gemspec
107
109
  - lib/imgix/rails.rb
110
+ - lib/imgix/rails/url_helper.rb
108
111
  - lib/imgix/rails/version.rb
109
112
  - lib/imgix/rails/view_helper.rb
110
113
  - lib/imgix/railtie.rb
@@ -130,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
133
  version: '0'
131
134
  requirements: []
132
135
  rubyforge_project:
133
- rubygems_version: 2.4.7
136
+ rubygems_version: 2.4.5.1
134
137
  signing_key:
135
138
  specification_version: 4
136
139
  summary: Makes integrating imgix into your Rails app easier. It builds on imgix-rb