placeholdit 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 ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .DS_Store
19
+ .rvmrc
20
+ test_rails_project
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in placeholdit.gemspec
4
+ gemspec
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
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -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)
@@ -0,0 +1,7 @@
1
+ module Placeholdit
2
+ class Railtie < Rails::Railtie
3
+ initializer "placeholdit.view_helpers" do
4
+ ActionView::Base.send :include, ViewHelpers
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module Placeholdit
2
+ VERSION = "0.0.1"
3
+ end
@@ -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
@@ -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