serialize_json-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YzJkMmY0MDZmYzRiNThiYTQ2YjM3ZjlmMTg0MGI4NzRlZTAxOTNhMA==
5
+ data.tar.gz: !binary |-
6
+ ZDhmY2UwMzlkYzVjOWVkYjY3NWE1NzRjMDkyZjFkYThkZmI2MmViNw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ OGNlNWQ0YjY4OTU3ZTUwMzZmZGFlYmM3ODE3MzkwMGU5MzY2OWE5YTZmMzY5
10
+ NmVlZWJlZjU1YTIyZDkwMDM0Njk4YTUxOTIxZjdjNWE0MTVlNjMyMTA4ZWVm
11
+ OWEyZmQwNDQ1YzM3NjE5YTM0OTE5ZGFjOWE5N2U4NTI0YTdmYzU=
12
+ data.tar.gz: !binary |-
13
+ ZDRjNmIxMjMwM2FiNDQxOGM5YWI1ODdiNDM2MWFhODY0NWE3Y2IwNzI3MWI5
14
+ OTQ5Njg1ZGFiY2Y2MWJjZGNhN2Y5N2JhYmZlNzNmZDliNjQyOTQ5YmYwYjU1
15
+ ZDEyMDlhYjdmMzlhYmEyYmY1M2I1Y2NlOTRiMmY4OGY0ZmJiMGE=
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in serialize_json-rails.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Stepan Parunashvili
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,24 @@
1
+ # SerializeJson::Rails
2
+
3
+ SerializeJSON for your rails application
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'serialize_json-rails'
10
+
11
+ And then add the dependency in your application.js file
12
+ //= require serialize_json
13
+
14
+ Or install it yourself as:
15
+
16
+ $ gem install serialize_json-rails
17
+
18
+ ## Contributing
19
+
20
+ 1. Fork it
21
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
22
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
23
+ 4. Push to the branch (`git push origin my-new-feature`)
24
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,9 @@
1
+ require "serialize_json/rails/version"
2
+
3
+ module SerializeJson
4
+ module Rails
5
+ class Engine < ::Rails::Engine
6
+ end
7
+ end
8
+ end
9
+
@@ -0,0 +1,5 @@
1
+ module SerializeJson
2
+ module Rails
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'serialize_json/rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "serialize_json-rails"
8
+ spec.version = SerializeJson::Rails::VERSION
9
+ spec.authors = ["Travis Randolph", "Stepan Parunashvili"]
10
+ spec.email = ["travisr004@gmail.com", "stepan.p@gmail.com"]
11
+ spec.description = %q{Taking the serializeJSON library and converting it to a gem}
12
+ spec.summary = %q{Favorite the original too: https://github.com/marioizquierdo/jquery.serializeJSON}
13
+ spec.homepage = "https://github.com/travisR004"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,119 @@
1
+ /*!
2
+ SerializeJSON jQuery plugin.
3
+ https://github.com/marioizquierdo/jquery.serializeJSON
4
+ version 1.1.1 (Feb 16, 2014)
5
+
6
+ Copyright (c) 2012 Mario Izquierdo
7
+ Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
8
+ and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
9
+ */
10
+ (function ($) {
11
+ "use strict";
12
+
13
+ $.fn.serializeJSON = function () {
14
+ var obj, formAsArray;
15
+ obj = {};
16
+ formAsArray = this.serializeArray();
17
+
18
+ $.each(formAsArray, function (i, input) {
19
+ var name, value, keys;
20
+ name = input.name;
21
+ value = input.value;
22
+
23
+ // Split the input name in programatically readable keys
24
+ // name = "foo" => keys = ['foo']
25
+ // name = "[foo]" => keys = ['foo']
26
+ // name = "foo[inn][bar]" => keys = ['foo', 'inn', 'bar']
27
+ // name = "foo[inn][arr][0]" => keys = ['foo', 'inn', 'arr', '0']
28
+ // name = "arr[][val]" => keys = ['arr', '', 'val']
29
+ keys = $.map(name.split('['), function (key) {
30
+ var last;
31
+ last = key[key.length - 1];
32
+ return last === ']' ? key.substring(0, key.length - 1) : key;
33
+ });
34
+ if (keys[0] === '') { keys.shift(); } // "[foo][inn]" should be same as "foo[inn]"
35
+
36
+ // Set value in the object using the keys
37
+ $.deepSet(obj, keys, value);
38
+ });
39
+ return obj;
40
+ };
41
+
42
+ // Auxiliar function to check if a variable is an Object
43
+ var isObject = function (obj) {
44
+ return obj === Object(obj);
45
+ };
46
+
47
+ // Auxiliar function to check if a variable is a valid Array index
48
+ var isValidArrayIndex = function(val){
49
+ return /^[0-9]+$/.test(String(val));
50
+ };
51
+
52
+ /**
53
+ Access the object in a deep key and assigns the value:
54
+
55
+ // Examples:
56
+ deepSet(obj, ['foo'], v) //=> obj['foo'] = v
57
+ deepSet(obj, ['foo', 'inn'], v) //=> obj['foo']['inn'] = v // Create the inner obj['foo'] object, if needed
58
+ deepSet(obj, ['foo', 'inn', 'inn'], v) //=> obj['foo']['inn']['inn'] = v
59
+ deepSet(obj, ['0'], v) //=> obj[0] = v // obj may be an Array
60
+ deepSet(obj, [''], v) //=> obj.push(v) // assume obj as array, and add a new value to the end
61
+ deepSet(obj, ['arr', '0'], v) //=> obj['arr']['0'] = v // obj['arr'] is created as Array if needed
62
+ deepSet(obj, ['arr', ''], v) //=> obj['arr'].push(v)
63
+ deepSet(obj, ['foo', 'arr', '0'], v) //=> obj['foo']['arr'][0] = v // obj['foo'] is created as object and obj['foo']['arr'] as a Array, if needed
64
+ deepSet(obj, ['arr', '0', 'foo'], v) //=> obj['arr']['0']['foo'] = v // obj['foo'] is created as object and obj['foo']['arr'] as a Array and obj['foo']['arr'][0] as object, if needed
65
+
66
+ // Complex example with array empty index,
67
+ // it creates a new element, unless there is a nested non repeated key, so it assigns to the last element object:
68
+ var arr = []
69
+ deepSet(arr, [''], v) //=> arr === [v]
70
+ deepSet(arr, ['', 'foo'], v) //=> arr === [v, {foo: v}]
71
+ deepSet(arr, ['', 'bar'], v) //=> arr === [v, {foo: v, bar: v}]
72
+ deepSet(arr, ['', 'bar'], v) //=> arr === [v, {foo: v, bar: v}, {bar: v}]
73
+ */
74
+ $.deepSet = function (obj, keys, value) {
75
+ var key, nextKey, tail, objectOrArray, lastKey, lastElement;
76
+
77
+ if (!keys || keys.length === 0) { throw new Error("ArgumentError: keys param expected to be an array with least one key"); }
78
+ key = keys[0];
79
+
80
+ if (keys.length == 1) { // only one key, then it's not a deepSet, just assign the value.
81
+ if (key === '') {
82
+ obj.push(value); // empty key is used to add values to the array
83
+ } else {
84
+ obj[key] = value; // other keys can be used as array indexes or object keys
85
+ }
86
+
87
+ } else { // more keys menas a deepSet. Apply recursively
88
+
89
+ nextKey = keys[1];
90
+
91
+ // Empty key is used to add values to the array => merge next keys in the object element.
92
+ if (key === '') {
93
+ lastKey = obj.length - 1;
94
+ lastElement = obj[obj.length - 1];
95
+ if (isObject(lastElement) && !lastElement[nextKey]) { // if nextKey is a new attribute in the last object element then set the new value in there.
96
+ key = lastKey;
97
+ } else { // if the array does not have an object as last element, create one.
98
+ obj.push({});
99
+ key = lastKey + 1;
100
+ }
101
+ }
102
+
103
+ // obj[key] defaults to Object or Array, depending on the next key
104
+ if (obj[key] === undefined) {
105
+ if (nextKey === '' || isValidArrayIndex(nextKey)) { // if is '', 1, 2, 3 ... then use an Array
106
+ obj[key] = [];
107
+ } else { // if is something else, use an Object
108
+ obj[key] = {};
109
+ }
110
+ }
111
+
112
+ // Recursively access the inner Object
113
+ tail = keys.slice(1);
114
+ $.deepSet(obj[key], tail, value);
115
+ }
116
+
117
+ };
118
+
119
+ }(jQuery));
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: serialize_json-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Travis Randolph
8
+ - Stepan Parunashvili
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-03-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: '1.3'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: '1.3'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ description: Taking the serializeJSON library and converting it to a gem
43
+ email:
44
+ - travisr004@gmail.com
45
+ - stepan.p@gmail.com
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - .gitignore
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - lib/serialize_json/rails.rb
56
+ - lib/serialize_json/rails/version.rb
57
+ - serialize_json-rails.gemspec
58
+ - vendor/assets/javascripts/serialize_json.js
59
+ homepage: https://github.com/travisR004
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.2.1
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: ! 'Favorite the original too: https://github.com/marioizquierdo/jquery.serializeJSON'
83
+ test_files: []