Module: Sinatra::JstPages::ClassMethods

Defined in:
lib/furnace-xray/lib/jst_pages.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`.



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/furnace-xray/lib/jst_pages.rb', line 135

def serve_jst(path, options={})
  get path do
    content_type :js
    jsts = jst_files.map { |(name, engine)|
      %{
        JST[#{name.inspect}] = (#{engine.function});
    }.strip.gsub(/^ {12}/, '')
    }

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