LoginSignup
1
2

More than 5 years have passed since last update.

scssからsassへ変換するスニペット

Last updated at Posted at 2015-04-10

はじめに

scssからまとめてsassに変更しようとするとsass-convertと言うコマンドがあるが、1ファイルずつしか出来ず、まとめて変換できない。

そこでまとめて変換できるスニペットを書いた

前提条件

Ruby2.2.0
Sass 3.4.13

sassのインストール

gem install sass

scssからsassへ変換

実行する対象のディレクトリに移動して
下記のスニペットをファイルにしてrubyで実行するか、irb, pryを起動して変換する


# 入力するSCSSのあるディレクトリパス
stylesheets_path = "assets/stylesheets/"

# 出力先のディレクトリパス
output_path = "output_stylesheets/"

Dir.glob("#{stylesheets_path}**/*.scss").each{ |f|
  # 変換先のファイル名を作成
  sass = f.gsub(".scss", ".sass")

  # 転送先のディレクトリを作成する
  path = f.reverse.sub!(/[^\/]+\//, "").reverse
  FileUtils.mkdir_p(output_path + path})

  # 外部コマンドで実行(普通にSassのライブラリを呼んでも良いと思う)
  system("sass-convert #{f} #{output_path + sass}")
}
1
2
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2