[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Getting away from the old php code

Marc Heiler

10/17/2006 10:57:00 PM

Hello,

How can i embed ruby code into a html page,
like php code, without using erb, nor
its IMO slightly ugly syntax? (I am
using Apache2.)

- Yes, I want to do this.

Basically what I'd like to do is replace
my old php scripts, which are in part
embedded, in part just simple html
generators. I figured that the
stuff that has to be rewritten in ruby
would be a lot easier to maintain and
extend, than continuing with
php (on webstuff). But I like to keep
the "embedded" logic simple as it
currently is. Ruby simply is
a much better language than php.


No, I dont need rails - i need a hammer
for my nail, not a hovering tank to shoot
down the whole building (read as:
complexity). :-)


--
Posted via http://www.ruby-....

9 Answers

Justin Collins

10/17/2006 11:05:00 PM

0

Marc Heiler wrote:
> Hello,
>
> How can i embed ruby code into a html page,
> like php code, without using erb, nor
> its IMO slightly ugly syntax? (I am
> using Apache2.)
>
> - Yes, I want to do this.
>
> Basically what I'd like to do is replace
> my old php scripts, which are in part
> embedded, in part just simple html
> generators. I figured that the
> stuff that has to be rewritten in ruby
> would be a lot easier to maintain and
> extend, than continuing with
> php (on webstuff). But I like to keep
> the "embedded" logic simple as it
> currently is. Ruby simply is
> a much better language than php.
>
>
> No, I dont need rails - i need a hammer
> for my nail, not a hovering tank to shoot
> down the whole building (read as:
> complexity). :-)
>

Why not use erb (or eruby)? The syntax is pretty much the same as PHP,
except with "<%" instead of "<?"
If you are really against it, though, you can google around for some
other web templating tools. I know several exist, but I've always been
fine with eruby.

-Justin

Eero Saynatkari

10/17/2006 11:07:00 PM

0

On 2006.10.18 07:57, Marc Heiler wrote:
> Hello,
>
> How can i embed ruby code into a html page,
> like php code, without using erb, nor
> its IMO slightly ugly syntax? (I am
> using Apache2.)

You can use any other template library, too,
Amrita2 for example.

Gavin Kistner

10/18/2006 1:04:00 AM

0

Marc Heiler wrote:
> How can i embed ruby code into a html page,
> like php code, without using erb, nor
> its IMO slightly ugly syntax? (I am
> using Apache2.)

What about ERB do you find offensive?

Or, put another way, what WOULD you like your HTML+Ruby to look like?

Here's a thread that's relevant, particular Harold Hausman's response:
http://rubyu...

I can attest to the simplicity of using Ruby Web (esp. along with
SQLite3 and Array Fields).

Gavin Kistner

10/18/2006 4:06:00 AM

0

Phrogz wrote:
> Here's a thread that's relevant, particular Harold Hausman's response:
> http://rubyu...
....except that 2 of the 3 URLs used in that response are already dead.

Ruby-Web : http://rubyforge.org/projects...
SQLite3 : http://rubyforge.org/projects/sq...
ArrayFields : http://www.codeforpeople.com/lib/ruby/ar...

Jeff Barczewski

10/18/2006 12:30:00 PM

0

On 10/17/06, Marc Heiler <shevegen@linuxmail.org> wrote:
> Hello,
>
> How can i embed ruby code into a html page,
> like php code, without using erb, nor
> its IMO slightly ugly syntax? (I am
> using Apache2.)
>

If you are familiar with PHPTAL which makes a standard static html
page into a dynamic one using an attribute language then you might
like MasterView which is a plugin for Rails which works similarly.

MasterView allows you to use the full power of rails partials,
layouts, helpers, etc while still keeping a WYSIWYG editable html
file. Any WYSIWYG changes that you apply to the html are used in the
final rendering (they are merged with the options in the attribute
directives.

MasterView is a Rubyforge project
http://rubyforge.org/projects/...

I also have a video and some screenshots here
http://maste...

I'd be glad to answer any questions that you have.

Blessings,

Jeff

Marc Heiler

10/23/2006 6:22:00 PM

0

Hi guys,

sorry for the delayed reply.


Thanks for the replies. I'll try to find out how the
<% is used by erb. There must be a way to patch it
to allow other delimiters, even if I am the only
one who will use that. :)

--
Posted via http://www.ruby-....

Eero Saynatkari

10/24/2006 3:42:00 AM

0

On 2006.10.24 03:21, Marc Heiler wrote:
> Hi guys,
>
> sorry for the delayed reply.
>
>
> Thanks for the replies. I'll try to find out how the
> <% is used by erb. There must be a way to patch it
> to allow other delimiters, even if I am the only
> one who will use that. :)

Is there any particular reason you do not want to use the
standard delimiter? This is how erb works:

# Template
<% math_result = 1 + 1%>
Hello, I am a math genious. 1 + 1 = <%= math_result %>.

# Result
Hello, I am a math genious. 1 + 1 = 2

Ezra Zygmuntowicz

10/24/2006 9:11:00 PM

0


On Oct 23, 2006, at 8:42 PM, Eero Saynatkari wrote:

> On 2006.10.24 03:21, Marc Heiler wrote:
>> Hi guys,
>>
>> sorry for the delayed reply.
>>
>>
>> Thanks for the replies. I'll try to find out how the
>> <% is used by erb. There must be a way to patch it
>> to allow other delimiters, even if I am the only
>> one who will use that. :)
>
> Is there any particular reason you do not want to use the
> standard delimiter? This is how erb works:
>
> # Template
> <% math_result = 1 + 1%>
> Hello, I am a math genious. 1 + 1 = <%= math_result %>.
>
> # Result
> Hello, I am a math genious. 1 + 1 = 2


If you really can't stand the <% syntax then download and install
the erubis gem. It is an Erb clone that behaves the same way ecept
it has many more features and is 3 times faster then Erb. It also
allows you to set the template delimiters to whatever you want. So if
you were totally off your rocker you could even do this:

<?php [:foo, :bar, :baz].each do |sym| ?>
<?= sym ?>
<?php end ?>

;-)


-- Ezra Zygmuntowicz
-- Lead Rails Evangelist
-- ez@engineyard.com
-- Engine Yard, Serious Rails Hosting
-- (866) 518-YARD (9273)



Marc Heiler

11/4/2006 4:02:00 PM

0

Hiyas again, and once again sorry for the delayed
reply. Reason I check not often is that I have
it on a long list of things to check regulary
after some time passes, and there are too many
places I have to keep track over time, forums, mailing
list and so on. :)
Hope you dont mind, I *do* read it all though but
it may take some time.

Anyway now, since some want an answer, first I start with a quote:

"Again, what is so bad about <% that makes PHP's <? so nice?
You've never given a reason that you don't want to use ERB."

Please do not misquote me. I never made the notion that <? is
nice. I do not really like it, either. :)
But I agree that I was not clear about it,
so the confusion is understandable.

I actually meant

<?php

instead of
<?

Thus I agree there is no real difference between using
<? or <%

Both look a bit like Snoopy starting to swear ;)


Also, in my old php stuff, I do not really use the
<? shortcut for it. But I'd like to have exactly the
same way for erb.

Anyway to answer that question:
* First, the % character reminds me of ASP Syntax.
* Second, as I now hopefully made clear - sorry that I
forgot that in my first comment - I am using the
longer version
<?php
ALWAYS.

* Third, I do not need it (php) to do line evaluation.
For clarification I do NOT use PHP to do line
evaluation such as the following:

<? print("this is php and it wants a ; !"); ?>

For me, using ruby such as in:

<% puts "ruby is much better everywhere ;-)" %>

or

<= some_assignment=5 >

I think it looks ugly in both cases, even though
ruby code doing the same tasks will always look cleaner
than php. :>

I prefer the longer PHP notion simply because
something such as:

<?php

seems less cryptic to me than:

<%

or also

<?

So in summary it is mostly a matter of personal taste.

Hope that cleared up some things now :)


"Frankly, there are ERB shortcuts:

% for stuff in @stuffs
% end

Check out the ERB docs."


I will be happy as soon as I can use:

<?ruby

instead. :)



"If you really can't stand the <% syntax then download and install
the erubis gem. It is an Erb clone that behaves the same way ecept
it has many more features and is 3 times faster then Erb. It also
allows you to set the template delimiters to whatever you want. So if
you were totally off your rocker you could even do this:


<?php [:foo, :bar, :baz].each do |sym| ?>
<?= sym ?>
<?php end ?>
"

WOOOOOOOOOT!
It looks extremely ugly (i mean the <?= part)
but the <?php thing looks very nice.

Thanks a LOT for the link, I will have a good look
at erubis. The <?php choosing alone seems nice enough
to use erubis. At least it seems to be better than
Erb when I read you correctly? Or is there a catch with
it... anyway off to look at erubis now :)



--
Posted via http://www.ruby-....