simple_form_select2 0.1.0

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.
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.4.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at rogerio.alcantara@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ source 'https://rails-assets.org' do
4
+ gem 'rails-assets-select2', '~> 4.0.3'
5
+ end
6
+
7
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Rogério Rodrigues de Alcântara
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # SimpleFormSelect2
2
+
3
+ `simple_form_select2` is a Ruby gem that enables use of [Select2](https://github.com/select2/select2) with
4
+ [SimpleForm](https://github.com/plataformatec/simple_form).
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'simple_form_select2'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install simple_form_select2
21
+
22
+ ## Usage
23
+
24
+ Require the Javascript in your `application.js` (or other preferred) file via sprockets:
25
+
26
+ ```javascript
27
+ //= require simple_form_select2
28
+ ```
29
+
30
+ Optionally import the CSS in your `application.css.scss` (or other preferred) file. For
31
+ sprockets-based apps:
32
+
33
+ ```javascript
34
+ //= require simple_form_select2
35
+ ```
36
+
37
+ When rendering form via SimpleForm's `simple_form_for` method, supply the new association via the `:as` option along with a `:source` option to specify the data source URL:
38
+
39
+ ```ruby
40
+ simple_form_for @comment do |f|
41
+ f.association :user, as: :select2, source: users_path(format: :json), label: :name, value: :id
42
+ end
43
+ ```
44
+
45
+ You can also render a multiple select2 as follows:
46
+
47
+ ```ruby
48
+ simple_form_for @comment do |f|
49
+ f.association :users, as: :select2, source: users_path(format: :json), label: :name, value: :id, multiple: true
50
+ end
51
+ ```
52
+
53
+ ## Development
54
+
55
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
56
+
57
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
58
+
59
+ ## Contributing
60
+
61
+ Bug reports and pull requests are welcome on GitHub at https://github.com/roalcantara/simple_form_select2. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
62
+
63
+ ## License
64
+
65
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new :spec
5
+
6
+ task default: :spec
@@ -0,0 +1,2 @@
1
+ //= require select2/select2.full
2
+ //= require ./simple_form_select2
@@ -0,0 +1,35 @@
1
+ window.SimpleForm = {};
2
+ class SimpleForm.Select2Input
3
+ constructor: ->
4
+ @$autocomplete = $('.simple_form select.select2')
5
+ @$attribute = @$autocomplete.data('attribute')
6
+ @$identifier = @$autocomplete.data('identifier')
7
+ @$theme = @$autocomplete.data('theme')
8
+ @$source = @$autocomplete.data('source')
9
+ @$allow_clear = !@$autocomplete.prop('multiple')
10
+ @bind()
11
+
12
+ bind: ->
13
+ @bind_autocomplete()
14
+
15
+ bind_autocomplete: =>
16
+ if @$autocomplete.length > 0
17
+ @$autocomplete.select2
18
+ theme: @$theme
19
+ allowClear: @$allow_clear
20
+ ajax:
21
+ url: @$source
22
+ dataType: 'json'
23
+ delay: 250
24
+ data: (params) ->
25
+ q: params.term
26
+ processResults: (data, params) =>
27
+ params.page = params.page or 1
28
+ results: data.map (item) =>
29
+ { id: item[@$identifier], text: item[@$attribute] }
30
+ pagination: more: params.page * 30 < data.total_count
31
+ cache: true
32
+ minimumInputLength: 1
33
+
34
+ $(document).on 'ready page:load', ->
35
+ window.SimpleForm.select2_input = new SimpleForm.Select2Input()
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'simple_form_typeahead'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,23 @@
1
+ module SimpleForm
2
+ module Inputs
3
+ class Select2Input < CollectionSelectInput
4
+ private
5
+
6
+ def input_html_options
7
+ html_options = {}
8
+ html_options[:data] = {
9
+ theme: options[:theme],
10
+ source: options[:source],
11
+ attribute: options[:attribute],
12
+ identifier: options[:identifier],
13
+ placeholder: options[:placeholder]
14
+ }
15
+ html_options[:multiple] = true if options[:multiple]
16
+
17
+ super.deep_merge(
18
+ html_options
19
+ )
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module SimpleFormSelect2
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,8 @@
1
+ require 'rails-assets-select2'
2
+ require 'simple_form_select2/version'
3
+ require 'simple_form/inputs/select2_input'
4
+
5
+ module SimpleFormSelect2
6
+ class Engine < ::Rails::Engine
7
+ end
8
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'simple_form_select2/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'simple_form_select2'
9
+ spec.version = SimpleFormSelect2::VERSION
10
+ spec.authors = ['Rogério Rodrigues de Alcântara']
11
+ spec.email = ['rogerio.alcantara@gmail.com']
12
+
13
+ spec.summary = 'SimpleForm Select2 autocomplete'
14
+ spec.description = 'Select2 autocomplete wrapper for SimpleForm associations'
15
+ spec.homepage = 'https://github.com/roalcantara/simple_form_select2'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_dependency 'activesupport', '~> 5.0'
24
+ spec.add_dependency 'simple_form', '~> 3.4'
25
+ spec.add_dependency 'rails-assets-select2', '~> 4.0', '>= 4.0.3'
26
+
27
+ spec.add_development_dependency 'bundler', '~> 1.13'
28
+ spec.add_development_dependency 'rake', '~> 10.0'
29
+ spec.add_development_dependency 'rspec', '~> 3.0'
30
+ spec.add_development_dependency 'rails', '~> 5.0'
31
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe SimpleFormSelect2 do
4
+ it 'has a version number' do
5
+ expect(SimpleFormSelect2::VERSION).not_to be nil
6
+ end
7
+ end
@@ -0,0 +1,19 @@
1
+ require 'rails/all'
2
+ require 'simple_form'
3
+ require 'simple_form_select2'
4
+
5
+ # Requires supporting ruby files with custom matchers and macros, etc,
6
+ # in spec/support/ and its subdirectories.
7
+ Dir[File.expand_path('spec/support/**/*.rb')].each(&method(:require))
8
+
9
+ RSpec.configure do |config|
10
+ # Run specs in random order to surface order dependencies. If you find an
11
+ # order dependency and want to debug it, you can fix the order by providing
12
+ # the seed, which is printed after each run.
13
+ # --seed 1234
14
+ config.order = 'random'
15
+
16
+ # Enable filtered runs.
17
+ config.run_all_when_everything_filtered = true
18
+ config.filter_run focus: true
19
+ end
metadata ADDED
@@ -0,0 +1,171 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_form_select2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Rogério Rodrigues de Alcântara
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-07-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: simple_form
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rails-assets-select2
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.0'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 4.0.3
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '4.0'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 4.0.3
61
+ - !ruby/object:Gem::Dependency
62
+ name: bundler
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.13'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '1.13'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rake
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '10.0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '10.0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rspec
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '3.0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '3.0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: rails
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '5.0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '5.0'
117
+ description: Select2 autocomplete wrapper for SimpleForm associations
118
+ email:
119
+ - rogerio.alcantara@gmail.com
120
+ executables:
121
+ - console
122
+ - setup
123
+ extensions: []
124
+ extra_rdoc_files: []
125
+ files:
126
+ - ".gitignore"
127
+ - ".rspec"
128
+ - ".rubocop.yml"
129
+ - ".ruby-version"
130
+ - CODE_OF_CONDUCT.md
131
+ - Gemfile
132
+ - LICENSE.txt
133
+ - README.md
134
+ - Rakefile
135
+ - app/assets/javascripts/simple_form_select2/index.js
136
+ - app/assets/javascripts/simple_form_select2/simple_form_select2.coffee
137
+ - bin/console
138
+ - bin/setup
139
+ - lib/simple_form/inputs/select2_input.rb
140
+ - lib/simple_form_select2.rb
141
+ - lib/simple_form_select2/version.rb
142
+ - simple_form_select2.gemspec
143
+ - spec/simple_form_select2_spec.rb
144
+ - spec/spec_helper.rb
145
+ homepage: https://github.com/roalcantara/simple_form_select2
146
+ licenses:
147
+ - MIT
148
+ metadata: {}
149
+ post_install_message:
150
+ rdoc_options: []
151
+ require_paths:
152
+ - lib
153
+ required_ruby_version: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ required_rubygems_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ requirements: []
164
+ rubyforge_project:
165
+ rubygems_version: 2.6.11
166
+ signing_key:
167
+ specification_version: 4
168
+ summary: SimpleForm Select2 autocomplete
169
+ test_files:
170
+ - spec/simple_form_select2_spec.rb
171
+ - spec/spec_helper.rb