placeholdit 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +20 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +44 -0
- data/Rakefile +2 -0
- data/lib/placeholdit.rb +45 -0
- data/lib/placeholdit/railtie.rb +7 -0
- data/lib/placeholdit/version.rb +3 -0
- data/placeholdit.gemspec +20 -0
- data/spec/placeholdit_spec.rb +37 -0
- data/spec/spec_helper.rb +1 -0
- metadata +71 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Jeff Mehlhoff
|
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,44 @@
|
|
1
|
+
# Placeholdit
|
2
|
+
|
3
|
+
A Rails view helper for placeholder images via http://placehold.it
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'placeholdit'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install placeholdit
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
A basic 500x500 placeholder image:
|
22
|
+
|
23
|
+
$ <%= placeholdit_image_tag "500" %>
|
24
|
+
|
25
|
+
The same placeholder image with custom text:
|
26
|
+
|
27
|
+
$ <%= placeholdit_image_tag "500", text: "Buy me!" %>
|
28
|
+
|
29
|
+
The same placeholder image with a blue background:
|
30
|
+
|
31
|
+
$ <%= placeholdit_image_tag "500", text: "Buy me!", background_color: '#004eff' %>
|
32
|
+
|
33
|
+
The same placeholder image with a blue background and red text (not recommended):
|
34
|
+
|
35
|
+
$ <%= placeholdit_image_tag "500", text: "Buy me!", background_color: '#004eff', text_color: '#ff0000' %>
|
36
|
+
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
1. Fork it
|
41
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
42
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
43
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
44
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/placeholdit.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require "placeholdit/version"
|
2
|
+
|
3
|
+
module Placeholdit
|
4
|
+
module ViewHelpers
|
5
|
+
def placeholdit_image_tag(size, opts={})
|
6
|
+
|
7
|
+
size = "#{size}" unless size.is_a?(String)
|
8
|
+
src = "http://placehold.it/#{size}"
|
9
|
+
|
10
|
+
config = {
|
11
|
+
:alt => (opts[:text] || "A placeholder image"),
|
12
|
+
:class => "placeholder",
|
13
|
+
:height => (size.split('x')[1] || size.split('x')[0]),
|
14
|
+
:width => size.split('x')[0]
|
15
|
+
}.merge!(opts)
|
16
|
+
|
17
|
+
# Placehold.it preferences
|
18
|
+
if config[:background_color]
|
19
|
+
src += "/#{remove_hex_pound(config[:background_color])}"
|
20
|
+
end
|
21
|
+
if config[:text_color]
|
22
|
+
src += "/#{remove_hex_pound(config[:text_color])}"
|
23
|
+
end
|
24
|
+
if config[:text]
|
25
|
+
src += "&text=#{config[:text]}"
|
26
|
+
end
|
27
|
+
|
28
|
+
image_tag = "<img src='#{src}' alt='#{config[:alt]}' class='#{config[:class]}' height='#{config[:height]}' width='#{config[:width]}' />"
|
29
|
+
return image_tag.html_safe if defined?(Rails)
|
30
|
+
image_tag
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def remove_hex_pound(str)
|
36
|
+
if str.include?("#")
|
37
|
+
return str.delete("#")
|
38
|
+
end
|
39
|
+
str
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
require 'placeholdit/railtie' if defined?(Rails)
|
data/placeholdit.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/placeholdit/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Jeff Mehlhoff"]
|
6
|
+
gem.email = ["jeffmehlhoff@mac.com"]
|
7
|
+
gem.description = %q{A Rails view helper for placeholder images via http://placehold.it}
|
8
|
+
gem.summary = %q{A Rails view helper for placeholder images via http://placehold.it}
|
9
|
+
gem.homepage = "http://github.com/ohokay/placeholdit"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "placeholdit"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Placeholdit::VERSION
|
17
|
+
|
18
|
+
gem.add_development_dependency "rspec"
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class MyView
|
4
|
+
include Placeholdit::ViewHelpers
|
5
|
+
end
|
6
|
+
|
7
|
+
describe Placeholdit::ViewHelpers do
|
8
|
+
let(:view) { MyView.new }
|
9
|
+
|
10
|
+
it "should accept integers as params" do
|
11
|
+
view.placeholdit_image_tag(500).should == "<img src='http://placehold.it/500' alt='A placeholder image' class='placeholder' height='500' width='500' />"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should accept a string" do
|
15
|
+
view.placeholdit_image_tag("500").should == "<img src='http://placehold.it/500' alt='A placeholder image' class='placeholder' height='500' width='500' />"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should accept a componded WxH" do
|
19
|
+
view.placeholdit_image_tag("500x500").should == "<img src='http://placehold.it/500x500' alt='A placeholder image' class='placeholder' height='500' width='500' />"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should accept custom text" do
|
23
|
+
view.placeholdit_image_tag("500x500", text: 'Buy me!').should == "<img src='http://placehold.it/500x500&text=Buy me!' alt='Buy me!' class='placeholder' height='500' width='500' />"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should accept custom colors" do
|
27
|
+
view.placeholdit_image_tag("500", text_color: 'fff', background_color: '000').should == "<img src='http://placehold.it/500/000/fff' alt='A placeholder image' class='placeholder' height='500' width='500' />"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should strip the pound from hex colors" do
|
31
|
+
view.placeholdit_image_tag("500", text_color: '#fff', background_color: '000').should == "<img src='http://placehold.it/500/000/fff' alt='A placeholder image' class='placeholder' height='500' width='500' />"
|
32
|
+
view.placeholdit_image_tag("500", text_color: '#fff', background_color: '#000000').should == "<img src='http://placehold.it/500/000000/fff' alt='A placeholder image' class='placeholder' height='500' width='500' />"
|
33
|
+
view.placeholdit_image_tag("500", text_color: 'fff', background_color: '#000000').should == "<img src='http://placehold.it/500/000000/fff' alt='A placeholder image' class='placeholder' height='500' width='500' />"
|
34
|
+
view.placeholdit_image_tag("500", text_color: 'ffffff', background_color: '#000000').should == "<img src='http://placehold.it/500/000000/ffffff' alt='A placeholder image' class='placeholder' height='500' width='500' />"
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'placeholdit'
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: placeholdit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jeff Mehlhoff
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-11 00:00:00.000000000 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
requirement: &70257118635060 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *70257118635060
|
26
|
+
description: A Rails view helper for placeholder images via http://placehold.it
|
27
|
+
email:
|
28
|
+
- jeffmehlhoff@mac.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- .gitignore
|
34
|
+
- Gemfile
|
35
|
+
- LICENSE
|
36
|
+
- README.md
|
37
|
+
- Rakefile
|
38
|
+
- lib/placeholdit.rb
|
39
|
+
- lib/placeholdit/railtie.rb
|
40
|
+
- lib/placeholdit/version.rb
|
41
|
+
- placeholdit.gemspec
|
42
|
+
- spec/placeholdit_spec.rb
|
43
|
+
- spec/spec_helper.rb
|
44
|
+
has_rdoc: true
|
45
|
+
homepage: http://github.com/ohokay/placeholdit
|
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.6.2
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: A Rails view helper for placeholder images via http://placehold.it
|
69
|
+
test_files:
|
70
|
+
- spec/placeholdit_spec.rb
|
71
|
+
- spec/spec_helper.rb
|