Ask a Question related to Ruby, Design and Development.

  1. #1

    Default HTML generation

    Is there a list of all the different ways of outputting HTML in Ruby
    somewhere?

    I can think of using the "puts" statement, eRuby, and CGI. Any others?
    e.g.:

    "puts" statement:

    puts "<p>Hello, world! Your name is <b>#{name}</b>.</p>"

    eRuby:

    <p>Hello, world! Your name is <b><%=name%></b>.</p>

    CGI:

    cgi.puts { cgi.p { "Hello, world! Your name is #{cgi.b name}." } }

    Philip Mak Guest

  2. Similar Questions and Discussions

    1. PDF Generation Using ver 7
      Hi I have an existing code that silently generates pdfs by supplying file path and printing to "Acrobat PDFWriter", but it's using Acrobat ver 5....
    2. CF5 + XML generation
      Hi, I'm trying to create an XML file from pulled data in our DB. I don't know if I'm doing this the right way. Maybe someone can show me a...
    3. Key Generation
      Is it at all possible to generate contribute keys on the fly? without using the Contribute software? We have well over 100 customers who use the...
    4. HTML Generation (Next Generation CGI)
      Hi, This idea for the next generation of CGI has me thinking (see http://rubygarden.org/ruby?NextGenerationCGI). It seems that CGI would be best...
    5. HTML file generation from PHP scripts
      Thanks for the suggestion guys, but I did forget an important detail. I do not have access to a unix shell so the whole thing must be...
  3. #2

    Default Re: HTML generation

    On Sat, 13 Sep 2003 04:57:46 +0900
    Philip Mak <pmak@aaanime.net> wrote:
    > Is there a list of all the different ways of outputting HTML in Ruby
    > somewhere?
    >
    > I can think of using the "puts" statement, eRuby, and CGI. Any others?
    > e.g.:
    >
    > "puts" statement:
    >
    > puts "<p>Hello, world! Your name is <b>#{name}</b>.</p>"
    >
    > eRuby:
    >
    > <p>Hello, world! Your name is <b><%=name%></b>.</p>
    >
    > CGI:
    >
    > cgi.puts { cgi.p { "Hello, world! Your name is #{cgi.b name}." } }
    I'll shamelessly plug Mephle here. I have an HTML widget set in
    there:

    colors = ["Red", "Green", "Blue"]

    t = Table.new
    f = Form.new
    f << table

    t << Row["Name:", TextBox.new]
    t << Row["Age:", TextBox.new]
    t << Row["Favorite Color:", OptionList[*colors]]
    t << Row["", Submit["Send"]]

    html = t.to_s(...)

    Outputs nicely-indented HTML, as much as possible, too.

    --
    Ryan Pavlik <rpav@mephle.com>

    "Must use last ounce of strength to stab from beyond the grave." - 8BT

    Ryan Pavlik Guest

  4. #3

    Default Re: HTML generation

    There's amrita. A great concept, but I'm not too fond of the implementation.

    On Friday 12 September 2003 15:57, Philip Mak wrote:
    > Is there a list of all the different ways of outputting HTML in Ruby
    > somewhere?
    >
    > I can think of using the "puts" statement, eRuby, and CGI. Any others?
    > e.g.:
    >
    > "puts" statement:
    >
    > puts "<p>Hello, world! Your name is <b>#{name}</b>.</p>"
    >
    > eRuby:
    >
    > <p>Hello, world! Your name is <b><%=name%></b>.</p>
    >
    > CGI:
    >
    > cgi.puts { cgi.p { "Hello, world! Your name is #{cgi.b name}." } }
    --
    David Corbin <dcorbin@machturtle.com>


    David Corbin Guest

  5. #4

    Default Re: HTML generation

    On Saturday, September 13, 2003, 10:45:10 AM, David wrote:
    > There's amrita. A great concept, but I'm not too fond of the implementation.
    Please avoid top-posting. What do you dislike about the
    implementation? I haven't used it for quite a while, but I understand
    that after 1.something it became a lot faster.

    Gavin

    > On Friday 12 September 2003 15:57, Philip Mak wrote:
    >> Is there a list of all the different ways of outputting HTML in Ruby
    >> somewhere?
    >>
    >> I can think of using the "puts" statement, eRuby, and CGI. Any others?
    >> e.g.:
    >>
    >> "puts" statement:
    >>
    >> puts "<p>Hello, world! Your name is <b>#{name}</b>.</p>"
    >>
    >> eRuby:
    >>
    >> <p>Hello, world! Your name is <b><%=name%></b>.</p>
    >>
    >> CGI:
    >>
    >> cgi.puts { cgi.p { "Hello, world! Your name is #{cgi.b name}." } }

    Gavin Sinclair Guest

  6. #5

    Default Re: HTML generation

    On Friday 12 September 2003 21:21, Gavin Sinclair wrote:
    > On Saturday, September 13, 2003, 10:45:10 AM, David wrote:
    > > There's amrita. A great concept, but I'm not too fond of the
    > > implementation.
    >
    > Please avoid top-posting. What do you dislike about the
    > implementation? I haven't used it for quite a while, but I understand
    > that after 1.something it became a lot faster.
    >
    Sorry.

    It just seemed a little hard to do the things I wanted to do (like href
    manipulation) and I definately didn't like the way it automatically deletes
    things that are in the data structure (because they're nil). (That's what I
    remember, but it's been more than a month...)

    I took the concept and "grew my own" that's a little more flexible and
    powerful I think. The "key" of the hash can be an ID, or and ID + Attribute
    name, or in theory (though I haven't done this yet) an XPath expression. On
    the right side, there are a number of possible "manipulators", including a
    "delete", and "appender", "replacement" (the default I think), a Form object
    which populates INPUT elements, etc.

    I *intend* to package it up for use by others, but I'm so busy I don't know
    when I'll get it done. I don't really want to release something like that
    without good doc, examples, and unit tests.

    --
    David Corbin <dcorbin@machturtle.com>


    David Corbin Guest

  7. #6

    Default Re: HTML generation

    Gavin Sinclair wrote:
    > Please avoid top-posting.
    Why do people get so upset about this. Personally, I see nothing wrong
    with it.

    Alan Davies Guest

  8. #7

    Default Re: HTML generation

    > > Please avoid top-posting.
    >
    > Why do people get so upset about this. Personally, I see nothing
    wrong with it.

    Partly because the reader has to scroll down to find out the context of
    the reply. Its often a lot clearer to do as you did above and copy some
    context of the original message and put your comment below. It becomes
    important when you are using an email / newsgroup reader that doesn't do
    threading and messages are wildy out of order.

    Rob



    Robert McGovern Guest

  9. #8

    Default Re: HTML generation

    --- Robert McGovern <robertm@spellmanhv.co.uk> wrote: > > > Please avoid
    top-posting.
    > >
    > > Why do people get so upset about this. Personally, I see nothing
    > wrong with it.
    Well, sir. Have you ever tried reading HTML e-mails in Mutt (just one of
    severak MUA's for Linux?) I guess not, otherwise you'd be just as angry as
    I am about people sending HTML e-mails.

    E-mail is historically a text-only medium and should remain so. HTML
    e-mail just add a shed load of junk at the end that is superfluous to the
    content.

    -- Thomas Adam

    =====
    Thomas Adam

    "The Linux Weekend Mechanic" -- [url]www.linuxgazette.com[/url]

    __________________________________________________ ______________________
    Want to chat instantly with your online friends? Get the FREE Yahoo!
    Messenger [url]http://mail.messenger.yahoo.co.uk[/url]

    Thomas Adam Guest

  10. #9

    Default Re: HTML generation

    Philip Mak <pmak@aaanime.net> wrote:
    > Is there a list of all the different ways of outputting HTML in Ruby
    > somewhere?
    >
    > I can think of using the "puts" statement, eRuby, and CGI. Any others?
    > e.g.:
    >
    > "puts" statement:
    >
    > puts "<p>Hello, world! Your name is <b>#{name}</b>.</p>"
    >
    > eRuby:
    >
    > <p>Hello, world! Your name is <b><%=name%></b>.</p>
    >
    > CGI:
    >
    > cgi.puts { cgi.p { "Hello, world! Your name is #{cgi.b name}." } }
    >
    I use something very close to CGI but a bit easier. The problem with
    CGI, I find, is that you need to add the blocks together for
    sequential elements. e.g.

    cgi.p { "blah blah blah" } +
    cgi.p { "blah blah blah" }

    Which can actually get quite ugly and cause havoc for your code
    indentation, especially when you start introducing conditionals and
    loops. If possible I prefer printing on the fly, resulting in something
    like (simplified implementation alert):

    def paragraph
    print "<p>"; yield; print "</p>"
    end

    paragraph { print "blah blah blah" }
    paragraph { print "blah blah blah" }

    If you don't want to print to $stdout, you can set $stdout = something
    else beforehand or if you need thread safety (I assume setting $stdout
    isn't a very thread-safe thing to do), uglify your code a little mode by
    passing an IO object around.

    def paragraph(io)
    io << "<p>"; yield io; io << "</p>"
    end

    paragraph(io) { io << "blah blah blah" }
    paragraph(io) { io << "blah blah blah" }

    (You don't really need to use the block parameter but I pass it anyway
    just in case.)

    I find this method works really well. You end up with very neat code
    and its indentation level mimics that in the HTML output so its
    structure is always clear (and can be automatically re-indented with
    standard code indenters). You don't have to escape strings or
    rearrange your code to add iteration or conditionals and that turns
    out to be an enormous plus for neatness IMO. In fact, I think this
    method is even easier and less error-prone than hand coding HTML
    because it guarrantees you close off your open tags! e.g.

    table do
    tr("class"=>"headings") do
    th { print "Name" }
    th { print "Age" }
    end
    for person in people.sort
    tr("class"=>"record") do
    td { print person.name }
    td { print person.age }
    end
    end
    end

    And you also come up with context sensitive names instead of "tr" and
    "td". You can use Ruby's alias command or define methods which make
    things easier for particular tasks, and factor out common logic.
    Putting in another layer also lets you go back and change your
    definitions later if you need to, which is nice.

    e.g.

    def ages(headings)
    table({'class'=>'ages'}) do
    tr({'class'=>'headings'}) do
    headings.each do |i|
    th { print i }
    end
    end
    yield
    end
    end

    def record(*values)
    tr({'class'=>'record'}) do
    values.each do |i|
    td { print i }
    end
    end
    end

    ages 'Name Age'.split do
    for person in people.sort
    record person.name, person.age
    end
    end


    Anyway, just my 2c. ;)

    --
    Greg McIntyre ======[ [email]greg@puyo.cjb.net[/email] ]===[ [url]http://puyo.cjb.net[/url] ]===
    Greg McIntyre Guest

  11. #10

    Default Re: HTML generation

    > Well, sir. Have you ever tried reading HTML e-mails in Mutt (just one
    of
    > severak MUA's for Linux?) I guess not, otherwise you'd be just as
    angry as
    > I am about people sending HTML e-mails.
    *scratches head* Thomas did my email appear as html? as certainly from
    this end it looks like pure text.

    Robert McGovern Guest

  12. #11

    Default Re: HTML generation

    --- Robert McGovern <robertm@spellmanhv.co.uk> wrote: > > Well, sir.
    Have you ever tried reading HTML e-mails in Mutt (just one
    > of
    > > severak MUA's for Linux?) I guess not, otherwise you'd be just as
    > angry as
    > > I am about people sending HTML e-mails.
    >
    > *scratches head* Thomas did my email appear as html? as certainly from
    > this end it looks like pure text.
    > tainly from
    > this end it looks like pure text.
    Oh, sorry, I didn't mean to imply that your e-mails were NOT plain-text,
    because they are. I was just outlining why HTML e-mails in general are an
    annoyance.

    -- Thomas Adam

    =====
    Thomas Adam

    "The Linux Weekend Mechanic" -- [url]www.linuxgazette.com[/url]

    __________________________________________________ ______________________
    Want to chat instantly with your online friends? Get the FREE Yahoo!
    Messenger [url]http://mail.messenger.yahoo.co.uk[/url]

    Thomas Adam Guest

  13. #12

    Default Re: HTML generation

    On Wed, 2003-09-17 at 07:34, Alan Davies wrote:
    > Gavin Sinclair wrote:
    > > Please avoid top-posting.
    >
    > Why do people get so upset about this. Personally, I see nothing wrong
    > with it.
    A: Because people read from top to bottom.

    Q: Why is top posting bad?

    Yours,

    Tom



    Tom Copeland Guest

  14. #13

    Default Re: HTML generation

    On Wednesday, September 17, 2003, 9:34:45 PM, Alan wrote:
    > Gavin Sinclair wrote:
    > > Please avoid top-posting.
    > Why do people get so upset about this. Personally, I see nothing wrong
    > with it.
    It's pretty obvious really; top-posting leaves the thread of
    discussion out of order. It is usually preferable to reply to a
    specific context (i.e. insert your points among quoted text) than to
    reply to an entire message. Even if you want to reply to a whole
    message, you don't know who will reply to you, and top-posting ensures
    that subsequent replies, if using context threading, will be out of
    order.

    Basically, context threading (if that's the right word), combined with
    judicious snipping, helps the cause of clearer communication, which
    someone searching the archives in a year's time will appreciate.

    I'm sure there will be heaps of dissertations on this topic on the
    'net, both for and against. There are also discussions in the
    ruby-talk archives.

    Cheers,
    Gavin


    Gavin Sinclair Guest

  15. #14

    Default Re: HTML generation

    On Thursday, September 18, 2003, 12:33:42 AM, Tom wrote:
    > On Wed, 2003-09-17 at 07:34, Alan Davies wrote:
    >> Gavin Sinclair wrote:
    >> > Please avoid top-posting.
    >>
    >> Why do people get so upset about this. Personally, I see nothing wrong
    >> with it.
    > A: Because people read from top to bottom.
    > Q: Why is top posting bad?

    Sigh... one day I will learn succinctness... ;)

    Gavin


    Gavin Sinclair Guest

  16. #15

    Default Re: HTML generation

    On Wed, Sep 17, 2003 at 08:45:36PM +0900, Thomas Adam wrote:
    > --- Robert McGovern <robertm@spellmanhv.co.uk> wrote: > > > Please avoid
    > top-posting.
    > > >
    > > > Why do people get so upset about this. Personally, I see nothing
    > > wrong with it.
    >
    > Well, sir. Have you ever tried reading HTML e-mails in Mutt (just one of
    > severak MUA's for Linux?) I guess not, otherwise you'd be just as angry as
    > I am about people sending HTML e-mails.
    Are you using
    set implicit_autoview=yes

    ?

    HTML is still plain wrong but you won't have such a hard time reading
    spam now :-P

    --
    _ _
    | |__ __ _| |_ ___ _ __ ___ __ _ _ __
    | '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \
    | |_) | (_| | |_\__ \ | | | | | (_| | | | |
    |_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_|
    Running Debian GNU/Linux Sid (unstable)
    batsman dot geo at yahoo dot com

    Actually, typing random strings in the Finder does the equivalent of
    filename completion.
    -- Discussion on file completion vs. the Mac Finder

    Mauricio Fernández Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139