SASS and Lift in sbt

562 views
Skip to first unread message

steve

unread,
May 23, 2012, 4:53:02 PM5/23/12
to lif...@googlegroups.com
Hey guys,

I'm working on a Lift project that uses SASS files http://sass-lang.com/ .  Currently I'm using Compass http://compass-style.org/ to compile the SASS files (.scss) into normal .css files.  This is fine for me and the other front end developer, but when anyone else pulls our project, they have to install compass and run it to get the latest css files based on the SASS files we've been working on, unless we include them with the rest of our files in git which is a possible solution. Ideally I'd like to only push .scss files and have them compiled to css on everyones local machine when they compile the lift project in sbt.  I was wondering if anyone knows of a plugin for lift which will compile SASS files automatically whenever the project compiles, that was we can avoid pushing our css files into git and let everyone get the latest css on their machines when they compile our code. If it could also handle Compass that would be fantastic.

I couldn't find anything like that for lift, so if it doesn't exist, maybe someone can help me set up my project to do this?  Play has a SASS module that seems to do what I want, I would love if I could find the same for Lift. https://github.com/jlitola/play-sass

I'm not sure how clear my question was or how many of you are familiar with SASS and Compass, so I'll answer any questions.

I appreciate any help the community can offer.

Thanks!
Steve

Diego Medina

unread,
May 23, 2012, 6:49:29 PM5/23/12
to lif...@googlegroups.com

Isn't what you need more an sbt plugin, than a lift plugin?

I think someone asked for this not too long ago, and they found an sbt plugin that did the compile.

If you search for   sass you may find it (I hope)

Regards

Diego
Sent from my android cell

--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code

Stephen Giordano

unread,
May 24, 2012, 11:46:01 AM5/24/12
to lif...@googlegroups.com

Hey Diego,

Yeah, you might be right.  I only asked if there was lift plugin because theres a specifically Play 2.0 plugin that does this, so I thought there may be a similar one for lift.

I've tried searching for SASS sbt plugins and couldn't find any... :/  Searching for SASS in this group didn't yeild many results either.  When I get to the office, I'll try again.

But I agree an sbt is probably what I'm looking for.

-Steve

Antonio Salazar Cardozo

unread,
May 24, 2012, 2:32:46 PM5/24/12
to lif...@googlegroups.com
We use compass, but we just run compass itself. We have a (currently completely undocumented <_< >_>) sbt plugin at https://github.com/Shadowfiend/sbt-resource-management that helps us manage running compass and coffee and JavaScript compression in production and uploads to S3 and such. However, again, it just calls out to the executables. We'd rather not be tied to a version of SASS or compass that may lag behind the official bug fixes and improvements.
Thanks,
Antonio

Byron Gibson

unread,
May 24, 2012, 7:33:15 PM5/24/12
to lif...@googlegroups.com
Play uses SBT for building, dependencies, and plugins the same as Lift, and Play's sass plugin is definitely an SBT plugin, check the first sentence of its readme.

play-sass might be portable to Lift.  It makes an external call to the ruby-gem-installed SASS compiler and tells it where to look for .sass and .scss files.  You'd have to change dependencies in build.sbt, the Play entry in project/Build.scala, and modify the hardcoded Play code in src/main/scala/SassCompiler.scala and src/main/scala/SassPlugin.scala.  Both of those .scala files import Play libraries that I didn't look closely at, so not sure, just a thought.

Here's another SASS Java integration project that's probably portable to Lift as well, or maybe usable as is:


Also, SASS is written in Ruby, so I wonder if it could be ported it to JRuby, compiled to a JAR, then wrapped it in a Scala SBT plugin wrapper, and used in any SBT build that way?

Ben Phelan

unread,
May 25, 2012, 3:06:27 AM5/25/12
to lif...@googlegroups.com
There are also at least two really nice LESS plugins for SBT if you have the option of using LESS.  (IMHO LESS is much nicer.)

Rike-Benjamin Schuppner

unread,
May 25, 2012, 4:42:22 AM5/25/12
to lif...@googlegroups.com
A possibility could be to add JRuby as a sbt dependency and then register tasks which then call SASS or Compass. SASS, Compass and the like can be automatically downloaded and stored locally using bundler [1], so you could easily upgrade your projects to the very same version.
On the other hand, if the JRuby dependency is too much of an effort, I’d just go the bundler route: Tell all developers that some recent ruby version and the bundler gem is required, ship a Gemfile and Gemfile.lock with your project and then add some sbt task dependencies which simply run `bundle` and `bundle exec compass`.

Note: I asked a SO question some time ago [2] and was pointed to two projects trying to get some JRuby–sbt bridge ready [3,4]. I’ve always wanted to improve those projects with bundler and compass but unfortunately never got around to doing so.

Cheers
/rike

steve

unread,
May 25, 2012, 4:02:49 PM5/25/12
to lif...@googlegroups.com
Hey Rike,

Everything you said sounds cool.  All the developers I'm working with should already have ruby on their computer, so I think for the time being I can skip the step of adding JRuby as an sbt dependency(although, ideally I'd like to, I think).  

I created a Gemfile that installs compass and sass.  
This is all it is:
source :gemcutter
gem 'compass', '0.12.1'
gem 'sass', '3.1.15'

Seems to work fine.

I'm having trouble with the last part of your comment.  
and then add some sbt task dependencies which simply run `bundle` and `bundle exec compass`.

I've been reading through the sbt guide files and I can't seem to figure out how to do this.  I'm kind've a noob when it comes to sbt and a a lot of it is over my head.  Do you think you could help point me in the right direction for adding tasks to run on compile.  I'd love for 'compass compile' to run every time sbt compiles my project. 

Thanks!
-Steve

steve

unread,
May 25, 2012, 4:04:22 PM5/25/12
to lif...@googlegroups.com
Hey Ben,

I don't really have a choice here.  We're using SASS for this project.  But maybe I'll check out the LESS plugins to get an idea of how to implement a SASS one.

thanks,
Steve

steve

unread,
May 25, 2012, 4:06:13 PM5/25/12
to lif...@googlegroups.com
Antonio,

This plugin seems pretty cool. I was showing another developer.  It sure handles a lot of different things for you.  I'm gonna have to take a closer look at it.

Thanks,
Steve

Antonio Salazar Cardozo

unread,
May 25, 2012, 4:21:49 PM5/25/12
to lif...@googlegroups.com
Hahaha. Ok, that's it. I'm writing some quick documentation for it now. Look for it in the next hour or two :p
Thanks,
Antonio

steve

unread,
May 25, 2012, 4:52:48 PM5/25/12
to lif...@googlegroups.com
Cool, I'll be looking for it!

Antonio Salazar Cardozo

unread,
May 25, 2012, 6:05:41 PM5/25/12
to lif...@googlegroups.com
Ok, I've added a reasonably descriptive README. Let me know if you have any questions! :)
Thanks,
Antonio

steve

unread,
May 25, 2012, 6:35:57 PM5/25/12
to lif...@googlegroups.com
Cool, I'm gonna look this over this weekend!

Rike-Benjamin Schuppner

unread,
May 26, 2012, 8:21:37 AM5/26/12
to lif...@googlegroups.com
Hi Steve,


Am Freitag, 25. Mai 2012 22:02:49 UTC+2 schrieb steve:
Everything you said sounds cool.  All the developers I'm working with should already have ruby on their computer, so I think for the time being I can skip the step of adding JRuby as an sbt dependency(although, ideally I'd like to, I think).  

I created a Gemfile that installs compass and sass.  
This is all it is:
source :gemcutter
gem 'compass', '0.12.1'
gem 'sass', '3.1.15'

Seems to work fine.

Remember to also put Gemfile.lock under version control; and devs who want to have their gems installed locally should use `bundle install --path vendor` on first use.
 

I'm having trouble with the last part of your comment.  
and then add some sbt task dependencies which simply run `bundle` and `bundle exec compass`.

I've been reading through the sbt guide files and I can't seem to figure out how to do this.  I'm kind've a noob when it comes to sbt and a a lot of it is over my head.  Do you think you could help point me in the right direction for adding tasks to run on compile.  I'd love for 'compass compile' to run every time sbt compiles my project. 

A quick and really dirty hack would be adding this line to build.sbt

    compile in Compile ~= ( oldCompile => { if ("bundle exec compass".! != 0) throw new RuntimeException("Compass error"); oldCompile} )

It enriches the old compile command. Before it compiles, it executes the process `bundle exec compass`; a non-zero return code throws an exception, otherwise the regular compilation is triggered. (This can be done much nicer and one probably would use some more specialised exception; but I’m not too much into sbt definitions either. But hey, it seems to work.)

Cheers
/rike

Rike-Benjamin Schuppner

unread,
May 26, 2012, 8:24:34 AM5/26/12
to lif...@googlegroups.com

A quick and really dirty hack would be adding this line to build.sbt

    compile in Compile ~= ( oldCompile => { if ("bundle exec compass".! != 0) throw new RuntimeException("Compass error"); oldCompile} )

It enriches the old compile command. Before it compiles, it executes the process `bundle exec compass`; a non-zero return code throws an exception, otherwise the regular compilation is triggered. (This can be done much nicer and one probably would use some more specialised exception; but I’m not too much into sbt definitions either. But hey, it seems to work.)


sbt-resource-management looks much better, though. :)


steve

unread,
May 30, 2012, 11:15:00 AM5/30/12
to lif...@googlegroups.com
Hey Rike,

I tried adding compile in Compile ~= ( oldCompile => { if ("bundle exec compass".! != 0) throw new RuntimeException("Compass error"); oldCompile} ) to my build.scala file and it didn't. I don't get any error messages or anything, it just doesn't do anything.  I'm going to keep reading up on sbt and see if I can figure it out.  I'd love to have my SASS files automatically compile for the other developers so they don't have to think about it, but I think I may end up going with Antonio's sbt-resource-management plugin in the end.  They'll just have to compile the SASS files once whenever they git pull the latest version.  I think they can handle that and it'll probably be the simplest solution.

-Steve

steve

unread,
May 30, 2012, 11:15:51 AM5/30/12
to lif...@googlegroups.com
Plus, his plugin can handle a bunch of other things we'll eventually be doing, such as js/css minimization and file concatenation.

Antonio Salazar Cardozo

unread,
May 30, 2012, 11:46:10 AM5/30/12
to lif...@googlegroups.com
Notably, when developing, I keep compass watch running.

Also, it may be straightforward to set up sbt resources:compile-sass (or whatever else) to run as a git post-merge/post-rewrite hook.

And, while I haven't tested it, sbt-resource-management is set up so that running ~resources:copy-scripts will properly run CoffeeScript recompiles; it may also work for SASS recompiles (since I use compass watch locally, I haven't checked).
Thanks,
Antonio


On Wednesday, May 30, 2012 11:15:00 AM UTC-4, steve wrote:
Message has been deleted

steve

unread,
Jun 1, 2012, 10:32:51 AM6/1/12
to lif...@googlegroups.com
Hey Antonio, 

Thanks for taking the time on this plugin and writing up the ReadMe file and all.  I'm having some trouble getting your plugin to work and I believe it's directly related to my lack of knowledge when it comes to sbt.

First of all, the error I'm getting is this:

[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] ::          UNRESOLVED DEPENDENCIES         ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: com.openstudy#sbt-resource-management;0.1.1-SNAPSHOT: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] 
[warn] Note: Some unresolved dependencies have extra attributes.  Check that these dependencies exist with the requested attributes.
[warn] com.openstudy:sbt-resource-management:0.1.1-SNAPSHOT (sbtVersion=0.11.2, scalaVersion=2.9.1)
[warn] 


The way my project is set up, we have a Build.scala file and a plugins.sbt file.  I added addSbtPlugin("com.openstudy" % "sbt-resource-management" % "0.1.1-SNAPSHOT") to the plugins.sbt file, which is how we installed other plugins.  Clearly I'm missing something.  I'm using sbt version 0.11.2 and scala version 2.9.0.1.  I'm gonna ask some of the other developers for help tomorrrow, but if you or anyone else had some insight into this so I could solve it myself and get your plugin working, that would be awesome.

Thanks,
Steve

Antonio Salazar Cardozo

unread,
Jun 1, 2012, 2:47:46 PM6/1/12
to lif...@googlegroups.com
Hey Steve,
Did you remember to run sbt publish-local in your checkout of sbt-resource-management? It isn't currently published to any central repository, so you have to publish it locally yourself.
Thanks,
Antonio

steve

unread,
Jun 1, 2012, 4:01:28 PM6/1/12
to lif...@googlegroups.com
Hmm.  Yeah, that's probably it.  So does that mean that everyone will have to publish it locally on their machine in order to use it?

Thanks,
Steve

Antonio Salazar Cardozo

unread,
Jun 4, 2012, 9:59:56 AM6/4/12
to lif...@googlegroups.com
Sorry for the late reply. There are a couple of options here. You can have everyone do a local publish to their machines. You can also set up a company repository that you can publish to and everyone can pull from.

The last option is for me to publish to a central repository. That would be pretty cool, but I haven't done anything like that before. I'll ask Indrajit, David, and some of the other committers to see if anyone can give me some pointers on whether and how I can get it published to a central repository (hopefully one that's in the list of default repositories for a Lift project).
Thanks,
Antonio

Antonio Salazar Cardozo

unread,
Jun 5, 2012, 1:32:37 PM6/5/12
to lif...@googlegroups.com
Hey Steve,
With some help from the other Lift committers, I found out about sbt source plugins. There are revised usage instructions on the sbt-resource-management README that reflect the best way to use it, which does not require a publish-local. I've also version-bumped sbt-resource-management to 0.1.2 to include a few changes I made yesterday.

If you have any other issues or what have you, feel free to file an issue on the github issue tracker.
Thanks!
Antonio

On Friday, June 1, 2012 4:01:28 PM UTC-4, steve wrote:

steve

unread,
Jun 7, 2012, 5:46:03 PM6/7/12
to lif...@googlegroups.com
Hey Antonio,

Thanks for putting in the time to work on this.  I'm almost there, I think.  I'm getting this error:

[error] Expected end of input.
[error] resources:compile-sass
[error]          ^


I know that's not a lot of info to go on, but I thought maybe you had an idea why I'm getting this error.

Thanks!
-Steve

steve

unread,
Jun 7, 2012, 5:47:13 PM6/7/12
to lif...@googlegroups.com
If that's too vague, I could try to give more info or maybe even make a small example project to for people to take a look at.

Thanks,
Steve

Antonio Salazar Cardozo

unread,
Jun 7, 2012, 6:33:03 PM6/7/12
to lif...@googlegroups.com
Hey Steve,
I'd love to hepl, but I think we've stayed on the Lift list too long; this is slightly off-topic at this point. If you could file an issue on the github project at https://github.com/Shadowfiend/sbt-resource-management/issues , I'll help you there instead. Sound good?
Thanks,
Antonio
Reply all
Reply to author
Forward
0 new messages