Permalink
Browse files

Remove Formtastic and SimpleForm support

I didn't even implement these, they are not properly tested
and whenever there is an issue with them I have no idea
what to do.

When the test framework is stronger, maybe I'll come back
and rewrite them.
  • Loading branch information...
1 parent fefa3af commit 4271b3cb94e4353cc0b0592b58e741428f7ee7d8 @dabit dabit committed Sep 12, 2012
@@ -4,7 +4,6 @@
module Rails3JQueryAutocomplete
autoload :Orm , 'rails3-jquery-autocomplete/orm'
- autoload :FormtasticPlugin , 'rails3-jquery-autocomplete/formtastic_plugin'
unless ::Rails.version < "3.1"
require 'rails3-jquery-autocomplete/rails/engine'
@@ -14,11 +13,3 @@ module Rails3JQueryAutocomplete
class ActionController::Base
include Rails3JQueryAutocomplete::Autocomplete
end
-
-require 'rails3-jquery-autocomplete/formtastic'
-
-begin
- require 'simple_form'
- require 'rails3-jquery-autocomplete/simple_form_plugin'
-rescue LoadError
-end
@@ -1,41 +0,0 @@
-#
-# Load the formtastic plugin if using Formtastic
-#
-begin
- require 'formtastic'
- begin
- require "formtastic/version"
- rescue LoadError
- end
-
- if defined?(Formtastic::VERSION)
- #
- # Formtastic 2.x
- #
-
- module Formtastic
- module Inputs
- class AutocompleteInput
- include Base
- include Base::Stringish
-
- def to_html
- input_wrapping do
- label_html <<
- builder.autocomplete_field(method, options.delete(:url), input_html_options)
- end
- end
- end
- end
- end
- else
-
- #
- # Formtastic 1.x
- #
- class Formtastic::SemanticFormBuilder < ActionView::Helpers::FormBuilder
- include Rails3JQueryAutocomplete::FormtasticPlugin
- end
- end
-rescue LoadError
-end
@@ -1,84 +0,0 @@
-module SimpleForm
- module Inputs
- module Autocomplete
- #
- # Method used to rename the autocomplete key to a more standard
- # data-autocomplete key
- #
- def rewrite_autocomplete_option
- new_options = {}
- new_options["data-update-elements"] = JSON.generate(options.delete :update_elements) if options[:update_elements]
- new_options["data-id-element"] = options.delete :id_element if options[:id_element]
- input_html_options.merge new_options
- end
- end
-
- class AutocompleteInput < Base
- include Autocomplete
-
- def input
- @builder.autocomplete_field(
- attribute_name,
- options[:url],
- rewrite_autocomplete_option
- )
- end
-
- protected
- def limit
- column && column.limit
- end
-
- def has_placeholder?
- placeholder_present?
- end
- end
-
- class AutocompleteCollectionInput < CollectionInput
- include Autocomplete
-
- def input
- # http://www.codeofficer.com/blog/entry/form_builders_in_rails_discovering_field_names_and_ids_for_javascript/
- hidden_id = "#{object_name}_#{attribute_name}_hidden".gsub(/\]\[|[^-a-zA-Z0-9:.]/, "_").sub(/_$/, "")
- id_element = options[:id_element]
- if id_element
- id_element << ", #" << hidden_id
- else
- id_element = "#" + hidden_id
- end
- options[:id_element] = id_element
- autocomplete_options = rewrite_autocomplete_option
- #
- label_method, value_method = detect_collection_methods
- association = object.send(reflection.name)
- if association && association.respond_to?(label_method)
- autocomplete_options[:value] = association.send(label_method)
- end
- out = @builder.autocomplete_field(
- attribute_name,
- options[:url],
- autocomplete_options
- )
- hidden_options = if association && association.respond_to?(value_method)
- new_options = {}
- new_options[:value] = association.send(value_method)
- input_html_options.merge new_options
- else
- input_html_options
- end
- hidden_options[:id] = hidden_id
- out << @builder.hidden_field(
- attribute_name,
- hidden_options
- )
- out.html_safe
- end
- end
- end
-
- class FormBuilder
- map_type :autocomplete, :to => SimpleForm::Inputs::AutocompleteInput
- map_type :autocomplete_collection, :to => SimpleForm::Inputs::AutocompleteCollectionInput
- end
-
-end
@@ -1,31 +0,0 @@
-require 'test_helper'
-require 'view_test_helper'
-
-module Rails3JQueryAutocomplete
- class SimpleFormPluginTest < ActionView::TestCase
- def test_apply_autocomplete_class
- with_input_for @user, :name, :autocomplete
- assert_select "input#user_name.autocomplete[type=text][name='user[name]']"
- end
-
- def test_add_data_autocomplete_attribute
- with_input_for @user, :name, :autocomplete, :url => '/test'
- assert_select "input#user_name[data-autocomplete=/test]"
- end
-
- def test_add_data_update_elements_attribute
- with_input_for @user, :name, :autocomplete, :update_elements => { :id => '#this', :ego => '#that' }
- assert_select "input#user_name[data-update-elements='{&quot;id&quot;:&quot;#this&quot;,&quot;ego&quot;:&quot;#that&quot;}']"
- end
-
- def test_do_not_add_data_update_elements
- with_input_for @user, :name, :autocomplete, :url => '/test'
- assert_no_select "input#user_name[data-update-elements]"
- end
-
- def test_arbitrary_html_options
- with_input_for @user, :name, :autocomplete, :input_html => { :class => "superego" }
- assert_select "input#user_name.superego"
- end
- end
-end
View
@@ -60,7 +60,6 @@ def body
class ActionView::TestCase
include Rails3JQueryAutocomplete::Autocomplete
- include SimpleForm::ActionViewExtensions::FormHelper
setup :set_controller
setup :set_response

0 comments on commit 4271b3c

Please sign in to comment.