initial commit

This commit is contained in:
John Bintz 2012-10-17 14:40:13 -04:00
commit 5cda866980
11 changed files with 140 additions and 0 deletions

17
.gitignore vendored Normal file
View 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
View 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
View 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
View 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.

2
Rakefile Normal file
View File

@ -0,0 +1,2 @@
#!/usr/bin/env rake
require "bundler/gem_tasks"

View 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

View File

@ -0,0 +1,3 @@
require "formtastic-better_file_inputs/version"
require "formtastic-better_file_inputs/railtie" if defined?(Rails::Railtie)

View 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

View File

@ -0,0 +1,6 @@
class ImageFieldInput < FileFieldInput
def preview
template.image_tag(@url, :height => 50)
end
end

View 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

View File

@ -0,0 +1,5 @@
module Formtastic
module BetterFileInputs
VERSION = "0.0.1"
end
end