lorem-image-ware 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Lorem::Image::Ware
1
+ # LoremImageWare
2
2
 
3
3
  Rack middleware for proxying requests to [lorempixel.com](http://lorempixel.com)
4
4
 
@@ -10,7 +10,7 @@ that after a few page loads, images should load much faster. Without such local
10
10
  caching you will be stuck hammering their server on every page load, and waiting a
11
11
  few seconds for images to fill in.
12
12
 
13
- It is recommended to only load the middleware in development environtments.
13
+ It is recommended to only load the middleware in development environments.
14
14
 
15
15
  ## Installation
16
16
 
@@ -53,6 +53,10 @@ lorem_image_tag(:height => 400, :width => 200, :tag => "sports", :class => "some
53
53
  The helper will add a class of `lorem-image` to tags for you, as well as populate the dimensions
54
54
  and set inline height and width styling on the image.
55
55
 
56
+ ## Todo
57
+
58
+ Use cache-control and ETag support for browser caching
59
+
56
60
  ## Contributing
57
61
 
58
62
  1. Fork it
@@ -9,10 +9,14 @@ module LoremImageWare
9
9
  end
10
10
 
11
11
  def url(params)
12
- tag = params[:tag] || "abstract"
13
- url = ["http://lorempixel.com", @grayscale ? "g" : nil, params[:width], params[:height], tag].compact.join("/")
14
- url += "/?r=#{rand(20)}"
15
- url
12
+ type = params[:type] || "abstract"
13
+
14
+ [
15
+ "http://lorempixel.com",
16
+ @grayscale ? "g" : nil,
17
+ params[:width], params[:height], type,
18
+ "?r=#{rand(20)}"
19
+ ].compact.join("/")
16
20
  end
17
21
  end
18
22
 
@@ -21,20 +25,30 @@ module LoremImageWare
21
25
  "/lorem"
22
26
  end
23
27
 
28
+ def default_lorem_image_height
29
+ 200
30
+ end
31
+
32
+ def default_lorem_image_width
33
+ 400
34
+ end
35
+
24
36
  def lorem_image_path(options = {})
25
- height = options.fetch(:height, 200)
26
- width = options.fetch(:width, 400)
27
- tag = options.fetch(:tag, "abstract")
37
+ height = options.fetch(:height, default_lorem_image_height)
38
+ width = options.fetch(:width, default_lorem_image_width)
39
+ type = options.fetch(:type, "abstract")
28
40
 
29
- "#{lorem_image_root}/image/#{width}/#{height}/#{tag}?r=#{rand(99)}"
41
+ "#{lorem_image_root}/image/#{width}/#{height}/#{type}?r=#{rand(99)}"
30
42
  end
31
43
 
32
44
  def lorem_image_tag(options = {})
33
- height = options.fetch(:height, 200)
34
- width = options.fetch(:width, 400)
45
+ height = options.fetch(:height, default_lorem_image_height)
46
+ width = options.fetch(:width, default_lorem_image_width)
35
47
  html_class = [options[:class], "lorem-image"].compact.join(" ")
36
48
 
37
- %Q{<img src="#{lorem_image_path(options)}" class="#{html_class}" width="#{width}" height="#{height}" style="height: #{height}px; width: #{width}px;" />}
49
+ html = %Q{<img src="#{lorem_image_path(options)}"}
50
+ html += %Q{ class="#{html_class}" width="#{width}" height="#{height}"}
51
+ html += %Q{ style="height: #{height}px; width: #{width}px;" />}
38
52
  end
39
53
  end
40
54
 
@@ -51,8 +65,8 @@ module LoremImageWare
51
65
  def _call(env)
52
66
  request = Rack::Request.new(env)
53
67
 
54
- if request.fullpath =~ %r{^#{root}/image/(\d+)/(\d+)/?(/(\S+))?}i
55
- url = provider.url(width: $1, height: $2, tag: $4)
68
+ if request.fullpath =~ %r{^#{root}/image/(\d+)/(\d+)/?(/?([a-z]+))?}i
69
+ url = provider.url(width: $1, height: $2, type: $4)
56
70
  serve_image(url)
57
71
  else
58
72
  @app.call(env)
@@ -1,3 +1,3 @@
1
1
  module LoremImageWare
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -13,12 +13,12 @@ class TestHelpers < MiniTest::Unit::TestCase
13
13
  end
14
14
 
15
15
  def test_image_path
16
- path = lorem_image_path(:height => 50, :width => 100, :tag => "sports")
16
+ path = lorem_image_path(:height => 50, :width => 100, :type => "sports")
17
17
  assert_match %r{^/lorem/image/100/50/sports\?r=\d+$}, path
18
18
  end
19
19
 
20
20
  def test_image_tag
21
- image_tag = lorem_image_tag(:height => 50, :width => 100, :tag => "sports", :class => "klass")
21
+ image_tag = lorem_image_tag(:height => 50, :width => 100, :type => "sports", :class => "klass")
22
22
  assert_match %r{<img src="/lorem/image/100/50/sports\?r=\d+" class="klass lorem-image" width="100" height="50" style="height: 50px; width: 100px;" />}, image_tag
23
23
  end
24
24
  end
@@ -1,11 +1,9 @@
1
1
  require_relative "./test_helper"
2
2
  require "ostruct"
3
3
 
4
- class TestCase < MiniTest::Unit::TestCase
4
+ class TestMiddleware < MiniTest::Unit::TestCase
5
5
  include Rack::Test::Methods
6
- end
7
6
 
8
- class TestPassThru < TestCase
9
7
  def app
10
8
  Rack::Builder.new do
11
9
  use LoremImageWare::Middleware
@@ -22,19 +20,6 @@ class TestPassThru < TestCase
22
20
  get "/hello"
23
21
  assert_equal "path = /hello", last_response.body
24
22
  end
25
- end
26
-
27
- class TestSimpleLorem < TestCase
28
- def setup
29
- @provider = MiniTest::Mock.new
30
- end
31
-
32
- def app
33
- Rack::Builder.new do
34
- use LoremImageWare::Middleware
35
- run lambda { |env| [200, { 'Content-Type' => "text/plain" }, ["path = #{env['PATH_INFO']}"]] }
36
- end
37
- end
38
23
 
39
24
  def test_width_and_height
40
25
  get "/lorem/image/400/200"
@@ -44,7 +29,7 @@ class TestSimpleLorem < TestCase
44
29
  assert last_response.headers["Content-Length"].to_i > 0
45
30
  end
46
31
 
47
- def test_tag_param
32
+ def test_type_param
48
33
  get "/lorem/image/400/200/sports"
49
34
  assert_equal 200, last_response.status
50
35
  assert_equal "image/jpeg", last_response.headers["Content-Type"]
@@ -7,9 +7,9 @@ class TestLoremPixelProvider < MiniTest::Unit::TestCase
7
7
  assert_match %r{http://lorempixel.com/400/200/abstract/\?r=\d+$}, url
8
8
  end
9
9
 
10
- def test_optional_tag
10
+ def test_optional_type
11
11
  provider = LoremImageWare::LoremPixelProvider.new
12
- url = provider.url(width: 200, height: 100, tag: "sports")
12
+ url = provider.url(width: 200, height: 100, type: "sports")
13
13
  assert_match %r{http://lorempixel.com/200/100/sports/\?r=\d+$}, url
14
14
  end
15
15
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lorem-image-ware
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2013-01-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
16
- requirement: &2156488720 !ruby/object:Gem::Requirement
16
+ requirement: &2165773000 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2156488720
24
+ version_requirements: *2165773000
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &2156488300 !ruby/object:Gem::Requirement
27
+ requirement: &2165772580 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2156488300
35
+ version_requirements: *2165772580
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rack-test
38
- requirement: &2156487880 !ruby/object:Gem::Requirement
38
+ requirement: &2165772160 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2156487880
46
+ version_requirements: *2165772160
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: minitest
49
- requirement: &2156487460 !ruby/object:Gem::Requirement
49
+ requirement: &2165788120 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2156487460
57
+ version_requirements: *2165788120
58
58
  description: rack middleware for proxying requests to lorempixel.com
59
59
  email:
60
60
  - xternal1+github@gmail.com
@@ -88,7 +88,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
88
88
  version: '0'
89
89
  segments:
90
90
  - 0
91
- hash: 1682226714333622018
91
+ hash: 393796808403588033
92
92
  required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  none: false
94
94
  requirements:
@@ -97,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
97
  version: '0'
98
98
  segments:
99
99
  - 0
100
- hash: 1682226714333622018
100
+ hash: 393796808403588033
101
101
  requirements: []
102
102
  rubyforge_project:
103
103
  rubygems_version: 1.8.15