image_input 0.0.3 → 0.0.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e05a8c96a19bdf1a9bbcb5440ad4873e745984df5d699e3c245891088598ce80
4
- data.tar.gz: 9f663e1a8463389ab87b7065de53901655ad1222736b08ea116d6d8766f02885
3
+ metadata.gz: 0a60c559fc547a126d4786f8824f501dc0cdf424762cb2be77a374dd72b16207
4
+ data.tar.gz: a91af36aee1196eed5ed5cf20ba01d1ac7e3b60af321882e8ac05610a85de01e
5
5
  SHA512:
6
- metadata.gz: da40acec7591bfa36a3cce7e9ca72586a0aea77f3f3118435d85a03dea47e5d69931a65695eebd5b1738aba355d6434c0350018090a3b9bfa7938ca149b35b40
7
- data.tar.gz: 501a41dbc3c290989637bc351bccc3aafc5e4b7ea386ce9f1dca05598b5e85bada12107e8bf52b51681913d28a971c1921d10317bf92895248fbb5cd0272bce0
6
+ metadata.gz: eeb1f2e83c7e12fc3c49fe7de8c81c1f084d7714fb6d084bb3a894570384e346f06ec40933130c7fb06dccbac5d7157c24fcc0f81428e5b4f94efee59938d8b2
7
+ data.tar.gz: 7e3e26c2cbcf5f3f7a9c858d5982d6aa30309e23a353b5169812788dd10d46dbc9dbbf6f123ff1129f274c9045d78f11ff1213ea390b1e49fda263cc4ec7a1c6
data/README.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  A Rails helper for a simple, clean image input for use with Active Storage.
4
4
 
5
+ Example usage:
6
+
7
+ ```ruby
8
+ class User < ApplicationRecord
9
+ has_one_attached :profile_picture
10
+ end
11
+ ```
12
+
5
13
  ```erb
6
14
  <%= form_with(model: User.new) do |form| %>
7
15
  <%= image_input form, :profile_picture %>
@@ -23,6 +31,14 @@ bundle install
23
31
  yarn add @mainkatz/image-input
24
32
  ```
25
33
 
34
+ Register Stimulus controller. By default in Rails, this is in `controllers/index.js`.
35
+
36
+ ```js
37
+ import ImageInputController from '@mainkatz/dropzone-input';
38
+
39
+ application.register('image-input', ImageInputController);
40
+ ```
41
+
26
42
  ## Development
27
43
 
28
44
  To develop this locally you can update your Gemfile:
@@ -2,15 +2,16 @@
2
2
  <%= form.file_field(
3
3
  field,
4
4
  class: 'hidden',
5
+ accept: accept,
5
6
  data: {
6
7
  target: 'image-input.field',
7
8
  action: 'change->image-input#onFileChosen'
8
9
  }
9
10
  ) %>
10
11
 
11
- <% if form.object.public_send(field).attached? %>
12
+ <% if blob.attached? && blob.image? %>
12
13
  <%= image_tag(
13
- form.object.public_send(field).variant(resize_to_limit: [300, 300]),
14
+ blob.variant(resize_to_limit: [300, 300]),
14
15
  data: { target: 'image-input.image' },
15
16
  class: 'rounded-md mb-4'
16
17
  ) %>
@@ -22,7 +23,9 @@
22
23
  data-action="click->image-input#chooseFile"
23
24
  data-target="image-input.button"
24
25
  >
25
- <%= form.object.public_send(field).attached? ? 'Change' : 'Choose file' %>
26
+ <%= blob.attached? ? 'Change' : 'Choose file' %>
26
27
  </a>
27
- <span class="hidden font-mono text-sm" data-target="image-input.fileNameLabel"></span>
28
+ <span class="<%= 'hidden' unless blob.attached? %> font-mono text-sm" data-target="image-input.fileNameLabel">
29
+ <%= blob.try(:filename) %>
30
+ </span>
28
31
  </div>
@@ -2,8 +2,14 @@
2
2
 
3
3
  module ImageInput
4
4
  module Helpers
5
- def image_input(form, field)
6
- render 'image_input/input', form: form, field: field
5
+ def image_input(form, field, accept: %i(png jpeg gif))
6
+ render(
7
+ 'image_input/input',
8
+ form: form,
9
+ field: field,
10
+ blob: form.object.public_send(field),
11
+ accept: accept.map { |a| Mime[a].to_s }.join(',')
12
+ )
7
13
  end
8
14
  end
9
15
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ImageInput
4
- VERSION = '0.0.3'
4
+ VERSION = '0.0.4'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: image_input
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Katz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-01 00:00:00.000000000 Z
11
+ date: 2020-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails