Jruby -S gem maven ... html_to_pdf.rb


#1

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:

http://gist.github.com/97636

and here’s my initial sample app

html_to_pdf.rb
http://gist.github.com/97646

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

#2

Stephen B. wrote:

http://gist.github.com/97636

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
http://gist.github.com/97646

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

#3

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…

http://github.com/jruby/maven_gem/tree/master


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

#4

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…

http://github.com/jruby/maven_gem/tree/master

Thanks,

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

http://github.com/stepheneb/maven_gem/commit/86ab7b51c5e283cd349908f1b162856e1de96ca8

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

#5

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