Milk+ea

Weblog Is My Hobby.

バッチファイル(.bat)で"compass create"を実行

コマンドでcompass createは覚えているんだけどその後の--sass ~~ みたいなのが毎回「分からんなんだっけ、調べるのめんどくさっ」ってなるのでバッチファイルで簡単に作れるようにした。
ちなみに、Windows7です。

まず、compassをcreateする先のディレクトリを作成してください。僕はC:\compassにしています。というか、ここにしてください。動きません。

C:\compassの中にcompass_create.batという名前で以下のコードのファイルを作成します。

compass create %FILE% --syntax sass --css-dir "css" --javascripts-dir "js" --images-dir "img"

(scssを使うならたぶん、--syntax sassを消すといいと思います。)
(javascripts-dirとimage-dirの名前は変えていいですが、css-dirの名前は変えないで…動きません。)

コマンドプロンプトを開いたとこのホームディレクトリに(僕はC:\Users\[ユーザ名])名前はcompass.batで以下のコードで保存します。

@echo off

set FILE=%1

rem argが指定していたら実行
if %FILE% neq '' (

  rem compassフォルダに移動
  cd C:\compass

  rem compassコマンドを実行して、作成されたフォルダに移動
  call compass_create.bat
  cd C:\compass\%FILE%

  rem config.rbに書き込む
  echo output_style = :expanded >> config.rb
  echo line_comments = false >> config.rb

  rem js, imgフォルダを作成
  mkdir js, img
  rem css, sassフォルダの中身を全部削除
  del /Q css, sass
  rem index.html, style.css, style.sassをそれぞれ作成
  type null > index.html & type null > css/style.css & type null > sass/style.sass

  rem 作成したフォルダを開く
  start "" "."

)

あとはホームディレクトリで

compass.bat iemon

コマンドプロンプトで打つと勝手に作成したcompassのフォルダが開いて画像みたいな感じになってます。

f:id:totora0155:20130606182243p:plain

こちらツリー、ie.cssとかの最初からあるcssは使わないので消しました。つかうならcompass.batのdel /Q css, sassのとこを消してください。cacheの中はよくわかんないのでほっとく。

│  config.rb
│  index.html
│
├─.sass-cache
│  ├─848a6ce014bfebf3be8356c526a4220db37375a9
│  │      _utilities.scssc
│  │
│  ├─b549465b4271c63a6444b7f64920b1a60789f5ca
│  │      ie.sassc
│  │      print.sassc
│  │      screen.sassc
│  │
│  └─dfed15293399f860c57e71e3dd774a8ad2648b24
│          _reset.scssc
│
├─css
│      style.css
│
├─img
├─js
└─sass
       style.sass

config.rbは、output_style = :expandedとline_comments = falseが追加されてます。

# Require any additional compass plugins here.

# Set this to the root of your project when deployed:
http_path = "/"
css_dir = "css"
sass_dir = "sass"
images_dir = "img"
javascripts_dir = "js"

# You can select your preferred output style here (can be overridden via the command line):
# output_style = :expanded or :nested or :compact or :compressed

# To enable relative paths to assets via compass helper functions. Uncomment:
# relative_assets = true

# To disable debugging comments that display the original location of your selectors. Uncomment:
# line_comments = false

preferred_syntax = :sass
output_style = :expanded 
line_comments = false 

感想、初めて使ったけどバッチファイルすんげえええヽ(*゚ω。)ノ