Class: JBundle::Server
- Inherits:
-
Object
- Object
- JBundle::Server
- Defined in:
- lib/jbundle/server.rb
Instance Method Summary collapse
-
#call(env) ⇒ Object
Configure JBundle on every request.
-
#initialize(jfile = JBundle::JFILE) ⇒ Server
constructor
A new instance of Server.
Constructor Details
Instance Method Details
#call(env) ⇒ Object
Configure JBundle on every request. Expensive but allows for reloading changes to JFile
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/jbundle/server.rb', line 13 def call(env) bundle_name = env['PATH_INFO'].split('/').last begin JBundle.config_from_file(@jfile) compiler = JBundle.build(bundle_name) body = compiler.buildable? ? compiler.src : compiler.raw_src [200, {'Content-Type' => ::Rack::Mime.mime_type(compiler.ext)}, [body]] rescue NoBundleError => boom p = bundle_name == '' ? '[bundle_name].js' : bundle_name [404, {'Content-Type' => 'text/plain'}, ["No bundle defined. Try defining /#{p} in your JFile"]] rescue NoJFileError => boom [404, {'Content-Type' => 'text/plain'}, [boom.]] end end |