fanforce-internal-utils 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/fanforce/utils/utils.rb +27 -0
- data/lib/fanforce/utils/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NGQzYWQ0MGI5YzE2MTBhY2JkYzIwZmY5MDM3ZmNkYTJjNmM2NjVlYw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZTFkODYwOTc5ZTdlYmE0MmE0NzAwYzAyZWExNjMxODc4MGQ0MjI4Yw==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZjU4MTEzODM5YWE1MWJmMzEyZWI2MmIzYmYxNjllZWNmNzU4NzRjZmQ5MDcx
|
10
|
+
YWQyMTA5ZWUwYmEzMjdjOTQ5NGNhYTBlNTBlZmIwOTNhNGRmZjI5MzliNDRm
|
11
|
+
NzliNmQ2MzJlOGQ1OTVhZGE5Yjc1ZThiMzI0NDE2YmVkODkxODk=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YjZmZjZhOTJhMDhlNjAzYTJhODc4ZjM2OTIxODE2OWM3NGEzZmM1YjAyM2Mw
|
14
|
+
ZDA0NjAwYjVjN2ZlMjZhOWE1MzIzNWY2ZjVkZDg1ZWU0ZDQ0MzY4ZWE4ZTQ4
|
15
|
+
Mzc2YjI3NjJjZjEwNjFlNzE1M2U4NWJkZjJiNTE2YmQ1ZThkOGE=
|
data/lib/fanforce/utils/utils.rb
CHANGED
@@ -64,6 +64,33 @@ module Fanforce::Utils
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
+
def decode_json(str, symbolize_keys=true)
|
68
|
+
MultiJson.load(str, :symbolize_keys => symbolize_keys)
|
69
|
+
end
|
70
|
+
|
71
|
+
# Creates a string representation of a javascript object for $.tmpl
|
72
|
+
def compile_jquery_tmpls(options={}, &block)
|
73
|
+
begin require 'haml' rescue LoadError raise "You must have the haml gem installed for Fanforce.compile_jquery_templates to work." end
|
74
|
+
context = Object.new
|
75
|
+
class << context
|
76
|
+
include Haml::Helpers
|
77
|
+
end
|
78
|
+
context.init_haml_helpers
|
79
|
+
|
80
|
+
format = if options[:format] == 'html' then :html else options[:callback].present? ? :jsonp : :json end
|
81
|
+
|
82
|
+
return context.capture_haml(&block) if format == :html
|
83
|
+
single_line_html = context.capture_haml(&block).split(/\r?\n/).inject('') {|sl, l| sl += l.strip + ' ' }
|
84
|
+
matches = single_line_html.scan(/<script id=[\"'](.*?)[\"'](?:.*?)>(.*?)(?:<\/script>)/mi)
|
85
|
+
|
86
|
+
templates = matches.inject({}) {|t,m| t[m[0]] = m[1]; t }
|
87
|
+
if format == :jsonp
|
88
|
+
"#{options[:callback]}(#{templates.to_json})"
|
89
|
+
else
|
90
|
+
templates.to_json
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
67
94
|
end
|
68
95
|
|
69
96
|
module Fanforce::InternalUtils
|