Question

I cannot figure out how to do this. All my main .less files are in /app/css/less, with @import'ed files in /app/css/less/bootstrap. My main stylesheet is /app/css/less/style.less which should be compiled to '/public/css/style.css'.

Using a classic Sinatra app structure (not base), I have the following in various files (unrelated code left out): ****Gemfile

# encoding: utf-8
source :rubygems

gem 'sinatra'
gem 'thin'
gem 'less'
gem 'therubyracer'
gem 'haml', '~> 3.2.0.rc.1'
gem 'sinatra-partial'
gem 'sinatra-assetpack', :git => 'git://github.com/rupe/sinatra-assetpack.git', :require => 'sinatra/assetpack'

****myapp.rb

# encoding: utf-8

require 'rubygems'
require 'bundler/setup'

require 'sinatra'
require 'haml'
require 'sinatra/partial'
require 'sinatra/assetpack'
require 'less'

assets do
  Less.paths .lt.lt "#{settings.root}/app/css/less"
  Less.paths .lt.lt "#{settings.root}/app/css/less/bootstrap"
  serve '/css', from: '/app/css/less'
  css :style, [
    '/css/style.css'
  ]
  prebuild true
end

****layout.haml

!= css :style, :media => 'screen'

Which produces this stylesheet related tag in the served up html:

link rel="stylesheet" href="/css/style.496718.css" media="screen"

but does not actually compile the file style.49718.css. In fact, it doesn't compile any files at all.

note: The git branch, referred to in Gemfile, is a copy of the 'pbaker' branch that fixed Less support (supposedly). I have tried the standard gem, and other versions, all without any luck.

What could be the possible cause(s)?

NOTE: A related question, but not duplicate (as it refers to @import issues only), can be found here.

Was it helpful?

Solution

Finally figured out what the problem was, I had to use the --all option when running bundle package. So bundle package --all created a local cache of my custom git fork of the sinatra-assetpack gem, and all works "as advertised" now :)

OTHER TIPS

As an alternative (and for google's posterity), there's been a bunch of work on the AssetPack gem recently (with less support now built in).

This Gist has a full example of less support: https://gist.github.com/4652773.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top