placebear 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b8b6e75cabf45a0d5d08eeb4e90926c0e0974cde
4
- data.tar.gz: b205788bb90f2a5c5e7b7ec9b3c7329e5553a130
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NDM5Mjc4NGJmMmNiNzUyMzE5ZDEzNDY4MjYxYzI4OWEyODhmNzUzYg==
5
+ data.tar.gz: !binary |-
6
+ OTcwZTE2Zjk1OTZlMzAzY2JhYjA4MjZmM2E0M2FjNzFiMmQzMjBmNw==
5
7
  SHA512:
6
- metadata.gz: ea8856f5f9680663714ba9812f8c4eef94c0ba19c58e2b2ae078a6f2dd4c481f3e78d32b4aae01a719bfa7fe21988cfe7bc1f8a54ebaac73f4b43943d41e980e
7
- data.tar.gz: 3bdd2a93668c83d5176cefc0afcf0f65fb941d6169d0108f0004597b12b8647d930563b1157eaa6ab78500ea6a72222d60747cc41c0bd48fe5f99f89b507007e
8
+ metadata.gz: !binary |-
9
+ Njc1NzUzOGY2NWY4YWNlY2Q1MjYxM2U4YzA0NzAwYmQyMjAwZjQ5MTI2Zjc4
10
+ YzViYTQ1NjM5ODU3ZTQxZmU2YmU1OTlmOGIzMzFmODM0NGNlMmQ4NzU5YmQ0
11
+ MGJhNzNkYWQ2NmU4ZDU3MTMwNzUxNDJhZWNjMGEwNWFlMmRmZDM=
12
+ data.tar.gz: !binary |-
13
+ ODAzNjAzYmU3Nzk0NzhlOWM3OGRhNDk2ZmQwODg1MWM1NTQwNzdhNzU1M2Rh
14
+ MjM5NjQzOGRjMzYyODAwNjU1YjZjNDA2M2YzMWNkZTI4MDcyN2ZlNWQwNGEw
15
+ ZWZhODdmNDdhZjE4NDZkNTExMjAyYWM3OGJkYjk2NzMyNzBmNWE=
data/README.md CHANGED
@@ -23,6 +23,45 @@ Or install it yourself as:
23
23
  ```ruby
24
24
  <%= place_bear 200, 400 %>
25
25
  <%= place_bear_gray 200 %>
26
+
27
+ <%= place_bear 200, 400, img_class: 'class-image_element' %>
28
+
29
+ <%= place_bear 200, 400, grayscale: true %>
30
+ ```
31
+
32
+ ###The following are all the same
33
+ ```ruby
34
+ PlaceBear.image
35
+ PlaceBear.bear
36
+ place_bear
37
+ place_bear(300)
38
+ place_bear(300,300)
39
+ ```
40
+ All of these return the following html
41
+ ```html
42
+ <img src='http://placebear.com/300/300' />
43
+ ```
44
+
45
+ ###The grayscaled version
46
+ ```ruby
47
+ PlaceBear.grayscale
48
+ PlaceBear.gray
49
+ place_bear_grayscale
50
+ place_bear_gray
51
+ place_bear_gray(300)
52
+ place_bear_gray(300, 300)
53
+ ```
54
+ which all return the following html
55
+ ```html
56
+ <img src='http://placebear.com/g/300/300' />
57
+ ```
58
+
59
+ ###With a custom class
60
+ ```ruby
61
+ place_bear_gray(300, nil, img_class: 'img-place_bear')
62
+ ```
63
+ ```html
64
+ <img src='http://placebear.com/g/300/300' class='img-place-bear' />
26
65
  ```
27
66
 
28
67
  ## Contributing
@@ -1,12 +1,14 @@
1
1
  module PlaceBear::Helpers
2
2
  # @see PlaceBear.image
3
- def place_bear(width = nil, height = nil, grayscale = false, img_class: nil)
4
- PlaceBear.image(width, height, grayscale: grayscale, img_class: img_class)
3
+ def place_bear(width = nil, height = nil, options = {})
4
+ options[:img_class] ||= nil
5
+ PlaceBear.image(width, height, grayscale: false, img_class: options[:img_class])
5
6
  end
6
7
 
7
8
  # @see PlaceBear.grayscale
8
- def place_bear_grayscale(width = nil, height = nil, img_class: nil)
9
- PlaceBear.grayscale(width, height, img_class: img_class)
9
+ def place_bear_grayscale(width = nil, height = nil, options = {})
10
+ options[:img_class] ||= nil
11
+ PlaceBear.grayscale(width, height, img_class: options[:img_class])
10
12
  end
11
13
  alias place_bear_gray place_bear_grayscale
12
14
  end
@@ -1,8 +1,7 @@
1
- require 'active_support/all'
1
+ require 'cgi'
2
2
 
3
3
  class PlaceBear
4
- DEFAULT_WIDTH = 300
5
- DEFAULT_HEIGHT = 300
4
+ DEFAULT_SIZE = 300
6
5
 
7
6
  # Returns the URL for an optionally grayscale placebear with
8
7
  # the given width and height. If the width is given but the height
@@ -11,19 +10,15 @@ class PlaceBear
11
10
  # @param [Number] width the width of the placebear
12
11
  # @param [Number] height the height of the placebear
13
12
  # @param [Boolean] grayscale whether or not to make the placebear grayscale
14
- def self.image(width = nil, height = nil, grayscale: false, img_class: nil )
15
- if width.nil?
16
- width = DEFAULT_WIDTH
17
- height = DEFAULT_HEIGHT
18
- elsif height.nil?
19
- height = width
20
- end
13
+ def self.image(width = nil, height = nil, options = {} )
14
+ options[:grayscale] ||= false
15
+ options[:img_class] ||= nil
16
+ width = height if width.nil?
17
+ height = width if height.nil?
18
+ width = height = DEFAULT_SIZE if width.nil? && height.nil?
21
19
 
22
- if grayscale.present?
23
- "<img src='http://placebear.com/g/#{width}/#{height}' #{"class='"+img_class+"'" if img_class.present?}>".html_safe
24
- else
25
- "<img src='http://placebear.com/#{width}/#{height}' #{"class='"+img_class+"'" if img_class.present?}>".html_safe
26
- end
20
+ img_tag = image_string(width, height, options[:grayscale], options[:img_class])
21
+ CGI::escapeHTML(img_tag)
27
22
  end
28
23
 
29
24
  # Returns the URL for a grayscale placebear with the given
@@ -32,12 +27,24 @@ class PlaceBear
32
27
  #
33
28
  # @param [Number] width the width of the placebear
34
29
  # @param [Number] height the height of the placebear
35
- def self.grayscale(width = nil, height = nil, img_class: nil)
36
- self.image(width, height, grayscale: true, img_class: img_class)
30
+ def self.grayscale(width = nil, height = nil, options = {})
31
+ options ||= {}
32
+ options[:img_class] ||= nil
33
+ self.image(width, height, grayscale: true, img_class: options[:img_class])
37
34
  end
38
35
 
39
36
  class << self
40
37
  alias_method :bear, :image
41
38
  alias_method :gray, :grayscale
42
39
  end
40
+
41
+ private
42
+
43
+ def self.image_string(width, height, grayscale, img_class)
44
+ img_tag = "<img src='http://placebear.com/"
45
+ img_tag +='g/' if grayscale
46
+ img_tag += "#{width}/#{height}'"
47
+ img_tag += " class='#{img_class}'" unless img_class.nil?
48
+ img_tag += ' />'
49
+ end
43
50
  end
@@ -1,3 +1,3 @@
1
1
  module Placebear
2
- VERSION = "0.0.3"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -9,18 +9,17 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["dannysperry"]
10
10
  spec.email = ["danny.sperry@gmail.com"]
11
11
  spec.summary = %q{a simple rails helper method for writting placebear image tags in rails}
12
- spec.description = %q{PlaceBear's code is taken heavily from https://github.com/BinaryMuse/placekitten}
12
+ spec.description = %q{A simple ruby wrapper around the http://placebear.com library}
13
13
  spec.homepage = ""
14
14
  spec.license = "MIT"
15
15
  spec.platform = Gem::Platform::RUBY
16
+ spec.required_ruby_version = '>= 1.9.3'
16
17
 
17
18
  spec.files = `git ls-files -z`.split("\x0")
18
19
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
20
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
21
  spec.require_paths = ["lib"]
21
22
 
22
- spec.add_dependency "activesupport"
23
-
24
23
  spec.add_development_dependency "bundler", "~> 1.7"
25
24
  spec.add_development_dependency "rake", "~> 10.0"
26
25
  spec.add_development_dependency "minitest", "~> 4.7.3"
@@ -5,19 +5,27 @@ class PlaceBearHelpersTest < Minitest::Unit::TestCase
5
5
  include PlaceBear::Helpers
6
6
 
7
7
  def test_placebear_helper
8
- assert_equal "<img src='http://placebear.com/300/300' >".html_safe, place_bear(300)
8
+ assert_equal "&lt;img src='http://placebear.com/300/300' /&gt;", place_bear(300)
9
9
  end
10
10
 
11
11
  def test_placebear_grayscale_helper
12
- assert_equal "<img src='http://placebear.com/g/300/300' >".html_safe, place_bear_grayscale(300)
12
+ assert_equal "&lt;img src='http://placebear.com/g/300/300' /&gt;", place_bear_grayscale(300)
13
13
  end
14
14
 
15
15
  def test_placebear_gray_alias
16
- assert_equal "<img src='http://placebear.com/g/500/200' >".html_safe, place_bear_gray(500,200)
16
+ assert_equal "&lt;img src='http://placebear.com/g/500/200' /&gt;", place_bear_gray(500,200)
17
17
  end
18
18
 
19
19
  def test_placebear_gray_with_no_params
20
- assert_equal "<img src='http://placebear.com/g/300/300' >".html_safe, place_bear_gray
20
+ assert_equal "&lt;img src='http://placebear.com/g/300/300' /&gt;", place_bear_gray
21
+ end
22
+
23
+ def test_placebear_with_image_class
24
+ assert_equal "&lt;img src='http://placebear.com/300/300' class='some_class' /&gt;", place_bear(300, 300, img_class: 'some_class')
25
+ end
26
+
27
+ def test_placebear_gray_with_image_class
28
+ assert_equal "&lt;img src='http://placebear.com/g/300/300' class='some_class' /&gt;", place_bear_gray(300, 300, img_class: 'some_class')
21
29
  end
22
30
 
23
31
  end
@@ -2,37 +2,38 @@ require 'placebear'
2
2
  require 'test_helper'
3
3
 
4
4
  class PlaceBearTest < Minitest::Unit::TestCase
5
- def test_returns_activesupport_safebuffer
6
- assert_equal PlaceBear.image(400).class, ActiveSupport::SafeBuffer
5
+ def test_grayscale
6
+ assert_equal "&lt;img src='http://placebear.com/g/400/400' /&gt;", PlaceBear.grayscale(400)
7
7
  end
8
8
 
9
- def test_grayscale
10
- assert_equal "<img src='http://placebear.com/g/400/400' >".html_safe, PlaceBear.grayscale(400)
9
+ def test_placebear_defaults_to_300_with_no_params
10
+ assert_equal "&lt;img src='http://placebear.com/300/300' /&gt;", PlaceBear.image
11
11
  end
12
12
 
13
- def test_placebear_without_params
14
- assert_equal "<img src='http://placebear.com/300/300' >".html_safe, PlaceBear.image
13
+ def test_placebear_height_equals_width_if_height_is_nil
14
+ assert_equal "&lt;img src='http://placebear.com/400/400' /&gt;", PlaceBear.image(400)
15
+ assert_equal "&lt;img src='http://placebear.com/400/400' /&gt;", PlaceBear.image(400, nil)
15
16
  end
16
17
 
17
- def test_placebear
18
- assert_equal "<img src='http://placebear.com/400/400' >".html_safe, PlaceBear.image(400)
18
+ def test_placebear_width_equals_height_if_width_is_nil
19
+ assert_equal "&lt;img src='http://placebear.com/400/400' /&gt;", PlaceBear.image(nil, 400)
19
20
  end
20
21
 
21
22
  def test_bear_alias
22
- assert_equal "<img src='http://placebear.com/400/400' >".html_safe, PlaceBear.image(400)
23
+ assert_equal "&lt;img src='http://placebear.com/400/400' /&gt;", PlaceBear.image(400)
23
24
  end
24
25
 
25
26
  def test_gray_alias
26
- assert_equal "<img src='http://placebear.com/g/300/300' >".html_safe, PlaceBear.grayscale(300)
27
+ assert_equal "&lt;img src='http://placebear.com/g/300/300' /&gt;", PlaceBear.grayscale(300)
27
28
  end
28
29
 
29
30
  def test_adds_img_class
30
- assert_equal "<img src='http://placebear.com/400/400' class='some_class'>".html_safe, PlaceBear.image(400, 400, img_class:'some_class')
31
+ assert_equal "&lt;img src='http://placebear.com/400/400' class='some_class' /&gt;", PlaceBear.image(400, 400, img_class: 'some_class', grayscale: false)
31
32
  end
32
33
 
33
34
  def test_adds_img_class_to_grayscale
34
- assert_equal "<img src='http://placebear.com/g/400/400' class='some_class'>".html_safe, PlaceBear.grayscale(400, 400, img_class:'some_class')
35
- assert_equal "<img src='http://placebear.com/g/400/400' class='some_class'>".html_safe, PlaceBear.image(400, 400, img_class:'some_class', grayscale: true)
35
+ assert_equal "&lt;img src='http://placebear.com/g/400/400' class='some_class' /&gt;", PlaceBear.grayscale(400, 400, img_class: 'some_class')
36
+ assert_equal "&lt;img src='http://placebear.com/g/400/400' class='some_class' /&gt;", PlaceBear.image(400, 400, grayscale: true, img_class: 'some_class')
36
37
  end
37
38
 
38
39
  end
metadata CHANGED
@@ -1,79 +1,65 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: placebear
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - dannysperry
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-31 00:00:00.000000000 Z
11
+ date: 2015-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: activesupport
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: bundler
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
- - - "~>"
17
+ - - ~>
32
18
  - !ruby/object:Gem::Version
33
19
  version: '1.7'
34
20
  type: :development
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
- - - "~>"
24
+ - - ~>
39
25
  - !ruby/object:Gem::Version
40
26
  version: '1.7'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rake
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
- - - "~>"
31
+ - - ~>
46
32
  - !ruby/object:Gem::Version
47
33
  version: '10.0'
48
34
  type: :development
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
- - - "~>"
38
+ - - ~>
53
39
  - !ruby/object:Gem::Version
54
40
  version: '10.0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: minitest
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
- - - "~>"
45
+ - - ~>
60
46
  - !ruby/object:Gem::Version
61
47
  version: 4.7.3
62
48
  type: :development
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
- - - "~>"
52
+ - - ~>
67
53
  - !ruby/object:Gem::Version
68
54
  version: 4.7.3
69
- description: PlaceBear's code is taken heavily from https://github.com/BinaryMuse/placekitten
55
+ description: A simple ruby wrapper around the http://placebear.com library
70
56
  email:
71
57
  - danny.sperry@gmail.com
72
58
  executables: []
73
59
  extensions: []
74
60
  extra_rdoc_files: []
75
61
  files:
76
- - ".gitignore"
62
+ - .gitignore
77
63
  - Gemfile
78
64
  - LICENSE.txt
79
65
  - README.md
@@ -82,7 +68,6 @@ files:
82
68
  - lib/placebear/helpers.rb
83
69
  - lib/placebear/place_bear.rb
84
70
  - lib/placebear/version.rb
85
- - placebear-0.0.1.gem
86
71
  - placebear.gemspec
87
72
  - test/placebear_helpers_test.rb
88
73
  - test/placebear_test.rb
@@ -97,17 +82,17 @@ require_paths:
97
82
  - lib
98
83
  required_ruby_version: !ruby/object:Gem::Requirement
99
84
  requirements:
100
- - - ">="
85
+ - - ! '>='
101
86
  - !ruby/object:Gem::Version
102
- version: '0'
87
+ version: 1.9.3
103
88
  required_rubygems_version: !ruby/object:Gem::Requirement
104
89
  requirements:
105
- - - ">="
90
+ - - ! '>='
106
91
  - !ruby/object:Gem::Version
107
92
  version: '0'
108
93
  requirements: []
109
94
  rubyforge_project:
110
- rubygems_version: 2.4.1
95
+ rubygems_version: 2.4.2
111
96
  signing_key:
112
97
  specification_version: 4
113
98
  summary: a simple rails helper method for writting placebear image tags in rails