frontkit-rails 0.0.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/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in frontkit-rails.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,15 @@
1
+ module FrontKit
2
+ module MetaHelper
3
+
4
+ def meta_tags
5
+ push_meta_tag property: 'fk:state', content: FrontKit.encode(frontend_state)
6
+ String.new.tap do |buffer|
7
+ buffer << csrf_meta_tags
8
+ meta_tags_container.each do |meta_hash|
9
+ buffer << tag(:meta, meta_hash)
10
+ end
11
+ end.html_safe
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require 'frontkit-rails/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'frontkit-rails'
7
+ s.version = FrontKit::VERSION
8
+ s.authors = ['Pavel Pravosud']
9
+ s.email = ['rwz@duckroll.ru']
10
+ s.homepage = ''
11
+ s.summary = %q{Bunch of rails/js helpers.}
12
+ s.description = %q{Bunch of rails/js helpers packed in asset pipeline friendly engine.}
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ['lib']
18
+
19
+ # specify any dependencies here; for example:
20
+ s.add_development_dependency 'rspec'
21
+ s.add_development_dependency 'execjs'
22
+ s.add_runtime_dependency 'railties', '>= 3.1.0'
23
+ s.add_runtime_dependency 'sprockets'
24
+ s.add_runtime_dependency 'multi_json'
25
+ end
@@ -0,0 +1,5 @@
1
+ require 'frontkit-rails/engine' if defined?(Rails)
2
+ require 'frontkit-rails/version'
3
+
4
+ module FrontKit
5
+ end
@@ -0,0 +1,42 @@
1
+ require 'frontkit-rails/serializer'
2
+ require 'frontkit-rails/state'
3
+ require 'frontkit-rails/meta_container'
4
+ require 'active_support/concern'
5
+
6
+ module FrontKit
7
+ module Base
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ helper_method :frontend_state, :push_frontend_state,
12
+ :merge_frontend_state, :meta_tags_container,
13
+ :push_meta_tag
14
+ end
15
+
16
+ # instance methods
17
+
18
+ def frontend_state
19
+ @_frontend_state ||= FrontKit::State.new(
20
+ production: Rails.env.production?,
21
+ alert: alert,
22
+ notice: notice
23
+ )
24
+ end
25
+
26
+ def push_frontend_state(key, value)
27
+ front_end_state[key] = value
28
+ end
29
+
30
+ def merge_frontend_state(hash)
31
+ frontend_state.deep_merge!(hash)
32
+ end
33
+
34
+ def meta_tags_container
35
+ @_meta_tags_container ||= FrontKit::MetaContainer.new
36
+ end
37
+
38
+ def push_meta_tag(hash)
39
+ meta_tags_container.push(hash)
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,11 @@
1
+ require 'frontkit-rails/base'
2
+
3
+ module FrontKit
4
+ class Engine < ::Rails::Engine
5
+
6
+ config.to_prepare do
7
+ ApplicationController.send :include, FrontKit::Base
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,29 @@
1
+ module FrontKit
2
+ class MetaContainer
3
+ VALID_ATTRS = %w(name property content)
4
+ ESCAPE_ATTRS = %w(content)
5
+
6
+ def initialize
7
+ @container = []
8
+ end
9
+
10
+ def push(hash)
11
+ escaped_hash = hash.inject(Hash.new) do |memo, (key, value)|
12
+ key = key.to_s.downcase
13
+ value = CGI.escapeHTML(value) if key.in?(ESCAPE_ATTRS)
14
+ memo[key] = value; memo
15
+ end
16
+
17
+ invalid_attrs = escaped_hash.keys - VALID_ATTRS
18
+ if invalid_attrs.any?
19
+ raise ArgumentError, "Illegal meta tag attributes: #{invalid_attrs * ', '}"
20
+ end
21
+
22
+ @container.push(escaped_hash)
23
+ end
24
+
25
+ def each(&block)
26
+ @container.uniq.each { |escaped_hash| block.call(escaped_hash) }
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,21 @@
1
+ require 'base64'
2
+ require 'multi_json'
3
+
4
+ module FrontKit
5
+ class Serializer
6
+ def encode(hash)
7
+ Base64.encode64(MultiJson.encode(hash)).strip
8
+ end
9
+
10
+ def decode(str)
11
+ MultiJson.decode(Base64.decode64(str))
12
+ end
13
+ end
14
+
15
+ class << self
16
+ attr_accessor :serializer
17
+ delegate :encode, :decode, to: 'serializer'
18
+ end
19
+
20
+ self.serializer = Serializer.new
21
+ end
@@ -0,0 +1,4 @@
1
+ module FrontKit
2
+ class State < HashWithIndifferentAccess
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module FrontKit
2
+ VERSION = '0.0.0'
3
+ end
@@ -0,0 +1,5 @@
1
+ REMOVE_CHARS = /[^a-z\d\+\=\/]/ig
2
+
3
+ this.Base64 =
4
+ encode64: (str) -> window.btoa(Unicode.unpack(str))
5
+ decode64: (str) -> Unicode.pack(window.atob(str.replace(REMOVE_CHARS, '')))
@@ -0,0 +1,2 @@
1
+ //= require ./unicode
2
+ //= require ./base64
@@ -0,0 +1,42 @@
1
+ this.Unicode =
2
+ unpack: (utfstring) ->
3
+ utfstring = utfstring.replace /\r\n/g, '\n'
4
+ string = ''
5
+
6
+ for i in [0 .. utfstring.length]
7
+ c = utfstring.charCodeAt(i)
8
+
9
+ if c < 128
10
+ string += String.fromCharCode(c)
11
+ else if (c > 127) && (c < 2048)
12
+ string += String.fromCharCode((c >> 6) | 192)
13
+ string += String.fromCharCode((c & 63) | 128)
14
+ else
15
+ string += String.fromCharCode((c >> 12) | 224)
16
+ string += String.fromCharCode(((c >> 6) & 63) | 128)
17
+ string += String.fromCharCode((c & 63) | 128)
18
+
19
+ string
20
+
21
+ pack: (string) ->
22
+ utfstring = ''
23
+ i = c = c1 = c2 = 0
24
+
25
+ while i < string.length
26
+
27
+ c = string.charCodeAt(i)
28
+
29
+ if c < 128
30
+ utfstring += String.fromCharCode(c)
31
+ i++
32
+ else if (c > 191) && (c < 224)
33
+ c2 = string.charCodeAt(i+1)
34
+ utfstring += String.fromCharCode(((c & 31) << 6) | (c2 & 63))
35
+ i += 2
36
+ else
37
+ c2 = string.charCodeAt(i+1)
38
+ c3 = string.charCodeAt(i+2)
39
+ utfstring += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63))
40
+ i += 3
41
+
42
+ utfstring
@@ -0,0 +1,63 @@
1
+ (function (console) {
2
+
3
+ var i,
4
+ global = this,
5
+ fnProto = Function.prototype,
6
+ fnApply = fnProto.apply,
7
+ fnBind = fnProto.bind,
8
+ bind = function (context, fn) {
9
+ return fnBind ?
10
+ fnBind.call( fn, context ) :
11
+ function () {
12
+ return fnApply.call( fn, context, arguments );
13
+ };
14
+ },
15
+ methods = ['assert','count','debug','dir','dirxml','error','group','groupCollapsed','groupEnd','info','log','markTimeline','profile','profileEnd','table','time','timeEnd','trace','warn'],
16
+ emptyFn = function(){},
17
+ empty = {},
18
+ timeCounters;
19
+
20
+ for (i = methods.length; i--;) empty[methods[i]] = emptyFn;
21
+
22
+ if (console) {
23
+
24
+ if (!console.time) {
25
+ console.timeCounters = timeCounters = {};
26
+
27
+ console.time = function(name, reset){
28
+ if (name) {
29
+ var time = +new Date, key = "KEY" + name.toString();
30
+ if (reset || !timeCounters[key]) timeCounters[key] = time;
31
+ }
32
+ };
33
+
34
+ console.timeEnd = function(name){
35
+ var diff,
36
+ time = +new Date,
37
+ key = "KEY" + name.toString(),
38
+ timeCounter = timeCounters[key];
39
+
40
+ if (timeCounter) {
41
+ diff = time - timeCounter;
42
+ console.info( name + ": " + diff + "ms" );
43
+ delete timeCounters[key];
44
+ }
45
+ return diff;
46
+ };
47
+ }
48
+
49
+ for (i = methods.length; i--;) {
50
+ console[methods[i]] = methods[i] in console ?
51
+ bind(console, console[methods[i]]) : emptyFn;
52
+ }
53
+ console.disable = function () { global.console = empty; };
54
+ empty.enable = function () { global.console = console; };
55
+
56
+ empty.disable = console.enable = emptyFn;
57
+
58
+ } else {
59
+ console = global.console = empty;
60
+ console.disable = console.enable = emptyFn;
61
+ }
62
+
63
+ })( typeof console === 'undefined' ? null : console );
@@ -0,0 +1,14 @@
1
+ initialized = false
2
+
3
+ FK.FB =
4
+ init: (opts) ->
5
+ # todo
6
+
7
+ ready: (callback) ->
8
+ if initialized
9
+ callback.call null
10
+ else
11
+ $(window).bind('fb_init', callback)
12
+
13
+
14
+ $(window).bind 'fb_init', -> initialized = true
@@ -0,0 +1,56 @@
1
+ this.FK = FK = FrontKit =
2
+
3
+ updaters: []
4
+
5
+ decode: (str) ->
6
+ JSON.parse(Base64.decode64(str))
7
+
8
+ meta: (id) ->
9
+ @Driver.meta(id)
10
+
11
+ log: (args...) ->
12
+ args.unshift('FK:')
13
+ console.log(args...)
14
+
15
+ ready: (callback) ->
16
+ @Driver.onready(callback)
17
+
18
+ push: (callback) ->
19
+ @updaters.push(callback)
20
+
21
+ update: (element=document) ->
22
+ @log "Running application update on: ", element
23
+ for updater in @updaters
24
+ updater.call null, @Driver.prepare(element)
25
+
26
+ init: ->
27
+ if content = @meta('fk:state')
28
+ gotState = true
29
+ content = @decode(content)
30
+ else
31
+ development = !!window.location.port ||
32
+ /\.(?:dev|local)$/.test window.location.hostname ||
33
+ 'localhost' == window.location.hostname
34
+ content = { production: !development }
35
+
36
+ @state = new State(content)
37
+
38
+ console.disable() if !!@state.production
39
+
40
+ if gotState
41
+ @log 'Got application state: ', @state
42
+ else
43
+ @log 'No application state detected'
44
+
45
+ this.ready -> FK.update()
46
+
47
+ class State
48
+ constructor: (state) ->
49
+ FK.Driver.extend this, state
50
+
51
+ get: (path) ->
52
+ for chunk in path.split('.')
53
+ value = (value or this)[chunk]
54
+ return null unless value?
55
+
56
+ value
@@ -0,0 +1,4 @@
1
+ //= require console
2
+ //= require json2
3
+ //= require base64
4
+ //= require ./fk
@@ -0,0 +1,12 @@
1
+ $ = jQuery
2
+
3
+ driver =
4
+ meta: (str) -> $("""meta[property="#{str}"]""").attr('content')
5
+ extend: (args...) -> $.extend(args...)
6
+ fire: (object, eventName, args...) -> $(object).trigger(eventName, args...)
7
+ onready: $
8
+ prepare: $
9
+
10
+ FK.Driver = driver
11
+
12
+ FK.init()
@@ -0,0 +1,487 @@
1
+ /*
2
+ http://www.JSON.org/json2.js
3
+ 2011-10-19
4
+
5
+ Public Domain.
6
+
7
+ NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
8
+
9
+ See http://www.JSON.org/js.html
10
+
11
+
12
+ This code should be minified before deployment.
13
+ See http://javascript.crockford.com/jsmin.html
14
+
15
+ USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
16
+ NOT CONTROL.
17
+
18
+
19
+ This file creates a global JSON object containing two methods: stringify
20
+ and parse.
21
+
22
+ JSON.stringify(value, replacer, space)
23
+ value any JavaScript value, usually an object or array.
24
+
25
+ replacer an optional parameter that determines how object
26
+ values are stringified for objects. It can be a
27
+ function or an array of strings.
28
+
29
+ space an optional parameter that specifies the indentation
30
+ of nested structures. If it is omitted, the text will
31
+ be packed without extra whitespace. If it is a number,
32
+ it will specify the number of spaces to indent at each
33
+ level. If it is a string (such as '\t' or '&nbsp;'),
34
+ it contains the characters used to indent at each level.
35
+
36
+ This method produces a JSON text from a JavaScript value.
37
+
38
+ When an object value is found, if the object contains a toJSON
39
+ method, its toJSON method will be called and the result will be
40
+ stringified. A toJSON method does not serialize: it returns the
41
+ value represented by the name/value pair that should be serialized,
42
+ or undefined if nothing should be serialized. The toJSON method
43
+ will be passed the key associated with the value, and this will be
44
+ bound to the value
45
+
46
+ For example, this would serialize Dates as ISO strings.
47
+
48
+ Date.prototype.toJSON = function (key) {
49
+ function f(n) {
50
+ // Format integers to have at least two digits.
51
+ return n < 10 ? '0' + n : n;
52
+ }
53
+
54
+ return this.getUTCFullYear() + '-' +
55
+ f(this.getUTCMonth() + 1) + '-' +
56
+ f(this.getUTCDate()) + 'T' +
57
+ f(this.getUTCHours()) + ':' +
58
+ f(this.getUTCMinutes()) + ':' +
59
+ f(this.getUTCSeconds()) + 'Z';
60
+ };
61
+
62
+ You can provide an optional replacer method. It will be passed the
63
+ key and value of each member, with this bound to the containing
64
+ object. The value that is returned from your method will be
65
+ serialized. If your method returns undefined, then the member will
66
+ be excluded from the serialization.
67
+
68
+ If the replacer parameter is an array of strings, then it will be
69
+ used to select the members to be serialized. It filters the results
70
+ such that only members with keys listed in the replacer array are
71
+ stringified.
72
+
73
+ Values that do not have JSON representations, such as undefined or
74
+ functions, will not be serialized. Such values in objects will be
75
+ dropped; in arrays they will be replaced with null. You can use
76
+ a replacer function to replace those with JSON values.
77
+ JSON.stringify(undefined) returns undefined.
78
+
79
+ The optional space parameter produces a stringification of the
80
+ value that is filled with line breaks and indentation to make it
81
+ easier to read.
82
+
83
+ If the space parameter is a non-empty string, then that string will
84
+ be used for indentation. If the space parameter is a number, then
85
+ the indentation will be that many spaces.
86
+
87
+ Example:
88
+
89
+ text = JSON.stringify(['e', {pluribus: 'unum'}]);
90
+ // text is '["e",{"pluribus":"unum"}]'
91
+
92
+
93
+ text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t');
94
+ // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'
95
+
96
+ text = JSON.stringify([new Date()], function (key, value) {
97
+ return this[key] instanceof Date ?
98
+ 'Date(' + this[key] + ')' : value;
99
+ });
100
+ // text is '["Date(---current time---)"]'
101
+
102
+
103
+ JSON.parse(text, reviver)
104
+ This method parses a JSON text to produce an object or array.
105
+ It can throw a SyntaxError exception.
106
+
107
+ The optional reviver parameter is a function that can filter and
108
+ transform the results. It receives each of the keys and values,
109
+ and its return value is used instead of the original value.
110
+ If it returns what it received, then the structure is not modified.
111
+ If it returns undefined then the member is deleted.
112
+
113
+ Example:
114
+
115
+ // Parse the text. Values that look like ISO date strings will
116
+ // be converted to Date objects.
117
+
118
+ myData = JSON.parse(text, function (key, value) {
119
+ var a;
120
+ if (typeof value === 'string') {
121
+ a =
122
+ /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
123
+ if (a) {
124
+ return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
125
+ +a[5], +a[6]));
126
+ }
127
+ }
128
+ return value;
129
+ });
130
+
131
+ myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
132
+ var d;
133
+ if (typeof value === 'string' &&
134
+ value.slice(0, 5) === 'Date(' &&
135
+ value.slice(-1) === ')') {
136
+ d = new Date(value.slice(5, -1));
137
+ if (d) {
138
+ return d;
139
+ }
140
+ }
141
+ return value;
142
+ });
143
+
144
+
145
+ This is a reference implementation. You are free to copy, modify, or
146
+ redistribute.
147
+ */
148
+
149
+ /*jslint evil: true, regexp: true */
150
+
151
+ /*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
152
+ call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
153
+ getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
154
+ lastIndex, length, parse, prototype, push, replace, slice, stringify,
155
+ test, toJSON, toString, valueOf
156
+ */
157
+
158
+
159
+ // Create a JSON object only if one does not already exist. We create the
160
+ // methods in a closure to avoid creating global variables.
161
+
162
+ var JSON;
163
+ if (!JSON) {
164
+ JSON = {};
165
+ }
166
+
167
+ (function () {
168
+ 'use strict';
169
+
170
+ function f(n) {
171
+ // Format integers to have at least two digits.
172
+ return n < 10 ? '0' + n : n;
173
+ }
174
+
175
+ if (typeof Date.prototype.toJSON !== 'function') {
176
+
177
+ Date.prototype.toJSON = function (key) {
178
+
179
+ return isFinite(this.valueOf())
180
+ ? this.getUTCFullYear() + '-' +
181
+ f(this.getUTCMonth() + 1) + '-' +
182
+ f(this.getUTCDate()) + 'T' +
183
+ f(this.getUTCHours()) + ':' +
184
+ f(this.getUTCMinutes()) + ':' +
185
+ f(this.getUTCSeconds()) + 'Z'
186
+ : null;
187
+ };
188
+
189
+ String.prototype.toJSON =
190
+ Number.prototype.toJSON =
191
+ Boolean.prototype.toJSON = function (key) {
192
+ return this.valueOf();
193
+ };
194
+ }
195
+
196
+ var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
197
+ escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
198
+ gap,
199
+ indent,
200
+ meta = { // table of character substitutions
201
+ '\b': '\\b',
202
+ '\t': '\\t',
203
+ '\n': '\\n',
204
+ '\f': '\\f',
205
+ '\r': '\\r',
206
+ '"' : '\\"',
207
+ '\\': '\\\\'
208
+ },
209
+ rep;
210
+
211
+
212
+ function quote(string) {
213
+
214
+ // If the string contains no control characters, no quote characters, and no
215
+ // backslash characters, then we can safely slap some quotes around it.
216
+ // Otherwise we must also replace the offending characters with safe escape
217
+ // sequences.
218
+
219
+ escapable.lastIndex = 0;
220
+ return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
221
+ var c = meta[a];
222
+ return typeof c === 'string'
223
+ ? c
224
+ : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
225
+ }) + '"' : '"' + string + '"';
226
+ }
227
+
228
+
229
+ function str(key, holder) {
230
+
231
+ // Produce a string from holder[key].
232
+
233
+ var i, // The loop counter.
234
+ k, // The member key.
235
+ v, // The member value.
236
+ length,
237
+ mind = gap,
238
+ partial,
239
+ value = holder[key];
240
+
241
+ // If the value has a toJSON method, call it to obtain a replacement value.
242
+
243
+ if (value && typeof value === 'object' &&
244
+ typeof value.toJSON === 'function') {
245
+ value = value.toJSON(key);
246
+ }
247
+
248
+ // If we were called with a replacer function, then call the replacer to
249
+ // obtain a replacement value.
250
+
251
+ if (typeof rep === 'function') {
252
+ value = rep.call(holder, key, value);
253
+ }
254
+
255
+ // What happens next depends on the value's type.
256
+
257
+ switch (typeof value) {
258
+ case 'string':
259
+ return quote(value);
260
+
261
+ case 'number':
262
+
263
+ // JSON numbers must be finite. Encode non-finite numbers as null.
264
+
265
+ return isFinite(value) ? String(value) : 'null';
266
+
267
+ case 'boolean':
268
+ case 'null':
269
+
270
+ // If the value is a boolean or null, convert it to a string. Note:
271
+ // typeof null does not produce 'null'. The case is included here in
272
+ // the remote chance that this gets fixed someday.
273
+
274
+ return String(value);
275
+
276
+ // If the type is 'object', we might be dealing with an object or an array or
277
+ // null.
278
+
279
+ case 'object':
280
+
281
+ // Due to a specification blunder in ECMAScript, typeof null is 'object',
282
+ // so watch out for that case.
283
+
284
+ if (!value) {
285
+ return 'null';
286
+ }
287
+
288
+ // Make an array to hold the partial results of stringifying this object value.
289
+
290
+ gap += indent;
291
+ partial = [];
292
+
293
+ // Is the value an array?
294
+
295
+ if (Object.prototype.toString.apply(value) === '[object Array]') {
296
+
297
+ // The value is an array. Stringify every element. Use null as a placeholder
298
+ // for non-JSON values.
299
+
300
+ length = value.length;
301
+ for (i = 0; i < length; i += 1) {
302
+ partial[i] = str(i, value) || 'null';
303
+ }
304
+
305
+ // Join all of the elements together, separated with commas, and wrap them in
306
+ // brackets.
307
+
308
+ v = partial.length === 0
309
+ ? '[]'
310
+ : gap
311
+ ? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']'
312
+ : '[' + partial.join(',') + ']';
313
+ gap = mind;
314
+ return v;
315
+ }
316
+
317
+ // If the replacer is an array, use it to select the members to be stringified.
318
+
319
+ if (rep && typeof rep === 'object') {
320
+ length = rep.length;
321
+ for (i = 0; i < length; i += 1) {
322
+ if (typeof rep[i] === 'string') {
323
+ k = rep[i];
324
+ v = str(k, value);
325
+ if (v) {
326
+ partial.push(quote(k) + (gap ? ': ' : ':') + v);
327
+ }
328
+ }
329
+ }
330
+ } else {
331
+
332
+ // Otherwise, iterate through all of the keys in the object.
333
+
334
+ for (k in value) {
335
+ if (Object.prototype.hasOwnProperty.call(value, k)) {
336
+ v = str(k, value);
337
+ if (v) {
338
+ partial.push(quote(k) + (gap ? ': ' : ':') + v);
339
+ }
340
+ }
341
+ }
342
+ }
343
+
344
+ // Join all of the member texts together, separated with commas,
345
+ // and wrap them in braces.
346
+
347
+ v = partial.length === 0
348
+ ? '{}'
349
+ : gap
350
+ ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}'
351
+ : '{' + partial.join(',') + '}';
352
+ gap = mind;
353
+ return v;
354
+ }
355
+ }
356
+
357
+ // If the JSON object does not yet have a stringify method, give it one.
358
+
359
+ if (typeof JSON.stringify !== 'function') {
360
+ JSON.stringify = function (value, replacer, space) {
361
+
362
+ // The stringify method takes a value and an optional replacer, and an optional
363
+ // space parameter, and returns a JSON text. The replacer can be a function
364
+ // that can replace values, or an array of strings that will select the keys.
365
+ // A default replacer method can be provided. Use of the space parameter can
366
+ // produce text that is more easily readable.
367
+
368
+ var i;
369
+ gap = '';
370
+ indent = '';
371
+
372
+ // If the space parameter is a number, make an indent string containing that
373
+ // many spaces.
374
+
375
+ if (typeof space === 'number') {
376
+ for (i = 0; i < space; i += 1) {
377
+ indent += ' ';
378
+ }
379
+
380
+ // If the space parameter is a string, it will be used as the indent string.
381
+
382
+ } else if (typeof space === 'string') {
383
+ indent = space;
384
+ }
385
+
386
+ // If there is a replacer, it must be a function or an array.
387
+ // Otherwise, throw an error.
388
+
389
+ rep = replacer;
390
+ if (replacer && typeof replacer !== 'function' &&
391
+ (typeof replacer !== 'object' ||
392
+ typeof replacer.length !== 'number')) {
393
+ throw new Error('JSON.stringify');
394
+ }
395
+
396
+ // Make a fake root object containing our value under the key of ''.
397
+ // Return the result of stringifying the value.
398
+
399
+ return str('', {'': value});
400
+ };
401
+ }
402
+
403
+
404
+ // If the JSON object does not yet have a parse method, give it one.
405
+
406
+ if (typeof JSON.parse !== 'function') {
407
+ JSON.parse = function (text, reviver) {
408
+
409
+ // The parse method takes a text and an optional reviver function, and returns
410
+ // a JavaScript value if the text is a valid JSON text.
411
+
412
+ var j;
413
+
414
+ function walk(holder, key) {
415
+
416
+ // The walk method is used to recursively walk the resulting structure so
417
+ // that modifications can be made.
418
+
419
+ var k, v, value = holder[key];
420
+ if (value && typeof value === 'object') {
421
+ for (k in value) {
422
+ if (Object.prototype.hasOwnProperty.call(value, k)) {
423
+ v = walk(value, k);
424
+ if (v !== undefined) {
425
+ value[k] = v;
426
+ } else {
427
+ delete value[k];
428
+ }
429
+ }
430
+ }
431
+ }
432
+ return reviver.call(holder, key, value);
433
+ }
434
+
435
+
436
+ // Parsing happens in four stages. In the first stage, we replace certain
437
+ // Unicode characters with escape sequences. JavaScript handles many characters
438
+ // incorrectly, either silently deleting them, or treating them as line endings.
439
+
440
+ text = String(text);
441
+ cx.lastIndex = 0;
442
+ if (cx.test(text)) {
443
+ text = text.replace(cx, function (a) {
444
+ return '\\u' +
445
+ ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
446
+ });
447
+ }
448
+
449
+ // In the second stage, we run the text against regular expressions that look
450
+ // for non-JSON patterns. We are especially concerned with '()' and 'new'
451
+ // because they can cause invocation, and '=' because it can cause mutation.
452
+ // But just to be safe, we want to reject all unexpected forms.
453
+
454
+ // We split the second stage into 4 regexp operations in order to work around
455
+ // crippling inefficiencies in IE's and Safari's regexp engines. First we
456
+ // replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
457
+ // replace all simple value tokens with ']' characters. Third, we delete all
458
+ // open brackets that follow a colon or comma or that begin the text. Finally,
459
+ // we look to see that the remaining characters are only whitespace or ']' or
460
+ // ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
461
+
462
+ if (/^[\],:{}\s]*$/
463
+ .test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
464
+ .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
465
+ .replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
466
+
467
+ // In the third stage we use the eval function to compile the text into a
468
+ // JavaScript structure. The '{' operator is subject to a syntactic ambiguity
469
+ // in JavaScript: it can begin a block or an object literal. We wrap the text
470
+ // in parens to eliminate the ambiguity.
471
+
472
+ j = eval('(' + text + ')');
473
+
474
+ // In the optional fourth stage, we recursively walk the new structure, passing
475
+ // each name/value pair to a reviver function for possible transformation.
476
+
477
+ return typeof reviver === 'function'
478
+ ? walk({'': j}, '')
479
+ : j;
480
+ }
481
+
482
+ // If the text is not JSON parseable, then a SyntaxError is thrown.
483
+
484
+ throw new SyntaxError('JSON.parse');
485
+ };
486
+ }
487
+ }());
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: frontkit-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Pavel Pravosud
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70305089369160 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70305089369160
25
+ - !ruby/object:Gem::Dependency
26
+ name: execjs
27
+ requirement: &70305089368740 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70305089368740
36
+ - !ruby/object:Gem::Dependency
37
+ name: railties
38
+ requirement: &70305089368240 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: 3.1.0
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70305089368240
47
+ - !ruby/object:Gem::Dependency
48
+ name: sprockets
49
+ requirement: &70305089367820 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *70305089367820
58
+ - !ruby/object:Gem::Dependency
59
+ name: multi_json
60
+ requirement: &70305089367360 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: *70305089367360
69
+ description: Bunch of rails/js helpers packed in asset pipeline friendly engine.
70
+ email:
71
+ - rwz@duckroll.ru
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - Rakefile
79
+ - app/helpers/front_kit/meta_helper.rb
80
+ - frontkit-rails.gemspec
81
+ - lib/frontkit-rails.rb
82
+ - lib/frontkit-rails/base.rb
83
+ - lib/frontkit-rails/engine.rb
84
+ - lib/frontkit-rails/meta_container.rb
85
+ - lib/frontkit-rails/serializer.rb
86
+ - lib/frontkit-rails/state.rb
87
+ - lib/frontkit-rails/version.rb
88
+ - vendor/assets/javascripts/base64/base64.js.coffee
89
+ - vendor/assets/javascripts/base64/index.js
90
+ - vendor/assets/javascripts/base64/unicode.js.coffee
91
+ - vendor/assets/javascripts/console.js
92
+ - vendor/assets/javascripts/fk/fb.js.coffee
93
+ - vendor/assets/javascripts/fk/fk.js.coffee
94
+ - vendor/assets/javascripts/fk/index.js
95
+ - vendor/assets/javascripts/fk/jquery.js.coffee
96
+ - vendor/assets/javascripts/json2.js
97
+ homepage: ''
98
+ licenses: []
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 1.8.10
118
+ signing_key:
119
+ specification_version: 3
120
+ summary: Bunch of rails/js helpers.
121
+ test_files: []