numerous 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 81cd7af81cd06630de6c5c5977a968826255a02c
4
+ data.tar.gz: 22d6039e73429dabfe34569d7f5abf899e51cd37
5
+ SHA512:
6
+ metadata.gz: 4718911d49efb631de58edaaa5ead5ea6d3f1496cefdf991926a3c942d001447af1c7dbd102424ded5b49c2fbdcedd22e0233279b3208dd9f9d8fb18330263d7
7
+ data.tar.gz: 3c2fe0669927189d31fc6faef9d23f708083620388eff504f6e8d5156aa2a14fee5795e61ddc7d5a96b4f766d747a6000d4b7d82dfe12beafee210635b14fbda
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ .idea/
@@ -0,0 +1,5 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
4
+ </project>
5
+
data/.idea/misc.xml ADDED
@@ -0,0 +1,5 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectRootManager" version="2" project-jdk-name="RVM: ruby-1.9.3-p545" project-jdk-type="RUBY_SDK" />
4
+ </project>
5
+
data/.idea/modules.xml ADDED
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/numerous.iml" filepath="$PROJECT_DIR$/.idea/numerous.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
9
+
@@ -0,0 +1,23 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="CompassSettings">
4
+ <option name="compassSupportEnabled" value="true" />
5
+ </component>
6
+ <component name="FacetManager">
7
+ <facet type="gem" name="Ruby Gem">
8
+ <configuration>
9
+ <option name="GEM_APP_ROOT_PATH" value="$MODULE_DIR$" />
10
+ <option name="GEM_APP_TEST_PATH" value="" />
11
+ <option name="GEM_APP_LIB_PATH" value="$MODULE_DIR$/lib" />
12
+ </configuration>
13
+ </facet>
14
+ </component>
15
+ <component name="NewModuleRootManager">
16
+ <content url="file://$MODULE_DIR$" />
17
+ <orderEntry type="inheritedJdk" />
18
+ <orderEntry type="sourceFolder" forTests="false" />
19
+ <orderEntry type="library" scope="PROVIDED" name="bundler (v1.6.4, RVM: ruby-1.9.3-p545) [gem]" level="application" />
20
+ <orderEntry type="library" scope="PROVIDED" name="rake (v10.3.2, RVM: ruby-1.9.3-p545) [gem]" level="application" />
21
+ </component>
22
+ </module>
23
+
data/.idea/vcs.xml ADDED
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
7
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in numerous.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Geoffrey Hervet
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Numerous
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'numerous'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install numerous
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/numerous/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,3 @@
1
+ module Numerous
2
+ VERSION = "0.0.1"
3
+ end
data/lib/numerous.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "numerous/version"
2
+
3
+ module Numerous
4
+ # Your code goes here...
5
+ end
data/numerous.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'numerous/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "numerous"
8
+ spec.version = Numerous::VERSION
9
+ spec.authors = ["Geoffrey Hervet"]
10
+ spec.email = ["hervetg@gmail.com"]
11
+ spec.summary = 'Unobtrusive Javascript helper for dynamically creating fields_for objects for Rails'
12
+ spec.homepage = "https://github.com/kbparagua/numerous.js"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.6"
21
+ spec.add_development_dependency "rake"
22
+ end
@@ -0,0 +1,160 @@
1
+ // Numerous.js
2
+ // Unobtrusive Javascript helper for dynamically creating fields_for objects for Rails.
3
+ // Version 2.1.1
4
+ //
5
+ // Author: Karl Bryan Paragua
6
+ // Source: https://github.com/kbparagua/numerous.js
7
+
8
+
9
+ $(document).ready(function(e)
10
+ {
11
+ Numerous = {};
12
+
13
+ Numerous.init = function(options){
14
+ var forms = $('.numerous');
15
+
16
+ Numerous.addFormHash = {};
17
+ Numerous.options = options || {};
18
+
19
+
20
+ for (var i = 0, len = forms.length; i < len; i++){
21
+ var form = $(forms[i]),
22
+ fieldsFor = form.attr('id'),
23
+ list = fieldsFor.replace(/fields-for-/, ''),
24
+ addLinkId = 'add-to-' + list,
25
+ updateDiv = '#' + list,
26
+ listOptions = Numerous.options[list];
27
+
28
+
29
+ // Remove Numerous class and id
30
+ form.removeClass('numerous').attr('id','');
31
+
32
+
33
+ // use temp as a container because html()
34
+ // function only returns the inner html
35
+ var temp = $('<div></div>').append(form);
36
+ Numerous.addFormHash[addLinkId] = {
37
+ 'form' : temp.html(),
38
+ 'fields-for' : fieldsFor,
39
+ 'update-div' : updateDiv,
40
+ 'list' : list
41
+ };
42
+
43
+ form.remove();
44
+
45
+ Numerous.clickHandlerForAdd(addLinkId);
46
+ Numerous.createHandlersForRemove(list);
47
+
48
+ if (listOptions) {
49
+ var initialOption = listOptions['initial'],
50
+ addButton = $('#' + addLinkId),
51
+ initial = initialOption;
52
+
53
+ if ( typeof(initialOption) === 'function' ){ initial = initialOption(); }
54
+ for (var i = 0; i < initial; i++){ addButton.trigger('click'); }
55
+
56
+
57
+ var afterInitialize = listOptions['after-initialize'];
58
+ if (afterInitialize){ afterInitialize(); }
59
+ }
60
+ }
61
+ };
62
+
63
+
64
+
65
+ Numerous.clickHandlerForAdd = function(addLinkId){
66
+ var addLink = '#' + addLinkId;
67
+
68
+ $(addLink).click(function(e){
69
+ e.preventDefault();
70
+
71
+ var data = Numerous.addFormHash[this.id],
72
+ childIndex = new Date().getTime(),
73
+ form = data['form'].replace(/replace_this/g, childIndex);
74
+
75
+ form = $(form);
76
+ form.addClass(data['fields-for']);
77
+
78
+ var sampleInputName = form.find('[name*='+ childIndex + ']:first').attr('name'),
79
+ namePrefixRegex = new RegExp("^(\\[|\\]|\\w|\\s|-)+\\[" + childIndex + "\\]")
80
+ namePrefix = sampleInputName.match(namePrefixRegex)[0],
81
+ removeInputName = namePrefix + '[_destroy]',
82
+ removeInput = $('<input type="hidden" value="0" class="numerous-remove-field" name="' +
83
+ removeInputName +'"/>');
84
+
85
+ form.append(removeInput);
86
+ $(data['update-div']).append(form);
87
+
88
+ var options = Numerous.options[data['list']];
89
+ if (options){
90
+ var callback = options['add'];
91
+ if (callback){ callback(form); }
92
+ }
93
+ });
94
+ };
95
+
96
+
97
+ Numerous.createHandlersForRemove = function(list){
98
+ var element = '.fields-for-' + list + ' .numerous-remove';
99
+
100
+ $('body').off('click', element);
101
+ $('body').on('click', element, function(e){
102
+ e.preventDefault();
103
+
104
+ var _this = $(this),
105
+ form = _this.parent(),
106
+ destroyField = _this.siblings('.numerous-remove-field:first');
107
+
108
+ // If existing record
109
+ if (destroyField.length == 0) {
110
+ var idField = form.find('input[name*="[id]"]:first');
111
+
112
+ // No ID field. Existing record but not yet on database
113
+ if (idField.length == 0) {
114
+ form.remove();
115
+ }
116
+ else {
117
+ var prefix = idField.attr('name').replace('[id]',''),
118
+ destroyFieldName = prefix + '[_destroy]';
119
+
120
+ destroyField = $('<input type="hidden" value="0"' +
121
+ 'class="numerous-remove-field" name="' +
122
+ destroyFieldName +'"/>');
123
+
124
+ form.append(destroyField);
125
+ }
126
+ }
127
+
128
+ destroyField.attr('value', '1');
129
+
130
+ form.removeClass('fields-for-' + list);
131
+ form.hide();
132
+
133
+ var options = Numerous.options[list];
134
+ if (options){
135
+ var callback = options['remove'];
136
+ if (callback) { callback(form); }
137
+ }
138
+ });
139
+ };
140
+
141
+
142
+
143
+ // ***************************************************************************
144
+ // Helper Methods
145
+ // ***************************************************************************
146
+
147
+ Numerous.count = function(list){
148
+ return $('.fields-for-' + list).length;
149
+ };
150
+
151
+
152
+ Numerous.get = function(list){
153
+ return $('.fields-for-' + list);
154
+ };
155
+
156
+
157
+ Numerous.removeAll = function(list){
158
+ Numerous.get(list).find('.numerous-remove').trigger('click');
159
+ };
160
+ });
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: numerous
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Geoffrey Hervet
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description:
42
+ email:
43
+ - hervetg@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - .idea/encodings.xml
50
+ - .idea/misc.xml
51
+ - .idea/modules.xml
52
+ - .idea/numerous.iml
53
+ - .idea/vcs.xml
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - lib/numerous.rb
59
+ - lib/numerous/version.rb
60
+ - numerous.gemspec
61
+ - vendor/assets/javascripts/numerous.js
62
+ homepage: https://github.com/kbparagua/numerous.js
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.2.2
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Unobtrusive Javascript helper for dynamically creating fields_for objects
86
+ for Rails
87
+ test_files: []