Class: Rake::Pipeline::Middleware
- Inherits:
-
Object
- Object
- Rake::Pipeline::Middleware
- Defined in:
- lib/rake-pipeline/middleware.rb
Overview
This middleware is used to provide a server that will continuously compile your files on demand.
Instance Attribute Summary collapse
-
#pipeline ⇒ Object
Returns the value of attribute pipeline.
Instance Method Summary collapse
-
#call(env) ⇒ Array(Fixnum, Hash, #each)
Automatically compiles your assets if required and serves them up.
-
#initialize(app, pipeline) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app, pipeline) ⇒ Middleware
Returns a new instance of Middleware.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rake-pipeline/middleware.rb', line 21 def initialize(app, pipeline) @app = app if pipeline.is_a?(String) pipeline_source = File.read(pipeline) pipeline = Pipeline.class_eval "build do\n#{pipeline_source}\nend", pipeline, 1 end @pipeline = pipeline end |
Instance Attribute Details
#pipeline ⇒ Object
Returns the value of attribute pipeline.
17 18 19 |
# File 'lib/rake-pipeline/middleware.rb', line 17 def pipeline @pipeline end |
Instance Method Details
#call(env) ⇒ Array(Fixnum, Hash, #each)
Automatically compiles your assets if required and serves them up.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rake-pipeline/middleware.rb', line 37 def call(env) pipeline.invoke_clean path = env["PATH_INFO"] if filename = file_for(path) if File.directory?(filename) index = File.join(filename, "index.html") filename = File.file?(index) ? index : nil end if filename return response_for(filename) end end @app.call(env) end |