Module: Sinatra::JstPages::ClassMethods
- Defined in:
- lib/sinatra/jstpages.rb
Instance Method Summary collapse
-
#serve_jst(path, options = {}) ⇒ Object
### serve_jst(path, [options]) [class method] Serves JST files in given ‘path`.
Instance Method Details
#serve_jst(path, options = {}) ⇒ Object
### serve_jst(path, [options]) [class method] Serves JST files in given ‘path`.
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/sinatra/jstpages.rb', line 136 def serve_jst(path, ={}) get path do content_type :js jsts = jst_files().map { |(name, engine)| %{ JST[#{name.inspect}] = function() { if (!c[#{name.inspect}]) c[#{name.inspect}] = (#{engine.function}); return c[#{name.inspect}].apply(this, arguments); }; }.strip.gsub(/^ {12}/, '') } %{ (function(){ var c = {}; if (!window.JST) window.JST = {}; #{jsts.join("\n ")} })(); }.strip.gsub(/^ {12}/, '') end end |