activeadmin-dragonfly 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4c691189762d74ab54f89197f5c2ea895eab507b
4
+ data.tar.gz: 1a339d41b706fbaa49433efc979d74a679ce4a12
5
+ SHA512:
6
+ metadata.gz: f2a260f2fd93a58a2196bdfea79a89fb1c9ee750985a870d4e21a3165b19d288319aded8ac570d37841d8db6207dc0edec1bcbad98942207f66ea75f752509dd
7
+ data.tar.gz: 86607db6a5336644287dd7a2247c699ef2f5d1f93a914190469e03bead36744d0d321ae46096b6dbe12e55fdee664d52ab971bd6d52f636c72db72e36df2b45c
@@ -0,0 +1,30 @@
1
+ ### Gemfile
2
+
3
+ **As from version 0.1.0 this gem is only compatible with Dragonfly ~> 1.0.0. For older Dragonfly installations use version 0.0.2 of this gem.**
4
+
5
+ ```ruby
6
+ gem 'activeadmin-dragonfly', github: 'stefanoverna/activeadmin-dragonfly'
7
+ ```
8
+
9
+ ### Model
10
+
11
+ ```ruby
12
+ class BlogPost < ActiveRecord::Base
13
+ dragonfly_accessor :image
14
+ end
15
+ ```
16
+
17
+ ### Editor
18
+
19
+ ```ruby
20
+ ActiveAdmin.register BlogPost do
21
+ permit_params :image, :retained_image, :remove_image
22
+
23
+ form do |f|
24
+ # ...
25
+ f.input :image, as: :dragonfly
26
+ f.input :image, as: :dragonfly, input_html: { components: [:preview, :upload, :url, :remove ] }
27
+ # ...
28
+ end
29
+ end
30
+ ```
@@ -0,0 +1,24 @@
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
+
@@ -0,0 +1,51 @@
1
+ @import "bourbon";
2
+
3
+ .input.dragonfly {
4
+ .fragments {
5
+ ol {
6
+ li {
7
+ @include clearfix;
8
+
9
+ &.component-preview,
10
+ &.component-upload {
11
+ label {
12
+ display: none;
13
+ }
14
+ }
15
+
16
+ &.component-preview {
17
+ & > a {
18
+ float: left;
19
+ display: block;
20
+ padding: 5px;
21
+ background: white;
22
+ border: 1px solid #ccc;
23
+ border-radius: 2px;
24
+
25
+ img {
26
+ display: block;
27
+ }
28
+ }
29
+ }
30
+
31
+ &.component-remove {
32
+ label {
33
+ width: auto;
34
+ float: none;
35
+ text-align: left;
36
+ }
37
+ }
38
+
39
+ + li {
40
+ margin-top: 10px;
41
+ }
42
+ }
43
+ }
44
+ }
45
+
46
+ .component-preview {
47
+ .no-image {
48
+ line-height: 32px;
49
+ }
50
+ }
51
+ }
@@ -0,0 +1,7 @@
1
+ en:
2
+ formtastic:
3
+ dragonfly:
4
+ no_image: "No image present"
5
+ upload: "Upload"
6
+ url: "URL"
7
+ remove: "Remove?"
@@ -0,0 +1,8 @@
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?"
@@ -0,0 +1,20 @@
1
+ require 'dragonfly'
2
+
3
+ module ActiveAdmin
4
+ module Dragonfly
5
+
6
+ class Engine < ::Rails::Engine
7
+ initializer "precompile assets", group: :all do |app|
8
+ app.config.assets.precompile += [
9
+ "active_admin/active_admin_dragonfly.js",
10
+ "active_admin/active_admin_dragonfly.css"
11
+ ]
12
+ end
13
+
14
+ initializer "register stylesheets" do
15
+ ActiveAdmin.application.register_stylesheet "active_admin/active_admin_dragonfly.css", media: :screen
16
+ end
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ module ActiveAdmin
2
+ module Dragonfly
3
+ VERSION = "0.1.1"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require 'active_admin/dragonfly/engine'
2
+ require 'formtastic/inputs/dragonfly_input'
@@ -0,0 +1,120 @@
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
+ end
72
+
73
+ def fragment_preview_html
74
+ file = object.send(method)
75
+ if file.present?
76
+ if is_image?(file)
77
+ original_url = object.send(method).url
78
+ preview_size = input_html_options[:preview_size] || [ 75, 75 ]
79
+ preview_url = object.send(method).thumb("#{preview_size.first}x#{preview_size.last}#").url
80
+ fragment_label_html(:preview) << template.link_to(template.image_tag(preview_url), original_url)
81
+ else
82
+ fragment_download_html
83
+ end
84
+ else
85
+ fragment_label_html(:preview) << "<div class='no-image'>#{I18n.t("dragonfly.no_image")}</div>".html_safe
86
+ end
87
+ end
88
+
89
+ def fragment_download_html
90
+ file = object.send(method)
91
+ download = if file.present?
92
+ original_url = file.url
93
+ name = object.send("#{method}_name") rescue "Download"
94
+ name = name.blank? ? "Download" : name
95
+ template.link_to name, original_url
96
+ else
97
+ "<span class='no-file'>#{I18n.t("dragonfly.no_file")}</span>".html_safe
98
+ end
99
+ fragment_label_html(:download) << download
100
+ end
101
+
102
+ def fragment_url_html
103
+ fragment_label_html(:url) <<
104
+ builder.text_field("#{method}_url")
105
+ end
106
+
107
+ def fragment_remove_html
108
+ if object.send("#{method}_uid")
109
+ template.content_tag(:label, for: fragment_id(:remove)) do
110
+ builder.check_box("remove_#{method}") <<
111
+ " ".html_safe <<
112
+ I18n.t("dragonfly.remove")
113
+ end
114
+ end
115
+ end
116
+
117
+ end
118
+
119
+ end
120
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activeadmin-dragonfly
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Björn Wolf
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activeadmin
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.99'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.99'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dragonfly
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ description: For convenient use of dragonfly attachments within ActiveAdmin, this
42
+ gem adds a new input type and some stuff for retaining and removing.
43
+ email:
44
+ - bjoern@dreimannzelt.de
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - README.md
50
+ - Rakefile
51
+ - app/assets/stylesheets/active_admin/active_admin_dragonfly.css.scss
52
+ - config/locales/en.yml
53
+ - config/locales/it.yml
54
+ - lib/active_admin/dragonfly/engine.rb
55
+ - lib/active_admin/dragonfly/version.rb
56
+ - lib/activeadmin-dragonfly.rb
57
+ - lib/formtastic/inputs/dragonfly_input.rb
58
+ homepage: http://github.com/dreimannzelt/activeadmin-dragonfly
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.4.6
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Adds a new :dragonfly field type to ActiveAdmin
82
+ test_files: []