The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 20, 2019, 11:03:45 AM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: Installing LESS from scratch  (Read 2904 times)
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« on: June 27, 2012, 11:24:40 PM »

I needed to install LESS (the CSS3 preprocessor) onto a machine that has almost nothing, so here are the steps I took to get it done.

YMMV, but this worked OK.

Ruby's got to be installed, so I ran RailsReady to get it all set:
wget --no-check-certificate https://raw.github.com/joshfng/railsready/master/railsready.sh && bash railsready.sh

(Note that this script can take a really long time)

CAVEAT: You can't run this as root - it's got to be done as a normal user with SU privileges  Shocked so, using visudo, modify the sudoers file to include (your user name). Best way: look towards the bottom and find the root entry - just add you to look exactly the same. You might want to consider removing that line after you're done.  D'oh!

When done, do exec $SHELL.

Even as a SU, you'll still not have rights to the correct places, so for a moment open up a couple directories:
/usr/local/lib/ruby/gems/1.9.1 (or whatever the version when you're reading this) - use chmod -R 777 ./1.9.1. Later we'll chmod -R 775 it back.
Same with /usr/local/bin.

Gem will now run. To install lessc you'll need rubyracer, so
gem install rubyracer

Now install LESS:
gem install less

At this point clean up your work: 775 the gems dir and usr/local/bin. Again, you probably want to take yourself out of sudoers.

And you're ready! To compile a less script simply do this:
lessc inputscript.less > outputscript.css

My next step is to use Ruby to watch my directories and auto-compile scripts for me. As you can tell I'm not a fan of client side LESS compilation, but I also hate having to remember to recompile before I pull down a page modification. I'm using the steps I found here:
http://www.ravelrumba.com/blog/watch-compile-less-command-line/

Just in case he's gone someday, here's the content:
Quote
Unlike SASS and Stylus, the command line compiler that comes with LESS does not include a watch option to automatically compile LESS files whenever changes are made. There are several GUI apps that provide watch functionality but if GUIs aren’t your thing or if you need something that can run on a server, you’ll want a way to do this from the command line. Here’s an easy way.

Install watchr, which is a Ruby tool for monitoring directories and files. With watchr and LESS installed you can watch-compile directories and sub-directories with a single command:

watchr -e 'watch(".*\.less$") { |f| system("lessc #{f[0]} > #{f[0]}.css") }'
To make this a little more useful we can call it with a bash script. We’ll also print a status update on each compile. Successful compiles will print the compiled file name and any compile errors will be displayed in the console.

#!/bin/bash
# Requires watchr: https://github.com/mynyml/watchr
watchr -e 'watch(".*\.less$") { |f| system("lessc #{f[0]} > #{f[0]}.css && echo \"#{f[0]} > #{f[0]}.css\" ") }'
Name it something like watch_less.sh, put it in /usr/local/bin/ (or wherever you keep your executables), set permissions with chmod u+x watch_less.sh, and then just run watch_less.sh from your workspace.

Bonus
Here’s another option that uses inotify-tools (note: Linux-only) instead of watchr. This was suggested by @yoavweiss when I asked on Twitter if anyone had a recommended solution for watch-and-compiling LESS from the command line:

while true;do N=`find -name "*.less" `;inotifywait -qe modify $N ;for f in $N;do lessc $f ${f%.*}.css;done;done

The best response in the thread is a guy that says this:
Quote
elgreg February 6, 2012
You blog post couldn’t have been more perfectly timed. I just started a new project and heard about watchr at the Twitter Bootstrap 2.0 announcement. I’m on OS X and decided to use growlnotify instead of echo and run watch_less.sh with & to not have a constantly running window.

> watch_less.sh &
runs

#!/bin/bash
# Requires watchr: https://github.com/mynyml/watchr
watchr -e ‘watch(“.*\.less$”) { |f| system(“lessc #{f[0]} > #{f[0]}.css && growlnotify \”compiled\” -m \”#{f[0]} > #{f[0]}.css\”") }’

(installed growlnotify with homebrew >brew install growlnotify)

I'll see how it works and post back. Enjoy. Sort of.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!