placehold 0.0.1
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/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +60 -0
- data/Rakefile +2 -0
- data/lib/placehold/version.rb +3 -0
- data/lib/placehold.rb +41 -0
- data/placehold.gemspec +19 -0
- metadata +69 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Greg Chapple
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Placehold
|
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.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'placehold'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install placehold
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
To generate a placeholder image, use the following code:
|
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:
|
26
|
+
|
27
|
+
- abstract
|
28
|
+
- animals
|
29
|
+
- city
|
30
|
+
- food
|
31
|
+
- nightlife
|
32
|
+
- fashion
|
33
|
+
- people
|
34
|
+
- nature
|
35
|
+
- sports
|
36
|
+
- technics
|
37
|
+
- transport
|
38
|
+
|
39
|
+
HTML_options is a hash that can contain paramaters such as:
|
40
|
+
|
41
|
+
- id
|
42
|
+
- class
|
43
|
+
- alt
|
44
|
+
- style
|
45
|
+
|
46
|
+
### Example
|
47
|
+
|
48
|
+
<%= Place.hold 900, 350, 'people', {id: 'headerImage', alt: 'Header Image'} %>
|
49
|
+
|
50
|
+
Will produce:
|
51
|
+
|
52
|
+
<img src="http://lorempixum.com/900/350/people" id="headerImage" alt="Header Image">
|
53
|
+
|
54
|
+
## Contributing
|
55
|
+
|
56
|
+
1. Fork it
|
57
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
58
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
59
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
60
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/placehold.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require "placehold/version"
|
2
|
+
require 'htmlentities'
|
3
|
+
|
4
|
+
module Place
|
5
|
+
|
6
|
+
class Holding
|
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}'"
|
23
|
+
end
|
24
|
+
|
25
|
+
def return_string width, height, type, id=nil, cls=nil, style=nil, alt=nil
|
26
|
+
"<img src='http://lorempixel.com/#{width}/#{height}/#{type}' #{id} #{cls} #{style} #{alt}>"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.hold width, height, type = nil, html_opts = {}
|
31
|
+
image = Holding.new
|
32
|
+
if image.valid_type? type
|
33
|
+
type = type
|
34
|
+
else
|
35
|
+
type = ''
|
36
|
+
end
|
37
|
+
image.check_values(width, height, type, html_opts).html_safe
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
end
|
data/placehold.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/placehold/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Greg Chapple"]
|
6
|
+
gem.email = ["gregchapple1@gmail.com"]
|
7
|
+
gem.description = %q{A simple gem to generate placeholder images}
|
8
|
+
gem.summary = %q{A simple gem that provides links to popular placeholder image services}
|
9
|
+
gem.homepage = "http://github.com/gregchapple/placehold"
|
10
|
+
|
11
|
+
gem.add_dependency 'htmlentities'
|
12
|
+
|
13
|
+
gem.files = `git ls-files`.split($\)
|
14
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
15
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
16
|
+
gem.name = "placehold"
|
17
|
+
gem.require_paths = ["lib"]
|
18
|
+
gem.version = Placehold::VERSION
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: placehold
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Greg Chapple
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-14 00:00:00.000000000 Z
|
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'
|
30
|
+
description: A simple gem to generate placeholder images
|
31
|
+
email:
|
32
|
+
- gregchapple1@gmail.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- lib/placehold.rb
|
43
|
+
- lib/placehold/version.rb
|
44
|
+
- placehold.gemspec
|
45
|
+
homepage: http://github.com/gregchapple/placehold
|
46
|
+
licenses: []
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.8.24
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: A simple gem that provides links to popular placeholder image services
|
69
|
+
test_files: []
|