I want to parse less type content from database and store the result css in other column. I'm using the less-rails gem.
I have a Template model where I store the name, less_content & css_content
So far I have done this in a before_save callback:
def less_parser
parser = Less::Parser.new
self.css_content = parser.parse(self.less_content).to_css
end
This works very well. But the problem are the @import variables of less. If I write @import "file_name".
I get the following error:
Less::Error - 'file_name.less' wasn't found:
less (2.6.0) lib/less/parser.rb:74:in `block (2 levels) in parse'
at finish (/Users/Artau/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/less-2.6.0/lib/less/js/lib/less/parser.js:666:in `'
at tree.importVisitor.run (/Users/Artau/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/less-2.6.0/lib/less/js/lib/less/import-visitor.js:34:in `'
at Parser.parser.parse (/Users/Artau/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/less-2.6.0/lib/less/js/lib/less/parser.js:675:in `'
less (2.6.0) lib/less/parser.rb:64:in `block in parse'
less (2.6.0) lib/less/java_script/v8_context.rb:90:in `block in do_lock'
less (2.6.0) lib/less/java_script/v8_context.rb:88:in `call'
less (2.6.0) lib/less/java_script/v8_context.rb:88:in `Locker'
less (2.6.0) lib/less/java_script/v8_context.rb:88:in `do_lock'
less (2.6.0) lib/less/java_script/v8_context.rb:60:in `lock'
less (2.6.0) lib/less/java_script/v8_context.rb:30:in `exec'
less (2.6.0) lib/less/java_script.rb:26:in `exec'
less (2.6.0) lib/less/parser.rb:63:in `parse'
app/models/template.rb:32:in `less_parser'
Obviously I need to tell the Less::Parser where the file is. But I don't know how to do that.
Aucun commentaire:
Enregistrer un commentaire