== Attachment Magick

Attachment Magick is a gem to upload images and videos(vimeo and youtube) using swfupload.
Supports Mongoid and ActiveRecord.

== Installation

Add to Gemfile

  gem 'attachment_magick'


After the gem installation, run the generator

  rails g attachment_magick:install

The generator will install swfupload (js and css files) and will create some routes.

And if you are using ActiveRecord, run this too

  rails g attachment_magick:migration

Create a initializer like this (config/initializers/attachment_magick_setup.rb)

  AttachmentMagick.setup do |config|
    #config.default_add_partial = '/attachment_magick/add_image'  # default
    config.columns_amount = 16
    config.columns_width  = 52
    config.gutter         = 8
    config.orms           = ["ActiveRecord", "Mongoid"] # Mongoid is default
    
    config.custom_styles do
      publisher "52x"
      my_custom_style "50x50"
    end
  end

* Attachment Magick is based in 960 Grid System (http://960.gs/)

Add to application.rb

  config.middleware.insert 0, 'Dragonfly::Middleware', :images
  config.middleware.insert_before 'Dragonfly::Middleware', 'Rack::Cache', {
    :verbose     => true,
    :metastore   => "file:#{Rails.root}/tmp/dragonfly/cache/meta",
    :entitystore => "file:#{Rails.root}/tmp/dragonfly/cache/body"
  }

== Getting started

Include the js files to your application layout or page

  javascript_include_tag :defaults, "swfupload/handlers", "swfupload/swfupload"

Include AttachmentMagick Module to your model

  class Post
    include AttachmentMagick

    ...
  end

Call this helpers in form views

  attachment_progress_container @post
  attachment_for_view @post
  attachment_for_video @post
  attachment_for_flash @image.photo.url

For customize your list for images
  attachment_for_view @post, 'path/my_partial'


== Customizing views

=== Just Images

  <div class="attachment_magick_image" id="image_<%=image.id%>" style="width:inerit; margin-bottom:10px;">
    <%= image_tag image.photo.thumb(image._parent.class.style_publisher).url%>
    <input id ="image_id" type ="hidden" value ="<%=image.id%>">

    <%= link_to "[x]", "javascript://", :class => "remove_image", :style => "float:right;"%>
  </div>

  <%= attachment_for_view @post, "path_to_my_partial" %>

== Customizing sizes

  class Post
    include AttachmentMagick

    attachment_magick do
      grid_1 "100x100"
    end
  end

== Credits

Author: [Marco Singer](http://github.com/marcosinger)
Contributors: [Lucas Renan](http://github.com/lucasrenan), [Carlos Brando](http://github.com/carlosbrando)

== See in RubyGems.org
(http://rubygems.org/gems/attachment_magick)