placehold 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +12 -27
- data/lib/placehold.rb +13 -34
- data/lib/placehold/version.rb +1 -1
- data/placehold.gemspec +2 -4
- metadata +5 -21
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Placehold
|
2
2
|
|
3
|
-
Placehold is a simple gem that generates placeholder images in Rails. I made it because I was tired of having to look up placeholder image sites to remember what the URLS were.
|
3
|
+
Placehold is a simple gem that generates placeholder images in Rails. I made it because I was tired of having to look up placeholder image sites to remember what the URLS were. Currently the placeholder site used in this gem is [placehold.it](http://placehold.it)
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,38 +18,23 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
To generate a placeholder image,
|
22
|
-
|
23
|
-
<%= Place.hold width, height, type, html_options %>
|
24
|
-
|
25
|
-
Change the values width and height to whatever dimension you want your image to be. The type value can be any of the following:
|
21
|
+
To generate a placeholder image, do the following:
|
26
22
|
|
27
|
-
|
28
|
-
- animals
|
29
|
-
- city
|
30
|
-
- food
|
31
|
-
- nightlife
|
32
|
-
- fashion
|
33
|
-
- people
|
34
|
-
- nature
|
35
|
-
- sports
|
36
|
-
- technics
|
37
|
-
- transport
|
23
|
+
Include the Placehold module somewhere in your application/code
|
38
24
|
|
39
|
-
|
25
|
+
include Placehold
|
40
26
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
27
|
+
Then use the following where you want the placehold image to appear:
|
28
|
+
|
29
|
+
<%= placeholder_image width: 300, height: 150, bgcolor: '04acec', fgcolor: 'fff' %>
|
30
|
+
# => <img src="http://placehold.it/300x150/04acec/fff" alt="Placehold Image">
|
45
31
|
|
46
|
-
|
32
|
+
All the parameters in the above example are optional, and the defaults for **width** and **height** are **300** and **150** respectively.
|
47
33
|
|
48
|
-
|
34
|
+
## Planned updates
|
49
35
|
|
50
|
-
|
51
|
-
|
52
|
-
<img src="http://lorempixum.com/900/350/people" id="headerImage" alt="Header Image">
|
36
|
+
In the future I plan to add some other placeholder sites such as lorempixel.com.
|
37
|
+
Possibly going to add function to save placeholder image to assets folder so as not requesting new one each time you refresh your page (Rails apps).
|
53
38
|
|
54
39
|
## Contributing
|
55
40
|
|
data/lib/placehold.rb
CHANGED
@@ -1,41 +1,20 @@
|
|
1
|
-
|
2
|
-
require 'htmlentities'
|
1
|
+
module Placehold
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
@@types = ['abstract', 'food', 'people', 'technics', 'animals', 'nightlife', 'nature', 'transport', 'city', 'fashion', 'sports']
|
9
|
-
|
10
|
-
def valid_type? value
|
11
|
-
if @@types.include? value || value == ''
|
12
|
-
return true
|
13
|
-
else
|
14
|
-
return false
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def check_values width, height, type, opts
|
19
|
-
opts.each do |k,v|
|
20
|
-
instance_variable_set "@#{k}", v
|
21
|
-
end
|
22
|
-
return_string width, height, type, @id == nil ? nil : "id='#{@id}'", @class == nil ? nil : "class='#{@class}'", @style == nil ? nil : "style='#{@style}'", @alt == nil ? "alt='Placeholder Image'" : "alt='#{@alt}'"
|
3
|
+
def placehold_image args = {}
|
4
|
+
args.each do |key, val|
|
5
|
+
instance_variable_set "@#{key}", val
|
23
6
|
end
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
def self.hold width, height, type = nil, html_opts = {}
|
31
|
-
image = Holding.new
|
32
|
-
if image.valid_type? type
|
33
|
-
type = type
|
7
|
+
@width = 350 unless @width
|
8
|
+
@height = 150 unless @height
|
9
|
+
if @bgcolor and @fgcolor
|
10
|
+
colors = "/#{@bgcolor}/#{@fgcolor}"
|
11
|
+
elsif @bgcolor and !@fgcolor
|
12
|
+
colors = "/#{@bgcolor}"
|
34
13
|
else
|
35
|
-
|
14
|
+
colors = "/"
|
36
15
|
end
|
37
|
-
image.
|
16
|
+
image = "<img src='http://placehold.it/#{@width}x#{@height}#{colors}' alt='Placehold Image'>"
|
17
|
+
return image
|
38
18
|
end
|
39
|
-
|
40
19
|
|
41
20
|
end
|
data/lib/placehold/version.rb
CHANGED
data/placehold.gemspec
CHANGED
@@ -3,13 +3,11 @@ require File.expand_path('../lib/placehold/version', __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.authors = ["Greg Chapple"]
|
6
|
-
gem.email = ["
|
6
|
+
gem.email = ["info@gregchapple.com"]
|
7
7
|
gem.description = %q{A simple gem to generate placeholder images}
|
8
|
-
gem.summary = %q{A simple gem that
|
8
|
+
gem.summary = %q{A simple gem that returns an image generated by popular placeholder services}
|
9
9
|
gem.homepage = "http://github.com/gregchapple/placehold"
|
10
10
|
|
11
|
-
gem.add_dependency 'htmlentities'
|
12
|
-
|
13
11
|
gem.files = `git ls-files`.split($\)
|
14
12
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
15
13
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: placehold
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,27 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: htmlentities
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ! '>='
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '0'
|
22
|
-
type: :runtime
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ! '>='
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '0'
|
12
|
+
date: 2013-01-04 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
30
14
|
description: A simple gem to generate placeholder images
|
31
15
|
email:
|
32
|
-
-
|
16
|
+
- info@gregchapple.com
|
33
17
|
executables: []
|
34
18
|
extensions: []
|
35
19
|
extra_rdoc_files: []
|
@@ -65,5 +49,5 @@ rubyforge_project:
|
|
65
49
|
rubygems_version: 1.8.24
|
66
50
|
signing_key:
|
67
51
|
specification_version: 3
|
68
|
-
summary: A simple gem that
|
52
|
+
summary: A simple gem that returns an image generated by popular placeholder services
|
69
53
|
test_files: []
|