fanforce 0.3.6 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -120,4 +120,27 @@ module Fanforce::Utils
120
120
  MultiJson.load(str, :symbolize_keys => symbolize_keys)
121
121
  end
122
122
 
123
+ # Creates a string representation of a javascript object for $.tmpl
124
+ def compile_jquery_tmpls(options={}, &block)
125
+ begin require 'haml' rescue LoadError raise "You must have the haml gem installed for Fanforce.compile_jquery_templates to work." end
126
+ context = Object.new
127
+ class << context
128
+ include Haml::Helpers
129
+ end
130
+ context.init_haml_helpers
131
+
132
+ format = if options[:format] == 'html' then :html else options[:callback].present? ? :jsonp : :json end
133
+
134
+ return context.capture_haml(&block) if format == :html
135
+ single_line_html = context.capture_haml(&block).split(/\r?\n/).inject('') {|sl, l| sl += l.strip + ' ' }
136
+ matches = single_line_html.scan(/<script id=[\"'](.*?)[\"'](?:.*?)>(.*?)(?:<\/script>)/mi)
137
+
138
+ templates = matches.inject({}) {|t,m| t[m[0]] = m[1]; t }
139
+ if format == :jsonp
140
+ "#{options[:callback]}(#{templates.to_json})"
141
+ else
142
+ templates.to_json
143
+ end
144
+ end
145
+
123
146
  end
@@ -1,3 +1,3 @@
1
1
  class Fanforce
2
- VERSION = "0.3.6"
2
+ VERSION = "0.3.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fanforce
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: