center_image_tag 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/lib/center_image_tag/version.rb +1 -1
- data/lib/center_image_tag/view_helper.rb +7 -6
- data/spec/view_helper_spec.rb +70 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NDViYWU1ZmZlZGYzYzYwYmRiYjE1YjI0NzQ1ZjNiNTIxM2JiMzdmZQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OGMyMDQxYzMzODIzNWIxNmNiNmQ3NjBiZjk5YWI3YTRjYTA2NTg4Yw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OGNiOTU1MjJiYjZiYjIzMmM5ZDBmNGJmM2ZiNWE2OWUxZTgxZDJmNWQ3MTE2
|
10
|
+
ODZmMjI5MjdjYmViNzkxY2ZlZjExNTk2YjMyMjFhYmIwNzg3ZDk2OTEwNjBh
|
11
|
+
ZjM4ZjlmMWIzMDEwNzgwOGQ0NTE5Yzg5OTg5ZTIxM2MwOTFmZTg=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZjM2NGJhMGYyNmI0MWQ2YzI2YmMzNGMxMjUxMWZiYTUzZDlkZGNiNjIxNWFm
|
14
|
+
YjU2Y2E5OGYyZjUwMDIyZTZjMzIxNTcyNTEwOWM2YzA4MDAzMmQ0Y2RjNTQy
|
15
|
+
MTJmMzliOWNlNzQ1MTU1ZmY3MjllMDMxN2ZkZDlmZjM0ZjhhN2Y=
|
@@ -7,8 +7,9 @@ module CenterImageTag
|
|
7
7
|
include ActionView::Helpers::AssetTagHelper
|
8
8
|
|
9
9
|
def center_image_tag(source, options = {})
|
10
|
+
container_class = options.delete(:container_class)
|
10
11
|
if fluid_percentage = options.delete(:fluid)
|
11
|
-
return container_fluid fluid_percentage do
|
12
|
+
return container_fluid fluid_percentage, container_class do
|
12
13
|
clip do
|
13
14
|
image_tag(source, options) +
|
14
15
|
tag(:span, class: "vertical-align")
|
@@ -17,7 +18,7 @@ module CenterImageTag
|
|
17
18
|
else
|
18
19
|
width, height = dimension(options)
|
19
20
|
if width && height
|
20
|
-
return container_fixed width, height do
|
21
|
+
return container_fixed width, height, container_class do
|
21
22
|
clip do
|
22
23
|
image_tag(source, rebuild_options(options, width, height)) +
|
23
24
|
tag(:span, class: "vertical-align")
|
@@ -30,14 +31,14 @@ module CenterImageTag
|
|
30
31
|
end
|
31
32
|
|
32
33
|
private
|
33
|
-
def container_fluid(fluid_percentage, &block)
|
34
|
-
div class: "cit-standard-thumb cit-thumb-fluid" do
|
34
|
+
def container_fluid(fluid_percentage, outer_class, &block)
|
35
|
+
div class: "cit-standard-thumb cit-thumb-fluid #{outer_class}" do
|
35
36
|
div class: "cit-thumb-default", style: "padding-bottom: #{fluid_percentage}", &block
|
36
37
|
end
|
37
38
|
end
|
38
39
|
|
39
|
-
def container_fixed(width, height, &block)
|
40
|
-
div class: "cit-standard-thumb", style: "width: #{width}px" do
|
40
|
+
def container_fixed(width, height, outer_class, &block)
|
41
|
+
div class: "cit-standard-thumb #{outer_class}", style: "width: #{width}px" do
|
41
42
|
div class: "cit-thumb-default", style: "padding-bottom: #{height}px", &block
|
42
43
|
end
|
43
44
|
end
|
data/spec/view_helper_spec.rb
CHANGED
@@ -8,12 +8,32 @@ module CenterImageTag
|
|
8
8
|
expected = "<img alt=\"Image\" src=\"/images/image.png\" />"
|
9
9
|
expect(output).to eq expected
|
10
10
|
end
|
11
|
+
|
12
|
+
it 'ignores container_class options' do
|
13
|
+
output = View.new.center_image_tag 'image.png', container_class: 'custom-class'
|
14
|
+
expected = "<img alt=\"Image\" src=\"/images/image.png\" />"
|
15
|
+
expect(output).to eq expected
|
16
|
+
end
|
11
17
|
end
|
12
18
|
|
13
19
|
describe 'fluid' do
|
14
20
|
it 'renders the fluid image correctly' do
|
15
21
|
output = View.new.center_image_tag 'image.png', fluid: "56.25%"
|
16
|
-
expected = "<div class=\"cit-standard-thumb cit-thumb-fluid\">" +
|
22
|
+
expected = "<div class=\"cit-standard-thumb cit-thumb-fluid \">" +
|
23
|
+
"<div class=\"cit-thumb-default\" style=\"padding-bottom: 56.25%\">" +
|
24
|
+
"<div class=\"cit-thumb-clip\">" +
|
25
|
+
"<div class=\"cit-thumb-clip-inner\">" +
|
26
|
+
"<img alt=\"Image\" src=\"/images/image.png\" />" +
|
27
|
+
"<span class=\"vertical-align\" />" +
|
28
|
+
"</div>" +
|
29
|
+
"</div>" +
|
30
|
+
"</div>" +
|
31
|
+
"</div>"
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'renders the fluid image with container class' do
|
35
|
+
output = View.new.center_image_tag 'image.png', fluid: "56.25%", container_class: 'custom-class'
|
36
|
+
expected = "<div class=\"cit-standard-thumb cit-thumb-fluid custom-class\">" +
|
17
37
|
"<div class=\"cit-thumb-default\" style=\"padding-bottom: 56.25%\">" +
|
18
38
|
"<div class=\"cit-thumb-clip\">" +
|
19
39
|
"<div class=\"cit-thumb-clip-inner\">" +
|
@@ -30,7 +50,22 @@ module CenterImageTag
|
|
30
50
|
describe 'fixed' do
|
31
51
|
it 'renders the fixed image correctly from size options (size = widthxheight)' do
|
32
52
|
output = View.new.center_image_tag 'image.png', size: "200x100"
|
33
|
-
expected = "<div class=\"cit-standard-thumb\" style=\"width: 200px\">" +
|
53
|
+
expected = "<div class=\"cit-standard-thumb \" style=\"width: 200px\">" +
|
54
|
+
"<div class=\"cit-thumb-default\" style=\"padding-bottom: 100px\">" +
|
55
|
+
"<div class=\"cit-thumb-clip\">" +
|
56
|
+
"<div class=\"cit-thumb-clip-inner\">" +
|
57
|
+
"<img alt=\"Image\" src=\"/images/image.png\" width=\"200\" />" +
|
58
|
+
"<span class=\"vertical-align\" />" +
|
59
|
+
"</div>" +
|
60
|
+
"</div>" +
|
61
|
+
"</div>" +
|
62
|
+
"</div>"
|
63
|
+
expect(output).to eq expected
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'renders the fixed image correctly from size options (size = widthxheight) with container class' do
|
67
|
+
output = View.new.center_image_tag 'image.png', size: "200x100", container_class: 'custom-class'
|
68
|
+
expected = "<div class=\"cit-standard-thumb custom-class\" style=\"width: 200px\">" +
|
34
69
|
"<div class=\"cit-thumb-default\" style=\"padding-bottom: 100px\">" +
|
35
70
|
"<div class=\"cit-thumb-clip\">" +
|
36
71
|
"<div class=\"cit-thumb-clip-inner\">" +
|
@@ -45,7 +80,22 @@ module CenterImageTag
|
|
45
80
|
|
46
81
|
it 'renders the fixed image correctly from size options (single size value)' do
|
47
82
|
output = View.new.center_image_tag 'image.png', size: "200"
|
48
|
-
expected = "<div class=\"cit-standard-thumb\" style=\"width: 200px\">" +
|
83
|
+
expected = "<div class=\"cit-standard-thumb \" style=\"width: 200px\">" +
|
84
|
+
"<div class=\"cit-thumb-default\" style=\"padding-bottom: 200px\">" +
|
85
|
+
"<div class=\"cit-thumb-clip\">" +
|
86
|
+
"<div class=\"cit-thumb-clip-inner\">" +
|
87
|
+
"<img alt=\"Image\" src=\"/images/image.png\" width=\"200\" />" +
|
88
|
+
"<span class=\"vertical-align\" />" +
|
89
|
+
"</div>" +
|
90
|
+
"</div>" +
|
91
|
+
"</div>" +
|
92
|
+
"</div>"
|
93
|
+
expect(output).to eq expected
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'renders the fixed image correctly from size options (single size value) with container class' do
|
97
|
+
output = View.new.center_image_tag 'image.png', size: "200", container_class: 'custom-class'
|
98
|
+
expected = "<div class=\"cit-standard-thumb custom-class\" style=\"width: 200px\">" +
|
49
99
|
"<div class=\"cit-thumb-default\" style=\"padding-bottom: 200px\">" +
|
50
100
|
"<div class=\"cit-thumb-clip\">" +
|
51
101
|
"<div class=\"cit-thumb-clip-inner\">" +
|
@@ -58,9 +108,25 @@ module CenterImageTag
|
|
58
108
|
expect(output).to eq expected
|
59
109
|
end
|
60
110
|
|
111
|
+
|
61
112
|
it 'renders the fixed image correctly from width and height options' do
|
62
113
|
output = View.new.center_image_tag 'image.png', width: "200", height: 100
|
63
|
-
expected = "<div class=\"cit-standard-thumb\" style=\"width: 200px\">" +
|
114
|
+
expected = "<div class=\"cit-standard-thumb \" style=\"width: 200px\">" +
|
115
|
+
"<div class=\"cit-thumb-default\" style=\"padding-bottom: 100px\">" +
|
116
|
+
"<div class=\"cit-thumb-clip\">" +
|
117
|
+
"<div class=\"cit-thumb-clip-inner\">" +
|
118
|
+
"<img alt=\"Image\" src=\"/images/image.png\" width=\"200\" />" +
|
119
|
+
"<span class=\"vertical-align\" />" +
|
120
|
+
"</div>" +
|
121
|
+
"</div>" +
|
122
|
+
"</div>" +
|
123
|
+
"</div>"
|
124
|
+
expect(output).to eq expected
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'renders the fixed image correctly from width and height options with container class' do
|
128
|
+
output = View.new.center_image_tag 'image.png', width: "200", height: 100, container_class: 'custom-class'
|
129
|
+
expected = "<div class=\"cit-standard-thumb custom-class\" style=\"width: 200px\">" +
|
64
130
|
"<div class=\"cit-thumb-default\" style=\"padding-bottom: 100px\">" +
|
65
131
|
"<div class=\"cit-thumb-clip\">" +
|
66
132
|
"<div class=\"cit-thumb-clip-inner\">" +
|