Ask a Question related to Ruby, Design and Development.
-
Philip Mak #1
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
-
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.... -
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... -
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... -
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... -
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... -
Ryan Pavlik #2
Re: HTML generation
On Sat, 13 Sep 2003 04:57:46 +0900
Philip Mak <pmak@aaanime.net> wrote:
I'll shamelessly plug Mephle here. I have an HTML widget set in> 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}." } }
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
-
David Corbin #3
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
-
Gavin Sinclair #4
Re: HTML generation
On Saturday, September 13, 2003, 10:45:10 AM, David wrote:
Please avoid top-posting. What do you dislike about the> There's amrita. A great concept, but I'm not too fond of the implementation.
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
-
David Corbin #5
Re: HTML generation
On Friday 12 September 2003 21:21, Gavin Sinclair wrote:
Sorry.> 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.
>
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
-
Alan Davies #6
Re: HTML generation
Gavin Sinclair wrote:
Why do people get so upset about this. Personally, I see nothing wrong> Please avoid top-posting.
with it.
Alan Davies Guest
-
Robert McGovern #7
Re: HTML generation
> > Please avoid top-posting.
wrong with it.>
> Why do people get so upset about this. Personally, I see nothing
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
-
Thomas Adam #8
Re: HTML generation
--- Robert McGovern <robertm@spellmanhv.co.uk> wrote: > > > Please avoid
top-posting.Well, sir. Have you ever tried reading HTML e-mails in Mutt (just one of> wrong with it.> >
> > Why do people get so upset about this. Personally, I see nothing
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
-
Greg McIntyre #9
Re: HTML generation
Philip Mak <pmak@aaanime.net> wrote:
I use something very close to CGI but a bit easier. The problem with> 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}." } }
>
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
-
Robert McGovern #10
Re: HTML generation
> Well, sir. Have you ever tried reading HTML e-mails in Mutt (just one
ofangry as> severak MUA's for Linux?) I guess not, otherwise you'd be just as*scratches head* Thomas did my email appear as html? as certainly from> I am about people sending HTML e-mails.
this end it looks like pure text.
Robert McGovern Guest
-
Thomas Adam #11
Re: HTML generation
--- Robert McGovern <robertm@spellmanhv.co.uk> wrote: > > Well, sir.
Have you ever tried reading HTML e-mails in Mutt (just oneOh, sorry, I didn't mean to imply that your e-mails were NOT plain-text,> of> angry as> > severak MUA's for Linux?) I guess not, otherwise you'd be just 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.
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
-
Tom Copeland #12
Re: HTML generation
On Wed, 2003-09-17 at 07:34, Alan Davies wrote:
A: Because people read from top to bottom.> Gavin Sinclair wrote:>> > Please avoid top-posting.
> Why do people get so upset about this. Personally, I see nothing wrong
> with it.
Q: Why is top posting bad?
Yours,
Tom
Tom Copeland Guest
-
Gavin Sinclair #13
Re: HTML generation
On Wednesday, September 17, 2003, 9:34:45 PM, Alan wrote:
> Gavin Sinclair wrote:> > Please avoid top-posting.It's pretty obvious really; top-posting leaves the thread of> Why do people get so upset about this. Personally, I see nothing wrong
> with it.
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
-
Gavin Sinclair #14
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
-
Mauricio Fernández #15
Re: HTML generation
On Wed, Sep 17, 2003 at 08:45:36PM +0900, Thomas Adam wrote:
Are you using> --- Robert McGovern <robertm@spellmanhv.co.uk> wrote: > > > Please avoid
> top-posting.>> > wrong with it.> > >
> > > Why do people get so upset about this. Personally, I see nothing
> 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.
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



Reply With Quote

