toretore / barby

The Ruby barcode generator
http://toretore.github.com/barby/
MIT License
847 stars 171 forks source link

Porting to rails 3.2.8 #23

Closed luisfernandos closed 11 years ago

luisfernandos commented 11 years ago

Hi I was using rails 2.3.5 and ruby 1.8.7 and barby was working fine. Now I am porting my application to rails 3.2.8 and ruby 1.9.2p180 and from barby 0.4.2 to 0.5.0 This is part of my code:

require 'barby' require 'barby/barcode/code_128' require 'barby/outputter/rmagick_outputter'

def barcode(path,i,h,m,x) barcode = Barby::Code128B.new("#{i}")

File.open(path, 'w') do |f| f.write barcode.to_jpg(:height => h, :margin => m, :xdim => x) end end

when it reaches barcode = Barby::Code128B.new("#{i}"), it throws the exception RegexpError (/.../n has a non escaped non ASCII character in non ASCII-8BIT script)

doing some research it seems it is related to encode, perhaps barby needs some kind of update ??

Could you, please let me know you thoughts about that. Thanks a lot,

Fernando

toretore commented 11 years ago

Could you make a minimal program that will reproduce the results with a certain Ruby version? (Not Rails, it doesn't have anything to do with it)

On Feb 5, 2013, at 21:02, luisfernandos wrote:

Hi I was using rails 2.3.5 and ruby 1.8.7 and barby was working fine. Now I am porting my application to rails 3.2.8 and ruby 1.9.2p180 and from barby 0.4.2 to 0.5.0 This is part of my code:

require 'barby' require 'barby/barcode/code_128' require 'barby/outputter/rmagick_outputter'

def barcode(path,i,h,m,x) barcode = Barby::Code128B.new("#{i}")

File.open(path, 'w') do |f| f.write barcode.to_jpg(:height => h, :margin => m, :xdim => x) end end

when it reaches barcode = Barby::Code128B.new("#{i}"), it throws the exception RegexpError (/.../n has a non escaped non ASCII character in non ASCII-8BIT script)

doing some research it seems it is related to encode, perhaps barby needs some kind of update ??

Could you, please let me know you thoughts about that. Thanks a lot,

Fernando

— Reply to this email directly or view it on GitHub.

luisfernandos commented 11 years ago

Hi,

Sure, I will try to do a small ruby program to reproduce the problem. I forgot to mention that I am using windows...

Thanks for your reply,

Fernando

----- Original Message ----- From: Tore Darell To: toretore/barby Cc: luisfernandos Sent: Wednesday, February 06, 2013 2:45 PM Subject: Re: [barby] Porting to rails 3.2.8 (#23)

Could you make a minimal program that will reproduce the results with a certain Ruby version? (Not Rails, it doesn't have anything to do with it)

On Feb 5, 2013, at 21:02, luisfernandos wrote:

Hi I was using rails 2.3.5 and ruby 1.8.7 and barby was working fine. Now I am porting my application to rails 3.2.8 and ruby 1.9.2p180 and from barby 0.4.2 to 0.5.0 This is part of my code:

require 'barby' require 'barby/barcode/code_128' require 'barby/outputter/rmagick_outputter'

def barcode(path,i,h,m,x) barcode = Barby::Code128B.new("#{i}")

File.open(path, 'w') do |f| f.write barcode.to_jpg(:height => h, :margin => m, :xdim => x) end end

when it reaches barcode = Barby::Code128B.new("#{i}"), it throws the exception RegexpError (/.../n has a non escaped non ASCII character in non ASCII-8BIT script)

doing some research it seems it is related to encode, perhaps barby needs some kind of update ??

Could you, please let me know you thoughts about that. Thanks a lot,

Fernando

— Reply to this email directly or view it on GitHub.

— Reply to this email directly or view it on GitHub.

luisfernandos commented 11 years ago

Hi Tore,

I did a small program (attached) and runned with ruby, for my surprise it worked without problems. However I tried to execute the portions of the program in the rails console and I got problems with barby at: code_128.rb, line 210 data, *extra = data.split(/([#{CODEA+CODEB+CODEC}])/n)

Now with a little more information I did just a small test with irb, here it is: CODEA = "\xc5" CODEB = "\xc6" CODEC = "\xc7"

data = "Fernando" data.split(/([#{CODEA+CODEB+CODEC}])/n)

Here is the output when running with ruby 1.8.7. D:\BACKUP\Ruby187\bin>irb irb(main):001:0> CODEA = "\xc5" => "\305" irb(main):002:0> CODEB = "\xc6" => "\306" irb(main):003:0> CODEC = "\xc7" => "\307" irb(main):004:0> irb(main):005:0* data = "Fernando" => "Fernando" irb(main):006:0> data.split(/([#{CODEA+CODEB+CODEC}])/n) => ["Fernando"]

Here is the output when running with ruby 1.9.2. C:\Ruby192\bin>irb irb(main):001:0> CODEA = "\xc5" => "\xC5" irb(main):002:0> CODEB = "\xc6" => "\xC6" irb(main):003:0> CODEC = "\xc7" => "\xC7" irb(main):004:0> irb(main):005:0* data = "Fernando" => "Fernando" irb(main):006:0> data.split(/([#{CODEA+CODEB+CODEC}])/n) RegexpError: /.../n has a non escaped non ASCII character in non ASCII-8BIT scri pt from (irb):6 from C:/Ruby192/bin/irb:12:in `

'

Here is the output when running with ruby 1.9.3 D:\BACKUP\Ruby193\bin>irb irb(main):001:0> CODEA = "\xc5" => "\xC5" irb(main):002:0> CODEB = "\xc6" => "\xC6" irb(main):003:0> CODEC = "\xc7" => "\xC7" irb(main):004:0> irb(main):005:0* data = "Fernando" => "Fernando" irb(main):006:0> data.split(/([#{CODEA+CODEB+CODEC}])/n) RegexpError: /.../n has a non escaped non ASCII character in non ASCII-8BIT scri pt from (irb):6 from D:/BACKUP/Ruby193/bin/irb:12:in `

'

Perhaps you can give some light to this problem. Thanks in advance

----- Original Message ----- From: Tore Darell To: toretore/barby Cc: luisfernandos Sent: Wednesday, February 06, 2013 2:45 PM Subject: Re: [barby] Porting to rails 3.2.8 (#23)

Could you make a minimal program that will reproduce the results with a certain Ruby version? (Not Rails, it doesn't have anything to do with it)

On Feb 5, 2013, at 21:02, luisfernandos wrote:

Hi I was using rails 2.3.5 and ruby 1.8.7 and barby was working fine. Now I am porting my application to rails 3.2.8 and ruby 1.9.2p180 and from barby 0.4.2 to 0.5.0 This is part of my code:

require 'barby' require 'barby/barcode/code_128' require 'barby/outputter/rmagick_outputter'

def barcode(path,i,h,m,x) barcode = Barby::Code128B.new("#{i}")

File.open(path, 'w') do |f| f.write barcode.to_jpg(:height => h, :margin => m, :xdim => x) end end

when it reaches barcode = Barby::Code128B.new("#{i}"), it throws the exception RegexpError (/.../n has a non escaped non ASCII character in non ASCII-8BIT script)

doing some research it seems it is related to encode, perhaps barby needs some kind of update ??

Could you, please let me know you thoughts about that. Thanks a lot,

Fernando

— Reply to this email directly or view it on GitHub.

— Reply to this email directly or view it on GitHub.

luisfernandos commented 11 years ago

This is the attached file: require 'fileutils' require 'barby' require 'barby/barcode/code_128' require 'barby/outputter/rmagick_outputter'

def barcode(path,i) barcode = Barby::Code128B.new("#{i}")

File.open(path, 'w') do |f| f.write barcode.to_jpg(:height => 32, :margin => 1, :xdim => 8) end end

def generate_barcode() puts "Generating Barcode" dir = File.join("c:","SVN","elu-church-3.0","_protected","temp","event") if FileUtils.mkdir_p(dir) filename = "barcode.jpg" path = File.join("#{dir}",filename)

barcode = Barby::Code128B.new("#{record.id}")

  # TODO generate barcode, there is some problem with barby
  # it is throwing this exception:
  # RegexpError (/.../n has a non escaped non ASCII character in non ASCII-8BIT script):
  barcode(path,100)
end

end

puts "Generating Barcode" generate_barcode()

carlosantoniodasilva commented 11 years ago

@toretore Perhaps these guys need to be escaped with double slashes? Like:

    CODEA = "\\xc5"
    CODEB = "\\xc6"
    CODEC = "\\xc7"
>>     CODEA = "\xc5"
=> "\xC5"
>>     CODEB = "\xc6"
=> "\xC6"
>>     CODEC = "\xc7"
=> "\xC7"
>> /([#{CODEA+CODEB+CODEC}])/n
RegexpError: /.../n has a non escaped non ASCII character in non ASCII-8BIT script

>>     CODEA = "\\xc5"
=> "\\xc5"
>>     CODEB = "\\xc6"
=> "\\xc6"
>>     CODEC = "\\xc7"
=> "\\xc7"
>> /([#{CODEA+CODEB+CODEC}])/n
=> /([\xc5\xc6\xc7])/n

They explode with Ruby 2.0.0-p0. Worth a test.

toretore commented 11 years ago

Luis, Carlos,

Could you try this with the latest master? I can't replicate the problem on my end..

Just do a git clone of master, then run ruby with -Ilib

luisfernandos commented 11 years ago

Hi Toretore,

Did you try with the irb? I did a small program where you can replicate the problem. Here are the steps: 1) execute the irb. I am using windows so my command is: D:\BACKUP\Ruby193\bin>irb 2) Run the following code: CODEA = "\xc5" CODEB = "\xc6" CODEC = "\xc7" data = "Fernando" data.split(/([#{CODEA+CODEB+CODEC}])/n)

This is the piece of code I am getting errors in the gem. Later I will try to get it from master and try, but if you wanna try this small program ...

greenkarmet commented 11 years ago

I ran into this same problem with Ruby v 2.0.0-rc2. I was able to resolve the problem by setting the encoding for the file: lib/barby/barcode/code_128.rb to ASCII. i.e. I added this as the first line:

# encoding: ASCII

Hope it helps.

luisfernandos commented 11 years ago

Hi greenkarmet,

I thought the soluction would be something like that, I guess I tried a different encoding(utf8), perhaps that's why it didn't worked, I will give it a try again and let you guys know. THanks a lot for your reply

luisfernandos commented 11 years ago

Hi,

Following greenkarmet suggestion, it worked for me. I got another message"Encoding::UndefinedConversionError ("\xFF" from ASCII-8BIT to UTF-8):", but that was fixed in my own code, just to change the way I was opening the file instead of just w now it is wb, binary mode

File.open(path, 'w') to File.open(path, 'wb')

@toretore Is that possible to make this correction to the gem? I mean to add the encoding ?

luisfernandos commented 11 years ago

sorry, I just pushed the wrong button ...

toretore commented 11 years ago

Did you try the latest master?

On Mar 12, 2013, at 20:38, luisfernandos wrote:

sorry, I just pushed the wrong button ...

— Reply to this email directly or view it on GitHub.

luisfernandos commented 11 years ago

@toretore Sorry, just now I understood why you asked me to test with the master. I have noted that you put the encode there. I am programing in windows, so I am now installing the git on windows to check that. I will let you know, however I am pretty sure it will work

luisfernandos commented 11 years ago

Hi toretore,

I tried the master branch and it is working fine now. THanks a lot. If somebody like me(GitHub new guy) want to do a try, here is how I did.

1) Installed the GitHub for windows 2) Create an account if you don't have. 3) Use the button "Clone in Windows". This will give you a local branch. 4) Go to the local branch. In my machine it is located at: C:\Documents and Settings\Usuario\My Documents\GitHub\barby 5) Install the gem. gem install barby

6) Update you Gem file for Rails gem "barby", ">= 0.5.1" 7) run bundle install for your project.

carlosantoniodasilva commented 11 years ago

@toretore looks like it's working fine, thank you.

fechidal89 commented 11 years ago

How to install barby from github? step by step, I have this problem and want to try the latest master, but not install it. I probe with this https://groups.google.com/forum/#!topic/ruby-barby/uETvY6dZxBM but the command does nothing. Thanks and sorry for my ignorance.