Hello, I hope this isn’t a dumb question but I have inherited some jruby
code that is throwing a syntax error and I have virtually no experience
with ruby. The goal is to compile and deploy compass/sass CSS
stylesheet from our Java app using BSFManager and jruby. It works from
the command line.
The exception is as follows:
Caused by: org.jruby.exceptions.RaiseException: (SyntaxError)
:12: syntax error, unexpected tSTRING_BEG
ARGV.push('--css-dir').push('D:\S-Source\S-P-Cloud\s_pcloud_6_0_0_0_plt_uiconfig_dev\client\web\assets\style\shell\resources\css\')
(the exception points to the second apostrophe in the first push
parameter '-css-dir' [after dir])
The command is executed as follows:
result = manager.eval("jruby", "", 0, 0, compass);
the 'compass' script is as follows:
require 'rubygems'
version = ">= 0"
if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
version = $1
ARGV.shift
end
ARGV.push('compile')
ARGV.push('D:\S-Source\S-P-Cloud\s_pcloud_6_0_0_0_plt_uiconfig_dev\client\web\assets\style\shell\resources\sass\')
ARGV.push('--css-dir').push('D:\S-S\S-P-Cloud\s_pcloud_6_0_0_0_plt_uiconfig_dev\client\web\assets\style\shell\resources\css\')
ARGV.push('--sass-dir').push('D:\S-B~1\S-P~1\SW\assets\theme\theme000000000001224\shell\sass')
ARGV.push('--output-style').push('expanded')
ARGV.push('--force')
ARGV.push('--trace')
puts ARGV.inspect()
gem 'compass', version
load Gem.bin_path('compass', 'compass', version)
I'm really struggling to sort this out so if anyone has any pointers I
would really appreciate it.
Thanks in advance,
Sean
the first single quote. JRuby then sees “–css-dir”, and another
single-quote, which should mark the beginning of a new String. But
that’s not allowed. You have the same problem on this line.
Thanks in advance,
Sean
Please study how strings are defined in Ruby. (Here, you can escape the
last backslash, or drop it altogether.)
Hello, I hope this isn’t a dumb question but I have inherited some
jruby code that is throwing a syntax error and I have virtually no
experience with ruby. The goal is to compile and deploy compass/sass
CSS stylesheet from our Java app using BSFManager and jruby. It works
from the command line.
backslash of \ in front of ’ will make it from a string delimeter to
an actual ’ char:
a = ‘'’ #=> ’
So your first ARGV.push added:
"')
ARGV.push('" to the string then thought it so two unary minuses --,
fcall (css), minus, fcall (dir), then an unexpected '.
You should not use \ for path delim in Ruby source if you can avoid it
since it ends up being confused with literal escaping of chars. When
possible use File.join too (I can understand why you didn’t here)
since it will make it more cross-platform.
-Tom
result = manager.eval(“jruby”, “”, 0, 0, compass);