GithubHelp home page GithubHelp logo

davidstump / active_admin_jcrop Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ricardonacif/active_admin_jcrop

0.0 3.0 0.0 6.9 MB

Jcrop plugin for ActiveAdmin, enables cropping on image fields when editing

License: MIT License

Ruby 82.31% CoffeeScript 5.10% CSS 2.35% HTML 9.26% JavaScript 0.98%

active_admin_jcrop's Introduction

Active Admin Jcrop

Build Status Code Climate Gem Version

Cropping feature for Active Admin

Instalation

Add to your Gemfile:

gem 'activeadmin'
# Because active_admin_jcrop autoload modules by checking plugins you use, it's
# recommended to require it explictly before active_admin_jcrop
# e.g. if you use carrierwave
# gem 'carrierwave', :require => 'carrierwave'
gem 'active_admin_jcrop' #, git: 'git://github.com/Ricardonacif/active_admin_jcrop.git'

Configure your form to use Jcrop:

# RAILS_ROOT/app/admin/post.rb
ActiveAdmin.register Post do

  jcropable
  
  form do |f|                         
    f.inputs "Details" do
      f.input :image, as: :jcropable
    end                      
    f.actions
  end              
  
end

If you use Paperclip, you need to do nothing else, active_admin_jcrop will append it's processor to your attachment automatically. If CarrierWave is used, please invoke :active_admin_crop in your uploader, and include both modules:

class AvatarUploader < CarrierWave::Uploader::Base

  include CarrierWave::MiniMagick
  include ActiveAdminJcrop::AssetEngine::CarrierWave

  version :thumb do
    process :active_admin_crop
    process resize_to_fill: [500,320]
  end

end

Done! Now when there's a image attached, visit the edit page of the resource and click on the button Crop Image to open the crop modal. You don't need to save this resource, cropping will be done via ajax.

jCrop Options

Simple, just pass the options here:

# RAILS_ROOT/app/admin/post.rb
ActiveAdmin.register Post do

  jcropable
  
  form do |f|                         
    f.inputs "Details" do
      f.input :image, as: :jcropable,  jcrop_options: {aspectRatio: 1, showDimensions: true} # showDimensions will display the current crop dimensions in the upper left hand corner
    end                      
    f.actions
  end              
  
end

The default option for setSelect is [0,0,100,100]. For more available setting options, take a look at jCrop Manual.

Localization

Localize the crop feature by adding these entries:

    en:
      active_admin:
        crop:
          open_crop_modal: Crop Image
          save_cropped_image: Save Cropped Image
          cancel: Cancel

Dependencies

  • MRI +1.9.3 (All above 1.8.6 should work)
  • Rails 4.x (didn't tested with 3.2, but it might work)
  • MiniMagick

Supported ORM

  • ActiveRecord
  • Mongoid

Supported Asset Plugin

  • CarrierWave
  • Paperclip

TODO

  • make sure :active_admin_jcrop load after paperclip/carrierwave load
  • automate :active_admin_jcrop for CarrierWave uploader

Contributing

Any help is encouraged. Here are some ways you can contribute:

  • by using it
  • by telling people
  • by reporting bugs or suggesting new features on github issue tracker
  • by fixing bugs or implementing features

Thanks

This gem was based on Rails Admin Jcrop, so I'd like to thank those developers. Also, a special thanks to everyone that contributed to Active Admin and jCrop.

active_admin_jcrop's People

Contributors

arkadiybutermanov avatar emilmelnikov avatar nazarok avatar ricardonacif avatar stephancom avatar tamillarasan avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.