simple_form_fancy_uploads 0.0.1 → 0.0.2
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.
- data/README.md +16 -12
- data/lib/simple_form_fancy_uploads/image_preview_input.rb +3 -1
- data/lib/simple_form_fancy_uploads/version.rb +1 -1
- metadata +11 -11
data/README.md
CHANGED
@@ -9,35 +9,39 @@ This gem uses the new simple_form 2.0 ability to write your own form tags (check
|
|
9
9
|
|
10
10
|
There're only two new file inputs:
|
11
11
|
|
12
|
-
* ImagePreview
|
13
|
-
* AttachmentPreview
|
12
|
+
* `ImagePreview`: guess what? when you edit an entry that contains an uploaded image, it will be shown (how many times did you this in a CMS?)
|
13
|
+
* `AttachmentPreview`: this is a generic upload field, it will show a direct link to the file, so you can check *what* was uploaded.
|
14
14
|
|
15
15
|
## How it works
|
16
16
|
|
17
17
|
### Install
|
18
18
|
|
19
|
-
Simply add `simple_form_fancy_uploads` to your `Gemfile`
|
19
|
+
Simply add `gem 'simple_form_fancy_uploads'` to your `Gemfile` and run `bundle install`
|
20
20
|
|
21
21
|
### Usage
|
22
22
|
|
23
|
-
Here's a basic example, as you can see, it's just a matter of specify the input as
|
23
|
+
Here's a basic example, as you can see, it's just a matter of specify the input as `:image_preview` or `:attachment_preview`. If using `:image_preview`, you can also specify a `:preview_version => :some_version_name` inside the `:input_html` Hash. This will let you to show a custom version generated with Carrierwave. Nice, isn't it?
|
24
|
+
The default configuration of this gem is to not use `the default_url` method of carrierwave, if you want to show the default image defined in your upload class, you can use `:use_default_url => true` in the options hash.
|
24
25
|
|
25
26
|
```
|
26
27
|
<%= simple_form_for @some_model do |f| %>
|
27
|
-
<!-- we specify
|
28
|
-
|
29
|
-
<%= f.input :
|
28
|
+
<!-- we specify that this is an image form upload input, and we want to show the 'thumb' version
|
29
|
+
of the carrierwave upload to not break our layout with a non-resized image -->
|
30
|
+
<%= f.input :some_image_field, as: :image_preview, input_html: {preview_version: :thumb} %>
|
31
|
+
|
32
|
+
<!-- here's a *normal* attachment. with this input, a link to the filename will be shown
|
33
|
+
if there's an uploaded file -->
|
34
|
+
<%= f.input :some_attachment_field, as: :attachment_preview %>
|
30
35
|
<% end %>
|
31
36
|
```
|
32
37
|
|
33
|
-
|
34
|
-
|
35
|
-
## Dependencies
|
38
|
+
### Dependencies
|
36
39
|
|
37
40
|
To get it work, you need:
|
41
|
+
|
38
42
|
* [simple_form](https://github.com/plataformatec/simple_form) >= v2.0 (*repetita iuvant*)
|
39
43
|
* [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)
|
40
|
-
* ruby 1.9.
|
44
|
+
* ruby 1.9+ (it uses some 1.9's syntax)
|
41
45
|
|
42
46
|
### Testing
|
43
47
|
|
@@ -45,7 +49,7 @@ To get it work, you need:
|
|
45
49
|
* run `bundle install`
|
46
50
|
* run `rspec spec`
|
47
51
|
|
48
|
-
|
52
|
+
## Contributions & Bugs
|
49
53
|
|
50
54
|
* *the easy way:* go to [issues](issues/) page and blame me.
|
51
55
|
* *the hard way:* repeat the above points, then show your power and send a pull request.
|
@@ -2,8 +2,10 @@ module SimpleFormFancyUploads
|
|
2
2
|
class ImagePreviewInput < SimpleForm::Inputs::FileInput
|
3
3
|
def input
|
4
4
|
version = input_html_options.delete(:preview_version)
|
5
|
+
use_default_url = options.delete(:use_default_url) || false
|
6
|
+
|
5
7
|
out = ''
|
6
|
-
if object.send("#{attribute_name}?")
|
8
|
+
if object.send("#{attribute_name}?") || use_default_url
|
7
9
|
out << template.image_tag(object.send(attribute_name).tap {|o| break o.send(version) if version}.send('url'))
|
8
10
|
end
|
9
11
|
(out << super).html_safe
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_form_fancy_uploads
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-03-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &20580660 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,21 +21,21 @@ dependencies:
|
|
21
21
|
version: 3.2.1
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *20580660
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: simple_form
|
27
|
-
requirement: &
|
27
|
+
requirement: &20580080 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 2.0.
|
32
|
+
version: 2.0.1
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *20580080
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: carrierwave
|
38
|
-
requirement: &
|
38
|
+
requirement: &20579640 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *20579640
|
47
47
|
description: Use simple_form (>= v2.0) custom inputs to get image previews or a link
|
48
48
|
to uploaded file. Save time and code when you need useful file uploads.
|
49
49
|
email:
|
@@ -74,7 +74,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
74
74
|
version: '0'
|
75
75
|
segments:
|
76
76
|
- 0
|
77
|
-
hash:
|
77
|
+
hash: 414739297277227529
|
78
78
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
79
|
none: false
|
80
80
|
requirements:
|
@@ -83,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
83
|
version: '0'
|
84
84
|
segments:
|
85
85
|
- 0
|
86
|
-
hash:
|
86
|
+
hash: 414739297277227529
|
87
87
|
requirements: []
|
88
88
|
rubyforge_project:
|
89
89
|
rubygems_version: 1.8.10
|