placeholder 0.0.4 → 0.0.5
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.
- data/README.markdown +5 -1
- data/VERSION +1 -1
- data/lib/placeholder.rb +9 -2
- data/placeholder.gemspec +1 -1
- data/spec/placeholder_spec.rb +16 -6
- metadata +3 -3
data/README.markdown
CHANGED
@@ -28,6 +28,10 @@ If you just need a square image, simply do:
|
|
28
28
|
|
29
29
|
`= Placeholder.new(100)`
|
30
30
|
|
31
|
+
You can also pass CSS classes and an ID if you'd like:
|
32
|
+
|
33
|
+
`= Placeholder.new(80, :css_id => "gravatar", :css_classes => "active admin")`
|
34
|
+
|
31
35
|
About the Author
|
32
36
|
----------------
|
33
|
-
My name is [Matt Darby.](http://matt-darby.com) I’m a Partner and co-founder of [Protected Method LLC](http://www.protectedmethod.com) and hold a Master’s Degree in Computer Science from [Franklin University](http://www.franklin.edu) in sunny [Columbus, OH.](http://en.wikipedia.org/wiki/Columbus,_Ohio)
|
37
|
+
My name is [Matt Darby.](http://matt-darby.com) I’m a Partner and co-founder of [Protected Method LLC](http://www.protectedmethod.com) and hold a Master’s Degree in Computer Science from [Franklin University](http://www.franklin.edu) in sunny [Columbus, OH.](http://en.wikipedia.org/wiki/Columbus,_Ohio)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.5
|
data/lib/placeholder.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
class Placeholder
|
2
2
|
|
3
|
-
attr_accessor :height, :width, :bg_color, :fg_color, :text
|
3
|
+
attr_accessor :height, :width, :bg_color, :fg_color, :text, :css_classes, :css_id
|
4
4
|
|
5
5
|
def initialize(size, options = {})
|
6
6
|
measure(size)
|
@@ -16,7 +16,7 @@ class Placeholder
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def to_s
|
19
|
-
str = "<img src=\"#{url}\" alt=\"placeholder\" />"
|
19
|
+
str = "<img src=\"#{url}\" alt=\"placeholder\" #{css_stuff} />"
|
20
20
|
str.html_safe rescue str #Rails 3 sanitizes our little string.
|
21
21
|
end
|
22
22
|
|
@@ -44,4 +44,11 @@ class Placeholder
|
|
44
44
|
str
|
45
45
|
end
|
46
46
|
|
47
|
+
def css_stuff
|
48
|
+
str = ""
|
49
|
+
str += "class=\"#{@css_classes}\"" unless @css_classes.nil?
|
50
|
+
str += "id=\"#{@css_id}\"" unless @css_id.nil?
|
51
|
+
str
|
52
|
+
end
|
53
|
+
|
47
54
|
end
|
data/placeholder.gemspec
CHANGED
data/spec/placeholder_spec.rb
CHANGED
@@ -4,38 +4,48 @@ describe "Placeholder" do
|
|
4
4
|
|
5
5
|
it "should understand its size" do
|
6
6
|
p = Placeholder.new(300)
|
7
|
-
p.to_s.should == "<img src=\"http://placehold.it/300x300\" alt=\"placeholder\"
|
7
|
+
p.to_s.should == "<img src=\"http://placehold.it/300x300\" alt=\"placeholder\" />"
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should understand its height and width" do
|
11
11
|
p = Placeholder.new("200x300")
|
12
|
-
p.to_s.should == "<img src=\"http://placehold.it/200x300\" alt=\"placeholder\"
|
12
|
+
p.to_s.should == "<img src=\"http://placehold.it/200x300\" alt=\"placeholder\" />"
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should know about a bg_color" do
|
16
16
|
p = Placeholder.new(400, :bg_color => "FFFFFF")
|
17
|
-
p.to_s.should == "<img src=\"http://placehold.it/400x400/FFFFFF\" alt=\"placeholder\"
|
17
|
+
p.to_s.should == "<img src=\"http://placehold.it/400x400/FFFFFF\" alt=\"placeholder\" />"
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should know about a fg_color" do
|
21
21
|
p = Placeholder.new(400, :bg_color => "FFFFFF", :fg_color => "FE0000")
|
22
|
-
p.to_s.should == "<img src=\"http://placehold.it/400x400/FFFFFF/FE0000\" alt=\"placeholder\"
|
22
|
+
p.to_s.should == "<img src=\"http://placehold.it/400x400/FFFFFF/FE0000\" alt=\"placeholder\" />"
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should alert the user if they set :fg_color and not :bg_color" do
|
26
26
|
p = Placeholder.new(400, :fg_color => "FE0000")
|
27
|
-
p.to_s.should == "<img src=\"http://placehold.it/400x400/FE0000&text=Set+:bg_color+when+using+:fg_color\" alt=\"placeholder\"
|
27
|
+
p.to_s.should == "<img src=\"http://placehold.it/400x400/FE0000&text=Set+:bg_color+when+using+:fg_color\" alt=\"placeholder\" />"
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should know about its text" do
|
31
31
|
p = Placeholder.new(400, :text => "Sample Text")
|
32
|
-
p.to_s.should == "<img src=\"http://placehold.it/400x400&text=Sample+Text\" alt=\"placeholder\"
|
32
|
+
p.to_s.should == "<img src=\"http://placehold.it/400x400&text=Sample+Text\" alt=\"placeholder\" />"
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should throw an error when a size isn't passed in" do
|
36
36
|
lambda{ Placeholder.new }.should raise_error
|
37
37
|
end
|
38
38
|
|
39
|
+
it "should allow css_classes" do
|
40
|
+
p = Placeholder.new(300, :css_classes => "c1 c2")
|
41
|
+
p.to_s.should == "<img src=\"http://placehold.it/300x300\" alt=\"placeholder\" class=\"c1 c2\" />"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should allow css_id" do
|
45
|
+
p = Placeholder.new(300, :css_id => "gravatar")
|
46
|
+
p.to_s.should == "<img src=\"http://placehold.it/300x300\" alt=\"placeholder\" id=\"gravatar\" />"
|
47
|
+
end
|
48
|
+
|
39
49
|
context "in Rails 3" do
|
40
50
|
before do
|
41
51
|
class String
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: placeholder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 5
|
10
|
+
version: 0.0.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Matt Darby
|