rack-golden_frill 0.1.1 → 0.1.2

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.
@@ -10,7 +10,7 @@ module GoldenFrill
10
10
  # Optional:
11
11
  # frill_color: the color of the frill. If not provided, will be a darker color than the base
12
12
  def self.run!(opts)
13
- width, height, base_color, output_path = opts[:width], opts[:height], opts[:base_color], opts[:output_path]
13
+ width, height, base_color, output_path = opts[:width].to_i, opts[:height].to_i, opts[:base_color], opts[:output_path]
14
14
 
15
15
  bot_height = height.to_i + (width.to_f * GoldenRatio).to_i
16
16
  png = ChunkyPNG::Image.new(width.to_i, bot_height)
@@ -1,3 +1,3 @@
1
1
  module GoldenFrill
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -6,14 +6,13 @@ module Rack
6
6
  raise ArgumentError, "#{output_path} is not a directory" unless ::File.directory?(@root)
7
7
  end
8
8
 
9
- def call env
10
- unless env["PATH_INFO"] =~ /#{@root}/
9
+ def call env
10
+ unless env["PATH_INFO"] =~ /images\/frill_/
11
11
  return @app.call(env)
12
12
  end
13
13
 
14
+ command = env["PATH_INFO"].match(/\/frill_(.*)\.png/i)[1]
14
15
  request = ::Rack::Request.new(env)
15
- command = env["PATH_INFO"].match(/#{@root}\/frill_(.*)\.png/i)[1]
16
-
17
16
  image_path = ::File.join(@root,"frill_#{command}.png")
18
17
  if ::File.exist?(image_path)
19
18
  return ::Rack::File.new(@root).call(env)
@@ -21,10 +20,9 @@ module Rack
21
20
 
22
21
  opts = { :output_path => image_path }
23
22
  opts[:base_color], opts[:width], opts[:height], opts[:frill_color] = command.split('.')
24
- ::GoldenFrill.new(opts).run!
25
-
23
+ ::GoldenFrill.run!(opts)
26
24
  # Redirect to this URL since it will now be served.
27
- return [301, {'Location' => request.url}, 'Redirecting to created image.']
25
+ return [301, {'Location' => request.url}, ['Redirecting to created image.']]
28
26
  end
29
27
  end
30
28
  end
@@ -0,0 +1,22 @@
1
+ require 'test/unit'
2
+ require 'golden_frill'
3
+ require 'rack/golden_frill'
4
+ require 'rack/test'
5
+ require 'fileutils'
6
+ class TestRack < Test::Unit::TestCase
7
+ include Rack::Test::Methods
8
+ OUTPUT_ROOT = ::File.expand_path('./images', File::dirname(__FILE__))
9
+
10
+ def app
11
+ Rack::GoldenFrill.new lambda{|x| [200, {}, ["OK"]]}, OUTPUT_ROOT
12
+ end
13
+
14
+ def test_dynamic_generation
15
+ filename = 'frill_d4412d.14.36.png'
16
+
17
+ FileUtils.rm(File.join(OUTPUT_ROOT, filename)) rescue Errno::ENOENT
18
+ get "/images/#{filename}"
19
+ assert_equal 301, last_response.status
20
+ assert File.exists?(File.join(OUTPUT_ROOT, filename))
21
+ end
22
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 1
9
- version: 0.1.1
8
+ - 2
9
+ version: 0.1.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Alexander Bartlow
@@ -90,6 +90,7 @@ files:
90
90
  - lib/rack/golden_frill.rb
91
91
  - test/images/.gitignore
92
92
  - test/test_frills.rb
93
+ - test/test_rack.rb
93
94
  has_rdoc: true
94
95
  homepage: http://rubygems.org/gems/golden_frill
95
96
  licenses: []