Posted By

iloveitaly on 02/22/11


Tagged

textmate compile less


Versions (?)

TextMate Compile Less Files


 / Published in: Bash
 

When bound to cmd+s in textmate this can compile your LESS CSS files and output a CSS file.

For large projects I use a watch script which checks the SCM flag of all the less files in the project and then compiles those that need to be updated. Compiling 20+ less files can take a second or two, watch.bash eliminates that delay.

  1. compile_less()
  2. {
  3. ORIGINAL_FILE="$1"
  4. CSS_FILE=${ORIGINAL_FILE/less/css}
  5. lessc ${ORIGINAL_FILE} ${CSS_FILE}
  6.  
  7. # check if file is empty
  8. if [[ ! -s ${CSS_FILE} ]]; then
  9. rm ${CSS_FILE} &> /dev/null
  10. fi
  11. }
  12.  
  13. if [[ ${TM_FILEPATH} == *.less ]]; then
  14. compile_less $TM_FILEPATH
  15.  
  16. lessFileName=`basename ${TM_FILEPATH}`
  17. fgrep -r --include="*.less" $lessFileName $TM_PROJECT_DIRECTORY | while read line; do
  18. compile_less ${line%%:@import*}
  19. done
  20. fi

Report this snippet  

You need to login to post a comment.