Class: Rack::SassCompiler

Inherits:
AssetCompiler show all
Defined in:
lib/rack/sass_compiler.rb

Constant Summary

Constants inherited from AssetCompiler

AssetCompiler::F

Instance Attribute Summary collapse

Attributes inherited from AssetCompiler

#source_dir, #source_extension, #url

Instance Method Summary collapse

Methods inherited from AssetCompiler

#call, #response

Constructor Details

#initialize(app, options = {}) ⇒ SassCompiler

Returns a new instance of SassCompiler.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rack/sass_compiler.rb', line 8

def initialize(app, options={})
  options

  options = {
    :url => '/stylesheets',
    :content_type => 'text/css',
  }.merge(options)

  options[:sass_options] ||= {}
  options[:sass_options] = {
    :syntax => :scss,
    :cache  => false
  }.merge(options[:sass_options])

  @sass_options = options[:sass_options]
  options[:source_extension] ||= @sass_options[:syntax].to_s
  super
end

Instance Attribute Details

#sass_optionsObject

Returns the value of attribute sass_options.



6
7
8
# File 'lib/rack/sass_compiler.rb', line 6

def sass_options
  @sass_options
end

Instance Method Details

#compile(source_file) ⇒ Object



37
38
39
40
41
# File 'lib/rack/sass_compiler.rb', line 37

def compile(source_file)
  @sass_options[:load_paths] ||= []
  @sass_options[:load_paths]   = @sass_options[:load_paths] | get_load_paths(source_dir)
  Sass::Engine.new(::File.read(source_file), @sass_options).render
end

#get_load_paths(src_dir) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/rack/sass_compiler.rb', line 27

def get_load_paths(src_dir)
  paths = [src_dir]
  if defined?(Compass::Frameworks)
    Compass::Frameworks::ALL.each do |framework|
      paths << framework.stylesheets_directory if ::File.exists?(framework.stylesheets_directory)
    end
  end
  paths
end