Class: SassMyLess::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/SassMyLess.rb

Constant Summary collapse

ConvertList =
{
  # A bit dangerous, but it should work.
  '@(?!font-face|import|media|keyframes|-)' => '$',
  '\.([\w\-]*)\s*\((.*)\)\s*\{' => "@mixin \\1\(\\2\)\n{",
  '\.([\w\-]*\(.*\)\s*;)' => '@include \1',
  '~"(.*)"' => '#{"\1"}',
  'spin\(' => 'adjust-hue(',
}

Class Method Summary collapse

Class Method Details

.convert(input_dir, output_dir) ⇒ Object

Copies the entire directory to the output



14
15
16
17
18
19
20
# File 'lib/SassMyLess.rb', line 14

def self.convert(input_dir, output_dir)
  input_path = File.expand_path("#{input_dir}")
  output_path = File.expand_path("#{output_dir}")
  FileUtils.mkdir_p(input_path) unless Dir.exists?(output_path)
  FileUtils.cp_r "#{input_path}/.", "#{output_path}"
  self.traverse_dir output_path
end

.traverse_dir(directory) ⇒ Object

Traverses the output directory and converts every file.



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/SassMyLess.rb', line 25

def self.traverse_dir directory
  Dir.glob("#{directory}/*").each_with_object({}) do |f, h|
    if File.file?(f)
      src = open(f).read
      ConvertList.each do |regexp, with|
        src.gsub! /#{regexp}/, with
      end
      FileUtils.mv(f, f.gsub('.less', '.scss'))
    end
  end
end