Class: Rack::LessCss
- Inherits:
-
Object
- Object
- Rack::LessCss
- Defined in:
- lib/rack-lesscss.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, opts) ⇒ LessCss
constructor
A new instance of LessCss.
Constructor Details
#initialize(app, opts) ⇒ LessCss
Returns a new instance of LessCss.
6 7 8 9 10 11 |
# File 'lib/rack-lesscss.rb', line 6 def initialize(app, opts) @app = app @less_path = opts[:less_path] or raise ArgumentError, "You must specify less_path (path to directory containing .less files)" @css_route = opts[:css_route] || "/stylesheets" @css_route = @css_route[0..-2] if @css_route[-1] == "/" end |
Instance Method Details
#call(env) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rack-lesscss.rb', line 13 def call(env) if env['PATH_INFO'] =~ /#{Regexp.escape(@css_route)}\/([^\.]+)\.css/ begin headers = { 'Content-Type' => 'text/css', 'Cache-Control' => 'private' } body = "/* Generated from #{$1}.less by Rack::LessCss middleware */\n\n" body << Less::Engine.new(get_source($1)).to_css return [200, headers, body] rescue SyntaxError, StandardError => e puts "Rack::LessCss Error: #{e.}" end end @app.call(env) end |