Ruby Code to HTML

I need to HTMLify some Ruby code. Before I go make some crude solution, I thought I would ask if there is anything out there along these lines. Any pointers?

Thanks.

James Edward Gray II

James Edward Gray II wrote:

I need to HTMLify some Ruby code. Before I go make some crude solution, I thought I would ask if there is anything out there along these lines. Any pointers?

I seem to remember a tool like that. Would be in RAA if so.

Also, I think vim can do that.

Hal

Depends. What are you trying to accomplish? I have something that
takes ruby with special comments and makes a cross reference
(hyperlinked) between it and a specification document. But it doesn't
really "read" the ruby code, or format it--it just spits it out <CODE>
with <A>'s interpolated based on the comments.

     I briefly thought about linking methods calls to their definitions,
etc., but with duck typing that is...almost intractable. The best I
came up with was a sort of method search that sort of worked, but didn't
find dynamically defined methods, etc.

       -- Markus

···

On Fri, 2004-09-24 at 10:00, James Edward Gray II wrote:

I need to HTMLify some Ruby code. Before I go make some crude
solution, I thought I would ask if there is anything out there along
these lines. Any pointers?

Thanks.

James Edward Gray II

James Edward Gray II wrote:

I need to HTMLify some Ruby code. Before I go make some crude solution, I thought I would ask if there is anything out there along these lines. Any pointers?

Thanks.

James Edward Gray II

Vim. :slight_smile: If you use Vim, you can do

   :runtime! syntax/2html.vim

It'll create a new window with your Vim file converted to HTML.

···

--
Jamis Buck
jgb3@email.byu.edu
http://www.jamisbuck.org/jamis

"I use octal until I get to 8, and then I switch to decimal."

James Edward Gray II <james@grayproductions.net> writes:

I need to HTMLify some Ruby code. Before I go make some crude
solution, I thought I would ask if there is anything out there along
these lines. Any pointers?

There's an Emacs package called htmlize. If you want to htmlize every
Ruby file in a certain directory, open the directory with C-x d, hit %
m, give it a regular expression like .rb$, and do M-x
htmlize-many-files-dired. It will write one .html file for every .rb
file.

Here's htmlize: http://fly.srk.fer.hr/~hniksic/emacs/htmlize.el

RubyForge's ViewCVS setup uses enscript to do markup. Here's an
example:

The enscript colorizer file is here:

Yours,

Tom

···

On Fri, 2004-09-24 at 13:00, James Edward Gray II wrote:

I need to HTMLify some Ruby code. Before I go make some crude
solution, I thought I would ask if there is anything out there along
these lines. Any pointers?

There's a utility called rb2html that works well.

http://raa.ruby-lang.org/search.rhtml?search=rb2html

···

On Sat, 25 Sep 2004, James Edward Gray II wrote:

I need to HTMLify some Ruby code. Before I go make some crude
solution, I thought I would ask if there is anything out there along
these lines. Any pointers?

Thanks.

James Edward Gray II

--
Kurt Williams
Senior Engineer

kurt@nationalgeographic.com

I'm currently using xemacs to htmlify code (example code for my slides),
but if you find a html-izer that does real parsing, please share your find.

Thank you,

Brian

···

On Sat, 25 Sep 2004 02:00:28 +0900, James Edward Gray II wrote:

I need to HTMLify some Ruby code. Before I go make some crude solution, I
thought I would ask if there is anything out there along these lines. Any
pointers?

Thanks.

James Edward Gray II

--
Brian Schröder
http://www.brian-schroeder.de/

James Edward Gray II wrote:

I need to HTMLify some Ruby code. Before I go make some crude
solution, I thought I would ask if there is anything out there along
these lines. Any pointers?

Thanks.

James Edward Gray II

Well, I know I'm coming in a little late on the this thread, but for
completeness' sake, if nothing else, check out:
http://www.gnu.org/software/src-highlite/source-highlight.html\.

You might want to look at:
http://phrogz.net/JS/Classes/syntaxcolor.js

It's a little script I wrote which automagically syntax colors javascript code inside of <code class="js"> blocks, and shouldn't be *TOO* hard to extend to give at least basic ruby syntax coloring. (It's all regexp based, so complex things like properly coming in/out of %Q{ or %Qn won't work well. But at least it's a start.)

Man, with more time in my life, I'd love to write a general-purpose JS syntax-coloring state machine :slight_smile:

···

On Sep 24, 2004, at 1:00 PM, James Edward Gray II wrote:

I need to HTMLify some Ruby code. Before I go make some crude solution, I thought I would ask if there is anything out there along these lines. Any pointers?

James Edward Gray II wrote:

I need to HTMLify some Ruby code. Before I go make some crude solution, I thought I would ask if there is anything out there along these lines. Any pointers?

Attached is a tiny Rakefile that I use for some Ruby scripts of mine. It uses vim but converts FONT-burdened HTML into CSS-based one. Style files are attached as well. Should work on any platform that is supported by Ruby and vim.

Josef 'Jupp' Schugt

Rakefile.txt (3.37 KB)

default.css (2.78 KB)

vim.css (777 Bytes)

--- Hal Fulton <hal9000@hypermetrics.com> wrote:

···

James Edward Gray II wrote:
> I need to HTMLify some Ruby code. Before I go make some crude
solution,
> I thought I would ask if there is anything out there along these
lines.
> Any pointers?

I seem to remember a tool like that. Would be in RAA if so.

Also, I think vim can do that.

Hal

=====
"The Linux Weekend Mechanic" -- http://linuxgazette.net
"TAG Editor" -- http://linuxgazette.net

"<shrug> We'll just save up your sins, Thomas, and punish
you for all of them at once when you get better. The
experience will probably kill you. :)"

-- Benjamin A. Okopnik (Linux Gazette Technical Editor)

___________________________________________________________ALL-NEW Yahoo! Messenger - all new features - even more fun! http://uk.messenger.yahoo.com

A quick and dirty way might be:

#!/usr/bin/ruby

input = File.open( "file.rb" , "r" )
output = File.new( "file.html" , "w+" )

input.each_byte{ |c|
    case c.chr!
       when "\n"
          output.write( "<br>\n" )
       when "\s"
          output.write( "&nbsp;" )
       when "\t"
          output.write( 4.times{ "nbsp;" } )
       else
          output.write( c )
    end }

Zach

Sorry if I wasn't clear. I do want to identify elements of Ruby syntax.

Thanks for all the posted solutions. I'm looking through them to see if I can find what I need...

James Edward Gray II

···

On Sep 24, 2004, at 12:11 PM, Markus wrote:

     Depends. What are you trying to accomplish?

Hal Fulton wrote:

James Edward Gray II wrote:

I need to HTMLify some Ruby code. Before I go make some crude solution, I thought I would ask if there is anything out there along these lines. Any pointers?

I seem to remember a tool like that. Would be in RAA if so.

Also, I think vim can do that.

Exactly. I've written a Ruby script that uses vim to transform source codes easily to colorized html.

http://www.ntecs.de/viewcvs/viewcvs/colorize/

Regards,

   Michael

The ruby2html link posted earlier in this thread seemed to be a real parser. I want through it's source code, looking around. It didn't have any English documentation though, unfortunately.

James Edward Gray II

···

On Sep 24, 2004, at 2:59 PM, Brian Schroeder wrote:

On Sat, 25 Sep 2004 02:00:28 +0900, James Edward Gray II wrote:

I need to HTMLify some Ruby code. Before I go make some crude solution, I
thought I would ask if there is anything out there along these lines. Any
pointers?

Thanks.

James Edward Gray II

I'm currently using xemacs to htmlify code (example code for my slides),
but if you find a html-izer that does real parsing, please share your find.

Erps, I meant:
http://phrogz.net/JS/Classes/syntaxcolor_test.html

seen in action there, and in various files in that directory, like:
http://phrogz.net/JS/Classes/ExtendingJavaScriptObjectsAndClasses.html

(note the pretty colors sprinkled throughout, yet the source file is clean and easy to read/change)

···

On Sep 24, 2004, at 11:07 PM, Gavin Kistner wrote:

On Sep 24, 2004, at 1:00 PM, James Edward Gray II wrote:

I need to HTMLify some Ruby code. Before I go make some crude solution, I thought I would ask if there is anything out there along these lines. Any pointers?

You might want to look at:
http://phrogz.net/JS/Classes/syntaxcolor.js

Hi, Jamis!

* Jamis Buck <jgb3@email.byu.edu> [2004-09-24]:

   :runtime! syntax/2html.vim

That can be done in a shorter and more convenient way, just by
entering :TOhtml :slight_smile:

Julius

···

--
www.plenz.com

A better version might be:

···

--------------------------------------------------------------

input = File.open("baselayout_test.rb")
output = File.new( "baselayout_test.html" , "w+" )

input.each_byte{ |c|
    c=c.chr
    c.gsub!(/\n/ , "<br>\n" ) and output.write( c ) and next if( c=~/\n/ )
    c.gsub!(/\s/ , "&nbsp;" ) and output.write( c ) and next if( c=~/\s/ )
    c.gsub!(/\t/ , "&nbsp;&nbsp;&nbsp;&nbsp;" ) and output.write( c ) and next if( c=~/\t/ )
    output.write( c ) }

Zach Dennis wrote:

A quick and dirty way might be:

#!/usr/bin/ruby

input = File.open( "file.rb" , "r" )
output = File.new( "file.html" , "w+" )

input.each_byte{ |c|
   case c.chr!
      when "\n"
         output.write( "<br>\n" )
      when "\s"
         output.write( "&nbsp;" )
      when "\t"
         output.write( 4.times{ "nbsp;" } )
      else
         output.write( c )
   end }

Zach

A quick and dirty way might be:

Oh well if that's allowed, then how about:

File.open("file.rb") do |r|
  File.open("file.html","w") do |w|
    w.puts "<pre>"
    r.each_line do |line|
      line.gsub!(/&/,'&amp;')
      line.gsub!(/</,'&lt;')
      line.gsub!(/>/,'&gt;')
      w.puts line
    end
    w.puts "</pre>"
  end
end

:slight_smile: