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

#initialize(app, project) ⇒ Middleware

Returns a new instance of Middleware.

Parameters:



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

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

Instance Attribute Details

#projectObject

Returns the value of attribute project.



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

def project
  @project
end

Instance Method Details

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

Automatically compiles your assets if required and serves them up.

Parameters:

  • env (Hash)

    a Rack environment

Returns:

  • (Array(Fixnum, Hash, #each))

    A rack response



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

def call(env)
  project.invoke
  path = env["PATH_INFO"]

  if project.maps.has_key?(path)
    return project.maps[path].call(env)
  end

  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