Module: BigBand::Compass

Defined in:
lib/big_band/compass.rb

Overview

Integrates the Compass stylesheet framework with Sinatra.

Usage without doing something:

require "big_band"
class Foo < BigBand; end

If you create a directory called views/stylesheets and place your sass files in there, there you go. Just call stylesheet(name) form your view to get the correct stylesheet tag. The URL for your stylesheets will be /stylesheets/:name.css.

Of course you can use any other setup. Say, you want to store your stylesheets in views/css and want the URL to be /css/:name.css:

class Foo < BigBand
  get_compass("css")
end

But what about more complex setups?

class Foo < BigBand
  set :compass, :sass_dir => "/foo/bar/blah"
  get_compass("/foo/:name.css") do
    compass :one_stylesheet
  end
end

Note that already generated routes will be deactivated by calling get_compass again.

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Class Method Summary collapse

Class Method Details

.registered(klass) ⇒ Object



64
65
66
67
68
69
70
71
72
73
# File 'lib/big_band/compass.rb', line 64

def self.registered(klass)
  klass.register BasicExtensions
  klass.register AdvancedRoutes
  klass.extend ClassMethods
  klass.send :include, InstanceMethods
  klass.set :compass,
    :project_path => klass.root_path, :output_style => (klass.development? ? :expanded : :compressed),
    :sass_dir => klass.views / "stylesheets", :line_comments => klass.development?
  set_app_file(klass) if klass.app_file?
end

.set_app_file(klass) ⇒ Object



75
76
77
78
# File 'lib/big_band/compass.rb', line 75

def self.set_app_file(klass)
  klass.set :compass, :root_path => klass.root_path
  klass.get_compass("stylesheets") if (klass.views / "stylesheets").directory?
end

.set_compass(klass) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/big_band/compass.rb', line 80

def self.set_compass(klass)
  ::Compass.configuration do |config|
    config.sass_options ||= {}
    klass.compass.each do |option, value|
      if config.respond_to? option
        config.send "#{option}=", value
      else
        config.sass_options.merge! option.to_sym => value
      end
    end
  end
end