Class: Rack::Less::Base

Inherits:
Object
  • Object
show all
Includes:
Options
Defined in:
lib/rack/less/base.rb

Constant Summary

Constants included from Options

Options::RACK_ENV_NS

Instance Method Summary collapse

Methods included from Options

included

Constructor Details

#initialize(app, options = {}) {|_self| ... } ⇒ Base

Returns a new instance of Base.

Yields:

  • (_self)

Yield Parameters:



9
10
11
12
13
14
# File 'lib/rack/less/base.rb', line 9

def initialize(app, options={})
  @app = app
  initialize_options options
  yield self if block_given?
  validate_options
end

Instance Method Details

#call(env) ⇒ Object

The Rack call interface. The receiver acts as a prototype and runs each request in a clone object unless the rack.run_once variable is set in the environment. ripped from: github.com/rtomayko/rack-cache/blob/master/lib/rack/cache/context.rb



20
21
22
23
24
25
26
# File 'lib/rack/less/base.rb', line 20

def call(env)
  if env['rack.run_once']
    call! env
  else
    clone.call! env
  end
end

#call!(env) ⇒ Object

The real Rack call interface. if LESS CSS is being requested, this is an endpoint:

> generate the compiled css

> respond appropriately

Otherwise, call on up to the app as normal



33
34
35
36
37
38
39
40
41
42
# File 'lib/rack/less/base.rb', line 33

def call!(env)
  @default_options.each { |k,v| env[k] ||= v }
  @env = env

  if (@request = Request.new(@env.dup.freeze)).for_less?
    Response.new(@env.dup.freeze, @request.source.to_css).to_rack
  else
    @app.call(env)
  end
end