Module: WebStuff::LessToScss

Defined in:
lib/web_stuff/less_to_scss.rb

Class Method Summary collapse

Class Method Details

.convert(path) ⇒ Object


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/web_stuff/less_to_scss.rb', line 3

def self.convert(path)
  raise "Invalid less file" unless File.extname(path) == ".less"

  content = File.read(path)
  content.gsub!(/@\{?(\w+)\}?/, '$\1')
  content.gsub!(/^\.([\w\-]*)\s*\((.*)\)\s*\{/, '@mixin \1(\2){')
  content.gsub!(/^\.([\w\-]*\(.*\)\s*;)/, '@include \1')
  content.gsub!(/~"(.*)"/, '\#{\"\1\"}')
  content.gsub!(/\$import +["\'](.*?)\.less["\']/, '@import "\1.scss"')
  content.gsub!('$media', '@media')
  content.gsub!('$keyframes', '@-moz-')
  content.gsub!('$-o-', '@-o-')
  content.gsub!('$-webkit-', '@-webkit-')

  puts "Please check @arguments"

  Common::Util.write_file(File.join(File.dirname(path), File.basename(path, ".*") + ".scss"), content)
end