Module: Sinatra::JstPages::ClassMethods

Defined in:
lib/sinatra/jstpages.rb

Instance Method Summary collapse

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
# File 'lib/sinatra/jstpages.rb', line 136

def serve_jst(path, options={})
  get path do
    content_type :js
    jsts = jst_files(options).map do |(name, engine)|
      engine.compile!
    end

    %{
      (function(){
        var c = {};
        if (!window.JST) window.JST = {};
        #{jsts.join("\n  ")}
      })();
    }.strip.gsub(/^ {12}/, '')
  end
end