simple-image-uploader 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in simple-image-uploader.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Chim Kan
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Simple::Image::Uploader
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'simple-image-uploader'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install simple-image-uploader
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,6 @@
1
+ ******************************************************************
2
+ simple-image-uploader is Rails 3 Image uploader generator
3
+ ******************************************************************
4
+
5
+ Example:
6
+ rails g simple-image-uploader
@@ -0,0 +1,31 @@
1
+ module SimpleImageUploader
2
+ module Generators
3
+ class SimpleImageUploaderGenerator < Rails::Generators::Base
4
+ source_root File.expand_path('../templates', __FILE__)
5
+
6
+ def create_image_model
7
+ generate("model", "image description:string file:string")
8
+ rake("db:migrate")
9
+ end
10
+
11
+ def generate_image_everything
12
+ # Copy the controllers for user, sessions and password_reset
13
+ copy_file "images_controller.rb", "app/controllers/"
14
+ copy_file "file_uploader.rb", "app/uploaders/"
15
+ copy_file "image.rb", "app/models/"
16
+ directory "images", "app/views/images/"
17
+ end
18
+
19
+ def insert_routes
20
+ route("resources :images")
21
+ end
22
+
23
+ def add_gems
24
+ gem("carrierwave")
25
+ gem("mini_magick")
26
+ end
27
+
28
+
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,55 @@
1
+ # encoding: utf-8
2
+
3
+ class FileUploader < CarrierWave::Uploader::Base
4
+
5
+ # Include RMagick or MiniMagick support:
6
+ # include CarrierWave::RMagick
7
+ include CarrierWave::MiniMagick
8
+
9
+ # Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility:
10
+ # include Sprockets::Helpers::RailsHelper
11
+ # include Sprockets::Helpers::IsolatedHelper
12
+
13
+ # Choose what kind of storage to use for this uploader:
14
+ storage :file
15
+ # storage :fog
16
+
17
+ # Override the directory where uploaded files will be stored.
18
+ # This is a sensible default for uploaders that are meant to be mounted:
19
+ def store_dir
20
+ "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
21
+ end
22
+
23
+ # Provide a default URL as a default if there hasn't been a file uploaded:
24
+ # def default_url
25
+ # # For Rails 3.1+ asset pipeline compatibility:
26
+ # # asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
27
+ #
28
+ # "/images/fallback/" + [version_name, "default.png"].compact.join('_')
29
+ # end
30
+
31
+ # Process files as they are uploaded:
32
+ process :resize_and_pad => [500, 500, 'white' ]
33
+ #
34
+ # def scale(width, height)
35
+ # # do something
36
+ # end
37
+
38
+ # Create different versions of your uploaded files:
39
+ # version :thumb do
40
+ # process :scale => [50, 50]
41
+ # end
42
+
43
+ # Add a white list of extensions which are allowed to be uploaded.
44
+ # For images you might use something like this:
45
+ # def extension_white_list
46
+ # %w(jpg jpeg gif png)
47
+ # end
48
+
49
+ # Override the filename of the uploaded files:
50
+ # Avoid using model.id or version_name here, see uploader/store.rb for details.
51
+ # def filename
52
+ # "something.jpg" if original_filename
53
+ # end
54
+
55
+ end
@@ -0,0 +1,7 @@
1
+ class Image < ActiveRecord::Base
2
+ attr_accessible :description, :file, :remove_file
3
+
4
+ validates :description, :length => { maximum: 150 }
5
+
6
+ mount_uploader :file, FileUploader
7
+ end
@@ -0,0 +1,11 @@
1
+ <%= form_for @image, html: { multipart: true } do |f| %>
2
+ <p>
3
+ <%= f.label :description %><br />
4
+ <%= f.text_field :description %>
5
+ </p>
6
+ <p>
7
+ <%= f.label :file %><br />
8
+ <%= f.file_field :file %>
9
+ </p>
10
+ <p><%= f.submit %></p>
11
+ <% end %>
@@ -0,0 +1,7 @@
1
+
2
+ <%= render 'form' %>
3
+
4
+ <p>
5
+ <%= link_to "Show", @image %> |
6
+ <%= link_to "View All", images_path %>
7
+ </p>
@@ -0,0 +1,18 @@
1
+
2
+ <table>
3
+ <tr>
4
+ <th>Description</th>
5
+ <th>File</th>
6
+ </tr>
7
+ <% for image in @images %>
8
+ <tr>
9
+ <td><%= image.description %></td>
10
+ <td><%= image_tag image.file %></td>
11
+ <td><%= link_to "Show", image %></td>
12
+ <td><%= link_to "Edit", edit_image_path(image) %></td>
13
+ <td><%= link_to "Destroy", image, :confirm => 'Are you sure?', :method => :delete %></td>
14
+ </tr>
15
+ <% end %>
16
+ </table>
17
+
18
+ <p><%= link_to "New Image", new_image_path %></p>
@@ -0,0 +1,5 @@
1
+
2
+
3
+ <%= render 'form' %>
4
+
5
+ <p><%= link_to "Back to List", images_path %></p>
@@ -0,0 +1,15 @@
1
+
2
+ <p>
3
+ <strong>Description:</strong>
4
+ <%= @image.description %>
5
+ </p>
6
+ <p>
7
+ <strong>Image:</strong>
8
+ <%= image_tag @image.file %>
9
+ </p>
10
+
11
+ <p>
12
+ <%= link_to "Edit", edit_image_path(@image) %> |
13
+ <%= link_to "Destroy", @image, :confirm => 'Are you sure?', :method => :delete %> |
14
+ <%= link_to "View All", images_path %>
15
+ </p>
@@ -0,0 +1,42 @@
1
+ class ImagesController < ApplicationController
2
+ def index
3
+ @images = Image.all
4
+ end
5
+
6
+ def show
7
+ @image = Image.find(params[:id])
8
+ end
9
+
10
+ def new
11
+ @image = Image.new
12
+ end
13
+
14
+ def create
15
+ @image = Image.new(params[:image])
16
+ if @image.save
17
+ redirect_to @image, :notice => "Successfully created image."
18
+ else
19
+ render :action => 'new'
20
+ end
21
+ end
22
+
23
+ def edit
24
+ @image = Image.find(params[:id])
25
+ end
26
+
27
+ def update
28
+ @image = Image.find(params[:id])
29
+ if @image.update_attributes(params[:image])
30
+ redirect_to @image, :notice => "Successfully updated image."
31
+ else
32
+ render :action => 'edit'
33
+ end
34
+ end
35
+
36
+ def destroy
37
+ @image = Image.find(params[:id])
38
+ @image.remove_file!
39
+ @image.destroy
40
+ redirect_to images_url, :notice => "Successfully destroyed image."
41
+ end
42
+ end
@@ -0,0 +1,9 @@
1
+ require "simple-image-uploader/version"
2
+
3
+ module Simple
4
+ module Image
5
+ module Uploader
6
+ # Your code goes here...
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ module Simple
2
+ module Image
3
+ module Uploader
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple-image-uploader
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Chim Kan
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-03 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: ! 'simple-image-uploader creates Image scaffold with file upload and
15
+ removal. It is based on carrierwave and mini-imagegick gems. Image model, controller
16
+ and form are have simple code that allows any application to use image upload immediately.
17
+ Add simple-image-uploader gem to your Gemfile. Run bundle install. Then run ''rails
18
+ g simple-image-uploader''. Run rails s and check http://localhost:3000/images. '
19
+ email:
20
+ - designium@gmail.com
21
+ executables: []
22
+ extensions: []
23
+ extra_rdoc_files: []
24
+ files:
25
+ - lib/rails/generators/simple-image-uploader/simple-login-generator.rb
26
+ - lib/rails/generators/simple-image-uploader/templates/file_uploader.rb
27
+ - lib/rails/generators/simple-image-uploader/templates/image.rb
28
+ - lib/rails/generators/simple-image-uploader/templates/images/_form.html.erb
29
+ - lib/rails/generators/simple-image-uploader/templates/images/edit.html.erb
30
+ - lib/rails/generators/simple-image-uploader/templates/images/index.html.erb
31
+ - lib/rails/generators/simple-image-uploader/templates/images/new.html.erb
32
+ - lib/rails/generators/simple-image-uploader/templates/images/show.html.erb
33
+ - lib/rails/generators/simple-image-uploader/templates/images_controller.rb
34
+ - lib/rails/generators/simple-image-uploader/USAGE
35
+ - lib/simple-image-uploader/version.rb
36
+ - lib/simple-image-uploader.rb
37
+ - Gemfile
38
+ - LICENSE
39
+ - Rakefile
40
+ - README.md
41
+ homepage: ''
42
+ licenses: []
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project:
61
+ rubygems_version: 1.8.11
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: simple-image-uploader allows you to upload images to your Rails 3 app immediately
65
+ with minimum of effort.
66
+ test_files: []