dimensions-rails 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
data/lib/dimensions-rails.rb
CHANGED
@@ -2,34 +2,37 @@ require 'dimensions-rails/version'
|
|
2
2
|
require 'active_support/ordered_options'
|
3
3
|
require 'rails/railtie'
|
4
4
|
require 'dimensions'
|
5
|
+
require 'ostruct'
|
5
6
|
|
6
7
|
module Dimensions
|
7
8
|
module Rails
|
8
|
-
|
9
|
+
|
9
10
|
module Helper
|
10
|
-
|
11
|
+
|
11
12
|
# Use dimensions by @sstephenson to add automatic images size and improve browser rendering.
|
12
|
-
#
|
13
|
+
#
|
13
14
|
# How this improves browser rendering?
|
14
15
|
# https://developers.google.com/speed/docs/best-practices/rendering#SpecifyImageDimensions
|
15
|
-
#
|
16
|
+
#
|
16
17
|
def image_tag source, options = {}
|
17
18
|
unless options[:size] or options[:width] or options[:height]
|
18
|
-
fs_path = asset_paths.asset_for(source, nil)
|
19
|
-
|
20
|
-
|
19
|
+
fs_path = asset_paths.asset_for(source, nil) if respond_to? :asset_paths
|
20
|
+
fs_path = fs_path.present? ? fs_path.to_path : File.join(::Rails.public_path, source)
|
21
|
+
|
22
|
+
if fs_path.present? and File.exist? fs_path
|
23
|
+
options[:width], options[:height] = ::Dimensions.dimensions(fs_path)
|
21
24
|
end
|
22
25
|
end
|
23
26
|
super
|
24
27
|
end
|
25
|
-
|
28
|
+
|
26
29
|
end
|
27
|
-
|
30
|
+
|
28
31
|
class Railtie < ::Rails::Railtie
|
29
32
|
config.dimensions = ActiveSupport::OrderedOptions.new
|
30
33
|
config.dimensions.add_size_by_default = true
|
31
|
-
|
32
|
-
|
34
|
+
|
35
|
+
|
33
36
|
initializer 'dimensions.initialize' do
|
34
37
|
ActiveSupport.on_load(:action_view) do
|
35
38
|
include ::Dimensions::Rails::Helper
|
Binary file
|
@@ -6,10 +6,16 @@ describe ApplicationHelper, :type => :helper do
|
|
6
6
|
tag.should match('height="64"')
|
7
7
|
tag.should match('width="50"')
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
it "works with a missing image" do
|
11
11
|
tag = helper.image_tag('missing.png')
|
12
12
|
tag.should_not match('height=')
|
13
13
|
tag.should_not match('width=')
|
14
14
|
end
|
15
|
+
|
16
|
+
it 'works even if the image is not in the asset pipeline' do
|
17
|
+
tag = helper.image_tag('/outsiders/rails.png')
|
18
|
+
tag.should match('height="64"')
|
19
|
+
tag.should match('width="50"')
|
20
|
+
end
|
15
21
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dimensions-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: dimensions
|
16
|
-
requirement: &
|
16
|
+
requirement: &70264534466000 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70264534466000
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: railties
|
27
|
-
requirement: &
|
27
|
+
requirement: &70264534465460 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '3.0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70264534465460
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: actionpack
|
38
|
-
requirement: &
|
38
|
+
requirement: &70264534464840 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '3.0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70264534464840
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: activesupport
|
49
|
-
requirement: &
|
49
|
+
requirement: &70264534464100 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '3.0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70264534464100
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rails
|
60
|
-
requirement: &
|
60
|
+
requirement: &70264534463340 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '3.0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70264534463340
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec-rails
|
71
|
-
requirement: &
|
71
|
+
requirement: &70264534462720 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: '2.0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70264534462720
|
80
80
|
description: Use dimensions by @sstephenson to add automatic images size and improve
|
81
81
|
browser rendering
|
82
82
|
email:
|
@@ -127,6 +127,7 @@ files:
|
|
127
127
|
- spec/dummy/public/422.html
|
128
128
|
- spec/dummy/public/500.html
|
129
129
|
- spec/dummy/public/favicon.ico
|
130
|
+
- spec/dummy/public/outsiders/rails.png
|
130
131
|
- spec/dummy/script/rails
|
131
132
|
- spec/helper/dimensions-rails_spec.rb
|
132
133
|
- spec/spec_helper.rb
|
@@ -144,7 +145,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
144
145
|
version: '0'
|
145
146
|
segments:
|
146
147
|
- 0
|
147
|
-
hash:
|
148
|
+
hash: 463973146420150992
|
148
149
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
150
|
none: false
|
150
151
|
requirements:
|
@@ -153,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
153
154
|
version: '0'
|
154
155
|
segments:
|
155
156
|
- 0
|
156
|
-
hash:
|
157
|
+
hash: 463973146420150992
|
157
158
|
requirements: []
|
158
159
|
rubyforge_project:
|
159
160
|
rubygems_version: 1.8.17
|
@@ -194,6 +195,7 @@ test_files:
|
|
194
195
|
- spec/dummy/public/422.html
|
195
196
|
- spec/dummy/public/500.html
|
196
197
|
- spec/dummy/public/favicon.ico
|
198
|
+
- spec/dummy/public/outsiders/rails.png
|
197
199
|
- spec/dummy/script/rails
|
198
200
|
- spec/helper/dimensions-rails_spec.rb
|
199
201
|
- spec/spec_helper.rb
|