Module: Sinatra::CompassSupport

Defined in:
lib/sinatra/support/compasssupport.rb

Overview

Adds Compass support.

CompassSupport lets you use the Compass CSS framework in your application. More information about Compass can be found in compass-style.org.

Usage

require 'sinatra/support/compasssupport'

class Main
  register Sinatra::CompassSupport
end

After this, anytime a sass or scss is rendered, you may use Compass's extensions by simply importing them (eg, +@import 'compass/layout'+).

Example

All you need to use is in the section above. Here's a slightly more-complicated example:

class Main
  register Sinatra::CompassSupport

  get '/' do
    scss :mysheet
  end
end

And in views/mysheet.scss:

@import 'compass/css3';

Caveats

When When using with CssSupport, you may need to change Compass's sass_dir config to where you're serving CSS files from.

path = File.join(app.root, 'css')

serve_css '/css', from: path

Compass.configuration do |c|
  c.sass_dir = path
end

If you are getting errors about Sass functions, you may need to upgrade your HAML and Sass gems.

If your project uses Bundler, you will need to add Compass to your Gemfile.

# Gemfile
gem "compass", "~> 0.11.1"

If you are getting errors about US-ASCII encoding, you may have to change your application's default external encoding to utf-8.

Encoding.default_external = 'utf-8'

Class Method Summary (collapse)

Class Method Details

+ (Object) registered(app)



61
62
63
64
65
# File 'lib/sinatra/support/compasssupport.rb', line 61

def self.registered(app)
  require 'compass'

  add_compass_engine_options app
end