initial commit
This commit is contained in:
commit
5cda866980
17
.gitignore
vendored
Normal file
17
.gitignore
vendored
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
*.gem
|
||||||
|
*.rbc
|
||||||
|
.bundle
|
||||||
|
.config
|
||||||
|
.yardoc
|
||||||
|
Gemfile.lock
|
||||||
|
InstalledFiles
|
||||||
|
_yardoc
|
||||||
|
coverage
|
||||||
|
doc/
|
||||||
|
lib/bundler/man
|
||||||
|
pkg
|
||||||
|
rdoc
|
||||||
|
spec/reports
|
||||||
|
test/tmp
|
||||||
|
test/version_tmp
|
||||||
|
tmp
|
4
Gemfile
Normal file
4
Gemfile
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
source 'https://rubygems.org'
|
||||||
|
|
||||||
|
# Specify your gem's dependencies in formtastic-better_file_inputs.gemspec
|
||||||
|
gemspec
|
22
LICENSE
Normal file
22
LICENSE
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
Copyright (c) 2012 John Bintz
|
||||||
|
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
a copy of this software and associated documentation files (the
|
||||||
|
"Software"), to deal in the Software without restriction, including
|
||||||
|
without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be
|
||||||
|
included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
9
README.md
Normal file
9
README.md
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
Built for Active Admin primarily. You get the following:
|
||||||
|
|
||||||
|
``` ruby
|
||||||
|
= f.input :file, :as => :file_field
|
||||||
|
= f.input :image, :as => :image_field
|
||||||
|
```
|
||||||
|
|
||||||
|
You can remove the existing file, and get a preview of uploaded images. Will add more as I go.
|
||||||
|
|
17
formtastic-better_file_inputs.gemspec
Normal file
17
formtastic-better_file_inputs.gemspec
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# -*- encoding: utf-8 -*-
|
||||||
|
require File.expand_path('../lib/formtastic-better_file_inputs/version', __FILE__)
|
||||||
|
|
||||||
|
Gem::Specification.new do |gem|
|
||||||
|
gem.authors = ["John Bintz"]
|
||||||
|
gem.email = ["john@coswellproductions.com"]
|
||||||
|
gem.description = %q{TODO: Write a gem description}
|
||||||
|
gem.summary = %q{TODO: Write a gem summary}
|
||||||
|
gem.homepage = ""
|
||||||
|
|
||||||
|
gem.files = `git ls-files`.split($\)
|
||||||
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
||||||
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
||||||
|
gem.name = "formtastic-better_file_inputs"
|
||||||
|
gem.require_paths = ["lib"]
|
||||||
|
gem.version = Formtastic::BetterFileInputs::VERSION
|
||||||
|
end
|
3
lib/formtastic-better_file_inputs.rb
Normal file
3
lib/formtastic-better_file_inputs.rb
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
require "formtastic-better_file_inputs/version"
|
||||||
|
require "formtastic-better_file_inputs/railtie" if defined?(Rails::Railtie)
|
||||||
|
|
42
lib/formtastic-better_file_inputs/file_field_input.rb
Normal file
42
lib/formtastic-better_file_inputs/file_field_input.rb
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
require 'delegate'
|
||||||
|
|
||||||
|
class FileFieldInput < Formtastic::Inputs::FileInput
|
||||||
|
def file_field
|
||||||
|
builder.file_field(method, input_html_options)
|
||||||
|
end
|
||||||
|
|
||||||
|
def remove_checkbox
|
||||||
|
template.content_tag(:label) do
|
||||||
|
builder.check_box("remove_#{method}") << localized_string(method, " Remove", :"remove_#{method}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def preview
|
||||||
|
''
|
||||||
|
end
|
||||||
|
|
||||||
|
def url_display
|
||||||
|
template.content_tag(:div, @url) << template.content_tag(:br)
|
||||||
|
end
|
||||||
|
|
||||||
|
def existing_file_info
|
||||||
|
if @url = builder.object.send(method).url
|
||||||
|
preview << remove_checkbox << url_display
|
||||||
|
else
|
||||||
|
''
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def div_wrapper
|
||||||
|
template.content_tag(:div, :style => 'margin-left: 20%') do
|
||||||
|
file_field << existing_file_info.html_safe
|
||||||
|
end.html_safe
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_html
|
||||||
|
input_wrapping do
|
||||||
|
label_html << div_wrapper
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
6
lib/formtastic-better_file_inputs/image_field_input.rb
Normal file
6
lib/formtastic-better_file_inputs/image_field_input.rb
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
class ImageFieldInput < FileFieldInput
|
||||||
|
def preview
|
||||||
|
template.image_tag(@url, :height => 50)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
13
lib/formtastic-better_file_inputs/railtie.rb
Normal file
13
lib/formtastic-better_file_inputs/railtie.rb
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
module Formtastic
|
||||||
|
module BetterFileInputs
|
||||||
|
class Railtie < ::Rails::Railtie
|
||||||
|
initializer 'formtastic-better_file_inputs.initialize' do
|
||||||
|
if defined?(Formtastic::Inputs)
|
||||||
|
require 'formtastic-better_file_inputs/file_field_input'
|
||||||
|
require 'formtastic-better_file_inputs/image_field_input'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
5
lib/formtastic-better_file_inputs/version.rb
Normal file
5
lib/formtastic-better_file_inputs/version.rb
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
module Formtastic
|
||||||
|
module BetterFileInputs
|
||||||
|
VERSION = "0.0.1"
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user