GithubHelp home page GithubHelp logo

Comments (20)

metaskills avatar metaskills commented on May 23, 2024

Yea, I have noticed that too. Not sure what to do about it, I just use the method you described that works. Seems to be a necessity when you put sprockets, less, and rails together?

from less-rails.

metaskills avatar metaskills commented on May 23, 2024

This is from @christiannelson

Thanks for the tips. I have an explanation of the problem. There's a discrepancy between how lessc work and less-rails + sprockets. When lessc processes a file including imports, it makes the contents of those imported files available to other imports.

To illustrate the problem using twitter bootstrap as an example: run "lessc bootstrap.less", you'll see it works. run "lessc type.less", it bombs because it doesn't know about a mixin (that makes sense, type depends on mixins). When requiring bootstrap in a rails application, it bombs in the same way as running lessc on one of the dependency files.

In my example application (https://github.com/christiannelson/less-rails-example), I have a stripped down version of the problem and quick guide to how to grok it in the readme.

Digging deeper, it turns out that the call to context.environment[path](import processor, line 15) makes sprockets aware of the imported less file, which in turn triggers processing of that file (on its own). I added some output to my sample app to show it off:

# Asset: [preprocessors]
less-rails-example/app/assets/stylesheets/application.css: [Sprockets::DirectiveProcessor, Less::Rails::ImportProcessor]
# Results of the ImportPreprocessor
[]
less-rails-example/app/assets/stylesheets/global.css.less: [Sprockets::DirectiveProcessor, Less::Rails::ImportProcessor, Less::Rails::LessTemplate]
# Results of the ImportPreprocessor
["reset", "variables", "mixins", "type"]
less-rails-example/app/assets/stylesheets/variables.less: [Less::Rails::LessTemplate]
less-rails-example/app/assets/stylesheets/mixins.less: [Less::Rails::LessTemplate]
...

Commenting out lines 13-16 of the ImportPreprocessor prevents registering of the imported files and fixes the problem. Of course, then we don't get cache invalidation.

My fork of less-rails includes a commit that tweaks dummy_app to illustrate the problem: christiannelson@dd1023a

I think I have an okay grasp on the problem, but I don't have a solution for it at the moment. What do you recommend?

from less-rails.

metaskills avatar metaskills commented on May 23, 2024

@christiannelson, I have done some work on this tonight and this is what I came up with. https://gist.github.com/1412938

Basically I have changed the ImportProcessor to (1) not build the asset by only using the resolve method to get the path and then (2) using the depend_on vs depend_on_asset since any .less (not css.less file) is not a real sprockets renderable asset. This change seems to help a lot, but I still get this one failure. So I have not found the perfect solution.

  1) Error:
test_0003_must_hook_into_less_import_so_that_imported_paths_are_declared_as_sprocket_dependencies_of_the_source_file(BasicsSpec):
Less::ParseError: variable @gray is undefined

from less-rails.

christiannelson avatar christiannelson commented on May 23, 2024

@metaskills I applied your patch to my fork and it's working well on our project. I'm not sure why that spec is failing. I'll try to look into it, but I wonder if it's a problem with the spec, not the implementation.

from less-rails.

christiannelson avatar christiannelson commented on May 23, 2024

@shorrockin Chris, have you tried @metaskills' patch? I have it applied in my fork (https://github.com/christiannelson/less-rails). I'm curious if it fixes the problem for you... it works great for us (we've been beating on it for a while).

from less-rails.

cgunther avatar cgunther commented on May 23, 2024

@christiannelson I just tried using your fork instead of the published less-rails gem, however I'm getting:

$ bundle exec rake RAILS_ENV=development RAILS_GROUPS=assets assets:precompile --trace
** Invoke assets:precompile (first_time)
** Execute assets:precompile
** Invoke assets:precompile:all (first_time)
** Execute assets:precompile:all
** Invoke assets:precompile:primary (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:primary
rake aborted!
uninitialized constant Less::Rails::ImportProcessor::FileNotFound
  (in /Users/chrisgunther/Sites/wss/vendor/assets/stylesheets/bootstrap/bootstrap.css.less)
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/bundler/gems/less-rails-fc9e5a5af8f6/lib/less/rails/import_processor.rb:15:in `rescue in block in evaluate'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/bundler/gems/less-rails-fc9e5a5af8f6/lib/less/rails/import_processor.rb:13:in `block in evaluate'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/bundler/gems/less-rails-fc9e5a5af8f6/lib/less/rails/import_processor.rb:12:in `each'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/bundler/gems/less-rails-fc9e5a5af8f6/lib/less/rails/import_processor.rb:12:in `evaluate'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/tilt-1.3.3/lib/tilt/template.rb:76:in `render'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/context.rb:177:in `block in evaluate'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/context.rb:174:in `each'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/context.rb:174:in `evaluate'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/processed_asset.rb:12:in `initialize'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/base.rb:241:in `new'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/base.rb:241:in `block in build_asset'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/base.rb:262:in `circular_call_protection'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/base.rb:240:in `build_asset'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/index.rb:89:in `block in build_asset'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/caching.rb:19:in `cache_asset'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/index.rb:88:in `build_asset'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/base.rb:163:in `find_asset'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/index.rb:56:in `find_asset'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/processed_asset.rb:106:in `block in build_required_assets'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/processed_asset.rb:100:in `each'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/processed_asset.rb:100:in `build_required_assets'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/processed_asset.rb:16:in `initialize'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/base.rb:241:in `new'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/base.rb:241:in `block in build_asset'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/base.rb:262:in `circular_call_protection'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/base.rb:240:in `build_asset'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/index.rb:89:in `block in build_asset'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/caching.rb:19:in `cache_asset'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/index.rb:88:in `build_asset'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/base.rb:163:in `find_asset'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/index.rb:56:in `find_asset'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/bundled_asset.rb:16:in `initialize'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/base.rb:244:in `new'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/base.rb:244:in `build_asset'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/index.rb:89:in `block in build_asset'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/caching.rb:19:in `cache_asset'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/index.rb:88:in `build_asset'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/base.rb:163:in `find_asset'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/index.rb:56:in `find_asset'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/environment.rb:74:in `find_asset'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/actionpack-3.2.0/lib/sprockets/static_compiler.rb:20:in `block in compile'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/base.rb:212:in `block in each_logical_path'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/base.rb:200:in `block (2 levels) in each_file'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/base.rb:190:in `each'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/base.rb:190:in `each_entry'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/base.rb:198:in `block in each_file'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/base.rb:197:in `each'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/base.rb:197:in `each_file'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sprockets-2.1.2/lib/sprockets/base.rb:210:in `each_logical_path'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/actionpack-3.2.0/lib/sprockets/static_compiler.rb:18:in `compile'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/actionpack-3.2.0/lib/sprockets/assets.rake:52:in `internal_precompile'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/actionpack-3.2.0/lib/sprockets/assets.rake:66:in `block (3 levels) in <top (required)>'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/rake/task.rb:205:in `call'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/rake/task.rb:205:in `block in execute'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/rake/task.rb:200:in `each'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/rake/task.rb:200:in `execute'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/rake/task.rb:151:in `invoke_with_call_chain'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/rake/task.rb:144:in `invoke'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/actionpack-3.2.0/lib/sprockets/assets.rake:56:in `block (3 levels) in <top (required)>'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/rake/task.rb:205:in `call'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/rake/task.rb:205:in `block in execute'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/rake/task.rb:200:in `each'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/rake/task.rb:200:in `execute'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/rake/task.rb:151:in `invoke_with_call_chain'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/rake/task.rb:144:in `invoke'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/actionpack-3.2.0/lib/sprockets/assets.rake:19:in `invoke_or_reboot_rake_task'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/actionpack-3.2.0/lib/sprockets/assets.rake:25:in `block (2 levels) in <top (required)>'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/rake/task.rb:205:in `call'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/rake/task.rb:205:in `block in execute'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/rake/task.rb:200:in `each'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/rake/task.rb:200:in `execute'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/rake/task.rb:151:in `invoke_with_call_chain'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/rake/task.rb:144:in `invoke'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/rake/application.rb:116:in `invoke_task'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/rake/application.rb:94:in `block (2 levels) in top_level'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/rake/application.rb:94:in `each'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/rake/application.rb:94:in `block in top_level'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/rake/application.rb:133:in `standard_exception_handling'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/rake/application.rb:88:in `top_level'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/rake/application.rb:66:in `block in run'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/rake/application.rb:133:in `standard_exception_handling'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/rake/application.rb:63:in `run'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/bin/rake:32:in `<top (required)>'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/bin/rake:19:in `load'
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/bin/rake:19:in `<main>'
Tasks: TOP => assets:precompile:primary

I'm on Rails 3.2.

I'm using Bootstrap too. In my application.css file I require =* require bootstrap/bootstrap. That points to vendor/assets/stylesheets/bootstrap/bootstrap.css.less. That file simply @import's the .less files of Bootstrap in the same subdirectory.

I did add config.less.paths << File.join(config.root, 'vendor', 'assets', 'stylesheets', 'bootstrap') to my application.rb file so the @import's could find the right files (it'd fail to find reset.less, for example, without it.

from less-rails.

christiannelson avatar christiannelson commented on May 23, 2024

@cgunther Thanks for trying! We're on Rails 3.1.3 and bundle assets all the time. I'll take a look later and see if I see anything interesting with Rails 3.2.

from less-rails.

cgunther avatar cgunther commented on May 23, 2024

One thing I left out, my setup works fine in development, only fails when I try to precompile assets via rake.

I'll try taking some stabs at it and see if I can come up with anything.

from less-rails.

cgunther avatar cgunther commented on May 23, 2024

Changing the rescue call in lib/less/rails/import_processor.rb to rescue Sprockets::FileNotFound solved that error.

It seems now that Rails is trying to compile the individual Bootstrap .less files, and each is failing because of missing variables, yet I don't need each file compiled as they already are compiled into my application.css file. Short of adding each file to the config.assets.precompile array, is there a way to prevent Rails/Sprockets from trying to compile each?

from less-rails.

christiannelson avatar christiannelson commented on May 23, 2024

@cgunther I upgraded our app to rails 3.2 and it seems to be working (rails s and rake assets:precompile).

The behavior you're describing sounds like what I was seeing before applying @metaskills patch (ie: my fork).

I have a file called home.css.less that contains about 6 @imports. The @import calls import straight up less files and they're not processed by sprockets. I'm referencing stuff defined in one less in other less files (we're using bootstrap too). It's all hunky-dory. Our application.css (sprockets manifest) requires home.

I have a very simple example app for playing around with this (https://github.com/christiannelson/less-rails-example).

If you can you produce a test case that demonstrates the issue you're having it'll be easier to diagnose/fix the problem.

from less-rails.

cgunther avatar cgunther commented on May 23, 2024

I just pulled down your example app and hit a similar problem. Here's the output trying to precompile assets:

$ RAILS_ENV=development rake assets:precompile 
/Users/chrisgunther/.rbenv/versions/1.9.3-p0/bin/ruby /Users/chrisgunther/.rbenv/versions/1.9.3-p0/bin/rake assets:precompile:all RAILS_ENV=development RAILS_GROUPS=assets
rake aborted!
variable @gray is undefined
  (in /Users/chrisgunther/Sites/less-rails-example/app/assets/stylesheets/mixins.less)

Tasks: TOP => assets:precompile:primary
(See full trace by running task with --trace)
rake aborted!
Command failed with status (1): [/Users/chrisgunther/.rbenv/versions/1.9.3-...]

Tasks: TOP => assets:precompile
(See full trace by running task with --trace)

It seems Rails/Sprockets is trying to compile the individual .less files in addition to files such as application.css, and therefore fails since some variables are defined outside of the given file. The application.css file appears to compile just fine.

I solved this in my app by restructuring my .less files. Instead of storing them in vendor/assets/stylesheets, I moved them to vendor/assets/frameworks and added that to the config.less.paths variable. This allows Less to see it for @import however Sprockets doesn't see it to try and compile it.

from less-rails.

christiannelson avatar christiannelson commented on May 23, 2024

Interestingly, in our production application we have a similar setup to my example application (though more files) and we can precompile assets without a problem. I hope to have some time this evening to look into this some more. It's been back-burner for me because my fork with your patch has been working awesome.

from less-rails.

 avatar commented on May 23, 2024

I can confirm that christian's fork

christiannelson@fc9e5a5

works for me on Rails 3.1.1.

Current master of less-rails remains broken for me; @import does not find files in subdirectories, variables are not visible across files.

from less-rails.

loopj avatar loopj commented on May 23, 2024

I'm not convinced this issue is solved.

Cloning @christiannelson's less-rails-example and running

bundle exec rake RAILS_GROUPS=assets assets:precompile --trace

still fails, even if you update less-rails to master of point to git://github.com/metaskills/less-rails.git

rake aborted!
variable @gray is undefined
  (in /Users/james/less-rails-example/app/assets/stylesheets/mixins.less)
at /Library/Ruby/Gems/1.8/gems/less-2.0.9/lib/less/js/lib/less/parser.js:373:31
/Library/Ruby/Gems/1.8/gems/less-2.0.9/lib/less/parser.rb:88:in `to_css'
/Library/Ruby/Gems/1.8/gems/less-2.0.9/lib/less/parser.rb:13:in `calljs'
/Library/Ruby/Gems/1.8/gems/less-2.0.9/lib/less/parser.rb:27:in `lock'
/Library/Ruby/Gems/1.8/gems/less-2.0.9/lib/less/parser.rb:25:in `lock'
/Library/Ruby/Gems/1.8/gems/less-2.0.9/lib/less/parser.rb:12:in `calljs'
/Library/Ruby/Gems/1.8/gems/less-2.0.9/lib/less/parser.rb:87:in `to_css'

I'm seeing the exact same broken behavior on my own project with both Rails 3.1 and Rails 3.2.

from less-rails.

loopj avatar loopj commented on May 23, 2024

The issue seems related to what @cgunther was saying above, sprockets sees everything in app/assets and vendor/assets and tries to compile the less files itself.

>> Rails.application.config.assets.paths
=> ["/Users/james/less-rails-example/app/assets/images", "/Users/james/less-rails-example/app/assets/javascripts", "/Users/james/less-rails-example/app/assets/stylesheets", "/Users/james/less-rails-example/vendor/assets/stylesheets"]

The only way I was able to solve this was to use the hack @cgunther suggested, of moving the .less files to a place sprockets can't see. In my case, every subdirectory under app/assets seems to get added to the sprockets search path, so I've had to move the less files to public/less for now as a hack.

from less-rails.

flynfish avatar flynfish commented on May 23, 2024

Are there any updates on this issue? I am getting the same error...

from less-rails.

metaskills avatar metaskills commented on May 23, 2024

Yea, this was fixed. The project tests were updated, we are green, and every way possible to use less in rails is even tested in less-rails-bootstrap and less-rails-bootstrap-test

from less-rails.

flynfish avatar flynfish commented on May 23, 2024

Ok maybe I am doing something really stupid.. I just grabbed the less-rails-bootstrap-test and ran the the precompile.

RAILS_ENV=production bundle exec rake assets:precompile --trace

The precompile works fine. If I now go into mixins.less and add the .test rule the precompile will fail.

.test {
  .border-radius(4px);
}

error:

.border-radius is undefined
 (in /Users/klamy/dev/projects/less-rails-bootstrap-test/app/assets/stylesheets/full_control/mixins.less)
at /Users/klamy/.rvm/gems/ruby-1.9.3-p125@less-rails-test/gems/less-2.0.10/lib/less/js/lib/less/parser.js:385:31
/Users/klamy/.rvm/gems/ruby-1.9.3-p125@less-rails-test/gems/less-2.0.10/lib/less/parser.rb:88:in `block in to_css'

Am I doing something wrong there?

from less-rails.

metaskills avatar metaskills commented on May 23, 2024

First, just bundle exec rake assets:precompile will do just fine. Rails does the env change stuff for you.

Second, I think you are just experiencing the wonderful world of LESS.js. If you want that to work, I believe you have to tell the parser by doing a @import "twitter/bootstrap/mixins"; at the top of that full_control/mixins.less file. If you can show that this is not how default LESS.js works, then I would be open to accepting a patch to fix it.

from less-rails.

hlascelles avatar hlascelles commented on May 23, 2024

I found this issue was fixed by preventing the less precompiler from parsing all files in alphabetical order. This comment gave a config change that solved the problem for me.

#35 (comment)

from less-rails.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.