refile-input 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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +33 -0
- data/lib/inputs/refile_input.rb +53 -0
- data/refile-input.gemspec +16 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a4326a76a2926e07d25c11c0c24a76aa60a02d96
|
4
|
+
data.tar.gz: 8171891dadeff653b7fdf90253fe5925014e5634
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f67d06ec7654ed4508976ea16fe8228d3f0eec8cb151634e271cb21234f5bc175c10d73061604f796f8ed9f11d669b36dc4fdacd5e18bacee4aaf4402f3e03e7
|
7
|
+
data.tar.gz: b0dac2932246038f70b7447b242a2ee115d14f3e73a78e5e8d3fd42eae5919c68316704f0da8c9d62fe915d88c13c9d84a8e0278d2c7e5123964eb57b3aa2f2a
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Jonas Nicklas
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Refile Input
|
2
|
+
|
3
|
+
Refile Input gem adds custom input type to formtastic to use refile file uploader. Well, name is self-explanatory and gem is super-simple. It's built upon refile's input helper.
|
4
|
+
|
5
|
+
# Installation
|
6
|
+
|
7
|
+
Add the gem:
|
8
|
+
|
9
|
+
``` ruby
|
10
|
+
gem "refile_input", require: ["inputs/refile_input"]
|
11
|
+
```
|
12
|
+
|
13
|
+
Use the gem:
|
14
|
+
|
15
|
+
``` ruby
|
16
|
+
form do |f|
|
17
|
+
f.input :image, as: :refile
|
18
|
+
end
|
19
|
+
```
|
20
|
+
|
21
|
+
# Available options
|
22
|
+
|
23
|
+
Gem brings support of the following options:
|
24
|
+
|
25
|
+
* `direct` determines whether file should be uploaded asynchronously or not. Uploading host might me changed with `host` option. More about it read in refile [documentation](https://github.com/elabs/refile/). Note that refile's js should be included on the page.
|
26
|
+
* `image_preview` is an option to generate image preview. As arguments it accepts list of refile `attachment_url` options. Read more [here](https://github.com/elabs/refile/#4-rails-helpers).
|
27
|
+
* all formtastic's options such as `hint`, `label`, etc.
|
28
|
+
|
29
|
+
# License
|
30
|
+
|
31
|
+
[MIT](LICENSE.txt)
|
data/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
require 'rake'
|
3
|
+
Bundler.setup
|
4
|
+
Bundler::GemHelper.install_tasks
|
5
|
+
|
6
|
+
def cmd(command)
|
7
|
+
puts command
|
8
|
+
fail unless system command
|
9
|
+
end
|
10
|
+
|
11
|
+
require File.expand_path('../spec/support/detect_rails_version', __FILE__)
|
12
|
+
|
13
|
+
# Import all our rake tasks
|
14
|
+
FileList['tasks/**/*.rake'].each { |task| import task }
|
15
|
+
|
16
|
+
task default: :test
|
17
|
+
|
18
|
+
begin
|
19
|
+
require 'jasmine'
|
20
|
+
load 'jasmine/tasks/jasmine.rake'
|
21
|
+
rescue LoadError
|
22
|
+
task :jasmine do
|
23
|
+
abort 'Jasmine is not available. In order to run jasmine, you must: (sudo) gem install jasmine'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
task :console do
|
28
|
+
require 'irb'
|
29
|
+
require 'irb/completion'
|
30
|
+
|
31
|
+
ARGV.clear
|
32
|
+
IRB.start
|
33
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
class RefileInput < Formtastic::Inputs::FileInput
|
2
|
+
def file_input_html_options
|
3
|
+
options[:data] ||= {}
|
4
|
+
|
5
|
+
attacher = object.send(:"#{method}_attacher")
|
6
|
+
options[:accept] = attacher.accept
|
7
|
+
|
8
|
+
if options[:direct]
|
9
|
+
host = Refile.host || options[:host]
|
10
|
+
backend_name = Refile.backends.key(attacher.cache)
|
11
|
+
|
12
|
+
url = ::File.join(host, Rails.application.routes.url_helpers.refile_app_path, backend_name)
|
13
|
+
options[:data].merge!(direct: true, as: "file", url: url)
|
14
|
+
end
|
15
|
+
|
16
|
+
if options[:presigned] and attacher.cache.respond_to?(:presign)
|
17
|
+
options[:data].merge!(direct: true).merge!(attacher.cache.presign.as_json)
|
18
|
+
end
|
19
|
+
|
20
|
+
options.merge(input_html_options)
|
21
|
+
end
|
22
|
+
|
23
|
+
def hidden_input_html_options
|
24
|
+
attacher = object.send(:"#{method}_attacher")
|
25
|
+
{ value: attacher.data.to_json, object: object, id: nil }
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_html
|
29
|
+
input_wrapping do
|
30
|
+
label_html <<
|
31
|
+
builder.hidden_field(method, hidden_input_html_options) <<
|
32
|
+
builder.file_field(method, file_input_html_options) <<
|
33
|
+
image_preview_content
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def image_preview_content
|
40
|
+
image_preview? ? image_preview_html(options[:image_preview]) : ''
|
41
|
+
end
|
42
|
+
|
43
|
+
def image_preview?
|
44
|
+
!!options[:image_preview]
|
45
|
+
end
|
46
|
+
|
47
|
+
def image_preview_html(options)
|
48
|
+
refile_app_path = Rails.application.routes.url_helpers.refile_app_path
|
49
|
+
url = Refile.attachment_url @object, method, *options, prefix: refile_app_path
|
50
|
+
|
51
|
+
template.image_tag url, class: 'image-preview'
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'refile-input'
|
3
|
+
s.license = 'MIT'
|
4
|
+
s.version = '0.0.1'
|
5
|
+
s.authors = ["Petr Sergeev", "Sindre Moen"]
|
6
|
+
s.email = ["peter@hyper.no", "sindre@hyper.no"]
|
7
|
+
s.description = "This adds custom input to support refile file uploader to formtastic form builder"
|
8
|
+
s.summary = "Refile input type for formtastic"
|
9
|
+
s.homepage = "https://github.com/hyperoslo/refile-input"
|
10
|
+
|
11
|
+
s.files = `git ls-files`.split("\n").sort
|
12
|
+
s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
|
13
|
+
|
14
|
+
s.add_dependency 'formtastic', '~> 3.1'
|
15
|
+
s.add_dependency 'refile', '~> 0.5'
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: refile-input
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Petr Sergeev
|
8
|
+
- Sindre Moen
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-02-02 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: formtastic
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '3.1'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '3.1'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: refile
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0.5'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0.5'
|
42
|
+
description: This adds custom input to support refile file uploader to formtastic
|
43
|
+
form builder
|
44
|
+
email:
|
45
|
+
- peter@hyper.no
|
46
|
+
- sindre@hyper.no
|
47
|
+
executables: []
|
48
|
+
extensions: []
|
49
|
+
extra_rdoc_files: []
|
50
|
+
files:
|
51
|
+
- ".gitignore"
|
52
|
+
- Gemfile
|
53
|
+
- LICENSE.txt
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- lib/inputs/refile_input.rb
|
57
|
+
- refile-input.gemspec
|
58
|
+
homepage: https://github.com/hyperoslo/refile-input
|
59
|
+
licenses:
|
60
|
+
- MIT
|
61
|
+
metadata: {}
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 2.2.2
|
79
|
+
signing_key:
|
80
|
+
specification_version: 4
|
81
|
+
summary: Refile input type for formtastic
|
82
|
+
test_files: []
|
83
|
+
has_rdoc:
|