Module: SassPaths

Extended by:
Gem
Defined in:
lib/sass_paths.rb,
lib/sass_paths/gem.rb,
lib/sass_paths/version.rb,
lib/sass_paths/rails/engine.rb

Defined Under Namespace

Modules: Gem Classes: Engine

Constant Summary collapse

VERSION =
'2.0.0'.freeze

Class Method Summary collapse

Class Method Details

.append(*paths) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/sass_paths.rb', line 9

def append(*paths)
  existing_paths = paths.select { |path| Dir.exist? path }
  new_paths = [
    env_path.split(File::PATH_SEPARATOR),
    existing_paths
  ].flatten.compact.uniq
  self.env_path = new_paths
end

.append_gem_path(gem, path) ⇒ Object



18
19
20
# File 'lib/sass_paths.rb', line 18

def append_gem_path(gem, path)
  append(gem_sass_path(gem, path))
end

.env_pathObject



22
23
24
# File 'lib/sass_paths.rb', line 22

def env_path
  ENV['SASS_PATH'] || ''
end

.env_path=(*paths) ⇒ Object



26
27
28
# File 'lib/sass_paths.rb', line 26

def env_path=(*paths)
  ENV['SASS_PATH'] = paths.join(File::PATH_SEPARATOR)
end

.reload_paths!Object



30
31
32
33
34
# File 'lib/sass_paths.rb', line 30

def reload_paths!
  append(*Sass.load_paths)
  Sass.instance_variable_set('@load_paths', nil)
  Sass.load_paths
end

.with_replacements(replacements = {}) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/sass_paths.rb', line 36

def with_replacements(replacements = {})
  reload_paths!
  old_paths = Sass.load_paths.dup
  tmp_paths = old_paths.map do |path|
    replacements[path] ? replacements[path] : path
  end
  self.env_path = tmp_paths
  reload_paths!
  yield
ensure
  self.env_path = old_paths
  reload_paths!
end