dink 0.0.4
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 +3 -0
- data/Gemfile +4 -0
- data/README.md +3 -0
- data/Rakefile +2 -0
- data/dink.gemspec +24 -0
- data/lib/dink/batch.rb +39 -0
- data/lib/dink/configuration.rb +104 -0
- data/lib/dink/image.rb +72 -0
- data/lib/dink/rack.rb +14 -0
- data/lib/dink/rails/.DS_Store +0 -0
- data/lib/dink/rails/helpers.rb +31 -0
- data/lib/dink/rails/hooks.rb +17 -0
- data/lib/dink/railtie.rb +34 -0
- data/lib/dink/receiver.rb +29 -0
- data/lib/dink/sender.rb +55 -0
- data/lib/dink/version.rb +3 -0
- data/lib/dink.rb +67 -0
- data/spec/batch_spec.rb +54 -0
- data/spec/configuration_spec.rb +15 -0
- data/spec/helpers_spec.rb +22 -0
- data/spec/hooks_spec.rb +6 -0
- data/spec/image_spec.rb +72 -0
- data/spec/receiver_spec.rb +10 -0
- data/spec/spec_helper.rb +28 -0
- data/spec/stilts_spec.rb +12 -0
- metadata +125 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
data/Rakefile
ADDED
data/dink.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "dink/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "dink"
|
7
|
+
s.version = Dink::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Graham Powrie"]
|
10
|
+
s.email = ["graham@developmentnow.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{On-the-fly image resizing and management for mobile devices}
|
13
|
+
s.description = %q{}
|
14
|
+
|
15
|
+
s.rubyforge_project = "dink"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency('addressable', '~> 2.2.2')
|
23
|
+
s.add_dependency('json', '~> 1.4.6')
|
24
|
+
end
|
data/lib/dink/batch.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
module Dink
|
2
|
+
class Batch
|
3
|
+
|
4
|
+
attr_accessor :images
|
5
|
+
|
6
|
+
# Batch is just an array of images
|
7
|
+
def initialize
|
8
|
+
self.images = []
|
9
|
+
end
|
10
|
+
|
11
|
+
# Send images to Dink for transformation, first +screen+ and translate +to_json+
|
12
|
+
def deliver
|
13
|
+
Dink.sender.send_image_process_data(self.to_json)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Ready images for transport across voidy vastness of teh interweb
|
17
|
+
def to_json
|
18
|
+
JSON.generate(self.images.collect{|i| i.to_hash})
|
19
|
+
end
|
20
|
+
|
21
|
+
# :nodoc:
|
22
|
+
def << image
|
23
|
+
self.images << image
|
24
|
+
end
|
25
|
+
|
26
|
+
# :nodoc:
|
27
|
+
def size
|
28
|
+
self.images.size
|
29
|
+
end
|
30
|
+
alias_method :length, :size
|
31
|
+
|
32
|
+
# :nodoc:
|
33
|
+
def empty?
|
34
|
+
return true if self.size == 0
|
35
|
+
false
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
module Dink
|
2
|
+
# Used to set up and modify settings for the notifier.
|
3
|
+
class Configuration
|
4
|
+
|
5
|
+
OPTIONS = [:api_key, :host, :http_open_timeout, :http_read_timeout, :project_root,
|
6
|
+
:port, :protocol, :secure, :framework].freeze
|
7
|
+
|
8
|
+
# The API key for your project, found on the project edit form.
|
9
|
+
attr_accessor :api_key
|
10
|
+
|
11
|
+
# The host to connect to
|
12
|
+
attr_accessor :host
|
13
|
+
|
14
|
+
# The CDN host to connect to
|
15
|
+
attr_accessor :cdn_host
|
16
|
+
|
17
|
+
# The port on which your server runs (defaults to 443 for secure
|
18
|
+
# connections, 80 for insecure connections).
|
19
|
+
attr_accessor :port
|
20
|
+
|
21
|
+
# +true+ for https connections, +false+ for http connections.
|
22
|
+
attr_accessor :secure
|
23
|
+
|
24
|
+
# The path to the project in which the error occurred, such as the RAILS_ROOT
|
25
|
+
attr_accessor :project_root
|
26
|
+
|
27
|
+
# The logger used by
|
28
|
+
attr_accessor :logger
|
29
|
+
|
30
|
+
# The framework is configured to use
|
31
|
+
attr_accessor :framework
|
32
|
+
|
33
|
+
# The HTTP open timeout in seconds (defaults to 2).
|
34
|
+
attr_accessor :http_open_timeout
|
35
|
+
|
36
|
+
# The HTTP read timeout in seconds (defaults to 5).
|
37
|
+
attr_accessor :http_read_timeout
|
38
|
+
|
39
|
+
alias_method :secure?, :secure
|
40
|
+
|
41
|
+
def initialize
|
42
|
+
@secure = false
|
43
|
+
@host ||= 'dink.developmentnow.com'
|
44
|
+
@port ||= 80
|
45
|
+
@cdn_host = 'd15ceu2kbcb932.cloudfront.net'
|
46
|
+
@framework = 'Standalone'
|
47
|
+
@protocol = protocol
|
48
|
+
@http_open_timeout = 2
|
49
|
+
@http_read_timeout = 10
|
50
|
+
end
|
51
|
+
|
52
|
+
# Allows config options to be read like a hash
|
53
|
+
#
|
54
|
+
# @param [Symbol] option Key for a given attribute
|
55
|
+
def [](option)
|
56
|
+
send(option)
|
57
|
+
end
|
58
|
+
|
59
|
+
def url
|
60
|
+
url = URI::HTTP.build({
|
61
|
+
:host => @host,
|
62
|
+
:scheme => protocol,
|
63
|
+
:path => "/",
|
64
|
+
:port => @port
|
65
|
+
})
|
66
|
+
end
|
67
|
+
|
68
|
+
# Returns a hash of all configurable options
|
69
|
+
def to_hash
|
70
|
+
OPTIONS.inject({}) do |hash, option|
|
71
|
+
hash.merge(option.to_sym => send(option))
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# Returns a hash of all configurable options merged with +hash+
|
76
|
+
#
|
77
|
+
# @param [Hash] hash A set of configuration options that will take precedence over the defaults
|
78
|
+
def merge(hash)
|
79
|
+
to_hash.merge(hash)
|
80
|
+
end
|
81
|
+
|
82
|
+
def port
|
83
|
+
@port || default_port
|
84
|
+
end
|
85
|
+
|
86
|
+
def protocol
|
87
|
+
if secure?
|
88
|
+
'https'
|
89
|
+
else
|
90
|
+
'http'
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
private
|
95
|
+
|
96
|
+
def default_port
|
97
|
+
if secure?
|
98
|
+
443
|
99
|
+
else
|
100
|
+
80
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
data/lib/dink/image.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
module Dink
|
2
|
+
|
3
|
+
# Intermediate utility class for image manipulation
|
4
|
+
class Image
|
5
|
+
|
6
|
+
SLUG_ABBREVIATIONS = {
|
7
|
+
:device_width_ratio => "dwr"
|
8
|
+
}
|
9
|
+
|
10
|
+
PROCESS_OPTIONS = [
|
11
|
+
"device_width_ratio"
|
12
|
+
]
|
13
|
+
|
14
|
+
# The public location of the image
|
15
|
+
attr_accessor :source, :device_width_ratio
|
16
|
+
|
17
|
+
# :nodoc:
|
18
|
+
def initialize(source, options)
|
19
|
+
self.source = source
|
20
|
+
self.device_width_ratio = options[:device_width_ratio] || 1
|
21
|
+
end
|
22
|
+
|
23
|
+
# Generates a SHA1 represenation for a particular URL
|
24
|
+
def url_id
|
25
|
+
Digest::SHA1.hexdigest(self.source)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Combines resizing parameters into a short, unique slug to be appended to the final image name
|
29
|
+
def params_slug
|
30
|
+
PROCESS_OPTIONS.map do |option|
|
31
|
+
param_slug(option)
|
32
|
+
end.join("")
|
33
|
+
end
|
34
|
+
|
35
|
+
# The full image name, a combination of +url_id+ and +params_slug+
|
36
|
+
def name
|
37
|
+
url_id + "_" + params_slug
|
38
|
+
end
|
39
|
+
|
40
|
+
# Location on server that will server this image
|
41
|
+
def cdn_url
|
42
|
+
Dink.configuration.protocol + "://" +
|
43
|
+
Dink.configuration.cdn_host +
|
44
|
+
"/images/" +
|
45
|
+
Dink.configuration.api_key + "/" +
|
46
|
+
self.name
|
47
|
+
end
|
48
|
+
|
49
|
+
def deliver
|
50
|
+
Dink.sender.send_image_process_data("[#{self.to_json}]")
|
51
|
+
end
|
52
|
+
|
53
|
+
# Ready images for transport across voidy vastness of teh interweb
|
54
|
+
def to_json
|
55
|
+
JSON.generate(self.to_hash)
|
56
|
+
end
|
57
|
+
|
58
|
+
# A hash representation of the image attributes
|
59
|
+
def to_hash
|
60
|
+
{
|
61
|
+
:source => self.source,
|
62
|
+
:name => self.name,
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
def param_slug(param_name)
|
68
|
+
SLUG_ABBREVIATIONS[param_name.to_sym] + self.send(param_name).to_s
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
data/lib/dink/rack.rb
ADDED
Binary file
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Dink
|
2
|
+
module Helpers
|
3
|
+
include ActionView::Helpers
|
4
|
+
|
5
|
+
# Take image transform parameters and generate an image tag and stick it into the batch
|
6
|
+
def dink!(source, process_options = {}, image_options = {})
|
7
|
+
image = Dink::Image.new(source, process_options).deliver
|
8
|
+
Rails.logger.debug{ image.inspect }
|
9
|
+
# @image_batch << image
|
10
|
+
image_tag(image["results"]["url"], image_options)
|
11
|
+
end
|
12
|
+
|
13
|
+
# def stream_resize(image_source)
|
14
|
+
# b = Benchmark.measure do
|
15
|
+
# @params = Addressable::URI.parse(url.to_s) # TODO get URI.parse out of Addressable to remove the dependency
|
16
|
+
# @params.query_values = {:image_source => image_source, :stream => "1"}
|
17
|
+
# end
|
18
|
+
# # logger.debug { "STREAM BENCHMARK :: #{b}" }
|
19
|
+
#
|
20
|
+
# stream_url = url
|
21
|
+
# stream_url.path = "/resize"
|
22
|
+
# stream_url.query = @params.query
|
23
|
+
# stream_url.to_s
|
24
|
+
# end
|
25
|
+
|
26
|
+
def logger
|
27
|
+
Dink.configuration.logger
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Dink
|
2
|
+
module Hooks
|
3
|
+
|
4
|
+
def self.included(base)
|
5
|
+
base.before_filter :image_batch
|
6
|
+
base.append_before_filter :deliver_batch
|
7
|
+
end
|
8
|
+
|
9
|
+
def image_batch
|
10
|
+
@image_batch = Dink::Batch.new
|
11
|
+
end
|
12
|
+
def deliver_batch
|
13
|
+
@image_batch.deliver unless @image_batch.empty?
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
data/lib/dink/railtie.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'dink'
|
2
|
+
require 'rails'
|
3
|
+
|
4
|
+
module Dink
|
5
|
+
class Railtie < Rails::Railtie
|
6
|
+
initializer "dink.use_rack_middleware" do |app|
|
7
|
+
app.config.middleware.use "Dink::Rack"
|
8
|
+
end
|
9
|
+
|
10
|
+
config.before_initialize do
|
11
|
+
Dink.configure do |config|
|
12
|
+
# config.host = "localhost"
|
13
|
+
# config.port = 3000
|
14
|
+
config.logger ||= Rails.logger
|
15
|
+
config.framework = "Rails: #{::Rails::VERSION::STRING}"
|
16
|
+
end
|
17
|
+
|
18
|
+
config.to_prepare do
|
19
|
+
require 'dink/rails/hooks'
|
20
|
+
ActiveSupport.on_load(:action_controller) do
|
21
|
+
include Dink::Hooks
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
if defined?(ActionView::Base)
|
27
|
+
|
28
|
+
require 'dink/rails/helpers'
|
29
|
+
ActionView::Base.send :include, Dink::Helpers
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Dink
|
2
|
+
class Receiver
|
3
|
+
|
4
|
+
def initialize(options = {})
|
5
|
+
end
|
6
|
+
|
7
|
+
def receive(response)
|
8
|
+
case response
|
9
|
+
when Net::HTTPSuccess then
|
10
|
+
log :info, "Success: #{response.class}", response
|
11
|
+
|
12
|
+
return JSON.parse(response.body)
|
13
|
+
else
|
14
|
+
log :error, "Failure: #{response.class}", response
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def logger
|
19
|
+
Dink.configuration.logger
|
20
|
+
end
|
21
|
+
|
22
|
+
def log(level, message, response = nil)
|
23
|
+
logger.send level, LOG_PREFIX + message if logger
|
24
|
+
Dink.report_environment_info
|
25
|
+
Dink.report_response_body(response.body) if response && response.respond_to?(:body)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
data/lib/dink/sender.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
module Dink
|
2
|
+
class Sender
|
3
|
+
PROCESS_HEADERS = {
|
4
|
+
'Content-Type' => 'application/json',
|
5
|
+
'Accept' => 'application/json'
|
6
|
+
}
|
7
|
+
|
8
|
+
HTTP_ERRORS = [Timeout::Error,
|
9
|
+
Errno::EINVAL,
|
10
|
+
Errno::ECONNRESET,
|
11
|
+
EOFError,
|
12
|
+
Net::HTTPBadResponse,
|
13
|
+
Net::HTTPHeaderSyntaxError,
|
14
|
+
Net::ProtocolError,
|
15
|
+
Errno::ECONNREFUSED].freeze
|
16
|
+
|
17
|
+
attr_accessor :user_agent
|
18
|
+
|
19
|
+
def initialize(options = {})
|
20
|
+
[:protocol, :host, :port, :secure, :http_open_timeout, :http_read_timeout].each do |option|
|
21
|
+
instance_variable_set("@#{option}", options[option])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def send_image_process_data(data)
|
26
|
+
http = Net::HTTP.new(@host, @port)
|
27
|
+
|
28
|
+
http.read_timeout = @http_read_timeout
|
29
|
+
http.open_timeout = @http_open_timeout
|
30
|
+
http.use_ssl = false
|
31
|
+
headers = PROCESS_HEADERS.merge({'User-Agent' => user_agent})
|
32
|
+
|
33
|
+
log :debug "Sending to: #{@host}:#{@port}"
|
34
|
+
response = begin
|
35
|
+
http.post("/link/#{Dink.configuration.api_key}", data, headers)
|
36
|
+
rescue *HTTP_ERRORS => e
|
37
|
+
log :error, "Timeout while contacting the server. #{e}"
|
38
|
+
nil
|
39
|
+
end
|
40
|
+
|
41
|
+
Dink.receiver.receive(response)
|
42
|
+
end
|
43
|
+
|
44
|
+
def log(level, message, response = nil)
|
45
|
+
logger.send level, LOG_PREFIX + message if logger
|
46
|
+
Dink.report_environment_info
|
47
|
+
Dink.report_response_body(response.body) if response && response.respond_to?(:body)
|
48
|
+
end
|
49
|
+
|
50
|
+
def logger
|
51
|
+
Dink.configuration.logger
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
data/lib/dink/version.rb
ADDED
data/lib/dink.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
module Dink
|
2
|
+
require 'net/http'
|
3
|
+
require 'net/https'
|
4
|
+
require 'addressable/uri'
|
5
|
+
require 'json'
|
6
|
+
# begin
|
7
|
+
# require 'active_support'
|
8
|
+
# rescue LoadError
|
9
|
+
# require 'activesupport'
|
10
|
+
# end
|
11
|
+
|
12
|
+
require 'dink/configuration'
|
13
|
+
require 'dink/sender'
|
14
|
+
require 'dink/receiver'
|
15
|
+
require 'dink/rack'
|
16
|
+
require 'dink/image'
|
17
|
+
require 'dink/batch'
|
18
|
+
require 'dink/railtie' if defined?(Rails)
|
19
|
+
|
20
|
+
LOG_PREFIX = "[Dink] "
|
21
|
+
|
22
|
+
class << self
|
23
|
+
|
24
|
+
# The sender object is responsible for delivering formatted data to the server.
|
25
|
+
attr_accessor :sender
|
26
|
+
|
27
|
+
# A configuration object. Must act like a hash and return sensible
|
28
|
+
# values for all configuration options. See Dink::Configuration.
|
29
|
+
attr_accessor :configuration
|
30
|
+
|
31
|
+
# A receiver of requests
|
32
|
+
attr_accessor :receiver
|
33
|
+
|
34
|
+
def configure(silent = false)
|
35
|
+
self.configuration ||= Configuration.new
|
36
|
+
yield(configuration)
|
37
|
+
self.sender = Sender.new(configuration)
|
38
|
+
self.receiver = Receiver.new(configuration)
|
39
|
+
end
|
40
|
+
|
41
|
+
def logger
|
42
|
+
self.configuration.logger
|
43
|
+
end
|
44
|
+
|
45
|
+
# Prints out the environment info to the log for debugging help
|
46
|
+
def report_environment_info
|
47
|
+
write_verbose_log("Environment Info: #{environment_info}")
|
48
|
+
end
|
49
|
+
|
50
|
+
# Prints out the response body from Dink for debugging help
|
51
|
+
def report_response_body(response)
|
52
|
+
write_verbose_log("Response from Server: \n#{response}")
|
53
|
+
end
|
54
|
+
|
55
|
+
# Returns the Ruby version, Rails version, and current Rails environment
|
56
|
+
def environment_info
|
57
|
+
info = "[Ruby: #{RUBY_VERSION}]"
|
58
|
+
info << " [#{configuration.framework}]"
|
59
|
+
end
|
60
|
+
|
61
|
+
# Writes out the given message to the #logger
|
62
|
+
def write_verbose_log(message)
|
63
|
+
logger.info LOG_PREFIX + message if logger
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
data/spec/batch_spec.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../lib/dink/batch')
|
3
|
+
|
4
|
+
describe Dink::Batch do
|
5
|
+
before(:each) do
|
6
|
+
@image1, @image2 = random_image, random_image
|
7
|
+
@batch = Dink::Batch.new
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should gather up all the images on a page for resizing" do
|
11
|
+
pending "This should really be an integration test"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should accept new images like an array" do
|
15
|
+
@batch << @image1
|
16
|
+
@batch.size.should be 1
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should respond to empty?" do
|
20
|
+
@batch.empty?.should be true
|
21
|
+
@batch << @image1
|
22
|
+
@batch.empty?.should be false
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should respond to #to_json" do
|
26
|
+
@batch << @image1
|
27
|
+
@batch << @image2
|
28
|
+
@batch.to_json.should be_a_kind_of(String)
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#deliver" do
|
32
|
+
before(:each) do
|
33
|
+
@batch << @image1
|
34
|
+
@batch << @image2
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should send a hash of unprocessed images to Dink" do
|
38
|
+
Dink.sender.user_agent = "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3"
|
39
|
+
@batch.deliver
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# describe "#screen" do
|
44
|
+
# it "should check local cache to see if any of the images have already been processed" do
|
45
|
+
# pending
|
46
|
+
# end
|
47
|
+
# it "should skip sending of already processed images to Dink" do
|
48
|
+
# pending
|
49
|
+
# # cache fake result, try to resend image
|
50
|
+
# end
|
51
|
+
# end
|
52
|
+
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../lib/dink/rails/helpers')
|
3
|
+
|
4
|
+
describe Dink::Configuration do
|
5
|
+
|
6
|
+
it "should bla" do
|
7
|
+
pending
|
8
|
+
end
|
9
|
+
|
10
|
+
def assert_config_default(option, default_value, config = nil)
|
11
|
+
config ||= Dink::Configuration.new
|
12
|
+
assert_equal default_value, config.send(option)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "rails"
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/../lib/dink/rails/helpers')
|
4
|
+
include Dink::Helpers
|
5
|
+
|
6
|
+
describe Dink::Helpers do
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
@image_batch = Dink::Batch.new
|
10
|
+
@image = test_images[rand(3)]
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#transform" do
|
14
|
+
it "should respond with some image tag HTML" do
|
15
|
+
|
16
|
+
transform_image("http://bla.com/image.jpg", {}).should =~ /^\<img/
|
17
|
+
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
data/spec/hooks_spec.rb
ADDED
data/spec/image_spec.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../lib/dink/image')
|
3
|
+
|
4
|
+
describe Dink::Image do
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
@image = random_image
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should have some default values assigned" do
|
11
|
+
assert_default_value :device_width_ratio, 1
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#url_id" do
|
15
|
+
it "should generate a unique id for an image based on it's URL" do
|
16
|
+
id = @image.url_id
|
17
|
+
id.should be_a_kind_of(String)
|
18
|
+
id.length.should be 40
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#params_slug" do
|
23
|
+
it "should respond with a string representation of the transform parameters " do
|
24
|
+
@image.params_slug.should be_a_kind_of(String)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#name" do
|
29
|
+
it "should respond with the url_id and abbreviated transform params" do
|
30
|
+
@image.name.should =~ /^[\w\d]{40}_[\w\d]+$/
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#s3_url" do
|
35
|
+
it "should respond with the full url of a post-transform and distributed image" do
|
36
|
+
@image.cdn_url.should =~ /^http:\/\//
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#to_hash" do
|
41
|
+
it "should respond to to_hash" do
|
42
|
+
@image.to_hash.should be_a_kind_of(Hash)
|
43
|
+
end
|
44
|
+
it "should have some specific keys" do
|
45
|
+
hash = @image.to_hash
|
46
|
+
hash[:source].should_not be nil
|
47
|
+
hash[:name].should_not be nil
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "#cached?" do
|
52
|
+
it "should return true if the image name is in local cache" do
|
53
|
+
pending
|
54
|
+
end
|
55
|
+
it "should return false if the image name is not found in local cache" do
|
56
|
+
pending
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "#to_json" do
|
61
|
+
it "should respond to to_json" do
|
62
|
+
json = @image.to_json
|
63
|
+
json.should be_a_kind_of(String)
|
64
|
+
JSON.parse(json).should be_a_kind_of(Hash)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def assert_default_value(option, default_value)
|
69
|
+
default_value.should be @image.send(option)
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../lib/dink')
|
2
|
+
require "rails/all"
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
# == Mock Framework
|
6
|
+
config.mock_with :rspec
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
def test_images
|
11
|
+
[
|
12
|
+
{ :source => "http://www.crazy-frog.us/donthotlink-crazy-frog-1024x768-1.jpg",
|
13
|
+
:options => {} },
|
14
|
+
{ :source => "https://totalfright.websitesource.net/mm5/pics/32901.jpg",
|
15
|
+
:options => {} },
|
16
|
+
{ :source => "http://iamthatmommy.files.wordpress.com/2010/04/unicorn1.jpg",
|
17
|
+
:options => {} }
|
18
|
+
]
|
19
|
+
end
|
20
|
+
|
21
|
+
def random_image
|
22
|
+
image_number = rand(test_images.size)
|
23
|
+
Dink::Image.new(test_images[image_number][:source], test_images[image_number][:options])
|
24
|
+
end
|
25
|
+
|
26
|
+
Dink.configure do |c|
|
27
|
+
c.api_key = "1234123412341234"
|
28
|
+
end
|
data/spec/stilts_spec.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../lib/dink')
|
3
|
+
|
4
|
+
describe Dink do
|
5
|
+
|
6
|
+
describe "#configure" do
|
7
|
+
it "should have with an API key or raise an error" do
|
8
|
+
pending
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dink
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 4
|
9
|
+
version: 0.0.4
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Graham Powrie
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-02-18 00:00:00 -08:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: addressable
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 2
|
30
|
+
- 2
|
31
|
+
- 2
|
32
|
+
version: 2.2.2
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: json
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
segments:
|
44
|
+
- 1
|
45
|
+
- 4
|
46
|
+
- 6
|
47
|
+
version: 1.4.6
|
48
|
+
type: :runtime
|
49
|
+
version_requirements: *id002
|
50
|
+
description: ""
|
51
|
+
email:
|
52
|
+
- graham@developmentnow.com
|
53
|
+
executables: []
|
54
|
+
|
55
|
+
extensions: []
|
56
|
+
|
57
|
+
extra_rdoc_files: []
|
58
|
+
|
59
|
+
files:
|
60
|
+
- .gitignore
|
61
|
+
- Gemfile
|
62
|
+
- README.md
|
63
|
+
- Rakefile
|
64
|
+
- dink.gemspec
|
65
|
+
- lib/dink.rb
|
66
|
+
- lib/dink/batch.rb
|
67
|
+
- lib/dink/configuration.rb
|
68
|
+
- lib/dink/image.rb
|
69
|
+
- lib/dink/rack.rb
|
70
|
+
- lib/dink/rails/.DS_Store
|
71
|
+
- lib/dink/rails/helpers.rb
|
72
|
+
- lib/dink/rails/hooks.rb
|
73
|
+
- lib/dink/railtie.rb
|
74
|
+
- lib/dink/receiver.rb
|
75
|
+
- lib/dink/sender.rb
|
76
|
+
- lib/dink/version.rb
|
77
|
+
- spec/batch_spec.rb
|
78
|
+
- spec/configuration_spec.rb
|
79
|
+
- spec/helpers_spec.rb
|
80
|
+
- spec/hooks_spec.rb
|
81
|
+
- spec/image_spec.rb
|
82
|
+
- spec/receiver_spec.rb
|
83
|
+
- spec/spec_helper.rb
|
84
|
+
- spec/stilts_spec.rb
|
85
|
+
has_rdoc: true
|
86
|
+
homepage: ""
|
87
|
+
licenses: []
|
88
|
+
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
segments:
|
100
|
+
- 0
|
101
|
+
version: "0"
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
segments:
|
108
|
+
- 0
|
109
|
+
version: "0"
|
110
|
+
requirements: []
|
111
|
+
|
112
|
+
rubyforge_project: dink
|
113
|
+
rubygems_version: 1.3.7
|
114
|
+
signing_key:
|
115
|
+
specification_version: 3
|
116
|
+
summary: On-the-fly image resizing and management for mobile devices
|
117
|
+
test_files:
|
118
|
+
- spec/batch_spec.rb
|
119
|
+
- spec/configuration_spec.rb
|
120
|
+
- spec/helpers_spec.rb
|
121
|
+
- spec/hooks_spec.rb
|
122
|
+
- spec/image_spec.rb
|
123
|
+
- spec/receiver_spec.rb
|
124
|
+
- spec/spec_helper.rb
|
125
|
+
- spec/stilts_spec.rb
|