[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Ruby and PHP code in html-page

Vadim Shevchenko

7/12/2007 1:13:00 PM

For example I have such html-page:

test.html
==========

<html>
<body>
<%
puts 'hello'
%>

<hr>

<?php

phpinfo();

?>
</body>
</html>

===========

Main web-server script-language is Ruby.
I want to include PHP-code.

Is it posiible?

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

18 Answers

Jano Svitok

7/12/2007 2:23:00 PM

0

On 7/12/07, Vadim Shevchenko <veejar.net@gmail.com> wrote:
> For example I have such html-page:
>
> test.html
> ==========
>
> <html>
> <body>
> <%
> puts 'hello'
> %>
>
> <hr>
>
> <?php
>
> phpinfo();
>
> ?>
> </body>
> </html>
>
> ===========
>
> Main web-server script-language is Ruby.
> I want to include PHP-code.
>
> Is it posiible?

It is possible if you run the code first through ERB and then through
PHP or vice versa.

How slow it will be depends on your deployment type - i.e. whether do
you run PHP and/or Ruby as CGI, mod_ruby, using mongrel etc.

If mod_php allows you to define a post_request filter, that might
help. Or you could create a subrequest to php, and than process its
output.

I see a maintainability problem here - two languages intermixed.
The easier way would be to separate all the php or ruby stuff to a
separate webservice/subpage, and include its output to the main page.

...and if you want to really inter-mix ruby and php, that would be a
nightmare ;-)
as in:

<% 1..2.each do |i| %>
<?php

?>
<% end %>

J.

John Joyce

7/12/2007 5:55:00 PM

0


On Jul 12, 2007, at 9:23 AM, Jano Svitok wrote:

> On 7/12/07, Vadim Shevchenko <veejar.net@gmail.com> wrote:
>> For example I have such html-page:
>>
>> test.html
>> ==========
>>
>> <html>
>> <body>
>> <%
>> puts 'hello'
>> %>
>>
>> <hr>
>>
>> <?php
>>
>> phpinfo();
>>
>> ?>
>> </body>
>> </html>
>>
>> ===========
>>
>> Main web-server script-language is Ruby.
>> I want to include PHP-code.
>>
>> Is it posiible?
>
> It is possible if you run the code first through ERB and then through
> PHP or vice versa.
>
> How slow it will be depends on your deployment type - i.e. whether do
> you run PHP and/or Ruby as CGI, mod_ruby, using mongrel etc.
>
> If mod_php allows you to define a post_request filter, that might
> help. Or you could create a subrequest to php, and than process its
> output.
>
> I see a maintainability problem here - two languages intermixed.
> The easier way would be to separate all the php or ruby stuff to a
> separate webservice/subpage, and include its output to the main page.
>
> ...and if you want to really inter-mix ruby and php, that would be a
> nightmare ;-)
> as in:
>
> <% 1..2.each do |i| %>
> <?php
>
> ?>
> <% end %>
>
> J.
>
I've been thinking about this as well lately.
Since Rails is overkill for a lot of little things, it would be nice
if ERb had more ability.
ERb lacks some of the functionality and flexibility of embedded php.
With php you can just include a file, but ERb doesn't let you do that
(AFAIK).

John Joyce

James Britt

7/12/2007 6:28:00 PM

0

John Joyce wrote:

> I've been thinking about this as well lately.
> Since Rails is overkill for a lot of little things, it would be nice if
> ERb had more ability.

Look at Ramaze or Nitro. Or IOWA or Cerise. Or Merb. Or Camping.

Or roll your own.

Rule your world.

--
James Britt

http://www.... - Hacking in the Desert
http://www.jame... - Playing with Better Toys

Jeremy Henty

7/12/2007 6:43:00 PM

0

On 2007-07-12, John Joyce <dangerwillrobinsondanger@gmail.com> wrote:

> With php you can just include a file, but ERb doesn't let you do
> that (AFAIK).

<%= IO.read "yes_it_does.txt" %>

Jeremy Henty

Phrogz

7/12/2007 6:55:00 PM

0

On Jul 12, 12:43 pm, Jeremy Henty <onepo...@starurchin.org> wrote:
> On 2007-07-12, John Joyce <dangerwillrobinsondan...@gmail.com> wrote:
>
> > With php you can just include a file, but ERb doesn't let you do
> > that (AFAIK).
>
> <%= IO.read "yes_it_does.txt" %>

Not quite when you want the included file to have ERB commands in it:

C:\>type main.erb
<%=$foo%>
<%=IO.read('inc.erb')%>

C:\>type inc.erb
<%=$foo%>

C:\>irb
irb(main):001:0> require 'erb'
irb(main):002:0> $foo = 'Hello World'
irb(main):003:0> ERB.new( IO.read( 'main.erb' ) ).run
Hello World
<%=$foo%>


Jeremy Henty

7/12/2007 9:50:00 PM

0

On 2007-07-12, Phrogz <phrogz@mac.com> wrote:
> On Jul 12, 12:43 pm, Jeremy Henty <onepo...@starurchin.org> wrote:
>> On 2007-07-12, John Joyce <dangerwillrobinsondan...@gmail.com> wrote:
>>
>> > With php you can just include a file, but ERb doesn't let you do
>> > that (AFAIK).
>>
>> <%= IO.read "yes_it_does.txt" %>
>
> Not quite when you want the included file to have ERB commands in it:

Good point!

<%= ERB.new(IO.read("how_about_this_then.erb")).result(binding) %>

Jeremy Henty

Travis D Warlick Jr

7/12/2007 10:46:00 PM

0

John Joyce wrote:
>
> I've been thinking about this as well lately.
> Since Rails is overkill for a lot of little things, it would be nice if
> ERb had more ability.
> ERb lacks some of the functionality and flexibility of embedded php.
> With php you can just include a file, but ERb doesn't let you do that
> (AFAIK).

Couldn't you just put the Erb inside the html? Like:

<html><body>
<!-- stuff up here -->
<%= Erb.new(IO.read(filename)).result %>
<!-- stuff down here -->
</body></html>

--
Travis Warlick

"Programming in Java is like dealing with your mom --
it's kind, forgiving, and gently chastising.
Programming in C++ is like dealing with a disgruntled
girlfriend -- it's cold, unforgiving, and doesn't tell
you what you've done wrong."

John Joyce

7/12/2007 10:49:00 PM

0


On Jul 12, 2007, at 4:50 PM, Jeremy Henty wrote:

> On 2007-07-12, Phrogz <phrogz@mac.com> wrote:
>> On Jul 12, 12:43 pm, Jeremy Henty <onepo...@starurchin.org> wrote:
>>> On 2007-07-12, John Joyce <dangerwillrobinsondan...@gmail.com>
>>> wrote:
>>>
>>>> With php you can just include a file, but ERb doesn't let you do
>>>> that (AFAIK).
>>>
>>> <%= IO.read "yes_it_does.txt" %>
>>
>> Not quite when you want the included file to have ERB commands in it:
>
> Good point!
>
> <%= ERB.new(IO.read("how_about_this_then.erb")).result(binding) %>
>
> Jeremy Henty
>
That's OK I guess, but it's not as graceful as usual Ruby things.
I guess I'm going to look into Camping and those others.
I checked out the Merb site once but it was all RDoc with no solid
examples.
CGI is just too ugly, it might as well be Perl for that, I wish
DreamHost would run mod_ruby...
I'm just finding that Rails is just way more than what I want or
need. Lots of cool stuff in it, but the problem is that there is just
so much there. Getting started is easy enough, but things start to
grind down to a crawl as you beginning unravelling all the details.
It's like any big framework, it's highly productive and useful AFTER
you've spent months learning it. There's definitely a learning curve
and things start to get pretty complicated pretty quickly.

It's too bad that ERb itself isn't better tutorialized.

John Joyce

7/12/2007 10:57:00 PM

0


On Jul 12, 2007, at 5:46 PM, Travis D Warlick Jr wrote:

> John Joyce wrote:
>>
>> I've been thinking about this as well lately.
>> Since Rails is overkill for a lot of little things, it would be
>> nice if
>> ERb had more ability.
>> ERb lacks some of the functionality and flexibility of embedded php.
>> With php you can just include a file, but ERb doesn't let you do that
>> (AFAIK).
>
> Couldn't you just put the Erb inside the html? Like:
>
> <html><body>
> <!-- stuff up here -->
> <%= Erb.new(IO.read(filename)).result %>
> <!-- stuff down here -->
> </body></html>
>
> --
> Travis Warlick
>
> "Programming in Java is like dealing with your mom --
> it's kind, forgiving, and gently chastising.
> Programming in C++ is like dealing with a disgruntled
> girlfriend -- it's cold, unforgiving, and doesn't tell
> you what you've done wrong."
>
Let me toy with it a bit and see how much I love/hate it.

JJ

John Joyce

7/12/2007 11:09:00 PM

0


On Jul 12, 2007, at 6:00 PM, Logan Capaldo wrote:

> On 7/12/07, John Joyce <dangerwillrobinsondanger@gmail.com> wrote:
>>
>>
>> On Jul 12, 2007, at 4:50 PM, Jeremy Henty wrote:
>>
>> > On 2007-07-12, Phrogz <phrogz@mac.com> wrote:
>> >> On Jul 12, 12:43 pm, Jeremy Henty <onepo...@starurchin.org> wrote:
>> >>> On 2007-07-12, John Joyce <dangerwillrobinsondan...@gmail.com>
>> >>> wrote:
>> >>>
>> >>>> With php you can just include a file, but ERb doesn't let you do
>> >>>> that (AFAIK).
>> >>>
>> >>> <%= IO.read "yes_it_does.txt" %>
>> >>
>> >> Not quite when you want the included file to have ERB commands
>> in it:
>> >
>> > Good point!
>> >
>> > <%= ERB.new(IO.read("how_about_this_then.erb")).result(binding) %>
>> >
>> > Jeremy Henty
>> >
>> That's OK I guess, but it's not as graceful as usual Ruby things.
>> I guess I'm going to look into Camping and those others.
>> I checked out the Merb site once but it was all RDoc with no solid
>> examples.
>
>
> You can of course make it more graceful:
>
> def erb_include(path, b = nil)
> b = binding unless b
> ERB.new(IO.read(path)).result(b)
> end
>
>
> <%= erb_include("file.erb") %>
>
> It's still a bit icky w/ local vars :( [But that's part of the
> reason I
> don't like templating like this anyway]
>
>
> CGI is just too ugly, it might as well be Perl for that, I wish
>> DreamHost would run mod_ruby...
>> I'm just finding that Rails is just way more than what I want or
>> need. Lots of cool stuff in it, but the problem is that there is just
>> so much there. Getting started is easy enough, but things start to
>> grind down to a crawl as you beginning unravelling all the details.
>> It's like any big framework, it's highly productive and useful AFTER
>> you've spent months learning it. There's definitely a learning curve
>> and things start to get pretty complicated pretty quickly.
>>
>> It's too bad that ERb itself isn't better tutorialized.
>>
>>
Doesn't seem to work with DreamHost's eruby.cgi or with their
erb.cgi ...
or I'm just an idiot groping in the dark. (mostly likely reason)