rstacruz / sinatra-assetpack

Package your assets transparently in Sinatra.
http://ricostacruz.com/sinatra-assetpack/
MIT License
541 stars 97 forks source link

Compiling Less files in a Classic app #61

Closed rupe closed 11 years ago

rupe commented 11 years ago

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, 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/phillbaker/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.

What could be the possible cause(s)?

rupe commented 11 years ago

Alright, I tried setting RACK_ENV=production for the prebuild option, and now get "*\ Building /assets/style.css..." messages ????? And an empty style.496718.css file is created in my session, in a non-existent /assets folder what is going on???

I am using the pbaker repo...

rupe commented 11 years ago

Ok, fixed that with:

 css :style, '/css/style.css', [
    '/css/style.css'
  ]
rupe commented 11 years ago

Well it's not just Less, I copied a compiled style.css file over to app/css and changed the serve/from to app/css and doesn't even serve up the regular compiled css file. So my problem is with assetpack not serving up files...

rupe commented 11 years ago

I seem to have solved this by using the --all option with bundler, so bundle package --all has assetpack serving up style.nnnnnn.css ... so far.

rupe commented 11 years ago

And it stopped working again, don't know why. I'm moving on....

j15e commented 11 years ago

Sorry! I think less support was incomplete, should be fixed in next release.

rupe commented 11 years ago

Any timeline for next release?

j15e commented 11 years ago

Soon, but as I did a release yesterday I won't release a new one today yet, use git in your Gemfile (seems like you already do, juste update it)

rupe commented 11 years ago

Oh, great, I didn't realize there was a new release ... it had been a while :D Great work, thanks.

On Monday, January 14, 2013 at 10:31 PM, Jean-Philippe Doyle wrote:

Soon, but as I did a release yesterday I won't release a new one today yet, use git in your Gemfile (seems like you already do, juste update it)

— Reply to this email directly or view it on GitHub (https://github.com/rstacruz/sinatra-assetpack/issues/61#issuecomment-12252035).

j15e commented 11 years ago

Released today, let me know if this fixes the issue

rupe commented 11 years ago

I'm afraid I haven't even tried LESS support yet, as I'm having other problems using this gem (opening an issue now).

phillbaker commented 11 years ago

I just updated to the newest version of the gem (0.1.2) and LESS support is broken for me (versus gem 'sinatra-assetpack'#, :require => 'sinatra/assetpack', :git => 'git://github.com/phillbaker/sinatra-assetpack.git', :ref => "9302731670bfc2f8e4628aa7985b64929ff1e376" where it works.)

For example (taken from sinatra),

assets do
    serve '/css',    :from => 'app/css'
    css :styles, '/css/styles.css', [
      '/css/bootstrap.css' # .less version of bootstrap
    ]

    css_compression :less
end

Leads to

Less::ParseError - 'reset.less' wasn't found.
:
    at less.Parser.parser.parse.i (.../ruby/1.9.1/gems/less-2.2.2/lib/less/js/lib/less/parser.js:390:69)
    .../ruby/1.9.1/gems/less-2.2.2/lib/less/parser.rb:61:in `block in to_css'
    .../ruby/1.9.1/gems/less-2.2.2/lib/less/java_script/v8_context.rb:90:in `block in do_lock'
    .../ruby/1.9.1/gems/less-2.2.2/lib/less/java_script/v8_context.rb:88:in `call'
    .../ruby/1.9.1/gems/less-2.2.2/lib/less/java_script/v8_context.rb:88:in `Locker'
    .../ruby/1.9.1/gems/less-2.2.2/lib/less/java_script/v8_context.rb:88:in `do_lock'
    .../ruby/1.9.1/gems/less-2.2.2/lib/less/java_script/v8_context.rb:60:in `lock'
    .../ruby/1.9.1/gems/less-2.2.2/lib/less/java_script/v8_context.rb:30:in `exec'
    .../ruby/1.9.1/gems/less-2.2.2/lib/less/java_script.rb:26:in `exec'
    .../ruby/1.9.1/gems/less-2.2.2/lib/less/parser.rb:61:in `to_css'
    .../ruby/1.9.1/gems/tilt-1.3.3/lib/tilt/css.rb:68:in `evaluate'
    .../ruby/1.9.1/gems/tilt-1.3.3/lib/tilt/template.rb:76:in `render'
    .../ruby/1.9.1/gems/sinatra-1.3.4/lib/sinatra/base.rb:711:in `render'
    .../ruby/1.9.1/gems/sinatra-assetpack-0.1.2/lib/sinatra/assetpack/class_methods.rb:73:in `block (3 levels) in add_individual_routes!'
    .../ruby/1.9.1/gems/tilt-1.3.3/lib/tilt.rb:127:in `fetch'
    .../ruby/1.9.1/gems/sinatra-assetpack-0.1.2/lib/sinatra/assetpack/class_methods.rb:72:in `block (2 levels) in add_individual_routes!'
...[truncated backtrace]

Based on the bootstrap file that has: @import "reset.less";

@j15e, any idea what changed that could have effected this? LESS gem is the same.

phillbaker commented 11 years ago

My fault, things are swell. See explanation at http://stackoverflow.com/a/12099530. Full example of Sinatra AssetPack + Less at https://gist.github.com/4652773.

rupe commented 11 years ago

Oh?!? I didn't realize there was a css_compression :less option available, must have missed it.

I will give LESS compilation and CSS asset serving another try once I've figured out my other issue. Thanks.

rupe commented 11 years ago

Just a comment on the :less option for css_compression, does this really make sense? I was under the impression that this option is used to determine how the SERVED css file is compressed, not how support files are compiled or what "template language" they use. Am I looking at this the wrong way?