Ruby Code to HTML

  • Thread starter James Edward Gray II
  • Start date
J

James Edward Gray II

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
 
H

Hal Fulton

James said:
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
 
M

Markus

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
 
T

Thomas Adam

--- Hal Fulton said:
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
 
J

Jamis Buck

James said:
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. :) 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
(e-mail address removed)
http://www.jamisbuck.org/jamis

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

Zach Dennis

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
 
M

Mikael Brockman

James Edward Gray II said:
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
 
Z

Zach Dennis

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 ) }
 
J

James Edward Gray II

Depends. What are you trying to accomplish?

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
 
B

Brian Candler

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

:)
 
K

Kent Sibilev

If you need to parse Ruby code and access to elements of Ruby syntax,
take a look at the CVS HEAD version of Ruby 1.9. It comes with the
ripper library integrated.

Cheers,
Kent.
 
B

Brian Schroeder

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.

Thank you,

Brian
 
J

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.

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
 
G

Gavin Kistner

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

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 :)
 
H

Henrik Horneber

Hi!


The scite editor, which comes with the ruby one click installer, has an
export to html feature.

Works okay for me.

regards,
Henrik
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,227
Latest member
Daniella65

Latest Threads

Top