simple_strap_file 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +34 -0
- data/Rakefile +2 -0
- data/app/assets/javascripts/simple_strap_file.js +18 -0
- data/app/assets/stylesheets/simple_strap_file.css +19 -0
- data/app/inputs/file_input.rb +13 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/file_input.rb +23 -0
- data/lib/simple_strap_file/version.rb +3 -0
- data/lib/simple_strap_file.rb +7 -0
- data/simple_strap_file.gemspec +26 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b697bc4191b2878f53f8d5de2ac6319b5e2cc631
|
4
|
+
data.tar.gz: 5a8a1782e7e9072b47e75fdde96952c429985e35
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 13acaca21908ebd5853ab8662b37f94bfeb6cdec8fc26f1d26da1a0ee66c1ba6785d38360c09e750f0ef1d07dbf962fdb4f7aa4918bba5dcb8625c304d60bcf5
|
7
|
+
data.tar.gz: 5989ee217a92823aa13bb7b308ab5812aaea2d362c9e160a3657da39006e932463482882c38aeb23c7963e9b0abcde947b82bc3baf9993169522e4defff9fe59
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Mike Cowan
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# SimpleStrapFile
|
2
|
+
|
3
|
+
[Simple Form](https://github.com/plataformatec/simple_form) component that provides a pretty file input using [Twitter Bootstrap](http://getbootstrap.com/) for styling.
|
4
|
+
|
5
|
+
> Based on ['Whipping File Inputs Into Shape with Bootstrap 3'](http://www.abeautifulsite.net/whipping-file-inputs-into-shape-with-bootstrap-3/) by [Cory LaViska](https://twitter.com/claviska).
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
### Prerequisites
|
10
|
+
> *It is assumed you have installed Bootstrap and Simple Form already*
|
11
|
+
|
12
|
+
Ensure you have applied Bootstrap styling to Simple Form using:
|
13
|
+
|
14
|
+
`rails generate simple_form:install --bootstrap`
|
15
|
+
|
16
|
+
### Gem
|
17
|
+
Add `gem 'simple_strap_file'` to your application's Gemfile and run `bundle`.
|
18
|
+
|
19
|
+
### Assets
|
20
|
+
Import styling in `app/assets/stylesheets/application.css`:
|
21
|
+
|
22
|
+
`*= require simple_strap_file`
|
23
|
+
|
24
|
+
Require Javascripts in `app/assets/javascripts/application.js`
|
25
|
+
|
26
|
+
`//= require simple_strap_file`
|
27
|
+
|
28
|
+
## Contributing
|
29
|
+
|
30
|
+
1. Fork it (https://github.com/michaelcowan/simple_strap_file/fork)
|
31
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
32
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
33
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
34
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
$(document).on('change', '.btn-file :file', function() {
|
2
|
+
var input = $(this),
|
3
|
+
numFiles = input.get(0).files ? input.get(0).files.length : 1,
|
4
|
+
label = input.val().replace(/\\/g, '/').replace(/.*\//, '');
|
5
|
+
input.trigger('fileselect', [numFiles, label]);
|
6
|
+
});
|
7
|
+
|
8
|
+
$(document).ready( function() {
|
9
|
+
$('.btn-file :file').on('fileselect', function(event, numFiles, label) {
|
10
|
+
var input = $(this).parents('.input-group').find(':text'),
|
11
|
+
log = numFiles > 1 ? numFiles + ' files selected' : label;
|
12
|
+
if( input.length ) {
|
13
|
+
input.val(log);
|
14
|
+
} else {
|
15
|
+
if( log ) alert(log);
|
16
|
+
}
|
17
|
+
});
|
18
|
+
});
|
@@ -0,0 +1,19 @@
|
|
1
|
+
.btn-file {
|
2
|
+
position: relative;
|
3
|
+
overflow: hidden;
|
4
|
+
}
|
5
|
+
.btn-file input[type=file] {
|
6
|
+
position: absolute;
|
7
|
+
top: 0;
|
8
|
+
right: 0;
|
9
|
+
min-width: 100%;
|
10
|
+
min-height: 100%;
|
11
|
+
font-size: 100px;
|
12
|
+
text-align: right;
|
13
|
+
filter: alpha(opacity=0);
|
14
|
+
opacity: 0;
|
15
|
+
outline: none;
|
16
|
+
background: white;
|
17
|
+
cursor: inherit;
|
18
|
+
display: block;
|
19
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class FileInput < SimpleForm::Inputs::FileInput
|
2
|
+
# http://www.abeautifulsite.net/whipping-file-inputs-into-shape-with-bootstrap-3/
|
3
|
+
def input(wrapper_options=nil)
|
4
|
+
button = template.content_tag(:div, class: 'input-group') do
|
5
|
+
(template.content_tag(:span, class: 'input-group-btn') do
|
6
|
+
template.content_tag(:span, class: 'btn btn-primary btn-file') do
|
7
|
+
@builder.file_field(attribute_name) + raw('Browse…')
|
8
|
+
end
|
9
|
+
end) +
|
10
|
+
template.tag(:input, class: 'form-control', type: 'text', readonly: true)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "simple_strap_file"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/file_input.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module SimpleForm
|
2
|
+
module Inputs
|
3
|
+
class FileInput < Base
|
4
|
+
def input
|
5
|
+
idf = "#{lookup_model_names.join("_")}_#{reflection_or_attribute_name}"
|
6
|
+
input_html_options[:style] ||= 'display:none;'
|
7
|
+
|
8
|
+
button = template.content_tag(:div, class: 'input-append', style: 'display: table; width: 100%') do
|
9
|
+
(template.content_tag(:span, style: 'display: table-cell; width: 100%' ) do
|
10
|
+
template.tag(:input, id: "pbox_#{idf}", class: 'string form-control', type: 'text')
|
11
|
+
end) +
|
12
|
+
template.content_tag(:a, "Browse", class: 'btn', style: 'float: right', onclick: "$('input[id=#{idf}]').click();")
|
13
|
+
end
|
14
|
+
|
15
|
+
script = template.content_tag(:script, type: 'text/javascript') do
|
16
|
+
"$('input[id=#{idf}]').change(function() { s = $(this).val(); $('#pbox_#{idf}').val(s.slice(s.lastIndexOf('\\\\\\\\')+1)); });".html_safe
|
17
|
+
end
|
18
|
+
|
19
|
+
@builder.file_field(attribute_name, input_html_options) + button + script
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'simple_strap_file/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "simple_strap_file"
|
8
|
+
spec.version = SimpleStrapFile::VERSION
|
9
|
+
spec.authors = ["Mike Cowan"]
|
10
|
+
spec.email = ["mike.c.cowan@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "Simple Form component that provides a pretty file input using Bootstrap"
|
13
|
+
spec.description = "Brings form file inputs in line with the other Bootstrap themed fields"
|
14
|
+
spec.homepage = "https://github.com/michaelcowan/simple-strap-file"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
|
25
|
+
spec.add_dependency "simple_form", "~> 3.1"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple_strap_file
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mike Cowan
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.8'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: simple_form
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.1'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.1'
|
55
|
+
description: Brings form file inputs in line with the other Bootstrap themed fields
|
56
|
+
email:
|
57
|
+
- mike.c.cowan@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- app/assets/javascripts/simple_strap_file.js
|
68
|
+
- app/assets/stylesheets/simple_strap_file.css
|
69
|
+
- app/inputs/file_input.rb
|
70
|
+
- bin/console
|
71
|
+
- bin/setup
|
72
|
+
- file_input.rb
|
73
|
+
- lib/simple_strap_file.rb
|
74
|
+
- lib/simple_strap_file/version.rb
|
75
|
+
- simple_strap_file.gemspec
|
76
|
+
homepage: https://github.com/michaelcowan/simple-strap-file
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata: {}
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.4.5
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Simple Form component that provides a pretty file input using Bootstrap
|
100
|
+
test_files: []
|