Class: DevTask::Css2scss

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

Class Method Summary collapse

Class Method Details

.convert(css, options = { }) ⇒ Object



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

def convert(css, options = { })
  @scss =  Sass::CSS.new(css).render(:scss)

  @scss.gsub!(/url\(.*?\)/){ |v|
    _file = (v.match(/([^\/]+)\)/) && $1).gsub(/'/, '')
    case
    when v =~ /\/images\// then "image-url('#{ _file }')"
    when v =~ /\/fonts\// then  "font-url('#{ _file }')"
    else
      v
    end
  }

  @scss.gsub(/@import url\(([^\)]*).css\);?/){ "@import '#{options[:prefix]}/#{$1}';" }
rescue Sass::SyntaxError => e
  puts "!"*90
  puts "[ CSS -> SCSS ] #{e}"

end