stilts 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/stilts/configuration.rb +1 -12
- data/lib/stilts/image.rb +63 -0
- data/lib/stilts/rails/helpers.rb +7 -11
- data/lib/stilts/rails/hooks.rb +17 -0
- data/lib/stilts/railtie.rb +11 -3
- data/lib/stilts/receiver.rb +9 -0
- data/lib/stilts/version.rb +1 -1
- data/lib/stilts.rb +2 -3
- data/spec/configuration_spec.rb +15 -0
- data/spec/helpers_spec.rb +21 -0
- data/spec/hooks_spec.rb +19 -0
- data/spec/image_spec.rb +55 -0
- data/spec/receiver_spec.rb +9 -0
- data/spec/spec_helper.rb +20 -0
- data/spec/stilts_spec.rb +12 -0
- metadata +21 -5
data/lib/stilts/configuration.rb
CHANGED
@@ -18,21 +18,9 @@ module Stilts
|
|
18
18
|
# +true+ for https connections, +false+ for http connections.
|
19
19
|
attr_accessor :secure
|
20
20
|
|
21
|
-
# A list of parameters that should be filtered out of what is sent to Hoptoad.
|
22
|
-
# By default, all "password" attributes will have their contents replaced.
|
23
|
-
attr_reader :params_filters
|
24
|
-
|
25
|
-
# A list of filters for cleaning and pruning the backtrace. See #filter_backtrace.
|
26
|
-
attr_reader :backtrace_filters
|
27
|
-
|
28
|
-
# A list of filters for ignoring exceptions. See #ignore_by_filter.
|
29
|
-
attr_reader :ignore_by_filters
|
30
|
-
|
31
21
|
# The path to the project in which the error occurred, such as the RAILS_ROOT
|
32
22
|
attr_accessor :project_root
|
33
23
|
|
34
|
-
# The url of the notifier library being used to send notifications
|
35
|
-
attr_accessor :notifier_url
|
36
24
|
|
37
25
|
# The logger used by
|
38
26
|
attr_accessor :logger
|
@@ -46,6 +34,7 @@ module Stilts
|
|
46
34
|
@secure = false
|
47
35
|
@host = 'localhost'
|
48
36
|
@framework = 'Standalone'
|
37
|
+
@protocol = protocol
|
49
38
|
end
|
50
39
|
|
51
40
|
# Allows config options to be read like a hash
|
data/lib/stilts/image.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
module Stilts
|
2
|
+
|
3
|
+
# Intermediate utility class for image manipulation
|
4
|
+
class Image
|
5
|
+
|
6
|
+
SLUG_ABBREVIATIONS = {
|
7
|
+
:device_width_ratio => "dwr"
|
8
|
+
}
|
9
|
+
|
10
|
+
TRANSFORM_OPTIONS = [
|
11
|
+
"device_width_ratio"
|
12
|
+
]
|
13
|
+
|
14
|
+
# The public location of the image
|
15
|
+
attr_accessor :url, :device_width_ratio
|
16
|
+
|
17
|
+
# :nodoc:
|
18
|
+
def initialize(args)
|
19
|
+
self.url = args[:url]
|
20
|
+
self.device_width_ratio = args[: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.url)
|
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
|
+
TRANSFORM_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 transformed_url
|
42
|
+
Stilts.configuration.protocol + "://" +
|
43
|
+
Stilts.configuration.host +
|
44
|
+
"/transform/" +
|
45
|
+
Stilts.configuration.api_key +
|
46
|
+
"/" + self.name
|
47
|
+
end
|
48
|
+
|
49
|
+
# A hash representation of the image attributes
|
50
|
+
def to_hash
|
51
|
+
{
|
52
|
+
:url => self.url,
|
53
|
+
:name => self.name,
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
def param_slug(param_name)
|
59
|
+
SLUG_ABBREVIATIONS[param_name.to_sym] + self.send(param_name).to_s
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
data/lib/stilts/rails/helpers.rb
CHANGED
@@ -1,23 +1,19 @@
|
|
1
1
|
module Stilts
|
2
2
|
module Helpers
|
3
|
+
include ActionView::Helpers
|
3
4
|
|
4
|
-
def
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
logger.debug { "RESIZER BENCHMARK :: #{b}" }
|
9
|
-
|
10
|
-
image_url = url
|
11
|
-
image_url.path = ""
|
12
|
-
image_tag("#{image_url}#{@response['image_url']}")
|
5
|
+
def transform(image)
|
6
|
+
image = Stilts::Image.new(image)
|
7
|
+
# @response = Stilts.sender.send_to_resizer({:image_source => image_source}.to_json.to_s)
|
8
|
+
image_tag(image.transformed_url)
|
13
9
|
end
|
14
10
|
|
15
11
|
def stream_resize(image_source)
|
16
12
|
b = Benchmark.measure do
|
17
|
-
@params = Addressable::URI.parse(url.to_s)
|
13
|
+
@params = Addressable::URI.parse(url.to_s) # TODO get URI.parse out of Addressable to remove the dependency
|
18
14
|
@params.query_values = {:image_source => image_source, :stream => "1"}
|
19
15
|
end
|
20
|
-
logger.debug { "STREAM BENCHMARK :: #{b}" }
|
16
|
+
# logger.debug { "STREAM BENCHMARK :: #{b}" }
|
21
17
|
|
22
18
|
stream_url = url
|
23
19
|
stream_url.path = "/resize"
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Stilts
|
2
|
+
module Hooks
|
3
|
+
|
4
|
+
def self.included(base)
|
5
|
+
base.before_filter :clear_resize_batch
|
6
|
+
base.after_filter :resize_batch
|
7
|
+
end
|
8
|
+
|
9
|
+
def clear_resize_batch
|
10
|
+
@resize_batch = []
|
11
|
+
end
|
12
|
+
def resize_batch
|
13
|
+
@resize_batch
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
data/lib/stilts/railtie.rb
CHANGED
@@ -15,11 +15,19 @@ module Stilts
|
|
15
15
|
config.framework = "Rails: #{::Rails::VERSION::STRING}"
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
|
-
|
18
|
+
config.to_prepare do
|
19
|
+
require 'stilts/rails/hooks'
|
20
|
+
ActiveSupport.on_load(:action_controller) do
|
21
|
+
include Stilts::Hooks
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
if defined?(ActionView::Base)
|
27
|
+
|
20
28
|
require 'stilts/rails/helpers'
|
21
29
|
ActionView::Base.send :include, Stilts::Helpers
|
22
|
-
|
30
|
+
|
23
31
|
end
|
24
32
|
end
|
25
33
|
end
|
data/lib/stilts/version.rb
CHANGED
data/lib/stilts.rb
CHANGED
@@ -11,9 +11,8 @@ module Stilts
|
|
11
11
|
require 'stilts/configuration'
|
12
12
|
require 'stilts/sender'
|
13
13
|
require 'stilts/rack'
|
14
|
-
require 'stilts/
|
15
|
-
|
16
|
-
|
14
|
+
require 'stilts/image'
|
15
|
+
require 'stilts/railtie' if defined?(Rails)
|
17
16
|
|
18
17
|
LOG_PREFIX = "[Stilts] "
|
19
18
|
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../lib/stilts/rails/helpers')
|
3
|
+
|
4
|
+
describe Stilts::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 ||= Stilts::Configuration.new
|
12
|
+
assert_equal default_value, config.send(option)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "rails"
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/../lib/stilts/rails/helpers')
|
4
|
+
include Stilts::Helpers
|
5
|
+
|
6
|
+
describe Stilts::Helpers do
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
@image = test_images[rand(3)]
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#transform" do
|
13
|
+
it "should respond with some image tag HTML" do
|
14
|
+
|
15
|
+
transform(@image).should =~ /^\<img/
|
16
|
+
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
data/spec/hooks_spec.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../lib/stilts/rails/hooks')
|
3
|
+
|
4
|
+
describe Stilts::Hooks do
|
5
|
+
it "should gather up all the images on a page for resizing" do
|
6
|
+
pending "This should really be an integration test"
|
7
|
+
end
|
8
|
+
it "should check local cache to see if any of the images have already been processed" do
|
9
|
+
pending
|
10
|
+
end
|
11
|
+
it "should send a hash of unprocessed images to Stilts" do
|
12
|
+
pending
|
13
|
+
end
|
14
|
+
it "should skip sending of already processed images to Stilts" do
|
15
|
+
pending
|
16
|
+
# cache fake result, try to resend image
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
data/spec/image_spec.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../lib/stilts/image')
|
3
|
+
|
4
|
+
describe Stilts::Image do
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
@image = Stilts::Image.new(test_images[rand(3)])
|
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 "#transformed_url" do
|
35
|
+
it "should respond with the full url of a post-transform image" do
|
36
|
+
@image.transformed_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[:url].should_not be nil
|
47
|
+
hash[:name].should_not be nil
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def assert_default_value(option, default_value)
|
52
|
+
default_value.should be @image.send(option)
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../lib/stilts')
|
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
|
+
{ :url => "http://www.crazy-frog.us/donthotlink-crazy-frog-1024x768-1.jpg" },
|
13
|
+
{ :url => "https://totalfright.websitesource.net/mm5/pics/32901.jpg" },
|
14
|
+
{ :url => "http://iamthatmommy.files.wordpress.com/2010/04/unicorn1.jpg"}
|
15
|
+
]
|
16
|
+
end
|
17
|
+
|
18
|
+
Stilts.configure do |c|
|
19
|
+
c.api_key = "1234123412341234"
|
20
|
+
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/stilts')
|
3
|
+
|
4
|
+
describe Stilts 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
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Graham Powrie
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-01-
|
17
|
+
date: 2011-01-19 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -48,12 +48,22 @@ files:
|
|
48
48
|
- Rakefile
|
49
49
|
- lib/stilts.rb
|
50
50
|
- lib/stilts/configuration.rb
|
51
|
+
- lib/stilts/image.rb
|
51
52
|
- lib/stilts/rack.rb
|
52
53
|
- lib/stilts/rails/.DS_Store
|
53
54
|
- lib/stilts/rails/helpers.rb
|
55
|
+
- lib/stilts/rails/hooks.rb
|
54
56
|
- lib/stilts/railtie.rb
|
57
|
+
- lib/stilts/receiver.rb
|
55
58
|
- lib/stilts/sender.rb
|
56
59
|
- lib/stilts/version.rb
|
60
|
+
- spec/configuration_spec.rb
|
61
|
+
- spec/helpers_spec.rb
|
62
|
+
- spec/hooks_spec.rb
|
63
|
+
- spec/image_spec.rb
|
64
|
+
- spec/receiver_spec.rb
|
65
|
+
- spec/spec_helper.rb
|
66
|
+
- spec/stilts_spec.rb
|
57
67
|
- stilts.gemspec
|
58
68
|
has_rdoc: true
|
59
69
|
homepage: ""
|
@@ -87,5 +97,11 @@ rubygems_version: 1.3.7
|
|
87
97
|
signing_key:
|
88
98
|
specification_version: 3
|
89
99
|
summary: On-the-fly image resizing and management for mobile devices
|
90
|
-
test_files:
|
91
|
-
|
100
|
+
test_files:
|
101
|
+
- spec/configuration_spec.rb
|
102
|
+
- spec/helpers_spec.rb
|
103
|
+
- spec/hooks_spec.rb
|
104
|
+
- spec/image_spec.rb
|
105
|
+
- spec/receiver_spec.rb
|
106
|
+
- spec/spec_helper.rb
|
107
|
+
- spec/stilts_spec.rb
|