placekitten 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/README.md +9 -0
- data/VERSION +1 -1
- data/lib/placekitten/helpers.rb +5 -2
- data/lib/placekitten/placekitten.rb +16 -4
- data/test/placekitten_helpers_test.rb +5 -0
- data/test/placekitten_test.rb +20 -0
- metadata +1 -1
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -34,6 +34,15 @@ Rails Helpers
|
|
34
34
|
include PlaceKitten::Helpers
|
35
35
|
end
|
36
36
|
|
37
|
+
# in your views:
|
38
|
+
<%= image_tag placekitten(400, 500) %>
|
39
|
+
<%= image_tag placekitten_gray(400, 500) %>
|
40
|
+
|
41
|
+
Contributing
|
42
|
+
------------
|
43
|
+
|
44
|
+
Just fork the project, create a topic branch, push your changes, and issue a Pull Request. Avoid changing `Rakefile` or `VERSION` (or do it in a separate commit so I can skip pulling those changes).
|
45
|
+
|
37
46
|
License
|
38
47
|
-------
|
39
48
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.1.0
|
data/lib/placekitten/helpers.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
module PlaceKitten::Helpers
|
2
|
-
|
2
|
+
# @see PlaceKitten.image
|
3
|
+
def placekitten(width = nil, height = nil, grayscale = false)
|
3
4
|
PlaceKitten.image(width, height, grayscale)
|
4
5
|
end
|
5
6
|
|
6
|
-
|
7
|
+
# @see PlaceKitten.grayscale
|
8
|
+
def placekitten_grayscale(width = nil, height = nil)
|
7
9
|
PlaceKitten.grayscale(width, height)
|
8
10
|
end
|
11
|
+
alias placekitten_gray placekitten_grayscale
|
9
12
|
end
|
@@ -1,11 +1,22 @@
|
|
1
1
|
class PlaceKitten
|
2
|
+
DEFAULT_WIDTH = 300
|
3
|
+
DEFAULT_HEIGHT = 300
|
4
|
+
|
2
5
|
# Returns the URL for an optionally grayscale placekitten with
|
3
|
-
# the given width and height.
|
6
|
+
# the given width and height. If the width is given but the height
|
7
|
+
# is not, the image will be square.
|
4
8
|
#
|
5
9
|
# @param [Number] width the width of the placekitten
|
6
10
|
# @param [Number] height the height of the placekitten
|
7
11
|
# @param [Boolean] grayscale whether or not to make the placekitten grayscale
|
8
|
-
def self.image(width =
|
12
|
+
def self.image(width = nil, height = nil, grayscale = false)
|
13
|
+
if width.nil?
|
14
|
+
width = DEFAULT_WIDTH
|
15
|
+
height = DEFAULT_HEIGHT
|
16
|
+
elsif height.nil?
|
17
|
+
height = width
|
18
|
+
end
|
19
|
+
|
9
20
|
if grayscale
|
10
21
|
"http://placekitten.com/g/#{width}/#{height}"
|
11
22
|
else
|
@@ -14,11 +25,12 @@ class PlaceKitten
|
|
14
25
|
end
|
15
26
|
|
16
27
|
# Returns the URL for a grayscale placekitten with the given
|
17
|
-
# width and height.
|
28
|
+
# width and height. If the width is given but the height
|
29
|
+
# is not, the image will be square.
|
18
30
|
#
|
19
31
|
# @param [Number] width the width of the placekitten
|
20
32
|
# @param [Number] height the height of the placekitten
|
21
|
-
def self.grayscale(width =
|
33
|
+
def self.grayscale(width = nil, height = nil)
|
22
34
|
self.image(width, height, true)
|
23
35
|
end
|
24
36
|
|
@@ -12,4 +12,9 @@ class KittenRailsTest < Test::Unit::TestCase
|
|
12
12
|
image = placekitten_gray(400, 500)
|
13
13
|
assert_equal "http://placekitten.com/g/400/500", image
|
14
14
|
end
|
15
|
+
|
16
|
+
def test_placekitten_grayscale_helper
|
17
|
+
image = placekitten_grayscale(400, 500)
|
18
|
+
assert_equal "http://placekitten.com/g/400/500", image
|
19
|
+
end
|
15
20
|
end
|
data/test/placekitten_test.rb
CHANGED
@@ -2,6 +2,16 @@ require 'placekitten'
|
|
2
2
|
require 'test/unit'
|
3
3
|
|
4
4
|
class KittenTest < Test::Unit::TestCase
|
5
|
+
def test_no_params
|
6
|
+
image = PlaceKitten.image
|
7
|
+
assert_equal "http://placekitten.com/#{PlaceKitten::DEFAULT_WIDTH}/#{PlaceKitten::DEFAULT_HEIGHT}", image
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_width_only
|
11
|
+
image = PlaceKitten.image(500)
|
12
|
+
assert_equal "http://placekitten.com/500/500", image
|
13
|
+
end
|
14
|
+
|
5
15
|
def test_width_height
|
6
16
|
image = PlaceKitten.image(300, 200)
|
7
17
|
assert_equal "http://placekitten.com/300/200", image
|
@@ -17,6 +27,16 @@ class KittenTest < Test::Unit::TestCase
|
|
17
27
|
assert_equal "http://placekitten.com/g/100/300", image
|
18
28
|
end
|
19
29
|
|
30
|
+
def test_grayscale_no_params
|
31
|
+
image = PlaceKitten.gray
|
32
|
+
assert_equal "http://placekitten.com/g/#{PlaceKitten::DEFAULT_WIDTH}/#{PlaceKitten::DEFAULT_HEIGHT}", image
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_grayscale_width_only
|
36
|
+
image = PlaceKitten.gray(500)
|
37
|
+
assert_equal "http://placekitten.com/g/500/500", image
|
38
|
+
end
|
39
|
+
|
20
40
|
def test_grayscale_method
|
21
41
|
image = PlaceKitten.grayscale(200, 400)
|
22
42
|
assert_equal "http://placekitten.com/g/200/400", image
|