generating webpages with Ruby... help with double quotes

Z

Zoe Phoenix

I want a program that I'm working on to generate some web pages for me,
but I'm having trouble with generating the pages in HTML, since it uses
the double quotes for links, as in <a
href="http://www.blahblahblah.com"></a>.

Since there are a lot of the links in this page, I need to know what the
best way to get around this problem is. Can someone help me, please?
 
R

reuben doetsch

[Note: parts of this message were removed to make it a legal post.]

You can just use single quotes. So
string= '<a href="http://www.blahblahblah.com"></a>.'

I want a program that I'm working on to generate some web pages for me,
but I'm having trouble with generating the pages in HTML, since it uses
the double quotes for links, as in <a
href="http://www.blahblahblah.com"></a>.

Since there are a lot of the links in this page, I need to know what the
best way to get around this problem is. Can someone help me, please?

Reuben Doetsch
 
T

Tim Pease

I want a program that I'm working on to generate some web pages for
me,
but I'm having trouble with generating the pages in HTML, since it
uses
the double quotes for links, as in <a
href="http://www.blahblahblah.com"></a>.

Since there are a lot of the links in this page, I need to know what
the
best way to get around this problem is. Can someone help me, please?

The are a few different ways to construct your HTML output:


%q(<p>your html <a href="http://foo.example.com">code</a> goes here)

%Q(<p>just another form that supports #{variable} expansion)

<<-HTML
<body>
<p>and the big daddy of them all -- the <em>heredoc</em> format</p>

<p>this will create a single string from the all the text found
between the opening <code><<-HTML</code> marker above and the closing
<code>HTML</code> marker below<p>

<p>you can use any uppercase string to mark your heredoc</p>

<p>heredocs also support #{variable} substitution</p>

<div id="foot">
<p>hope that helps</p>

<p>Blessings,<br />
TwP</p>
HTML
 
M

Michael T. Richter

[Note: parts of this message were removed to make it a legal post.]

I want a program that I'm working on to generate some web pages for me,
but I'm having trouble with generating the pages in HTML, since it uses
the double quotes for links, as in <a
href="http://www.blahblahblah.com"></a>.


Since there are a lot of the links in this page, I need to know what the
best way to get around this problem is. Can someone help me, please?


Strings have a large number of different representations for precisely
this reason:


"<a href=\"http://www.blahblahblah.com\">" # double-quoted strings do interpolation and have a lot of \-escapes.
'<a href="http://www.blahblahblah.com">' # single-quoted strings don't do interpolation and only \-escape \ and '.
%q{<a href="http://www.blahblahblah.com">} # same as a single-quoted string, but ' isn't special
%q|<a href="http://www.blahblahblah.com">| # the delimiter doesn't have to be braces
%Q{<a href="http://www.blahblahblah.com">} # same as double-quoted-string, but " isn't special


Then there's "here documents" and the like, and there's other variants
of these in the facets gem. Pick and choose the representation that
suits your needs best. (In your case I'd likely recommend %Q{string
here}, %Q(string here) or even %Q|string here|.)
 

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
474,266
Messages
2,571,077
Members
48,772
Latest member
Backspace Studios

Latest Threads

Top