Class: Rake::Pipeline::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/rake-pipeline/middleware.rb

Overview

This middleware is used to provide a server that will continuously compile your files on demand.

Examples:

use Rake::Pipeline::Middleware, Rake::Pipeline.build {
  input "app/assets"
  output "public"

  ...
}

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Middleware) initialize(app, pipeline)



21
22
23
24
# File 'lib/rake-pipeline/middleware.rb', line 21

def initialize(app, pipeline)
  @app = app
  @pipeline = pipeline
end

Instance Attribute Details

- (Object) pipeline

Returns the value of attribute pipeline



17
18
19
# File 'lib/rake-pipeline/middleware.rb', line 17

def pipeline
  @pipeline
end

Instance Method Details

- (Array(Fixnum, Hash, #each)) call(env)

Automatically compiles your assets if required and serves them up.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rake-pipeline/middleware.rb', line 31

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