administrate-field-carrierwave 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a1717d7fe72c576d5abfa8bf124e4d06aa287ff4
4
- data.tar.gz: d42a7557e8138438a623b5e5a772b81ce544f0f6
3
+ metadata.gz: 7be62a38a3fac45a480819d4857ff3fa59e60d9b
4
+ data.tar.gz: 7d12584f15145b96a35d959ab74e198003076c36
5
5
  SHA512:
6
- metadata.gz: 676084a803681761b6034240d7c090bf0c013ec65f10b755537a5591154a340d5fcfa75b72677fdcf817a8bdcf964f6427fae8cc3e359fefe3c1bab63dd3d01b
7
- data.tar.gz: 473f01457a42b5f521fa925b5b912696f4e323262c0d8cdaac5f2dbfb8afe757f39e0fe66c76514207fe0208015bbebb95425fb39a8abcef8908fcc731c67927
6
+ metadata.gz: a95819b7c3b8f5a3d6944a1f9f558b83425a8cf3ff02c435bec54c3dbf116760250722f8a06f3df35abc9363d0c5665d26fa0f06c42c4d571a4538926bede6e7
7
+ data.tar.gz: 32d07b5b76e3bf6e4b776f3d067c71b6b8f4b0fb208dbe1dbc147d522b18ecec87cd17b0544b48df9638cf363442ea4b6573e5ad6445456e9fa07a9bd258a6c1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## [v0.1.0](https://github.com/z-productions/administrate-field-carrierwave/tree/v0.1.0) (2016-11-30)
4
+ [Full Changelog](https://github.com/z-productions/administrate-field-carrierwave/compare/v0.0.3...v0.1.0)
5
+
6
+ * Add support for multiple files
7
+
3
8
  ## [v0.0.3](https://github.com/z-productions/administrate-field-carrierwave/tree/v0.0.3) (2016-11-29)
4
9
  [Full Changelog](https://github.com/z-productions/administrate-field-carrierwave/compare/v0.0.2...v0.0.3)
5
10
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- administrate-field-carrierwave (0.0.3)
4
+ administrate-field-carrierwave (0.1.0)
5
5
  administrate (~> 0.3.0)
6
6
  rails (>= 4.2)
7
7
 
data/README.md CHANGED
@@ -9,7 +9,7 @@ A plugin to upload and preview Carrierwave attachments in [Administrate].
9
9
  Add it to your `Gemfile`:
10
10
 
11
11
  ```ruby
12
- gem 'administrate-field-carrierwave', '~> 0.0.3'
12
+ gem 'administrate-field-carrierwave', '~> 0.1.0'
13
13
  ```
14
14
 
15
15
  Run:
@@ -22,12 +22,13 @@ Add to your `FooDashboard`:
22
22
 
23
23
  ```ruby
24
24
  ATTRIBUTE_TYPES = {
25
- bar: Field::Carrierwave.with_options(image: :standard)
25
+ bar: Field::Carrierwave.with_options(image: :standard, multiple: true)
26
26
  }.freeze
27
27
  ```
28
28
  ### Options
29
29
 
30
30
  * `image` (default: `nil`): a [version] that will be displayed in an `<img>` element.
31
+ * `multiple` (default: `false`): allows uploading of multiple files. **ATTENTION 🚨**: [requires CarrierWave’s `master` branch](https://github.com/carrierwaveuploader/carrierwave#multiple-file-uploads). Uploaded files will replace the current ones – if present – and not add to them.
31
32
 
32
33
  ## About
33
34
 
@@ -2,7 +2,7 @@ $:.push File.expand_path('../lib', __FILE__)
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = 'administrate-field-carrierwave'
5
- gem.version = '0.0.3'
5
+ gem.version = '0.1.0'
6
6
  gem.authors = ['Michele Gerarduzzi']
7
7
  gem.email = ['michele.gerarduzzi@gmail.com']
8
8
  gem.homepage = 'https://github.com/z-productions/administrate-field-carrierwave'
@@ -0,0 +1 @@
1
+ <%= link_to (file.filename || file.path).split('/').last, file.url, target: '_blank' %>
@@ -1,7 +1,8 @@
1
1
  <%#
2
2
  # Carrierwave Form Partial
3
3
 
4
- This partial renders a file input field.
4
+ This partial renders a file input field and a summary of the current
5
+ attachment(s) for this attribute
5
6
 
6
7
  ## Local variables:
7
8
 
@@ -16,12 +17,7 @@ This partial renders a file input field.
16
17
  <%= f.label field.attribute %>
17
18
  </div>
18
19
  <div class="field-unit__field">
19
- <%= f.file_field field.attribute %>
20
+ <%= f.file_field field.attribute, multiple: field.multiple? %>
20
21
  <br />
21
- <%- if field.uploaded? -%>
22
- <%= render 'fields/carrierwave/preview', field: field %>
23
- <%= link_to field.basename, field.url, title: field.filename, target: '_blank' %>
24
- <%- else -%>
25
- <span>No file uploaded yet</span>
26
- <%- end -%>
22
+ <%= render 'fields/carrierwave/show', field: field %>
27
23
  </div>
@@ -2,7 +2,7 @@
2
2
  # Carrierwave Index Partial
3
3
 
4
4
  This partial renders the URL of the attachment as a link that
5
- opens in a new window/tab
5
+ opens in a new window/tab, or the total number of attached files
6
6
 
7
7
  ## Local variables:
8
8
 
@@ -11,4 +11,8 @@ opens in a new window/tab
11
11
  A wrapper around the attribute pulled from the database.
12
12
  %>
13
13
 
14
- <%= link_to 'View', field.url, title: field.filename, target: '_blank' %>
14
+ <% if field.multiple? %>
15
+ <%= pluralize(field.files.size, field.attribute.to_s.humanize.downcase) %>
16
+ <% else %>
17
+ <%= link_to 'View', field.file.url, title: field.file.filename, target: '_blank' %>
18
+ <% end %>
@@ -1,3 +1 @@
1
- <% if field.image %>
2
- <p><%= image_tag field.url(field.image), alt: field.basename %></p>
3
- <% end %>
1
+ <%= link_to image_tag(file.url(field.image), alt: file.filename), file.url, target: '_blank' %>
@@ -1,8 +1,8 @@
1
1
  <%#
2
2
  # Carrierwave Show Partial
3
3
 
4
- This partial renders the URL of the attachment as a link that
5
- opens in a new window/tab, and an optional image preview
4
+ This partial renders a summary of the current attachment(s)
5
+ for this attribute
6
6
 
7
7
  ## Local variables:
8
8
 
@@ -11,5 +11,20 @@ opens in a new window/tab, and an optional image preview
11
11
  A wrapper around the attribute pulled from the database.
12
12
  %>
13
13
 
14
- <%= render 'fields/carrierwave/preview', field: field %>
15
- <%= link_to field.basename, field.url, title: field.filename, target: '_blank' %>
14
+ <% if field.multiple? %>
15
+ <% if field.files.any? %>
16
+ <ul>
17
+ <%- field.files.each do |file| %>
18
+ <li><%= render 'fields/carrierwave/file', file: file %></li>
19
+ <% end %>
20
+ </ul>
21
+ <% else %>
22
+ <span>No file(s) uploaded yet</span>
23
+ <% end %>
24
+ <% else %>
25
+ <% if field.image.present? %>
26
+ <%= render 'fields/carrierwave/preview', file: field.file, field: field %>
27
+ <% else %>
28
+ <%= render 'fields/carrierwave/file', file: field.file %>
29
+ <% end %>
30
+ <% end %>
@@ -6,18 +6,21 @@ module Administrate
6
6
  class Carrierwave < Administrate::Field::Base
7
7
  class Engine < ::Rails::Engine; end
8
8
 
9
- delegate :url, :filename, to: :data, allow_nil: true
10
-
11
9
  def image
12
10
  options.fetch(:image, nil)
13
11
  end
14
12
 
15
- def uploaded?
16
- url.present?
13
+ def multiple?
14
+ options.fetch(:multiple, false)
15
+ end
16
+
17
+ # One-element array when single file field, array of files when multiple
18
+ def files
19
+ Array[*data]
17
20
  end
18
21
 
19
- def basename
20
- File.basename(data.path)
22
+ def file
23
+ files.first
21
24
  end
22
25
  end
23
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: administrate-field-carrierwave
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michele Gerarduzzi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-29 00:00:00.000000000 Z
11
+ date: 2016-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: administrate
@@ -52,6 +52,7 @@ files:
52
52
  - LICENSE.md
53
53
  - README.md
54
54
  - administrate-field-carrierwave.gemspec
55
+ - app/views/fields/carrierwave/_file.html.erb
55
56
  - app/views/fields/carrierwave/_form.html.erb
56
57
  - app/views/fields/carrierwave/_index.html.erb
57
58
  - app/views/fields/carrierwave/_preview.html.erb