Jruby -S gem maven ... html_to_pdf.rb

I was playing with Charlie’s maven gem to make a small sample app
that takse and xhtml page and print’s it to a pdf.

There are some maven version strings that are not valid gem version
strings. Specifically the flying saucer pom specifies a version
string of something like: ‘R8pre6’.

Gem version strings must start with a number and a ‘.’

here’s a hacky patch for maven gem to fix this:

patch for ruby maven gem · GitHub

and here’s my initial sample app

html_to_pdf.rb
html_to_pdf.rb · GitHub

my xhtml is not valid yet so I’m not yet sure this works

comments or revisions most welcome!


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Stephen B. wrote:

patch for ruby maven gem · GitHub

Ahh this is a great start. I noticed this was new in RubyGems 1.3.2. I
think it may consider this to be a development version though, yes?

This is definitely a good first solution. Maybe I should get the
maven_gem sources pushed to github so you can maintain a fork…

and here’s my initial sample app

html_to_pdf.rb
html_to_pdf.rb · GitHub

That’s really cool :slight_smile: Maybe we’re on to something here!

  • Charlie

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Charles Oliver N. wrote:

Ahh this is a great start. I noticed this was new in RubyGems 1.3.2. I
think it may consider this to be a development version though, yes?

This is definitely a good first solution. Maybe I should get the
maven_gem sources pushed to github so you can maintain a fork…


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Charles Oliver N. wrote:

Ahh this is a great start. I noticed this was new in RubyGems
1.3.2. I think it may consider this to be a development version
though, yes?

This is definitely a good first solution. Maybe I should get the
maven_gem sources pushed to github so you can maintain a fork…

GitHub - jruby/maven_gem: A RubyGems plugin (and a utility) to install Maven artifacts as RubyGems

Thanks,

Here’s a revised and improved version of my patch:

I sent you a pull request.

And here’s a test script that I ran on my local maven repo to see
what the result of the new algorithm for generating gem version
strings from maven version strings produces.

http://gist.github.com/98383

I’d appreciate it if other folks who have large local repos could run
this script and scan to see if the conversions look reasonable.

It’s important to keep the maven version string around if we later
add dependency resolution so the ruby file created for loading the
maven jar now also codes these two constants:

::VERSION
::MAVEN_VERSION

So installing:

jruby -S gem maven org/xhtmlrenderer core-renderer R8pre2

Produces this ruby file in the new gem:

$ cat
$JRUBY_HOME/lib/ruby/gems/1.8/gems/core-renderer-8.2-java/lib/core-renderer.rb
class CoreRenderer
VERSION = ‘8.2’
MAVEN_VERSION = ‘R8pre2’
end
begin
require ‘java’
require File.dirname(FILE) + ‘/core-renderer-8.2.jar’
rescue LoadError
puts ‘JAR-based gems require JRuby to load. Please visit
www.jruby.org.’
raise
end


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Stephen B. wrote:

I sent you a pull request.

Applied!

dependency resolution so the ruby file created for loading the maven jar

$ cat
$JRUBY_HOME/lib/ruby/gems/1.8/gems/core-renderer-8.2-java/lib/core-renderer.rb

class CoreRenderer
VERSION = ‘8.2’
MAVEN_VERSION = ‘R8pre2’ end

I think I’ll change this to a module, since that seems more typical.

I also thought of another cool thing we could do with these
libraries…set up pre-imported modules for them!

So for example, if you installed itext, everything under the
com.lowagie.text package would go under the IText module, making my
itext example script like so:

require ‘rubygems’
require ‘itext’

file = File.open(‘Hello.pdf’, ‘w’)
document = Itext::Document.new
writer = Itext::Pdf::PdfWriter.get_instance(document,
file.to_outputstream)
paragraph = IText::Paragraph.new(‘Hello iText!’)

document.open
document.add(paragraph)
document.close

I’d like to be able to do this programmatically if possible, maybe by
looking at the packages present in the jar and mapping the lowest
package to a module named the same as the Maven artifact (here itext
becomes Itext, and subpackages get leading caps the same way).

Thoughts?

  • Charlie

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email