combo_auto_box 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. data/lib/combo_auto_box/active_record.rb +49 -0
  2. data/lib/combo_auto_box/engine.rb +6 -0
  3. data/lib/combo_auto_box/railtie.rb +12 -0
  4. data/lib/combo_auto_box/version.rb +3 -0
  5. data/lib/combo_auto_box.rb +12 -0
  6. data/spec/combo_auto_box_spec.rb +46 -0
  7. data/spec/database.yml +6 -0
  8. data/spec/finders/activerecord_test_connector.rb +113 -0
  9. data/spec/fixtures/job.rb +3 -0
  10. data/spec/fixtures/jobs.yml +8 -0
  11. data/spec/fixtures/people.yml +17 -0
  12. data/spec/fixtures/person.rb +3 -0
  13. data/spec/fixtures/schema.rb +12 -0
  14. data/spec/spec_helper.rb +16 -0
  15. data/test/combo_auto_box_rails_test.rb +18 -0
  16. data/test/dummy/Rakefile +7 -0
  17. data/test/dummy/config/application.rb +65 -0
  18. data/test/dummy/config/boot.rb +10 -0
  19. data/test/dummy/config/environment.rb +5 -0
  20. data/test/dummy/config/environments/development.rb +31 -0
  21. data/test/dummy/config/environments/production.rb +64 -0
  22. data/test/dummy/config/environments/test.rb +35 -0
  23. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  24. data/test/dummy/config/initializers/inflections.rb +15 -0
  25. data/test/dummy/config/initializers/mime_types.rb +5 -0
  26. data/test/dummy/config/initializers/secret_token.rb +7 -0
  27. data/test/dummy/config/initializers/session_store.rb +8 -0
  28. data/test/dummy/config/initializers/wrap_parameters.rb +10 -0
  29. data/test/dummy/config/locales/en.yml +5 -0
  30. data/test/dummy/config/routes.rb +2 -0
  31. data/test/dummy/config.ru +4 -0
  32. data/test/dummy/log/test.log +22 -0
  33. data/test/test_helper.rb +15 -0
  34. data/vendor/assets/images/combo_auto_box_expand.png +0 -0
  35. data/vendor/assets/javascripts/combo-auto-box.js +161 -0
  36. data/vendor/assets/stylesheets/combo-auto-box.css +16 -0
  37. metadata +174 -0
@@ -0,0 +1,49 @@
1
+ require 'active_support'
2
+ require 'active_record'
3
+
4
+ module ComboAutoBox #:nodoc:
5
+ module ActiveRecord
6
+ module ClassMethods
7
+ def has_combo_auto_box(options = {})
8
+ after_save :delete_combo_auto_box_cache
9
+ after_destroy :delete_combo_auto_box_cache
10
+
11
+ @options = options.symbolize_keys
12
+ @options[:term] ||= 'label'
13
+ @options[:id] ||= 'id'
14
+ @options[:order] ||= @options[:term].split(/\s+/).first
15
+
16
+ term_for_select = @options[:term].match(/AS label\s*$/i).nil? ? "#{@options[:term]} AS label" : @options[:term]
17
+ id_for_select = @options[:id].match(/AS id\s*$/i).nil? ? "#{@options[:id]} AS id" : @options[:id]
18
+ @options[:select] = "#{id_for_select}, #{term_for_select}"
19
+
20
+ class << self
21
+ define_method("combo_auto_box") do |term = '', params = {}|
22
+ Rails.cache.fetch(["combo-auto-box-#{self.to_s.parameterize}-search", term, params.sort].flatten) do
23
+ criteria = Hash.new
24
+ criteria["#{@options[:term]} LIKE ?"] = "%#{term}%"
25
+ params = params.stringify_keys
26
+ self.attribute_names.each do |key|
27
+ criteria["#{key} = ?"] = params[key] if !params[key].nil?
28
+ end
29
+
30
+ self.select(@options[:select]).where([criteria.keys.join(' AND '), criteria.values].flatten).order(@options[:order])
31
+ end
32
+ end
33
+ end
34
+
35
+ include InstanceMethods
36
+ end
37
+ end
38
+
39
+ module InstanceMethods #:nodoc:
40
+ def delete_combo_auto_box_cache
41
+ regexp = Regexp.new("combo-auto-box-#{self.class.to_s.parameterize}-search")
42
+ Rails.cache.delete_matched(regexp)
43
+ end
44
+ end
45
+
46
+ # mix into Active Record
47
+ ::ActiveRecord::Base.extend ClassMethods
48
+ end
49
+ end
@@ -0,0 +1,6 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'combo_auto_box')
2
+
3
+ module ComboAutoBox
4
+ class Engine < Rails::Engine
5
+ end
6
+ end
@@ -0,0 +1,12 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'combo_auto_box')
2
+
3
+ module ComboAutoBox
4
+ class Railtie < Rails::Railtie
5
+ initializer "combo_auto_box" do
6
+ ActiveSupport.on_load :active_record do
7
+ require 'combo_auto_box/active_record'
8
+ end
9
+ end
10
+ end
11
+ end
12
+
@@ -0,0 +1,3 @@
1
+ module ComboAutoBox
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,12 @@
1
+ module ComboAutoBox # :nodoc:
2
+ end
3
+
4
+ require File.join(File.dirname(__FILE__), 'combo_auto_box', 'version')
5
+
6
+ require File.join(File.dirname(__FILE__), 'combo_auto_box', 'engine')
7
+
8
+ if defined? Rails::Railtie
9
+ require File.join(File.dirname(__FILE__), 'combo_auto_box', 'railtie')
10
+ elsif defined? Rails::Initializer
11
+ $stderr.puts "\nCombo Auto Box is not compatible with Rails 2, use at your own risk.\n\n"
12
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+ require 'combo_auto_box/active_record'
3
+ require 'finders/activerecord_test_connector'
4
+
5
+ ActiverecordTestConnector.setup
6
+ abort unless ActiverecordTestConnector.able_to_connect
7
+
8
+ describe ComboAutoBox do
9
+ describe "Activer record stuff" do
10
+ extend ActiverecordTestConnector::FixtureSetup
11
+
12
+ fixtures :people, :jobs
13
+
14
+ context "on many multiple models" do
15
+ it "initializes combo auto box correctly" do
16
+ Person.combo_auto_box.should_not be_nil
17
+ Person.combo_auto_box.each do |item|
18
+ item.id.should_not be_nil
19
+ item.label.should_not be_nil
20
+ end
21
+
22
+ Job.combo_auto_box.should_not be_nil
23
+ Job.combo_auto_box.each do |item|
24
+ item.id.should_not be_nil
25
+ item.label.should_not be_nil
26
+ end
27
+ end
28
+
29
+ it "should returns multiple items in order" do
30
+ people = Person.combo_auto_box('a')
31
+ people.size.should == 3
32
+ people.first.label.should == 'Donna'
33
+ people.second.label.should == 'Jackie'
34
+ people.third.label.should == 'Michael'
35
+ end
36
+
37
+ it "should search by main term and by params" do
38
+ job = Job.combo_auto_box('a', {salary: 1000})
39
+ job.size.should == 1
40
+ job.first.label.should == 'Programmer'
41
+ end
42
+
43
+ end
44
+ end
45
+
46
+ end
data/spec/database.yml ADDED
@@ -0,0 +1,6 @@
1
+ mysql2:
2
+ adapter: mysql2
3
+ database: combo_auto_box
4
+ username: root
5
+ password: aidentro!
6
+ encoding: utf8
@@ -0,0 +1,113 @@
1
+ require 'active_record'
2
+ require 'active_record/fixtures'
3
+ require 'active_support/multibyte' # needed for Ruby 1.9.1
4
+
5
+ $query_count = 0
6
+ $query_sql = []
7
+
8
+ ignore_sql = /
9
+ ^(
10
+ PRAGMA | SHOW\ max_identifier_length |
11
+ SELECT\ (currval|CAST|@@IDENTITY|@@ROWCOUNT) |
12
+ SHOW\ (FIELDS|TABLES)
13
+ )\b |
14
+ \bFROM\ (sqlite_master|pg_tables|pg_attribute)\b
15
+ /x
16
+
17
+ ActiveSupport::Notifications.subscribe(/^sql\./) do |*args|
18
+ payload = args.last
19
+ unless payload[:name] =~ /^Fixture/ or payload[:sql] =~ ignore_sql
20
+ $query_count += 1
21
+ $query_sql << payload[:sql]
22
+ end
23
+ end
24
+
25
+ module ActiverecordTestConnector
26
+ extend self
27
+
28
+ attr_accessor :able_to_connect
29
+ attr_accessor :connected
30
+
31
+ FIXTURES_PATH = File.expand_path('../../fixtures', __FILE__)
32
+
33
+ Fixtures = defined?(ActiveRecord::Fixtures) ? ActiveRecord::Fixtures : ::Fixtures
34
+
35
+ # Set our defaults
36
+ self.connected = false
37
+ self.able_to_connect = true
38
+
39
+ def setup
40
+ unless self.connected || !self.able_to_connect
41
+ setup_connection
42
+ load_schema
43
+ add_load_path FIXTURES_PATH
44
+ self.connected = true
45
+ end
46
+ rescue Exception => e # errors from ActiveRecord setup
47
+ $stderr.puts "\nSkipping ActiveRecord tests: #{e}\n\n"
48
+ self.able_to_connect = false
49
+ end
50
+
51
+ private
52
+
53
+ def add_load_path(path)
54
+ dep = defined?(ActiveSupport::Dependencies) ? ActiveSupport::Dependencies : ::Dependencies
55
+ dep.autoload_paths.unshift path
56
+ end
57
+
58
+ def setup_connection
59
+ db = ENV['DB'].blank? ? 'mysql2' : ENV['DB']
60
+
61
+ configurations = YAML.load_file(File.expand_path('../../database.yml', __FILE__))
62
+ raise "no configuration for '#{db}'" unless configurations.key? db
63
+ configuration = configurations[db]
64
+
65
+ # ActiveRecord::Base.logger = Logger.new(STDOUT) if $0 == 'irb'
66
+ puts "using #{configuration['adapter']} adapter"
67
+
68
+ ActiveRecord::Base.configurations = { db => configuration }
69
+ ActiveRecord::Base.establish_connection(db)
70
+ ActiveRecord::Base.default_timezone = :utc
71
+ end
72
+
73
+ def load_schema
74
+ ActiveRecord::Base.silence do
75
+ ActiveRecord::Migration.verbose = false
76
+ load File.join(FIXTURES_PATH, 'schema.rb')
77
+ end
78
+ end
79
+
80
+ module FixtureSetup
81
+ def fixtures(*tables)
82
+ table_names = tables.map { |t| t.to_s }
83
+
84
+ fixtures = Fixtures.create_fixtures ActiverecordTestConnector::FIXTURES_PATH, table_names
85
+ @@loaded_fixtures = {}
86
+ @@fixture_cache = {}
87
+
88
+ unless fixtures.nil?
89
+ if fixtures.instance_of?(Fixtures)
90
+ @@loaded_fixtures[fixtures.table_name] = fixtures
91
+ else
92
+ fixtures.each { |f| @@loaded_fixtures[f.table_name] = f }
93
+ end
94
+ end
95
+
96
+ table_names.each do |table_name|
97
+ define_method(table_name) do |*fixtures|
98
+ @@fixture_cache[table_name] ||= {}
99
+
100
+ instances = fixtures.map do |fixture|
101
+ if @@loaded_fixtures[table_name][fixture.to_s]
102
+ @@fixture_cache[table_name][fixture] ||= @@loaded_fixtures[table_name][fixture.to_s].find
103
+ else
104
+ raise StandardError, "No fixture with name '#{fixture}' found for table '#{table_name}'"
105
+ end
106
+ end
107
+
108
+ instances.size == 1 ? instances.first : instances
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,3 @@
1
+ class Job < ActiveRecord::Base
2
+ has_combo_auto_box
3
+ end
@@ -0,0 +1,8 @@
1
+ programmer:
2
+ label: "Programmer"
3
+ salary: 1000
4
+
5
+ manager:
6
+ label: "Manager"
7
+ salary: 2000
8
+
@@ -0,0 +1,17 @@
1
+ eric:
2
+ name: "Eric"
3
+
4
+ donna:
5
+ name: "Donna"
6
+
7
+ fez:
8
+ name: "Fez"
9
+
10
+ steve:
11
+ name: "Steve"
12
+
13
+ michael:
14
+ name: "Michael"
15
+
16
+ jackie:
17
+ name: "Jackie"
@@ -0,0 +1,3 @@
1
+ class Person < ActiveRecord::Base
2
+ has_combo_auto_box({ term: 'name' })
3
+ end
@@ -0,0 +1,12 @@
1
+ ActiveRecord::Schema.define do
2
+
3
+ create_table "jobs", :force => true do |t|
4
+ t.column "label", :string
5
+ t.column "salary", :integer
6
+ end
7
+
8
+ create_table "people", :force => true do |t|
9
+ t.column "name", :string
10
+ end
11
+
12
+ end
@@ -0,0 +1,16 @@
1
+ require 'rspec'
2
+ require 'rails/all'
3
+ require 'rspec/rails'
4
+
5
+ begin
6
+ require 'ruby-debug'
7
+ rescue LoadError
8
+ # no debugger available
9
+ end
10
+
11
+ RSpec.configure do |config|
12
+ # config.include My::Pony, My::Horse, :type => :farm
13
+ # config.include MyExtras
14
+ # config.predicate_matchers[:swim] = :can_swim?
15
+ # config.mock_with :mocha
16
+ end
@@ -0,0 +1,18 @@
1
+ require File.expand_path('test_helper', File.dirname(__FILE__))
2
+
3
+ class ComboAutoBoxRailsTest < ActionDispatch::IntegrationTest
4
+ test 'can access combo auto box javascript' do
5
+ get '/assets/combo-auto-box.js'
6
+ assert_response :success
7
+ end
8
+
9
+ test 'can access combo auto box stylesheets' do
10
+ get '/assets/combo-auto-box.css'
11
+ assert_response :success
12
+ end
13
+
14
+ test 'can access combo auto box images' do
15
+ get '/assets/combo_auto_box_expand.png'
16
+ assert_response :success
17
+ end
18
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
3
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
+
5
+ require File.expand_path('../config/application', __FILE__)
6
+
7
+ Dummy::Application.load_tasks
@@ -0,0 +1,65 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ # Pick the frameworks you want:
4
+ # require "active_record/railtie"
5
+ # require "action_controller/railtie"
6
+ require "action_mailer/railtie"
7
+ # require "active_resource/railtie"
8
+ require "sprockets/railtie"
9
+ # require "rails/test_unit/railtie"
10
+
11
+ Bundler.require
12
+ require File.expand_path('../../../lib/combo_auto_box', File.dirname(__FILE__))
13
+
14
+ module Dummy
15
+ class Application < Rails::Application
16
+ # Settings in config/environments/* take precedence over those specified here.
17
+ # Application configuration should go into files in config/initializers
18
+ # -- all .rb files in that directory are automatically loaded.
19
+
20
+ # Custom directories with classes and modules you want to be autoloadable.
21
+ # config.autoload_paths += %W(#{config.root}/extras)
22
+
23
+ # Only load the plugins named here, in the order given (default is alphabetical).
24
+ # :all can be used as a placeholder for all plugins not explicitly named.
25
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
26
+
27
+ # Activate observers that should always be running.
28
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
29
+
30
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
31
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
32
+ # config.time_zone = 'Central Time (US & Canada)'
33
+
34
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
35
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
36
+ # config.i18n.default_locale = :de
37
+
38
+ # Configure the default encoding used in templates for Ruby 1.9.
39
+ config.encoding = "utf-8"
40
+
41
+ # Configure sensitive parameters which will be filtered from the log file.
42
+ config.filter_parameters += [:password]
43
+
44
+ # Enable escaping HTML in JSON.
45
+ config.active_support.escape_html_entities_in_json = true
46
+
47
+ # Use SQL instead of Active Record's schema dumper when creating the database.
48
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
49
+ # like if you have constraints or database-specific column types
50
+ # config.active_record.schema_format = :sql
51
+
52
+ # Enforce whitelist mode for mass assignment.
53
+ # This will create an empty whitelist of attributes available for mass-assignment for all models
54
+ # in your app. As such, your models will need to explicitly whitelist or blacklist accessible
55
+ # parameters by using an attr_accessible or attr_protected declaration.
56
+ # config.active_record.whitelist_attributes = true
57
+
58
+ # Enable the asset pipeline
59
+ config.assets.enabled = true
60
+
61
+ # Version of your assets, change this if you want to expire all your assets
62
+ config.assets.version = '1.0'
63
+ end
64
+ end
65
+
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ gemfile = File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ if File.exist?(gemfile)
5
+ ENV['BUNDLE_GEMFILE'] = gemfile
6
+ require 'bundler'
7
+ Bundler.setup
8
+ end
9
+
10
+ $:.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ Dummy::Application.initialize!
@@ -0,0 +1,31 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the web server when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Log error messages when you accidentally call methods on nil.
10
+ config.whiny_nils = true
11
+
12
+ # Show full error reports and disable caching
13
+ config.consider_all_requests_local = true
14
+ config.action_controller.perform_caching = false
15
+
16
+ # Don't care if the mailer can't send
17
+ config.action_mailer.raise_delivery_errors = false
18
+
19
+ # Print deprecation notices to the Rails logger
20
+ config.active_support.deprecation = :log
21
+
22
+ # Only use best-standards-support built into browsers
23
+ config.action_dispatch.best_standards_support = :builtin
24
+
25
+
26
+ # Do not compress assets
27
+ config.assets.compress = false
28
+
29
+ # Expands the lines which load the assets
30
+ config.assets.debug = true
31
+ end
@@ -0,0 +1,64 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # Code is not reloaded between requests
5
+ config.cache_classes = true
6
+
7
+ # Full error reports are disabled and caching is turned on
8
+ config.consider_all_requests_local = false
9
+ config.action_controller.perform_caching = true
10
+
11
+ # Disable Rails's static asset server (Apache or nginx will already do this)
12
+ config.serve_static_assets = false
13
+
14
+ # Compress JavaScripts and CSS
15
+ config.assets.compress = true
16
+
17
+ # Don't fallback to assets pipeline if a precompiled asset is missed
18
+ config.assets.compile = false
19
+
20
+ # Generate digests for assets URLs
21
+ config.assets.digest = true
22
+
23
+ # Defaults to nil and saved in location specified by config.assets.prefix
24
+ # config.assets.manifest = YOUR_PATH
25
+
26
+ # Specifies the header that your server uses for sending files
27
+ # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
28
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
29
+
30
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
31
+ # config.force_ssl = true
32
+
33
+ # See everything in the log (default is :info)
34
+ # config.log_level = :debug
35
+
36
+ # Prepend all log lines with the following tags
37
+ # config.log_tags = [ :subdomain, :uuid ]
38
+
39
+ # Use a different logger for distributed setups
40
+ # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
41
+
42
+ # Use a different cache store in production
43
+ # config.cache_store = :mem_cache_store
44
+
45
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server
46
+ # config.action_controller.asset_host = "http://assets.example.com"
47
+
48
+ # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
49
+ # config.assets.precompile += %w( search.js )
50
+
51
+ # Disable delivery errors, bad email addresses will be ignored
52
+ # config.action_mailer.raise_delivery_errors = false
53
+
54
+ # Enable threaded mode
55
+ # config.threadsafe!
56
+
57
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
58
+ # the I18n.default_locale when a translation can not be found)
59
+ config.i18n.fallbacks = true
60
+
61
+ # Send deprecation notices to registered listeners
62
+ config.active_support.deprecation = :notify
63
+
64
+ end
@@ -0,0 +1,35 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # The test environment is used exclusively to run your application's
5
+ # test suite. You never need to work with it otherwise. Remember that
6
+ # your test database is "scratch space" for the test suite and is wiped
7
+ # and recreated between test runs. Don't rely on the data there!
8
+ config.cache_classes = true
9
+
10
+ # Configure static asset server for tests with Cache-Control for performance
11
+ config.serve_static_assets = true
12
+ config.static_cache_control = "public, max-age=3600"
13
+
14
+ # Log error messages when you accidentally call methods on nil
15
+ config.whiny_nils = true
16
+
17
+ # Show full error reports and disable caching
18
+ config.consider_all_requests_local = true
19
+ config.action_controller.perform_caching = false
20
+
21
+ # Raise exceptions instead of rendering exception templates
22
+ config.action_dispatch.show_exceptions = false
23
+
24
+ # Disable request forgery protection in test environment
25
+ config.action_controller.allow_forgery_protection = false
26
+
27
+ # Tell Action Mailer not to deliver emails to the real world.
28
+ # The :test delivery method accumulates sent emails in the
29
+ # ActionMailer::Base.deliveries array.
30
+ config.action_mailer.delivery_method = :test
31
+
32
+
33
+ # Print deprecation notices to the stderr
34
+ config.active_support.deprecation = :stderr
35
+ end
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
+
6
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
+ # Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,15 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new inflection rules using the following format
4
+ # (all these examples are active by default):
5
+ # ActiveSupport::Inflector.inflections do |inflect|
6
+ # inflect.plural /^(ox)$/i, '\1en'
7
+ # inflect.singular /^(ox)en/i, '\1'
8
+ # inflect.irregular 'person', 'people'
9
+ # inflect.uncountable %w( fish sheep )
10
+ # end
11
+ #
12
+ # These inflection rules are supported but not enabled by default:
13
+ # ActiveSupport::Inflector.inflections do |inflect|
14
+ # inflect.acronym 'RESTful'
15
+ # end
@@ -0,0 +1,5 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
5
+ # Mime::Type.register_alias "text/html", :iphone
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+ # Make sure the secret is at least 30 characters and all random,
6
+ # no regular words or you'll be exposed to dictionary attacks.
7
+ Dummy::Application.config.secret_token = '49dfd6e5e224394dc63086a6507249b44ff1ca26e4a474ceb4e57f19aeacc345d514ee349e42e82b7a83d287041cf85487c0753f213534e4dbd02f355202a00b'
@@ -0,0 +1,8 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
4
+
5
+ # Use the database for sessions instead of the cookie-based default,
6
+ # which shouldn't be used to store highly confidential information
7
+ # (create the session table with "rails generate session_migration")
8
+ # Dummy::Application.config.session_store :active_record_store
@@ -0,0 +1,10 @@
1
+ # Be sure to restart your server when you modify this file.
2
+ #
3
+ # This file contains settings for ActionController::ParamsWrapper which
4
+ # is enabled by default.
5
+
6
+ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
+ ActiveSupport.on_load(:action_controller) do
8
+ wrap_parameters format: [:json]
9
+ end
10
+
@@ -0,0 +1,5 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ hello: "Hello world"
@@ -0,0 +1,2 @@
1
+ Rails.application.routes.draw do
2
+ end
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Dummy::Application
@@ -0,0 +1,22 @@
1
+ Started GET "/assets/moment.js" for 127.0.0.1 at 2013-05-24 10:36:57 -0300
2
+ Served asset /moment.js - 404 Not Found (2ms)
3
+ Started GET "/assets/moment/fr.js" for 127.0.0.1 at 2013-05-24 10:36:57 -0300
4
+ Served asset /moment/fr.js - 404 Not Found (2ms)
5
+ Started GET "/assets/moment.js" for 127.0.0.1 at 2013-05-24 10:36:57 -0300
6
+ Served asset /moment.js - 404 Not Found (1ms)
7
+ Started GET "/assets/combo-auto-box.js" for 127.0.0.1 at 2013-05-24 10:39:15 -0300
8
+ Compiled combo-auto-box.js (1ms) (pid 1046)
9
+ Served asset /combo-auto-box.js - 200 OK (62ms)
10
+ Started GET "/assets/combo_auto_box_expand.png" for 127.0.0.1 at 2013-05-24 10:40:26 -0300
11
+ Served asset /combo_auto_box_expand.png - 200 OK (42ms)
12
+ Started GET "/assets/combo-auto-box.js" for 127.0.0.1 at 2013-05-24 10:40:26 -0300
13
+ Served asset /combo-auto-box.js - 200 OK (24ms)
14
+ Started GET "/assets/combo-auto-box.css" for 127.0.0.1 at 2013-05-24 10:40:26 -0300
15
+ Compiled combo-auto-box.css (0ms) (pid 1072)
16
+ Served asset /combo-auto-box.css - 200 OK (29ms)
17
+ Started GET "/assets/combo_auto_box_expand.png" for 127.0.0.1 at 2013-05-24 15:49:37 -0300
18
+ Served asset /combo_auto_box_expand.png - 200 OK (16ms)
19
+ Started GET "/assets/combo-auto-box.js" for 127.0.0.1 at 2013-05-24 15:49:38 -0300
20
+ Served asset /combo-auto-box.js - 200 OK (2ms)
21
+ Started GET "/assets/combo-auto-box.css" for 127.0.0.1 at 2013-05-24 15:49:38 -0300
22
+ Served asset /combo-auto-box.css - 200 OK (2ms)
@@ -0,0 +1,15 @@
1
+ # Configure Rails Environment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
+ require "rails/test_help"
6
+
7
+ Rails.backtrace_cleaner.remove_silencers!
8
+
9
+ # Load support files
10
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
11
+
12
+ # Load fixtures from the engine
13
+ if ActiveSupport::TestCase.method_defined?(:fixture_path=)
14
+ ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
15
+ end
@@ -0,0 +1,161 @@
1
+ var ComboAutoBox = {
2
+ // constructor
3
+ addTo: function (container, options) {
4
+
5
+ // generatea an ID based on current time
6
+ var generateAnId = function(prefix) {
7
+ var now = new Date().getTime();;
8
+ while ($("#" + prefix +"-" + now).length != 0) {
9
+ now++;
10
+ }
11
+
12
+ return "combo-auto-box-" + now;
13
+ };
14
+
15
+ // binds autocomplete to text field
16
+ var bindAutoComplete = function (inputId) {
17
+ $('#' + inputId).keypress(function(e) {
18
+ if (e.which === 13) {
19
+ if (options.type == 'full') {
20
+ $('#' + inputId).autocomplete( "close" );
21
+ selectData($('#' + inputId).val());
22
+ }
23
+ return false;
24
+ }
25
+ });
26
+
27
+ $('#' + inputId).autocomplete({
28
+ source: function(request, response) {
29
+ var term = 'term=' + $('#' + inputId).val();
30
+ var params = (options.data == null) ? term : options.data + '&' + term;
31
+ return $.getJSON(options.source + '?' + params, response);
32
+ },
33
+ select: function(event, ui) {
34
+ if (options.type == 'simple') {
35
+ return selectData(ui.item.id);
36
+ } else {
37
+ return selectData($('#' + inputId).val());
38
+ }
39
+ }
40
+ });
41
+ };
42
+
43
+ // generates text field with html options
44
+ var generateInputTag = function () {
45
+ var html = 'input type="text"';
46
+ if (options.html != null) {
47
+ $.each(options.html, function(key, value) {
48
+ html = html + ' '+ key +'="' + value + '"';
49
+ });
50
+ }
51
+
52
+ if ((options.html == null) || (options.html.id == null)) {
53
+ html = html + ' id="' + generateAnId('combo-auto-box') + '"';
54
+ }
55
+
56
+ return '<' + html + '>';
57
+ };
58
+
59
+ // On click opens modal image tag inside "i" tag through css
60
+ var generateImageTag = function () {
61
+ return '<span class="expand"><i></i></span>';
62
+ };
63
+
64
+ // Global div for combo auto box
65
+ var generateDivTag = function () {
66
+ return '<div class="container-combo-auto-box">' + generateInputTag() + '</div>';
67
+ };
68
+
69
+ // dialog modal
70
+ var generateDivDialogModal = function (modalDialogId) {
71
+ $('<div id="'+ modalDialogId +'" class="dialog-modal"><div class="head"><span class="label">' + options.label + '</span><span class="close" title="Close">X</span></div><div class="list"><ul></ul></div></div>').appendTo('#' + container);
72
+
73
+ $('#' + modalDialogId + ' > div.head > span.close').click(function() {
74
+ $('#' + modalDialogId).dialog('close');
75
+ });
76
+
77
+ getListForModalDialog(modalDialogId);
78
+
79
+ $('#' + modalDialogId).dialog({
80
+ width: 400,
81
+ height: 400,
82
+ modal: true,
83
+ closeOnEscape: true,
84
+ autoOpen: false,
85
+ });
86
+
87
+ $("#" + modalDialogId).siblings('div.ui-dialog-titlebar').remove();
88
+
89
+ $('#' + container + ' > div.container-combo-auto-box > span.expand').click(function() {
90
+ openModalDialog(modalDialogId)
91
+ });
92
+ };
93
+
94
+ // Selects an item form modal dialog when clicked on
95
+ var selectValueFromModalDialog = function (value) {
96
+ $('#' + container + ' > div.container-combo-auto-box > input').val(value);
97
+ selectData(value);
98
+ };
99
+
100
+ // generates list for modal dialog
101
+ var getListForModalDialog = function (modalDialogId) {
102
+ var term = 'term=';
103
+ var params = (options.data == null) ? term : options.data + '&' + term;
104
+ var items = [];
105
+
106
+ $.getJSON(options.source + '?' + params, function(data) {
107
+ $.each(data, function(index){
108
+ items.push('<li><span class="combo-auto-box-item-id">' + data[index].id +'</span><span class="combo-auto-box-item-label">'+ data[index].label + '</span></li>');
109
+ });
110
+ $('#' + modalDialogId + ' > div.list').css('height', ($('#' + modalDialogId).dialog("option", "height") - 65) + 'px');
111
+ $('#' + modalDialogId + ' > div.list > ul').html(items.join(''));
112
+ $('#' + modalDialogId + ' > div.list > ul > li').click(function() {
113
+ $('#' + modalDialogId).dialog('close');
114
+ $('#' + container + ' > div.container-combo-auto-box > input').val($(this).children('span.combo-auto-box-item-label').text());
115
+ selectData($(this).children('span.combo-auto-box-item-id').text());
116
+ });
117
+ });
118
+ };
119
+
120
+ // opens modal dialog
121
+ var openModalDialog = function (modalDialogId) {
122
+ $('#' + modalDialogId).dialog("open");
123
+ };
124
+
125
+ // starting generate modial dialog
126
+ var generateModalDialog = function (textField) {
127
+ $(generateImageTag()).prependTo('#' + container + ' > div.container-combo-auto-box');
128
+
129
+ spanTag = $('#' + container + ' > div.container-combo-auto-box > span.expand');
130
+ spanTag.css('margin', '2px 0px 0px ' + (textField.width() + 9).toString() + 'px');
131
+
132
+ generateDivDialogModal(generateAnId('model-dialog'));
133
+ }
134
+
135
+ // on select data
136
+ var selectData = function (selectedData) {
137
+ if (options.complete != null) {
138
+ options.complete(selectedData);
139
+ }
140
+ }
141
+
142
+ // main
143
+ if (options == null) {
144
+ options = {};
145
+ }
146
+
147
+ if ((options.type == null) || ((options.type != 'simple') && (options.type != 'full'))) {
148
+ options.type = 'simple';
149
+ }
150
+
151
+ $('#' + container).html(generateDivTag());
152
+
153
+ textField = $('#' + container + ' > div.container-combo-auto-box > input');
154
+ bindAutoComplete(textField.attr('id'));
155
+
156
+ if (options.type == 'simple') {
157
+ generateModalDialog(textField);
158
+ }
159
+ }
160
+
161
+ }
@@ -0,0 +1,16 @@
1
+ span.combo-auto-box-item-id { display:none; }
2
+ div.container-combo-auto-box span.expand{display:block;position:absolute;cursor:pointer;display:block;margin:0px 0px 0px 0px; width:20px;}
3
+
4
+ div.container-combo-auto-box span.expand i{background-image:url(/assets/combo_auto_box_expand.png);width:19px;height:19px;display:block;font-size:0;}
5
+
6
+ div.dialog-modal div.head { display:block; width:394px; margin: -8px 25px 15px -15px; padding: 0 0 0 0; border: 1px solid #000; background-color:#CECECE; height:30px; -moz-border-radius:4px;-webkit-border-radius:4px;}
7
+ div.dialog-modal div.head span.label { float:left; margin: 5px 0 0 10px; padding: 0 0 0 0; text-weight: bold; }
8
+ div.dialog-modal div.head span.close { float:right; margin: 5px 10px 0 0; padding: 0 0 0 0; }
9
+ div.dialog-modal div.head span.close:hover { cursor:pointer; text-decoration:underline; }
10
+
11
+ div.dialog-modal div.list { display:block; width:100%; margin: -5px 0 0 0px; padding: 0 0 0 0; overflow-y:auto; overflow-x:hidden;}
12
+
13
+ div.dialog-modal div.list ul { list-style:none; width:100%; margin:2px 0 0 -40px; display:block;}
14
+
15
+ div.dialog-modal div.list ul li { padding: 5px 0 5px 3px; margin-left:0px; width:100%; border-bottom:1px solid #DCDCDC; font-size:12px; }
16
+ div.dialog-modal div.list ul li:hover { cursor:pointer; text-decoration:underline; }
metadata ADDED
@@ -0,0 +1,174 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: combo_auto_box
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Adilson Chacon
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.2'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.2'
30
+ - !ruby/object:Gem::Dependency
31
+ name: activerecord
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '3.2'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '3.2'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rails
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '3.2'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '3.2'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: Text Field Autocomplete To Replace Comboboxes.
79
+ email:
80
+ - adilsonchacon@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - lib/combo_auto_box/active_record.rb
86
+ - lib/combo_auto_box/engine.rb
87
+ - lib/combo_auto_box/railtie.rb
88
+ - lib/combo_auto_box/version.rb
89
+ - lib/combo_auto_box.rb
90
+ - vendor/assets/images/combo_auto_box_expand.png
91
+ - vendor/assets/javascripts/combo-auto-box.js
92
+ - vendor/assets/stylesheets/combo-auto-box.css
93
+ - spec/combo_auto_box_spec.rb
94
+ - spec/database.yml
95
+ - spec/finders/activerecord_test_connector.rb
96
+ - spec/fixtures/job.rb
97
+ - spec/fixtures/jobs.yml
98
+ - spec/fixtures/people.yml
99
+ - spec/fixtures/person.rb
100
+ - spec/fixtures/schema.rb
101
+ - spec/spec_helper.rb
102
+ - test/combo_auto_box_rails_test.rb
103
+ - test/dummy/Rakefile
104
+ - test/dummy/config.ru
105
+ - test/dummy/config/application.rb
106
+ - test/dummy/config/boot.rb
107
+ - test/dummy/config/environment.rb
108
+ - test/dummy/config/environments/development.rb
109
+ - test/dummy/config/environments/production.rb
110
+ - test/dummy/config/environments/test.rb
111
+ - test/dummy/config/initializers/backtrace_silencers.rb
112
+ - test/dummy/config/initializers/inflections.rb
113
+ - test/dummy/config/initializers/mime_types.rb
114
+ - test/dummy/config/initializers/secret_token.rb
115
+ - test/dummy/config/initializers/session_store.rb
116
+ - test/dummy/config/initializers/wrap_parameters.rb
117
+ - test/dummy/config/locales/en.yml
118
+ - test/dummy/config/routes.rb
119
+ - test/dummy/log/test.log
120
+ - test/test_helper.rb
121
+ homepage: https://github.com/adilsonchacon/combo_auto_box
122
+ licenses: []
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ! '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ none: false
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 1.8.24
142
+ signing_key:
143
+ specification_version: 3
144
+ summary: Text Field Autocomplete To Replace Comboboxes
145
+ test_files:
146
+ - spec/combo_auto_box_spec.rb
147
+ - spec/database.yml
148
+ - spec/finders/activerecord_test_connector.rb
149
+ - spec/fixtures/job.rb
150
+ - spec/fixtures/jobs.yml
151
+ - spec/fixtures/people.yml
152
+ - spec/fixtures/person.rb
153
+ - spec/fixtures/schema.rb
154
+ - spec/spec_helper.rb
155
+ - test/combo_auto_box_rails_test.rb
156
+ - test/dummy/Rakefile
157
+ - test/dummy/config.ru
158
+ - test/dummy/config/application.rb
159
+ - test/dummy/config/boot.rb
160
+ - test/dummy/config/environment.rb
161
+ - test/dummy/config/environments/development.rb
162
+ - test/dummy/config/environments/production.rb
163
+ - test/dummy/config/environments/test.rb
164
+ - test/dummy/config/initializers/backtrace_silencers.rb
165
+ - test/dummy/config/initializers/inflections.rb
166
+ - test/dummy/config/initializers/mime_types.rb
167
+ - test/dummy/config/initializers/secret_token.rb
168
+ - test/dummy/config/initializers/session_store.rb
169
+ - test/dummy/config/initializers/wrap_parameters.rb
170
+ - test/dummy/config/locales/en.yml
171
+ - test/dummy/config/routes.rb
172
+ - test/dummy/log/test.log
173
+ - test/test_helper.rb
174
+ has_rdoc: