placeholder 0.0.1 → 0.0.2
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 +9 -3
- data/VERSION +1 -1
- data/lib/placeholder.rb +14 -8
- data/placeholder.gemspec +2 -2
- data/spec/placeholder_spec.rb +13 -9
- metadata +4 -4
data/README.markdown
CHANGED
@@ -12,11 +12,17 @@ Install the gem: `[sudo] gem install placeholder`
|
|
12
12
|
|
13
13
|
Usage
|
14
14
|
-----
|
15
|
-
Placeholder requires a
|
15
|
+
Placeholder requires a size as the first argument and can accept `:text`, `:fg_color` and `:bg_color` arguments.
|
16
16
|
|
17
|
-
|
17
|
+
Examples
|
18
|
+
--------
|
19
|
+
This will place a 200x300 image placeholder into your page with the text "Whoa Now". The default text is the image size.
|
18
20
|
|
19
|
-
`= Placeholder.new(
|
21
|
+
`= Placeholder.new("200x300", :text => "Whoa Now")`
|
22
|
+
|
23
|
+
If you just need a square image, simply do:
|
24
|
+
|
25
|
+
`= Placeholder.new(100)`
|
20
26
|
|
21
27
|
About the Author
|
22
28
|
----------------
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/lib/placeholder.rb
CHANGED
@@ -2,16 +2,21 @@ class Placeholder
|
|
2
2
|
|
3
3
|
attr_accessor :size, :height, :width, :bg_color, :fg_color, :text
|
4
4
|
|
5
|
-
def initialize(options = {})
|
6
|
-
|
7
|
-
|
5
|
+
def initialize(size, options = {})
|
6
|
+
measure(size)
|
7
|
+
options.each{|(k,v)| instance_variable_set("@#{k}", v)}
|
8
|
+
end
|
9
|
+
|
10
|
+
def measure(size)
|
11
|
+
if size =~ /\d+x\d+/
|
12
|
+
@width, @height = size.split("x").map{|s| s.to_i}
|
13
|
+
else
|
14
|
+
@width, @height = size.to_i, size.to_i
|
8
15
|
end
|
9
|
-
|
10
|
-
@text.gsub!(" ", "+") unless @text == nil
|
11
16
|
end
|
12
17
|
|
13
18
|
def to_s
|
14
|
-
"<img src=\"#{url}\" alt=\"placeholder\"
|
19
|
+
"<img src=\"#{url}\" alt=\"placeholder\" />"
|
15
20
|
end
|
16
21
|
|
17
22
|
def url
|
@@ -19,11 +24,12 @@ class Placeholder
|
|
19
24
|
end
|
20
25
|
|
21
26
|
def size_str
|
22
|
-
|
27
|
+
"#{@width}x#{@height}"
|
23
28
|
end
|
24
29
|
|
25
30
|
def text_str
|
26
|
-
|
31
|
+
return "" if @text == nil
|
32
|
+
"&text=" + @text.gsub(" ", "+")
|
27
33
|
end
|
28
34
|
|
29
35
|
def color_str
|
data/placeholder.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{placeholder}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Matt Darby"]
|
12
|
-
s.date = %q{2010-08-
|
12
|
+
s.date = %q{2010-08-11}
|
13
13
|
s.description = %q{Easy image placeholders via Placehold.it}
|
14
14
|
s.email = %q{matt@protectedmethod.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/spec/placeholder_spec.rb
CHANGED
@@ -3,23 +3,27 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
3
3
|
describe "Placeholder" do
|
4
4
|
|
5
5
|
it "should understand its size" do
|
6
|
-
p = Placeholder.new(
|
7
|
-
p.to_s.should == "<img src=\"http://placehold.it/
|
6
|
+
p = Placeholder.new(300)
|
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
|
-
p = Placeholder.new(
|
12
|
-
p.to_s.should == "<img src=\"http://placehold.it/200x300\" alt=\"placeholder\"
|
11
|
+
p = Placeholder.new("200x300")
|
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 color" do
|
16
|
-
p = Placeholder.new(
|
17
|
-
p.to_s.should == "<img src=\"http://placehold.it/
|
16
|
+
p = Placeholder.new(400, :bg_color => "FFFFFF", :fg_color => "FE0000")
|
17
|
+
p.to_s.should == "<img src=\"http://placehold.it/400x400/FFFFFF/FE0000\" alt=\"placeholder\" />"
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should know about its text" do
|
21
|
-
p = Placeholder.new(
|
22
|
-
p.to_s.should == "<img src=\"http://placehold.it/
|
21
|
+
p = Placeholder.new(400, :text => "Sample Text")
|
22
|
+
p.to_s.should == "<img src=\"http://placehold.it/400x400&text=Sample+Text\" alt=\"placeholder\" />"
|
23
23
|
end
|
24
24
|
|
25
|
-
|
25
|
+
it "should throw an error when a size isn't passed in" do
|
26
|
+
lambda{ Placeholder.new }.should raise_error
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
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: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Matt Darby
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-08-
|
18
|
+
date: 2010-08-11 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|