Ruby Code to HTML

Discussion in 'Ruby' started by James Edward Gray II, Sep 24, 2004.

  1. 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, Sep 24, 2004
    #1
    1. Advertising

  2. James Edward Gray II

    Hal Fulton Guest

    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
    Hal Fulton, Sep 24, 2004
    #2
    1. Advertising

  3. James Edward Gray II

    Markus Guest

    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
    >
    Markus, Sep 24, 2004
    #3
  4. James Edward Gray II

    Thomas Adam Guest

    --- 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.
    >
    >
    > 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
    Thomas Adam, Sep 24, 2004
    #4
  5. James Edward Gray II

    Jamis Buck Guest

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

    http://www.jamisbuck.org/jamis

    "I use octal until I get to 8, and then I switch to decimal."
    Jamis Buck, Sep 24, 2004
    #5
  6. James Edward Gray II

    Zach Dennis Guest

    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
    Zach Dennis, Sep 24, 2004
    #6
  7. James Edward Gray II <> 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
    Mikael Brockman, Sep 24, 2004
    #7
  8. James Edward Gray II

    Tom Copeland Guest

    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?


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

    http://qurl.net/4M

    The enscript colorizer file is here:

    http://qurl.net/4N

    Yours,

    Tom
    Tom Copeland, Sep 24, 2004
    #8
  9. 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
    http://www.nationalgeographic.com
    Kurt Williams, Sep 24, 2004
    #9
  10. James Edward Gray II

    Zach Dennis Guest

    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
    >
    >
    >
    Zach Dennis, Sep 24, 2004
    #10
  11. On Sep 24, 2004, at 12:11 PM, Markus wrote:

    > 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
    James Edward Gray II, Sep 24, 2004
    #11
  12. > 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

    :)
    Brian Candler, Sep 24, 2004
    #12
  13. 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
    Michael Neumann, Sep 24, 2004
    #13
  14. James Edward Gray II

    Kent Sibilev Guest

    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.

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

    > On Sep 24, 2004, at 12:11 PM, Markus wrote:
    >
    >> 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
    >
    >
    Kent Sibilev, Sep 24, 2004
    #14
  15. 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.

    Thank you,

    Brian

    --
    Brian Schröder
    http://www.brian-schroeder.de/
    Brian Schroeder, Sep 24, 2004
    #15
  16. 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.


    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
    James Edward Gray II, Sep 24, 2004
    #16
  17. James Edward Gray II

    Tim Hunter Guest

    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.
    Tim Hunter, Sep 24, 2004
    #17
  18. 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

    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 :)
    Gavin Kistner, Sep 25, 2004
    #18
  19. 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


    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)
    Gavin Kistner, Sep 25, 2004
    #19
  20. Hi!


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

    Works okay for me.

    regards,
    Henrik
    Henrik Horneber, Sep 25, 2004
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Craig Kenisston

    HTML code warnings in asp.net html code view

    Craig Kenisston, Oct 7, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    2,066
    Martin Dechev
    Oct 7, 2004
  2. Anders K. Jacobsen [DK]

    How to stop HTML View from messing up HTML code

    Anders K. Jacobsen [DK], Jan 21, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    660
    Anders K. Jacobsen [DK]
    Jan 22, 2005
  3. Kevin

    include HTML code from html page

    Kevin, Sep 27, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    688
    Siva M
    Sep 27, 2005
  4. anne001
    Replies:
    1
    Views:
    356
  5. Adam Akhtar
    Replies:
    9
    Views:
    500
    Florian Gilcher
    Aug 16, 2008
Loading...

Share This Page