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, pipeline) ⇒ Middleware

Returns a new instance of Middleware.

Parameters:

  • app (#call)

    a Rack application

  • pipeline (String|Rake::Pipeline)

    either a path to an Assetfile to use to build a pipeline, or an existing pipeline.



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

def initialize(app, pipeline)
  @app = app
  @project = Rake::Pipeline::Project.new(pipeline)
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



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

def call(env)
  project.invoke_clean
  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