simple_form_fancy_uploads 0.0.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,20 @@
1
+ Copyright (c) 2012 Andrea Pavoni http://andreapavoni.com
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,54 @@
1
+ # SimpleForm fancy uploads
2
+
3
+ A set of [simple_form](https://github.com/plataformatec/simple_form) (>= v2.0) custom inputs to get image previews or a link to
4
+ uploaded file.
5
+
6
+ This gem uses the new simple_form 2.0 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
+
8
+ ## What you get
9
+
10
+ There're only two new file inputs:
11
+
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
+
15
+ ## How it works
16
+
17
+ ### Install
18
+
19
+ Simply add `simple_form_fancy_uploads` to your `Gemfile`
20
+
21
+ ### Usage
22
+
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`. On the image case, you can also specify a `:preview_size` inside the `:input_html` Hash, so you can show a custom version generated with Carrierwave. Nice, isn't it?
24
+
25
+ ```
26
+ <%= simple_form_for @some_model do |f| %>
27
+ <!-- we specify the new custom input, and we'll use the 'thumb' version of the carrierwave upload -->
28
+ <%= f.input :some_image_field, :as => :image_preview, :input_html => {:preview_size => :thumb} %>
29
+ <%= f.input :some_attachment_field, :as => :attachment_preview %>
30
+ <% end %>
31
+ ```
32
+
33
+
34
+
35
+ ## Dependencies
36
+
37
+ To get it work, you need:
38
+ * [simple_form](https://github.com/plataformatec/simple_form) >= v2.0 (*repetita iuvant*)
39
+ * [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.x
41
+
42
+ ### Testing
43
+
44
+ * clone this repo
45
+ * run `bundle install`
46
+ * run `rspec spec`
47
+
48
+ ### Contributions & Bugs
49
+
50
+ * *the easy way:* go to [issues](issues/) page and blame me.
51
+ * *the hard way:* repeat the above points, then show your power and send a pull request.
52
+
53
+ ## License
54
+ Copyright (c) 2012 Andrea Pavoni http://andreapavoni.com
@@ -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 = 'SimpleFormFancyUploads'
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,8 @@
1
+ require 'simple_form'
2
+ require 'simple_form_fancy_uploads/attachment_preview_input'
3
+ require 'simple_form_fancy_uploads/image_preview_input'
4
+
5
+ module SimpleFormFancyUploads
6
+ end
7
+
8
+ SimpleForm::Inputs.send(:include, SimpleFormFancyUploads)
@@ -0,0 +1,11 @@
1
+ module SimpleFormFancyUploads
2
+ class AttachmentPreviewInput < SimpleForm::Inputs::FileInput
3
+ def input
4
+ out = ''
5
+ if object.send("#{attribute_name}?")
6
+ out << template.link_to(object.send(attribute_name).filename, object.send(attribute_name).url)
7
+ end
8
+ (out << super).html_safe
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ module SimpleFormFancyUploads
2
+ class ImagePreviewInput < SimpleForm::Inputs::FileInput
3
+ def input
4
+ version = input_html_options.delete(:preview_version)
5
+ out = ''
6
+ if object.send("#{attribute_name}?")
7
+ out << template.image_tag(object.send(attribute_name).tap {|o| break o.send(version) if version}.send('url'))
8
+ end
9
+ (out << super).html_safe
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module SimpleFormFancyUploads
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :simple_form_fancy_uploads do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_form_fancy_uploads
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andrea Pavoni
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: &18060460 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *18060460
25
+ - !ruby/object:Gem::Dependency
26
+ name: simple_form
27
+ requirement: &18057680 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 2.0.0.rc
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *18057680
36
+ - !ruby/object:Gem::Dependency
37
+ name: carrierwave
38
+ requirement: &18072640 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *18072640
47
+ description: Use simple_form (>= v2.0) custom inputs to get image previews or a link
48
+ to uploaded file. Save time and code when you need useful file uploads.
49
+ email:
50
+ - andrea.pavoni@gmail.com
51
+ executables: []
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - lib/simple_form_fancy_uploads/image_preview_input.rb
56
+ - lib/simple_form_fancy_uploads/attachment_preview_input.rb
57
+ - lib/simple_form_fancy_uploads/version.rb
58
+ - lib/tasks/simple_form_fancy_uploads_tasks.rake
59
+ - lib/simple_form_fancy_uploads.rb
60
+ - MIT-LICENSE
61
+ - Rakefile
62
+ - README.md
63
+ homepage: http://github.com/apeacox/simple_form_fancy_uploads
64
+ licenses: []
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ segments:
76
+ - 0
77
+ hash: 3458735112251813435
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ segments:
85
+ - 0
86
+ hash: 3458735112251813435
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 1.8.10
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: simple_form custom inputs to get image/link previews with file uploads.
93
+ test_files: []