aws_imageshack 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README +22 -0
- data/Rakefile +48 -0
- data/aws_imageshack-0.1.0.gem +0 -0
- data/init.rb +3 -0
- data/install.rb +3 -0
- data/lib/aws_imageshack.rb +94 -0
- data/uninstall.rb +1 -0
- metadata +74 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 [name of plugin creator]
|
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
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
AwsImageshack
|
2
|
+
===========
|
3
|
+
|
4
|
+
v 0.1.0 : december 2010, first release
|
5
|
+
|
6
|
+
see wiki for more detailled information : http://wiki.github.com/supernini/aws_imageshack/
|
7
|
+
|
8
|
+
|
9
|
+
Example
|
10
|
+
=======
|
11
|
+
|
12
|
+
To use aws_imageshack, you need first to request a key at <a href="http://imageshack.us/content.php?page=developer">ImageShack</a>
|
13
|
+
|
14
|
+
#in your controller, create an action and place this code
|
15
|
+
|
16
|
+
def upload_function
|
17
|
+
@image_shack = aws_imageshack(:options => {:size => 5, :position => 'top', :image => @image_shack, :width => 50}, :params => params, :api_key => '234DNUWX2e44a0a56a245678963bcb127a1061ca')
|
18
|
+
#save @image_shack, the url of the uploaded image
|
19
|
+
end
|
20
|
+
|
21
|
+
That all !
|
22
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/clean'
|
4
|
+
require 'rake/testtask'
|
5
|
+
require 'rake/rdoctask'
|
6
|
+
require 'rake/packagetask'
|
7
|
+
require 'rake/gempackagetask'
|
8
|
+
|
9
|
+
desc 'Default: run unit tests.'
|
10
|
+
task :default => :test
|
11
|
+
|
12
|
+
desc 'Test the aws_imageshack plugin.'
|
13
|
+
Rake::TestTask.new(:test) do |t|
|
14
|
+
t.libs << 'lib'
|
15
|
+
t.libs << 'test'
|
16
|
+
t.pattern = 'test/**/*_test.rb'
|
17
|
+
t.verbose = true
|
18
|
+
end
|
19
|
+
|
20
|
+
desc 'Generate documentation for the aws_imageshack plugin.'
|
21
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
22
|
+
rdoc.rdoc_dir = 'rdoc'
|
23
|
+
rdoc.title = 'AwsImageshack'
|
24
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
25
|
+
rdoc.rdoc_files.include('README')
|
26
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
27
|
+
end
|
28
|
+
|
29
|
+
spec = Gem::Specification.new do |s|
|
30
|
+
s.name = "aws_imageshack"
|
31
|
+
s.version = "0.2.0"
|
32
|
+
s.author = "Denis FABIEN"
|
33
|
+
s.email = "denis@miseajour.net"
|
34
|
+
s.homepage = "http://www.miseajour.net/une-gem-pour-surveiller-la-modification-des-champs.html"
|
35
|
+
s.platform = Gem::Platform::RUBY
|
36
|
+
s.summary = "Use ImageShack to host your image, with un ajax upload form"
|
37
|
+
s.files = FileList[
|
38
|
+
'[a-zA-Z]*',
|
39
|
+
'lib/**/*']
|
40
|
+
s.require_path = "lib"
|
41
|
+
s.has_rdoc = false
|
42
|
+
s.extra_rdoc_files = ["README"]
|
43
|
+
end
|
44
|
+
|
45
|
+
desc 'Turn this plugin into a gem.'
|
46
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
47
|
+
pkg.gem_spec = spec
|
48
|
+
end
|
Binary file
|
data/init.rb
ADDED
data/install.rb
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
module AwsImageshack
|
2
|
+
def self.included(base)
|
3
|
+
base.extend(ClassMethods)
|
4
|
+
end
|
5
|
+
|
6
|
+
module PublicControllerMethods
|
7
|
+
def responds_to_parent(&block)
|
8
|
+
yield
|
9
|
+
if performed?
|
10
|
+
script = if location = erase_redirect_results
|
11
|
+
"document.location.href = '#{self.class.helpers.escape_javascript location.to_s}'"
|
12
|
+
else
|
13
|
+
response.body || ''
|
14
|
+
end
|
15
|
+
|
16
|
+
erase_results
|
17
|
+
response.headers['Content-Type'] = 'text/html; charset=UTF-8'
|
18
|
+
render :text => "<html><body><script type='text/javascript' charset='utf-8'>
|
19
|
+
var loc = document.location;
|
20
|
+
with(window.parent) { setTimeout(function() { window.eval('#{self.class.helpers.escape_javascript script}'); window.loc && loc.replace('about:blank'); }, 1) }
|
21
|
+
</script></body></html>"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# options
|
26
|
+
# - size : Size of the file input
|
27
|
+
# - style_css : Style apply to the file input (replace the default css)
|
28
|
+
# - class_css : Class apply to the file input
|
29
|
+
# - width : Witdh of image in the preview
|
30
|
+
# - height : Height of image in the preview
|
31
|
+
# - position : Position for the preview ( left, right, top, left)
|
32
|
+
def aws_imageshack(*args)
|
33
|
+
options = args.extract_options!
|
34
|
+
|
35
|
+
@aws_params = options[:params]
|
36
|
+
@aws_api_key = options[:api_key]
|
37
|
+
@aws_options = options[:options]
|
38
|
+
if @aws_params[:aws] and @aws_params[:aws][:fileupload]
|
39
|
+
image_link = aws_imageshack_save(@aws_params, @aws_api_key)
|
40
|
+
responds_to_parent do
|
41
|
+
render :update do |page|
|
42
|
+
page.replace 'aws_upload_form', :inline => aws_image_shack_form(image_link)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
return image_link
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def aws_imageshack_save(params, api_key)
|
50
|
+
require "net/http"
|
51
|
+
require "net/http/post/multipart"
|
52
|
+
|
53
|
+
name = params[:aws][:fileupload].original_filename
|
54
|
+
directory = 'tmp/uploads'
|
55
|
+
`mkdir "#{directory}"` if !File.exists?(directory)
|
56
|
+
path = File.join(directory, name)
|
57
|
+
File.open(path, "wb") { |f| f.write(params[:aws][:fileupload].read)}
|
58
|
+
extension = File.extname( path ).sub( /^\./, '' ).downcase
|
59
|
+
mime_type = params[:aws][:fileupload].content_type
|
60
|
+
|
61
|
+
url = URI.parse('http://www.imageshack.us/upload_api.php')
|
62
|
+
File.open(path) do |filedata|
|
63
|
+
req = Net::HTTP::Post::Multipart.new url.path,
|
64
|
+
"fileupload" => UploadIO.new(filedata, mime_type, path),
|
65
|
+
"key" => api_key
|
66
|
+
res = Net::HTTP.start(url.host, url.port) {|http| http.request(req)}
|
67
|
+
image_link = res.body.scan(/<image_link>(.*)<\/image_link>/)
|
68
|
+
return image_link[0].to_s
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
module ViewHelpersMethods
|
74
|
+
include ActionView::Helpers::FormTagHelper
|
75
|
+
def aws_image_shack_form(image = nil)
|
76
|
+
style_css = (@aws_options[:style_css] ? @aws_options[:style_css] : "height: 22px; border: 1px solid rgb(199, 199, 199); margin-bottom: 1px;") if !@aws_options[:class_css]
|
77
|
+
class_css = @aws_options[:class_css] ? @aws_options[:class_css] : ""
|
78
|
+
size = @aws_options[:size] ? @aws_options[:size] : 58
|
79
|
+
|
80
|
+
image_html = ''
|
81
|
+
image_html = image_tag(image, :style => "float: #{@aws_options[:position]};width: #{@aws_options[:width]}px; height: #{@aws_options[:height]}px") if image
|
82
|
+
|
83
|
+
content = ''
|
84
|
+
content += form_tag({:controller=> params[:controller], :action => params[:action]} , :id => 'aws_upload_form', :multipart => true, :target => 'aws_hidden_iframe', :style => 'text-align:center')
|
85
|
+
content += image_html+'</br>' if @aws_options[:position].downcase=='top'
|
86
|
+
content += file_field('aws', 'fileupload', :size => size, :class => class_css, :style => 'style_css', :onchange => "submit();")
|
87
|
+
content += '</br>'+image_html if @aws_options[:position].downcase!='top'
|
88
|
+
content += "<iframe id=\"aws_hidden_iframe\" name=\"aws_hidden_iframe\" style=\"display: none\"></iframe>"
|
89
|
+
content += "</form>"
|
90
|
+
return content
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
data/uninstall.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Uninstall hook code here
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aws_imageshack
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Denis FABIEN
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-12-29 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description:
|
23
|
+
email: denis@miseajour.net
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- README
|
30
|
+
files:
|
31
|
+
- aws_imageshack-0.1.0.gem
|
32
|
+
- init.rb
|
33
|
+
- install.rb
|
34
|
+
- MIT-LICENSE
|
35
|
+
- Rakefile
|
36
|
+
- README
|
37
|
+
- uninstall.rb
|
38
|
+
- lib/aws_imageshack.rb
|
39
|
+
has_rdoc: true
|
40
|
+
homepage: http://www.miseajour.net/une-gem-pour-surveiller-la-modification-des-champs.html
|
41
|
+
licenses: []
|
42
|
+
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
hash: 3
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
version: "0"
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
hash: 3
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
version: "0"
|
66
|
+
requirements: []
|
67
|
+
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 1.3.7
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: Use ImageShack to host your image, with un ajax upload form
|
73
|
+
test_files: []
|
74
|
+
|