Skip to content

Commit

Permalink
added readme and fixed some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
over committed Dec 10, 2008
1 parent 03ef299 commit 8b6e4ce
Show file tree
Hide file tree
Showing 15 changed files with 1,338 additions and 2 deletions.
20 changes: 20 additions & 0 deletions MIT-LICENSE
@@ -0,0 +1,20 @@
Copyright (c) 2008 [name of plugin creator]

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
86 changes: 84 additions & 2 deletions README
Expand Up @@ -3,10 +3,92 @@ EasySwfUpload


This plugin will help you to embed swf upload into your project This plugin will help you to embed swf upload into your project


First, install this plugin:
script/plugin install git://github.com/over/easy_swf_upload.git

Then, run generator:
script/generate easy_swf_upload

Example Example
======= =======


Example goes here. In your application.html.erb include javascripts:
<%= javascript_include_tag :defaults, "swfupload", "swfupload_plugin" %>

Plugin doesn't works without prototype javascript library.

Then, use this helper to embed swf upload to your application:

<%= swf_upload_area "Upload images", :url => upload_image_block_path,
:session_id => "_plugins_session",
:filetypes => "*.jpg; *.gif",
:button_style => "font-family: Arial, sans-serif; font-size: 14pt; font-weight:bold;" %>

In your controller:

class PagesController < ApplicationController
session :cookie_only => false # this is very important, don't forget to set it to false

def get_image_block
@image_block = ImageBlock.new(:file => params[:Filedata]) # here you can use your favourite plugin to work with attachments

# use RJS here
render :update do |page|
page['blocks'].insert("<div><img src="http://domain.com" /></div>")
end
end
end


Also, you need to customize uploading area, i used this css:

<style>

body {
font-family:Arial, Helvetica, Sans-serif;
font-size:12px;
}

.uploadContainer {
margin:0;
padding:0;
}
.uploadContainer li {
list-style:none;
margin:0;
padding:0;
padding:4px;
border:#CCC;
margin-bottom:10px;
position:relative;
height:22px;
}

.uploadContainer li h6 {
margin:0;
padding:0;
color:#000;
font-size:11px;
position:relative;
z-index:2;
}

.uploadContainer li div.progress {
margin:0;
padding:0;
position:absolute;
left:0;
bottom:0;
height:5px;
z-index:1;
background:#003ee3;
}
</style>

Uploading file template:
<li id="file_#{id}"><div class="progress" style="width:1%"></div><h6>#{title}</h6></li>



Thanks.


Copyright (c) 2008 [name of plugin creator], released under the MIT license Copyright (c) 2008 Mikhail Tabunov, released under the MIT license
22 changes: 22 additions & 0 deletions Rakefile
@@ -0,0 +1,22 @@
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'

desc 'Default: run unit tests.'
task :default => :test

desc 'Test the easy_swf_upload plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end

desc 'Generate documentation for the easy_swf_upload plugin.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'EasySwfUpload'
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README')
rdoc.rdoc_files.include('lib/**/*.rb')
end
27 changes: 27 additions & 0 deletions generators/easy_swf_upload/easy_swf_upload_generator.rb
@@ -0,0 +1,27 @@
class EasySwfUploadGenerator < Rails::Generator::Base
def manifest
record do |m|
m.file 'cgi_session_hack.rb',
'config/initializers/cgi_session_hack.rb',
:chmod => 0644,
:collision => :force
m.file 'swfupload.js',
'public/javascripts/swfupload.js',
:chmod => 0644,
:collision => :force
m.file 'swfupload.queue.js',
'public/javascripts/swfupload.queue.js',
:chmod => 0644,
:collision => :force
m.directory 'public/flash'
m.file 'swfupload.swf',
'public/flash/swfupload.swf',
:chmod => 0644,
:collision => :force
m.file 'swfupload_plugin.js',
'public/javascripts/swfupload_plugin.js',
:chmod => 0644,
:collision => :force
end
end
end
24 changes: 24 additions & 0 deletions generators/easy_swf_upload/templates/cgi_session_hack.rb
@@ -0,0 +1,24 @@
class CGI::Session
# allows getting session_id from query string if cookie_only is set to false
alias original_initialize initialize

def initialize(cgiwrapper, option = {})
unless option['cookie_only']
session_key = option['session_key'] || '_session_id'

env_table = cgiwrapper.send(:env_table) #todo find correct way to do this
session_id = [
env_table['QUERY_STRING'],
env_table['REQUEST_URI'][/\?(.+)/, 1]
].collect do |s|
s[/#{session_key}=([^&]{32,})/, 1] if s
end.compact.first

if session_id
cgiwrapper.instance_variable_set(:@cookies, {session_key => [CGI.unescape(session_id)]})
end
end

original_initialize(cgiwrapper, option)
end
end

0 comments on commit 8b6e4ce

Please sign in to comment.