简体   繁体   中英

How to use prawn on maglev

Being new to maglev I wanted to start with a small, but still useful example. So i decided to start moving the ruby classes I use to generate my invoices to maglev. However I ran in an unexpected problem using the (excellent) prawn PDF-library.

Being on rvm I generated a gemset for the application which is setup in a .rvmrc for the invoice directory. It gets used when I cd into it:

Using /Users/patru/.rvm/gems/maglev-head with gemset invoice

When I install prawn everything starts out fine, the gem seems to be installed and the ri-docs are being generated. However, trouble starts when rdoc should be created, the maglev provided gem command gives me

 gem install prawn
[INFO] The MagLev team publishes customized versions of some gems.
...
Successfully installed prawn-0.12.0
1 gem installed
Installing ri documentation for prawn-0.12.0...


RDoc failure in lib/prawn/images/jpg.rb at or around line 20 column 26

Before reporting this, could you check that the file
you're documenting compiles cleanly--RDoc is not a
full Ruby parser, and gets confused easily if fed
invalid programs.

The internal error was:

ERROR:  While generating documentation for prawn-0.12.0
... MESSAGE:   global $@ is a read-only variable
... RDOC args: --ri --op /Users/patru/.rvm/gems/maglev-head@invoice/doc/prawn-0.12.0/ri --title Prawn Documentation --main README -q lib README.md LICENSE COPYING GPLv2 GPLv3 --title prawn-0.12.0 Documentation --quiet
a RubySystemExit occurred (error 2752)

No big deal to live without documentation, it is good enough, but something else seems to go wrong, gem list says

Ascii85 (1.0.1)
bundler (1.0.21)
erector (0.8.3)
pdf-reader (0.10.1)
polyglot (0.3.3)
prawn (0.12.0)
rake (0.9.2)
treetop (1.4.10)
ttfunk (1.0.3)

so all seems to be well, but if I do

require 'ruby gems'
require 'prawn'

in irb (which works perfectly on my ree-1.8.7) I get a strange

NoMethodError: NoMethodError: undefined method `ruby_18' for 
from /Users/patru/.rvm/gems/maglev-head@invoice/gems/prawn-0.12.0/lib/prawn/core/object_store.rb:246:in `__compileClass'
from /Users/patru/.rvm/gems/maglev-head@invoice/gems/prawn-0.12.0/lib/prawn/core/object_store.rb:14:in `__compileClass'
from /Users/patru/.rvm/gems/maglev-head@invoice/gems/prawn-0.12.0/lib/prawn/core/object_store.rb:13:in `__compileClass'
from /Users/patru/.rvm/gems/maglev-head@invoice/gems/prawn-0.12.0/lib/prawn/core/object_store.rb:12
from /Users/patru/.rvm/rubies/maglev-head/src/kernel/bootstrap/Kernel.rb:831:in `gem_original_require'
from /Users/patru/.rvm/rubies/maglev-head/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
from /Users/patru/.rvm/rubies/maglev-head/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:57:in `require'
from /Users/patru/.rvm/gems/maglev-head@invoice/gems/prawn-0.12.0/lib/prawn/core.rb:78
from /Users/patru/.rvm/rubies/maglev-head/src/kernel/bootstrap/Kernel.rb:831:in `gem_original_require'
from /Users/patru/.rvm/rubies/maglev-head/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
from /Users/patru/.rvm/rubies/maglev-head/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:57:in `require'
from /Users/patru/.rvm/gems/maglev-head@invoice/gems/prawn-0.12.0/lib/prawn.rb:11
from /Users/patru/.rvm/rubies/maglev-head/src/kernel/bootstrap/Kernel.rb:831:in `gem_original_require'
from /Users/patru/.rvm/rubies/maglev-head/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:59:in `require'
from /Users/patru/.rvm/rubies/maglev-head/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:57:in `require'
from /Users/patru/.rvm/rubies/maglev-head/src/kernel/bootstrap/Kernel.rb:831:in `gem_original_require'
from /Users/patru/.rvm/rubies/maglev-head/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
from /Users/patru/.rvm/rubies/maglev-head/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:57:in `require'
from (irb):5:in `__compileEval'
from (irb):7:in `__compileEval'
from /Users/patru/.rvm/rubies/maglev-head/src/kernel/bootstrap/Kernel.rb:394:in `eval'
from /Users/patru/.rvm/rubies/maglev-head/lib/ruby/1.8/irb.rb:159:in `eval_input'
...

I am probably missing something obvious here. Suffice it to say that the 'erector' gem I installed as well (see the gem list above) can be required without problems, so I do not do everything wrong ;-)

It seems to be an interaction with irb. I can run the following script and it creates the correct pdf file:

require 'rubygems'
require 'prawn'

Prawn::Document.generate('hello.pdf') do
  text "Hello! from #{RUBY_ENGINE}"
end

It's probably best to file bug reports at https://github.com/maglev/maglev/issues

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM