Permalink
Browse files

Added simple_form integration

  • Loading branch information...
1 parent 3f75d95 commit 69ff8681b62828b5edeaf209b477473884bf28d3 @yumitsu yumitsu committed Jul 13, 2012
Showing with 27 additions and 2 deletions.
  1. +1 −1 .gemspec
  2. +3 −0 lib/uploadcare-rails/inject.rb
  3. +22 −0 lib/uploadcare-rails/simple_form.rb
  4. +1 −1 lib/uploadcare-rails/version.rb
View
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
s.description = "Rubygem to use UploadCare.com service and serve file uploads in your Rails projects."
s.authors = ["Alexander Zinchenko"]
s.email = 'az@uploadcare.com'
- s.files = Dir['lib/**/*.rb'] << 'init.rb'
+ s.files = (Dir['lib/**/*.rb'] + Dir['vendor/**/*']) << 'init.rb'
s.require_paths = ['lib']
s.homepage = 'http://github.com/uploadcare/uploadcare-rails'
@@ -17,5 +17,8 @@ class Railtie < Rails::Railtie
def self.try_inject
ActiveRecord::Base.send(:include, Uploadcare::Rails::ActiveRecord) if defined? ActiveRecord
ActionView::Helpers::FormBuilder.send(:include, Uploadcare::Rails::FormBuilder) if defined? ActionView
+ if defined? SimpleForm::Inputs
+ require 'uploadcare-rails/simple_form'
+ end
end
end
@@ -0,0 +1,22 @@
+require 'uploadcare-rails'
+
+module SimpleForm::Inputs
+ class UploadcareInput < Base
+ def input
+ config = ::Uploadcare::Rails.config
+ options = {}
+ options[:role] ||= case config["widget_type"]
+ when "plain"
+ "uploadcare-plain-uploader"
+ when "line"
+ "uploadcare-line-uploader"
+ else
+ "uploadcare-plain-uploader"
+ end
+ options["data-public-key"] ||= config["public_key"]
+ options[:type] ||= "hidden"
+
+ "#{@builder.input_field(attribute_name, input_html_options.merge(options))}".html_safe
+ end
+ end
+end
@@ -1,5 +1,5 @@
module Uploadcare
module Rails
- VERSION = "0.1.0"
+ VERSION = "0.1.1"
end
end

0 comments on commit 69ff868

Please sign in to comment.