simple_form_fancy_uploads 0.2.0 → 0.5.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
- SHA1:
3
- metadata.gz: 275c198cbd4275e72eae27ae2eb6cf4d0fe533b1
4
- data.tar.gz: 6f1f4b8c51cd8434789e23b040445cce1d1ed92b
2
+ SHA256:
3
+ metadata.gz: b9d0c08b86a6c512a5390b61724f6f37fdbe6ddbde017f52b1f631fd1b98a14f
4
+ data.tar.gz: dbef7728305d4169e0485640380ad84de8af429a34e853a050bc58a7c2b7745e
5
5
  SHA512:
6
- metadata.gz: 3b6f3aa9cc3151083e54d15af9ad005c359554ad9d06a1e52cba2db02c73b6dc70c0a4a982a4d91e724ec603eac6993d7f03cdddd207e0f3a5bcae8ad949fc15
7
- data.tar.gz: 084c3bb12ad36ab7a45fdf024ca254caab030ce50faaf7b62feed0cc5e9432f358d4e21aaf7534042b75bacdfff3457660084a86e08813e6a68db30bf739cb1a
6
+ metadata.gz: 9c7503a62a5f6d8c5f1598852941732c6c1295d8efd46922b2c61774594f1d7e53467eda7dc97a271105224373936c975ac6f115e13a326b37306c87a908b4fe
7
+ data.tar.gz: 626bf1e87d36d836d2b28065352369a2b34d0fc23a62abdada3d5a8345be73d682ecefb5e1b168ec92ff318370b792285468b09fd809b9ef90afb95784704342
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # SimpleForm fancy uploads
2
2
 
3
- A set of [simple_form](https://github.com/plataformatec/simple_form) (~> 3.1) custom inputs to get image previews or a link to
3
+ A set of [simple_form](https://github.com/plataformatec/simple_form) (~> 4.1) custom inputs to get image previews or a link to
4
4
  uploaded file.
5
5
 
6
- This gem uses the new simple_form 3.1 ability to write your own form tags (check the [simple_form-bootstrap](https://github.com/rafaelfranca/simple_form-bootstrap) example). In 90% of cases, you need some kind of preview when it comes to uploaded files (avatar, images, docs, etc..), why should I write the same markup each time?
6
+ This gem uses the simple_form ability to write your own form tags (check the [simple_form-bootstrap](https://github.com/rafaelfranca/simple_form-bootstrap) example). In 90% of cases, you need some kind of preview when it comes to uploaded files (avatar, images, docs, etc..), why should I write the same markup each time?
7
7
 
8
8
  ## What you get
9
9
 
@@ -36,13 +36,21 @@ If you need to fallback on Carrierwave's `#default_url` method to show a default
36
36
  <% end %>
37
37
  ```
38
38
 
39
+ If you want, you can pass the `preview_url` to the image on the input_html options. This might be useful when you don't have a model binded to the form.
40
+
41
+ ```
42
+ <%= simple_form_for :user do |f| %>
43
+ <%= f.input :image, as: :image_preview, input_html: { preview_url: image_url } %>
44
+ <% end %>
45
+ ```
46
+
39
47
  ### Dependencies
40
48
 
41
49
  To get it work, you need:
42
50
 
43
- * [simple_form](https://github.com/plataformatec/simple_form) ~> 3.1 (*repetita iuvant*)
51
+ * [simple_form](https://github.com/plataformatec/simple_form) ~> 4.1 (*repetita iuvant*)
44
52
  * [carrierwave](https://github.com/jnicklas/carrierwave) actually it's the most opinionated gem for uploads (thank you paperclip for the good times, but you know... life goes on)
45
- * ruby 1.9+ (it uses some 1.9's syntax)
53
+ * ruby 2.2.2+
46
54
 
47
55
  ### Testing
48
56
 
@@ -1,14 +1,27 @@
1
1
  module SimpleFormFancyUploads
2
2
  class ImagePreviewInput < SimpleForm::Inputs::FileInput
3
3
  def input(wrapper_options=nil)
4
- version = input_html_options.delete(:preview_version)
5
- use_default_url = options.delete(:use_default_url) || false
4
+ merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
5
+
6
+ url = preview_url(merged_input_options)
6
7
 
7
8
  out = ''
8
- if object.send("#{attribute_name}?") || use_default_url
9
- out << template.image_tag(object.send(attribute_name).tap {|o| break o.send(version) if version}.send('url'))
10
- end
9
+ out << template.image_tag(url) if url
10
+ out << @builder.input("#{attribute_name}_cache", as: 'hidden')
11
11
  (out << super).html_safe
12
12
  end
13
+
14
+ private
15
+
16
+ def preview_url(merged_input_options)
17
+ use_default_url = options.delete(:use_default_url) || false
18
+ version = merged_input_options.delete(:preview_version)
19
+
20
+ if merged_input_options[:preview_url]
21
+ merged_input_options[:preview_url]
22
+ elsif object && object.send("#{attribute_name}?") || use_default_url
23
+ object.send(attribute_name).tap {|o| break o.send(version) if version}.send('url')
24
+ end
25
+ end
13
26
  end
14
27
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleFormFancyUploads
2
- VERSION = "0.2.0"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_form_fancy_uploads
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrea Pavoni
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-12 00:00:00.000000000 Z
11
+ date: 2020-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,42 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 4.0.0
19
+ version: '5.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 4.0.0
26
+ version: '5.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: simple_form
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '3.1'
33
+ version: 5.0.2
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '3.1'
40
+ version: 5.0.2
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: carrierwave
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '1.3'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '1.3'
55
55
  description: Use simple_form (>= v2.0) custom inputs to get image previews or a link
56
56
  to uploaded file. Save time and code when you need useful file uploads.
57
57
  email:
@@ -86,8 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
86
  - !ruby/object:Gem::Version
87
87
  version: '0'
88
88
  requirements: []
89
- rubyforge_project:
90
- rubygems_version: 2.4.5
89
+ rubygems_version: 3.1.2
91
90
  signing_key:
92
91
  specification_version: 4
93
92
  summary: simple_form custom inputs to get image/link previews with file uploads.