├── .gitignore ├── Gemfile ├── Gemfile.lock ├── MIT-LICENSE ├── README.md ├── Rakefile ├── activeadmin-dragonfly.gemspec ├── app └── assets │ └── stylesheets │ └── active_admin │ └── active_admin_dragonfly.css.sass ├── config └── locales │ ├── en.yml │ └── it.yml └── lib ├── active_admin └── dragonfly │ ├── engine.rb │ └── version.rb ├── activeadmin-dragonfly.rb └── formtastic └── inputs └── dragonfly_input.rb /.gitignore: -------------------------------------------------------------------------------- 1 | .bundle 2 | bin 3 | 4 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gemspec 4 | 5 | gem 'activeadmin', github: 'gregbell/active_admin', branch: 'master' 6 | 7 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GIT 2 | remote: git://github.com/gregbell/active_admin.git 3 | revision: f21cff30e7212706a39710e2c70ad0af8087ccea 4 | branch: master 5 | specs: 6 | activeadmin (1.0.0.pre) 7 | arbre (~> 1.0) 8 | bourbon 9 | coffee-rails 10 | devise (~> 3.2) 11 | formtastic (~> 2.3.0.rc2) 12 | inherited_resources (~> 1.3) 13 | jquery-rails 14 | jquery-ui-rails 15 | kaminari (~> 0.15) 16 | rails (>= 3.2, < 4.1) 17 | ransack (~> 1.0) 18 | sass-rails 19 | 20 | PATH 21 | remote: . 22 | specs: 23 | activeadmin-dragonfly (0.0.2) 24 | activeadmin 25 | dragonfly (= 0.9.15) 26 | rack-cache 27 | 28 | GEM 29 | remote: https://rubygems.org/ 30 | specs: 31 | actionmailer (4.0.2) 32 | actionpack (= 4.0.2) 33 | mail (~> 2.5.4) 34 | actionpack (4.0.2) 35 | activesupport (= 4.0.2) 36 | builder (~> 3.1.0) 37 | erubis (~> 2.7.0) 38 | rack (~> 1.5.2) 39 | rack-test (~> 0.6.2) 40 | activemodel (4.0.2) 41 | activesupport (= 4.0.2) 42 | builder (~> 3.1.0) 43 | activerecord (4.0.2) 44 | activemodel (= 4.0.2) 45 | activerecord-deprecated_finders (~> 1.0.2) 46 | activesupport (= 4.0.2) 47 | arel (~> 4.0.0) 48 | activerecord-deprecated_finders (1.0.3) 49 | activesupport (4.0.2) 50 | i18n (~> 0.6, >= 0.6.4) 51 | minitest (~> 4.2) 52 | multi_json (~> 1.3) 53 | thread_safe (~> 0.1) 54 | tzinfo (~> 0.3.37) 55 | arbre (1.0.1) 56 | activesupport (>= 3.0.0) 57 | arel (4.0.1) 58 | atomic (1.1.14) 59 | bcrypt-ruby (3.1.2) 60 | bourbon (3.1.8) 61 | sass (>= 3.2.0) 62 | thor 63 | builder (3.1.4) 64 | coffee-rails (4.0.1) 65 | coffee-script (>= 2.2.0) 66 | railties (>= 4.0.0, < 5.0) 67 | coffee-script (2.2.0) 68 | coffee-script-source 69 | execjs 70 | coffee-script-source (1.6.3) 71 | devise (3.2.2) 72 | bcrypt-ruby (~> 3.0) 73 | orm_adapter (~> 0.1) 74 | railties (>= 3.2.6, < 5) 75 | thread_safe (~> 0.1) 76 | warden (~> 1.2.3) 77 | dragonfly (0.9.15) 78 | multi_json (~> 1.0) 79 | rack 80 | erubis (2.7.0) 81 | execjs (2.0.2) 82 | formtastic (2.3.0.rc2) 83 | actionpack (>= 3.0) 84 | has_scope (0.6.0.rc) 85 | actionpack (>= 3.2, < 5) 86 | activesupport (>= 3.2, < 5) 87 | hike (1.2.3) 88 | i18n (0.6.9) 89 | inherited_resources (1.4.1) 90 | has_scope (~> 0.6.0.rc) 91 | responders (~> 1.0.0.rc) 92 | jquery-rails (3.0.4) 93 | railties (>= 3.0, < 5.0) 94 | thor (>= 0.14, < 2.0) 95 | jquery-ui-rails (4.1.1) 96 | railties (>= 3.1.0) 97 | kaminari (0.15.1) 98 | actionpack (>= 3.0.0) 99 | activesupport (>= 3.0.0) 100 | mail (2.5.4) 101 | mime-types (~> 1.16) 102 | treetop (~> 1.4.8) 103 | mime-types (1.25.1) 104 | minitest (4.7.5) 105 | multi_json (1.8.4) 106 | orm_adapter (0.5.0) 107 | polyamorous (0.6.4) 108 | activerecord (>= 3.0) 109 | polyglot (0.3.3) 110 | rack (1.5.2) 111 | rack-cache (1.2) 112 | rack (>= 0.4) 113 | rack-test (0.6.2) 114 | rack (>= 1.0) 115 | rails (4.0.2) 116 | actionmailer (= 4.0.2) 117 | actionpack (= 4.0.2) 118 | activerecord (= 4.0.2) 119 | activesupport (= 4.0.2) 120 | bundler (>= 1.3.0, < 2.0) 121 | railties (= 4.0.2) 122 | sprockets-rails (~> 2.0.0) 123 | railties (4.0.2) 124 | actionpack (= 4.0.2) 125 | activesupport (= 4.0.2) 126 | rake (>= 0.8.7) 127 | thor (>= 0.18.1, < 2.0) 128 | rake (10.1.1) 129 | ransack (1.1.0) 130 | actionpack (>= 3.0) 131 | activerecord (>= 3.0) 132 | polyamorous (~> 0.6.0) 133 | responders (1.0.0) 134 | railties (>= 3.2, < 5) 135 | sass (3.2.13) 136 | sass-rails (4.0.1) 137 | railties (>= 4.0.0, < 5.0) 138 | sass (>= 3.1.10) 139 | sprockets-rails (~> 2.0.0) 140 | sprockets (2.10.1) 141 | hike (~> 1.2) 142 | multi_json (~> 1.0) 143 | rack (~> 1.0) 144 | tilt (~> 1.1, != 1.3.0) 145 | sprockets-rails (2.0.1) 146 | actionpack (>= 3.0) 147 | activesupport (>= 3.0) 148 | sprockets (~> 2.8) 149 | thor (0.18.1) 150 | thread_safe (0.1.3) 151 | atomic 152 | tilt (1.4.1) 153 | treetop (1.4.15) 154 | polyglot 155 | polyglot (>= 0.3.1) 156 | tzinfo (0.3.38) 157 | warden (1.2.3) 158 | rack (>= 1.0) 159 | 160 | PLATFORMS 161 | ruby 162 | 163 | DEPENDENCIES 164 | activeadmin! 165 | activeadmin-dragonfly! 166 | -------------------------------------------------------------------------------- /MIT-LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Andrea Pavoni http://andreapavoni.com 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. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # activeadmin-dragonfly 2 | 3 | ### :warning: Unmaintained :warning: 4 | 5 | Sorry, but I no longer work on ActiveAdmin often enough to justify mantaining this gem. Take it as it is. If you are interested to update and maintain the gem, please let me know! :heart: 6 | 7 | ### Gemfile 8 | 9 | ```ruby 10 | gem 'activeadmin-dragonfly', github: 'stefanoverna/activeadmin-dragonfly' 11 | ``` 12 | 13 | ### Model 14 | 15 | ```ruby 16 | class BlogPost < ActiveRecord::Base 17 | attr_accessible :image, :retained_image, :remove_image 18 | image_accessor :image 19 | end 20 | ``` 21 | 22 | ### Editor 23 | 24 | ```ruby 25 | ActiveAdmin.register BlogPost do 26 | form do |f| 27 | # ... 28 | f.input :image, as: :dragonfly 29 | f.input :image, as: :dragonfly, input_html: { components: [:preview, :upload, :url, :remove ] } 30 | # ... 31 | end 32 | end 33 | ``` 34 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env rake 2 | begin 3 | require 'bundler/setup' 4 | rescue LoadError 5 | puts 'You must `gem install bundler` and `bundle install` to run rake tasks' 6 | end 7 | begin 8 | require 'rdoc/task' 9 | rescue LoadError 10 | require 'rdoc/rdoc' 11 | require 'rake/rdoctask' 12 | RDoc::Task = Rake::RDocTask 13 | end 14 | 15 | RDoc::Task.new(:rdoc) do |rdoc| 16 | rdoc.rdoc_dir = 'rdoc' 17 | rdoc.title = 'SimpleFormDragonfly' 18 | rdoc.options << '--line-numbers' 19 | rdoc.rdoc_files.include('README.rdoc') 20 | rdoc.rdoc_files.include('lib/**/*.rb') 21 | end 22 | 23 | Bundler::GemHelper.install_tasks 24 | 25 | -------------------------------------------------------------------------------- /activeadmin-dragonfly.gemspec: -------------------------------------------------------------------------------- 1 | $:.push File.expand_path("../lib", __FILE__) 2 | 3 | # Maintain your gem's version: 4 | require "active_admin/dragonfly/version" 5 | 6 | # Describe your gem and declare its dependencies: 7 | Gem::Specification.new do |s| 8 | s.name = "activeadmin-dragonfly" 9 | s.version = ActiveAdmin::Dragonfly::VERSION 10 | s.authors = ["Stefano Verna"] 11 | s.email = ["stefano.verna@gmail.com"] 12 | s.homepage = "http://github.com/cantierecreativo/activeadmin-dragonfly" 13 | s.summary = "Adds a new :dragonfly field type to ActiveAdmin" 14 | s.description = "Adds a new :dragonfly field type to ActiveAdmin" 15 | 16 | s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.md"] 17 | 18 | s.add_dependency "activeadmin" 19 | s.add_dependency "dragonfly", "~> 1.0" 20 | s.add_dependency "rack-cache" 21 | end 22 | 23 | -------------------------------------------------------------------------------- /app/assets/stylesheets/active_admin/active_admin_dragonfly.css.sass: -------------------------------------------------------------------------------- 1 | @import bourbon 2 | 3 | .input.dragonfly 4 | padding: 0 5 | 6 | .fragments 7 | 8 | &> legend 9 | display: none 10 | 11 | ol 12 | 13 | li 14 | +clearfix 15 | 16 | label 17 | text-align: right 18 | 19 | &.component-remove 20 | label 21 | padding-left: 110px 22 | width: auto 23 | float: none 24 | text-align: left 25 | 26 | &.component-preview 27 | &> a 28 | float: left 29 | display: block 30 | padding: 5px 31 | background: white 32 | border: 1px solid #ccc 33 | border-radius: 2px 34 | 35 | img 36 | display: block 37 | 38 | .component-preview 39 | .no-image 40 | line-height: 32px 41 | -------------------------------------------------------------------------------- /config/locales/en.yml: -------------------------------------------------------------------------------- 1 | en: 2 | formtastic: 3 | dragonfly: 4 | no_image: "No image present" 5 | upload: "Upload" 6 | url: "URL" 7 | remove: "Remove?" 8 | -------------------------------------------------------------------------------- /config/locales/it.yml: -------------------------------------------------------------------------------- 1 | it: 2 | formtastic: 3 | dragonfly: 4 | no_image: "Nessuna immagine" 5 | no_file: "Nessun file disponibile" 6 | upload: "Upload" 7 | url: "URL" 8 | remove: "Rimuovi?" 9 | -------------------------------------------------------------------------------- /lib/active_admin/dragonfly/engine.rb: -------------------------------------------------------------------------------- 1 | require 'dragonfly' 2 | 3 | module ActiveAdmin 4 | module Dragonfly 5 | 6 | class Engine < ::Rails::Engine 7 | initializer "Railsyard precompile hook", group: :all do |app| 8 | # check if someone already initialized Dragonfly for Rails 9 | unless ActiveRecord::Base.methods.include? :image_accessor 10 | require 'dragonfly/rails/images' 11 | end 12 | 13 | app.config.assets.precompile += [ 14 | "active_admin/active_admin_dragonfly.js", 15 | "active_admin/active_admin_dragonfly.css" 16 | ] 17 | end 18 | 19 | initializer "register stylesheets" do 20 | ActiveAdmin.application.register_stylesheet "active_admin/active_admin_dragonfly.css", :media => :screen 21 | end 22 | end 23 | 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /lib/active_admin/dragonfly/version.rb: -------------------------------------------------------------------------------- 1 | module ActiveAdmin 2 | module Dragonfly 3 | VERSION = "0.0.2" 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /lib/activeadmin-dragonfly.rb: -------------------------------------------------------------------------------- 1 | require 'active_admin/dragonfly/engine' 2 | require 'formtastic/inputs/dragonfly_input' 3 | -------------------------------------------------------------------------------- /lib/formtastic/inputs/dragonfly_input.rb: -------------------------------------------------------------------------------- 1 | module Formtastic 2 | module Inputs 3 | 4 | class DragonflyInput < Formtastic::Inputs::FileInput 5 | 6 | def to_html 7 | components = input_html_options[:components] || [ :preview, :upload, :remove ] 8 | input_wrapping do 9 | fragments_wrapping do 10 | fragments_label << 11 | template.content_tag(:ol) do 12 | components.map do |component| 13 | template.content_tag(:li, class: "input component-#{component}") do 14 | fragment_html(component) 15 | end 16 | end.join.html_safe 17 | end 18 | end 19 | end 20 | end 21 | 22 | def fragments_wrapping(&block) 23 | template.content_tag(:fieldset, 24 | template.capture(&block).html_safe, 25 | fragments_wrapping_html_options 26 | ) 27 | end 28 | 29 | def fragments_wrapping_html_options 30 | { :class => "fragments" } 31 | end 32 | 33 | def fragments_label 34 | if render_label? 35 | template.content_tag(:legend, builder.label(method, label_text, :class => "label")) 36 | else 37 | "".html_safe 38 | end 39 | end 40 | 41 | def fragment_label_html(fragment) 42 | text = fragment_label(fragment) 43 | text.blank? ? "".html_safe : template.content_tag(:label, text, :for => fragment_id(fragment)) 44 | end 45 | 46 | def fragment_id(fragment) 47 | "#{input_html_options[:id]}_#{fragment}" 48 | end 49 | 50 | def fragment_label(fragment) 51 | labels_from_options = options[:labels] || {} 52 | if labels_from_options.key?(fragment) 53 | labels_from_options[fragment] 54 | else 55 | ::I18n.t(fragment.to_s, :default => fragment.to_s.humanize, :scope => [:dragonfly]) 56 | end 57 | end 58 | 59 | def fragment_html(fragment) 60 | send("fragment_#{fragment}_html") 61 | end 62 | 63 | def fragment_upload_html 64 | fragment_label_html(:upload) << 65 | builder.file_field(method, input_html_options) << 66 | builder.hidden_field("retained_#{method}") 67 | end 68 | 69 | def is_image?(file) 70 | file.mime_type =~ /png|bmp|gif|tif|jpe?g/ 71 | rescue Dragonfly::DataStorage::DataNotFound 72 | false 73 | end 74 | 75 | def fragment_preview_html 76 | file = object.send(method) 77 | if file.present? 78 | if is_image?(file) 79 | original_url = object.send(method).url 80 | preview_size = input_html_options[:preview_size] || [ 75, 75 ] 81 | preview_url = object.send(method).thumb("#{preview_size.first}x#{preview_size.last}#").url 82 | fragment_label_html(:preview) << template.link_to(template.image_tag(preview_url), original_url) 83 | else 84 | fragment_download_html 85 | end 86 | else 87 | fragment_label_html(:preview) << "