camo_image_tag 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +32 -0
- data/Rakefile +34 -0
- data/lib/camo_image_tag.rb +36 -0
- data/lib/camo_image_tag/version.rb +3 -0
- metadata +89 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2012 Jason Garber
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
= CamoImageTag
|
2
|
+
|
3
|
+
This plugin makes it easy to have your non-HTTPS image tags rewritten to take advantage of a {Camo}[https://github.com/atmos/camoi] proxy
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
To use it, add it to your Gemfile:
|
8
|
+
|
9
|
+
gem 'camo_image_tag'
|
10
|
+
|
11
|
+
== Configuration
|
12
|
+
|
13
|
+
You should specify two environment variables to tell Rails where to find your Camo proxy.
|
14
|
+
|
15
|
+
CAMO_KEY
|
16
|
+
CAMO_HOST
|
17
|
+
|
18
|
+
If you do not specify them, they will use the {Camo defaults}[https://github.com/atmos/camo/blob/master/test/proxy_test.rb].
|
19
|
+
|
20
|
+
== Testing
|
21
|
+
|
22
|
+
Camo Image Tag uses RSpec for its test coverage. Inside the gem
|
23
|
+
directory, you can run the specs for Ruby on Rails 3.x with:
|
24
|
+
|
25
|
+
rake spec
|
26
|
+
|
27
|
+
== Author
|
28
|
+
|
29
|
+
* Jason Garber
|
30
|
+
|
31
|
+
Copyright (c) 2012 Jason Garber (http://jasongarber.com/). Released under the MIT license
|
32
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'CamoImageTag'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'bundler'
|
24
|
+
Bundler.setup :default, :development
|
25
|
+
|
26
|
+
desc 'Default: run specs'
|
27
|
+
task :default => :spec
|
28
|
+
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new do |t|
|
31
|
+
t.pattern = "spec/**/*_spec.rb"
|
32
|
+
end
|
33
|
+
|
34
|
+
Bundler::GemHelper.install_tasks
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
require "action_view"
|
3
|
+
|
4
|
+
module CamoImageTag
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
alias_method_chain :image_tag, :camo
|
9
|
+
end
|
10
|
+
|
11
|
+
def image_tag_with_camo(source, options={})
|
12
|
+
if source && source =~ /^http:/
|
13
|
+
unless source =~ /^(?:cid|data):/ || source.blank?
|
14
|
+
options[:alt] = options.fetch(:alt){ image_alt(source) }
|
15
|
+
end
|
16
|
+
source = camo_uri(source)
|
17
|
+
end
|
18
|
+
image_tag_without_camo(source, options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def camo_uri(image_url)
|
22
|
+
hexdigest = OpenSSL::HMAC.hexdigest(
|
23
|
+
OpenSSL::Digest::Digest.new('sha1'), camo_config['key'], image_url)
|
24
|
+
encoded_image_url = image_url.to_enum(:each_byte).map { |byte| "%02x" % byte }.join
|
25
|
+
"#{camo_config['host']}/#{hexdigest}/#{encoded_image_url}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def camo_config
|
29
|
+
{ 'key' => ENV['CAMO_KEY'] || "0x24FEEDFACEDEADBEEFCAFE",
|
30
|
+
'host' => ENV['CAMO_HOST'] || "http://localhost:8081" }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
if defined?(ActionView::Base)
|
35
|
+
ActionView::Base.send :include, CamoImageTag
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: camo_image_tag
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jason Garber
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.10.0
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.10.0
|
46
|
+
description: Any absolute URL you pass to image_tag will be rewritten if it is not
|
47
|
+
https.
|
48
|
+
email:
|
49
|
+
- jg@jasongarber.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- lib/camo_image_tag/version.rb
|
55
|
+
- lib/camo_image_tag.rb
|
56
|
+
- MIT-LICENSE
|
57
|
+
- Rakefile
|
58
|
+
- README.rdoc
|
59
|
+
homepage: https://github.com/jgarber/camo_image_tag
|
60
|
+
licenses: []
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
hash: 1350323763342979023
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ! '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
segments:
|
81
|
+
- 0
|
82
|
+
hash: 1350323763342979023
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 1.8.23
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: Rails plugin to rewrite image_tags for camo
|
89
|
+
test_files: []
|