json2html-rails 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +54 -0
- data/Rakefile +1 -0
- data/json2html-rails.gemspec +23 -0
- data/lib/json2html/rails.rb +7 -0
- data/lib/json2html/rails/version.rb +5 -0
- data/vendor/assets/javascripts/.keep +0 -0
- data/vendor/assets/javascripts/jquery.json2html.js +74 -0
- data/vendor/assets/javascripts/json2html-rails.js +2 -0
- data/vendor/assets/javascripts/json2html.js +356 -0
- data/vendor/assets/stylesheets/.keep +0 -0
- metadata +89 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3abc1d6b0c26aaee21b92b649896a5c55c996d36
|
4
|
+
data.tar.gz: 5fa3163a94ace452509f89a1154715aee57ec7af
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d91ef05505a10cdc15193af5ccc0408fb661cc4e89528cd4072c88d718a2e3cd528d291f33e9dc4bb6b1d783979bec5c80b0ee62cee6e626bdd5aef84346e45f
|
7
|
+
data.tar.gz: 5f6efced69443441201a82dcdf9a5f5b19c5a58573b578f259dac215ba9371f3df9e776b6d3b05f9c9a3e7bbd223dd2dbd96043a53837deebd5d127ca4682c3b
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 rubyrider
|
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,54 @@
|
|
1
|
+
# Json2html::Rails
|
2
|
+
|
3
|
+
|
4
|
+
Instead of writing HTML templates json2html relies on JSON transforms to convert a source JSON objects to html. The benefit of using a JSON transform is that they are already readable by the browser and DO NOT require any compilation before use. In addition, json2html allows the following
|
5
|
+
|
6
|
+
Short hand notation for mapping data objects to markup
|
7
|
+
Event binding to DOM objects (exclusively with jquery.json2html)
|
8
|
+
Use of inline functions to allow for complex logic during transformation
|
9
|
+
Dynamic building of transform objects
|
10
|
+
|
11
|
+
Please checkout the original library:
|
12
|
+
https://github.com/moappi/jquery.json2html
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
Add this line to your application's Gemfile:
|
17
|
+
|
18
|
+
gem 'json2html-rails'
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
$ bundle
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
$ gem install json2html-rails
|
27
|
+
|
28
|
+
include the following line to your javascript file:
|
29
|
+
|
30
|
+
//require json2html-rails
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
###Example of a Transform?
|
35
|
+
|
36
|
+
var transform =
|
37
|
+
{tag:'li',id:'${id}',children:[
|
38
|
+
{tag:'span',html:'${name} ${year}'}
|
39
|
+
]};
|
40
|
+
|
41
|
+
Will render into the following html:
|
42
|
+
|
43
|
+
|
44
|
+
<li id=1123>
|
45
|
+
<span>Jack and Jill (2001)</span>
|
46
|
+
</li>
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
1. Fork it
|
51
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
52
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
53
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
54
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -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 'json2html/rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "json2html-rails"
|
8
|
+
spec.version = Json2html::Rails::VERSION
|
9
|
+
spec.authors = ["rubyrider"]
|
10
|
+
spec.email = ["irfan@e-solutionpark.com"]
|
11
|
+
spec.description = %q{jquery.json2html is a jquery plug-in that implements the HTML templating engine json2html for client side browers}
|
12
|
+
spec.summary = %q{json2html is a javascript HTML templating engine which converts json object to html using json transforms. Note that this jquery.json2html package includes the latest version of json2html.}
|
13
|
+
spec.homepage = "https://github.com/rubyrider/json2html-rails"
|
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", "vendor"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
File without changes
|
@@ -0,0 +1,74 @@
|
|
1
|
+
//Copyright (c) 2013 Crystalline Technologies
|
2
|
+
//
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'),
|
4
|
+
// to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
5
|
+
// and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
6
|
+
//
|
7
|
+
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
8
|
+
//
|
9
|
+
// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
10
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
11
|
+
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
12
|
+
|
13
|
+
(function($){
|
14
|
+
|
15
|
+
//Main method
|
16
|
+
$.fn.json2html = function(json, transform, _options){
|
17
|
+
|
18
|
+
//Make sure we have the json2html base loaded
|
19
|
+
if(typeof json2html === 'undefined') return(undefined);
|
20
|
+
|
21
|
+
//Default Options
|
22
|
+
var options = {
|
23
|
+
'append':true,
|
24
|
+
'replace':false,
|
25
|
+
'prepend':false,
|
26
|
+
'eventData':{}
|
27
|
+
};
|
28
|
+
|
29
|
+
//Extend the options (with defaults)
|
30
|
+
if( _options !== undefined ) $.extend(options, _options);
|
31
|
+
|
32
|
+
//Insure that we have the events turned (Required)
|
33
|
+
options.events = true;
|
34
|
+
|
35
|
+
//Make sure to take care of any chaining
|
36
|
+
return this.each(function(){
|
37
|
+
|
38
|
+
//let json2html core do it's magic
|
39
|
+
var result = json2html.transform(json, transform, options);
|
40
|
+
|
41
|
+
//Attach the html(string) result to the DOM
|
42
|
+
var dom = $(document.createElement('i')).html(result.html);
|
43
|
+
|
44
|
+
//Determine if we have events
|
45
|
+
for(var i = 0; i < result.events.length; i++) {
|
46
|
+
|
47
|
+
var event = result.events[i];
|
48
|
+
|
49
|
+
//find the associated DOM object with this event
|
50
|
+
var obj = $(dom).find("[json2html-event-id-"+event.type+"='" + event.id + "']");
|
51
|
+
|
52
|
+
//Check to see if we found this element or not
|
53
|
+
if(obj.length === 0) throw 'jquery.json2html was unable to attach event ' + event.id + ' to DOM';
|
54
|
+
|
55
|
+
//remove the attribute
|
56
|
+
$(obj).removeAttr('json2html-event-id-'+event.type);
|
57
|
+
|
58
|
+
//attach the event
|
59
|
+
$(obj).on(event.type,event.data,function(e){
|
60
|
+
//attach the jquery event
|
61
|
+
e.data.event = e;
|
62
|
+
|
63
|
+
//call the appropriate method
|
64
|
+
e.data.action.call($(this),e.data);
|
65
|
+
});
|
66
|
+
}
|
67
|
+
|
68
|
+
//Append it to the appropriate element
|
69
|
+
if (options.replace) $.fn.replaceWith.call($(this),$(dom).children());
|
70
|
+
else if (options.prepend) $.fn.prepend.call($(this),$(dom).children());
|
71
|
+
else $.fn.append.call($(this),$(dom).children());
|
72
|
+
});
|
73
|
+
};
|
74
|
+
})(jQuery);
|
@@ -0,0 +1,356 @@
|
|
1
|
+
//Copyright (c) 2013 Crystalline Technologies
|
2
|
+
//
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'),
|
4
|
+
// to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
5
|
+
// and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
6
|
+
//
|
7
|
+
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
8
|
+
//
|
9
|
+
// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
10
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
11
|
+
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
12
|
+
|
13
|
+
var json2html = {
|
14
|
+
|
15
|
+
/* ---------------------------------------- Public Methods ------------------------------------------------ */
|
16
|
+
'transform': function(json,transform,_options) {
|
17
|
+
|
18
|
+
//create the default output
|
19
|
+
var out = {'events':[],'html':''};
|
20
|
+
|
21
|
+
//default options (by default we don't allow events)
|
22
|
+
var options = {
|
23
|
+
'events':false
|
24
|
+
};
|
25
|
+
|
26
|
+
//extend the options
|
27
|
+
options = json2html._extend(options,_options);
|
28
|
+
|
29
|
+
//Make sure we have a transform & json object
|
30
|
+
if( transform !== undefined || json !== undefined ) {
|
31
|
+
|
32
|
+
//Normalize strings to JSON objects if necessary
|
33
|
+
var obj = typeof json === 'string' ? JSON.parse(json) : json;
|
34
|
+
|
35
|
+
//Transform the object (using the options)
|
36
|
+
out = json2html._transform(obj, transform, options);
|
37
|
+
}
|
38
|
+
|
39
|
+
//determine if we need the events
|
40
|
+
// otherwise return just the html string
|
41
|
+
if(options.events) return(out);
|
42
|
+
else return( out.html );
|
43
|
+
},
|
44
|
+
|
45
|
+
/* ---------------------------------------- Private Methods ------------------------------------------------ */
|
46
|
+
|
47
|
+
//Extend options
|
48
|
+
'_extend':function(obj1,obj2){
|
49
|
+
var obj3 = {};
|
50
|
+
for (var attrname in obj1) { obj3[attrname] = obj1[attrname]; }
|
51
|
+
for (var attrname in obj2) { obj3[attrname] = obj2[attrname]; }
|
52
|
+
return obj3;
|
53
|
+
},
|
54
|
+
|
55
|
+
//Append results
|
56
|
+
'_append':function(obj1,obj2) {
|
57
|
+
var out = {'html':'','event':[]};
|
58
|
+
if(typeof obj1 !== 'undefined' && typeof obj2 !== 'undefined') {
|
59
|
+
out.html = obj1.html + obj2.html;
|
60
|
+
|
61
|
+
out.events = obj1.events.concat(obj2.events);
|
62
|
+
}
|
63
|
+
|
64
|
+
return(out);
|
65
|
+
},
|
66
|
+
|
67
|
+
//isArray (fix for IE prior to 9)
|
68
|
+
'_isArray':function(obj) {
|
69
|
+
return Object.prototype.toString.call(obj) === '[object Array]';
|
70
|
+
},
|
71
|
+
|
72
|
+
//Transform object
|
73
|
+
'_transform':function(json, transform, options) {
|
74
|
+
|
75
|
+
var elements = {'events':[],'html':''};
|
76
|
+
|
77
|
+
//Determine the type of this object
|
78
|
+
if(json2html._isArray(json)) {
|
79
|
+
|
80
|
+
//Itterrate through the array and add it to the elements array
|
81
|
+
var len=json.length;
|
82
|
+
for(var j=0;j<len;++j) {
|
83
|
+
//Apply the transform to this object and append it to the results
|
84
|
+
elements = json2html._append(elements,json2html._apply(json[j], transform, j, options));
|
85
|
+
}
|
86
|
+
|
87
|
+
} else if(typeof json === 'object') {
|
88
|
+
|
89
|
+
//Apply the transform to this object and append it to the results
|
90
|
+
elements = json2html._append(elements,json2html._apply(json, transform, undefined, options));
|
91
|
+
}
|
92
|
+
|
93
|
+
//Return the resulting elements
|
94
|
+
return(elements);
|
95
|
+
},
|
96
|
+
|
97
|
+
//Apply the transform at the second level
|
98
|
+
'_apply':function(obj, transform, index, options) {
|
99
|
+
|
100
|
+
var element = {'events':[],'html':''};
|
101
|
+
|
102
|
+
//Itterate through the transform and create html as needed
|
103
|
+
if(json2html._isArray(transform)) {
|
104
|
+
|
105
|
+
var t_len = transform.length;
|
106
|
+
for(var t=0; t < t_len; ++t) {
|
107
|
+
//transform the object and append it to the output
|
108
|
+
element = json2html._append(element,json2html._apply(obj, transform[t], index, options));
|
109
|
+
}
|
110
|
+
|
111
|
+
} else if(typeof transform === 'object') {
|
112
|
+
|
113
|
+
//Get the tag element of this transform
|
114
|
+
if( transform.tag !== undefined ) {
|
115
|
+
|
116
|
+
//Create a new element
|
117
|
+
element.html += '<' + transform.tag;
|
118
|
+
|
119
|
+
//Create a new object for the children
|
120
|
+
var children = {'events':[],'html':''};
|
121
|
+
|
122
|
+
//innerHTML
|
123
|
+
var html;
|
124
|
+
|
125
|
+
//Look into the properties of this transform
|
126
|
+
for (var key in transform) {
|
127
|
+
|
128
|
+
switch(key) {
|
129
|
+
case 'tag':
|
130
|
+
//Do nothing as we have already created the element from the tag
|
131
|
+
break;
|
132
|
+
|
133
|
+
case 'children':
|
134
|
+
//Add the children
|
135
|
+
if(json2html._isArray(transform.children)) {
|
136
|
+
|
137
|
+
//Apply the transform to the children
|
138
|
+
children = json2html._append(children,json2html._apply(obj, transform.children, index, options));
|
139
|
+
} else if(typeof transform.children === 'function') {
|
140
|
+
|
141
|
+
//Get the result from the function
|
142
|
+
var temp = transform.children.call(obj, obj, index);
|
143
|
+
|
144
|
+
//Make sure we have an object result with the props
|
145
|
+
// html (string), events (array)
|
146
|
+
// OR a string (then just append it to the children
|
147
|
+
if(typeof temp === 'object') {
|
148
|
+
//make sure this object is a valid json2html response object
|
149
|
+
if(temp.html !== undefined && temp.events !== undefined) children = json2html._append(children,temp);
|
150
|
+
} else if(typeof temp === 'string') {
|
151
|
+
|
152
|
+
//append the result directly to the html of the children
|
153
|
+
children.html += temp;
|
154
|
+
}
|
155
|
+
}
|
156
|
+
break;
|
157
|
+
|
158
|
+
case 'html':
|
159
|
+
//Create the html attribute for this element
|
160
|
+
html = json2html._getValue(obj,transform,'html',index);
|
161
|
+
break;
|
162
|
+
|
163
|
+
default:
|
164
|
+
//Add the property as a attribute if it's not a key one
|
165
|
+
var isEvent = false;
|
166
|
+
|
167
|
+
//Check if the first two characters are 'on' then this is an event
|
168
|
+
if( key.length > 2 )
|
169
|
+
if(key.substring(0,2).toLowerCase() == 'on') {
|
170
|
+
|
171
|
+
//Determine if we should add events
|
172
|
+
if(options.events) {
|
173
|
+
|
174
|
+
//if so then setup the event data
|
175
|
+
var data = {
|
176
|
+
'action':transform[key],
|
177
|
+
'obj':obj,
|
178
|
+
'data':options.eventData,
|
179
|
+
'index':index
|
180
|
+
};
|
181
|
+
|
182
|
+
//create a new id for this event
|
183
|
+
var id = json2html._guid();
|
184
|
+
|
185
|
+
//append the new event to this elements events
|
186
|
+
element.events[element.events.length] = {'id':id,'type':key.substring(2),'data':data};
|
187
|
+
|
188
|
+
//Insert temporary event property (json2html-event-id) into the element
|
189
|
+
element.html += " json2html-event-id-"+key.substring(2)+"='" + id + "'";
|
190
|
+
}
|
191
|
+
//this is an event
|
192
|
+
isEvent = true;
|
193
|
+
}
|
194
|
+
|
195
|
+
//If this wasn't an event AND we actually have a value then add it as a property
|
196
|
+
if( !isEvent){
|
197
|
+
//Get the value
|
198
|
+
var val = json2html._getValue(obj, transform, key, index);
|
199
|
+
|
200
|
+
//Make sure we have a value
|
201
|
+
if(val !== undefined) {
|
202
|
+
var out;
|
203
|
+
|
204
|
+
//Determine the output type of this value (wrap with quotes)
|
205
|
+
if(typeof val === 'string') out = '"' + val.replace(/"/g, '"') + '"';
|
206
|
+
else out = val;
|
207
|
+
|
208
|
+
//creat the name value pair
|
209
|
+
element.html += ' ' + key + '=' + out;
|
210
|
+
}
|
211
|
+
}
|
212
|
+
break;
|
213
|
+
}
|
214
|
+
}
|
215
|
+
|
216
|
+
//close the opening tag
|
217
|
+
element.html += '>';
|
218
|
+
|
219
|
+
//add the innerHTML (if we have any)
|
220
|
+
if(html) element.html += html;
|
221
|
+
|
222
|
+
//add the children (if we have any)
|
223
|
+
element = json2html._append(element,children);
|
224
|
+
|
225
|
+
//add the closing tag
|
226
|
+
element.html += '</' + transform.tag + '>';
|
227
|
+
}
|
228
|
+
}
|
229
|
+
|
230
|
+
//Return the output object
|
231
|
+
return(element);
|
232
|
+
},
|
233
|
+
|
234
|
+
//Get a new GUID (used by events)
|
235
|
+
'_guid':function() {
|
236
|
+
var S4 = function() {
|
237
|
+
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
|
238
|
+
};
|
239
|
+
return (S4()+S4()+"-"+S4()+S4()+"-"+S4()+S4());
|
240
|
+
},
|
241
|
+
|
242
|
+
//Get the html value of the object
|
243
|
+
'_getValue':function(obj, transform, key,index) {
|
244
|
+
|
245
|
+
var out = '';
|
246
|
+
|
247
|
+
var val = transform[key];
|
248
|
+
var type = typeof val;
|
249
|
+
|
250
|
+
if (type === 'function') {
|
251
|
+
return(val.call(obj,obj,index));
|
252
|
+
} else if (type === 'string') {
|
253
|
+
var _tokenizer = new json2html._tokenizer([
|
254
|
+
/\$\{([^\}\{]+)\}/
|
255
|
+
],function( src, real, re ){
|
256
|
+
return real ? src.replace(re,function(all,name){
|
257
|
+
|
258
|
+
//Split the string into it's seperate components
|
259
|
+
var components = name.split('.');
|
260
|
+
|
261
|
+
//Set the object we use to query for this name to be the original object
|
262
|
+
var useObj = obj;
|
263
|
+
|
264
|
+
//Output value
|
265
|
+
var outVal = '';
|
266
|
+
|
267
|
+
//Parse the object components
|
268
|
+
var c_len = components.length;
|
269
|
+
for (var i=0;i<c_len;++i) {
|
270
|
+
|
271
|
+
if( components[i].length > 0 ) {
|
272
|
+
|
273
|
+
var newObj = useObj[components[i]];
|
274
|
+
useObj = newObj;
|
275
|
+
if(useObj === null || useObj === undefined) break;
|
276
|
+
}
|
277
|
+
}
|
278
|
+
|
279
|
+
//As long as we have an object to use then set the out
|
280
|
+
if(useObj !== null && useObj !== undefined) outVal = useObj;
|
281
|
+
|
282
|
+
return(outVal);
|
283
|
+
}) : src;
|
284
|
+
});
|
285
|
+
|
286
|
+
out = _tokenizer.parse(val).join('');
|
287
|
+
} else {
|
288
|
+
out = val;
|
289
|
+
}
|
290
|
+
|
291
|
+
return(out);
|
292
|
+
},
|
293
|
+
|
294
|
+
//Tokenizer
|
295
|
+
'_tokenizer':function( tokenizers, doBuild ){
|
296
|
+
|
297
|
+
if( !(this instanceof json2html._tokenizer ) )
|
298
|
+
return new json2html._tokenizer( tokenizers, doBuild );
|
299
|
+
|
300
|
+
this.tokenizers = tokenizers.splice ? tokenizers : [tokenizers];
|
301
|
+
if( doBuild )
|
302
|
+
this.doBuild = doBuild;
|
303
|
+
|
304
|
+
this.parse = function( src ){
|
305
|
+
this.src = src;
|
306
|
+
this.ended = false;
|
307
|
+
this.tokens = [ ];
|
308
|
+
do {
|
309
|
+
this.next();
|
310
|
+
} while( !this.ended );
|
311
|
+
return this.tokens;
|
312
|
+
};
|
313
|
+
|
314
|
+
this.build = function( src, real ){
|
315
|
+
if( src )
|
316
|
+
this.tokens.push(
|
317
|
+
!this.doBuild ? src :
|
318
|
+
this.doBuild(src,real,this.tkn)
|
319
|
+
);
|
320
|
+
};
|
321
|
+
|
322
|
+
this.next = function(){
|
323
|
+
var self = this,
|
324
|
+
plain;
|
325
|
+
|
326
|
+
self.findMin();
|
327
|
+
plain = self.src.slice(0, self.min);
|
328
|
+
|
329
|
+
self.build( plain, false );
|
330
|
+
|
331
|
+
self.src = self.src.slice(self.min).replace(self.tkn,function( all ){
|
332
|
+
self.build(all, true);
|
333
|
+
return '';
|
334
|
+
});
|
335
|
+
|
336
|
+
if( !self.src )
|
337
|
+
self.ended = true;
|
338
|
+
};
|
339
|
+
|
340
|
+
this.findMin = function(){
|
341
|
+
var self = this, i=0, tkn, idx;
|
342
|
+
self.min = -1;
|
343
|
+
self.tkn = '';
|
344
|
+
|
345
|
+
while(( tkn = self.tokenizers[i++]) !== undefined ){
|
346
|
+
idx = self.src[tkn.test?'search':'indexOf'](tkn);
|
347
|
+
if( idx != -1 && (self.min == -1 || idx < self.min )){
|
348
|
+
self.tkn = tkn;
|
349
|
+
self.min = idx;
|
350
|
+
}
|
351
|
+
}
|
352
|
+
if( self.min == -1 )
|
353
|
+
self.min = self.src.length;
|
354
|
+
};
|
355
|
+
}
|
356
|
+
};
|
File without changes
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: json2html-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- rubyrider
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-22 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.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
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: jquery.json2html is a jquery plug-in that implements the HTML templating
|
42
|
+
engine json2html for client side browers
|
43
|
+
email:
|
44
|
+
- irfan@e-solutionpark.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- .gitignore
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- json2html-rails.gemspec
|
55
|
+
- lib/json2html/rails.rb
|
56
|
+
- lib/json2html/rails/version.rb
|
57
|
+
- vendor/assets/javascripts/.keep
|
58
|
+
- vendor/assets/javascripts/jquery.json2html.js
|
59
|
+
- vendor/assets/javascripts/json2html-rails.js
|
60
|
+
- vendor/assets/javascripts/json2html.js
|
61
|
+
- vendor/assets/stylesheets/.keep
|
62
|
+
homepage: https://github.com/rubyrider/json2html-rails
|
63
|
+
licenses:
|
64
|
+
- MIT
|
65
|
+
metadata: {}
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
- vendor
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 2.1.11
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: json2html is a javascript HTML templating engine which converts json object
|
87
|
+
to html using json transforms. Note that this jquery.json2html package includes
|
88
|
+
the latest version of json2html.
|
89
|
+
test_files: []
|