Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby in HTML like PHP

Tags:

html

php

ruby

What would be the closest thing to having Ruby in HTML like for PHP with <?php ?> tags?

Can it be done without the need of frameworks that impose website structure or without the need to run Ruby servers, ecc... ?

Is there a way?

like image 836
JfredoJ Avatar asked Sep 29 '22 10:09

JfredoJ


2 Answers

rack-server-pages

Rack middleware and application for serving dynamic pages in very simple way. There are no controllers or models, just only views like a jsp, asp and php!

https://github.com/migrs/rack-server-pages

https://stackoverflow.com/a/32938202/988591

You can run it with "rackup" or any app server supporting rack. For example with passenger you just need to go to the folder where config.ru is and run "passenger start".

like image 132
JfredoJ Avatar answered Oct 02 '22 14:10

JfredoJ


You're looking for erb files.

Open a test.erb file and write this down:

<h1><%= "hello" %></h1>

then run it with:

ruby -rerb -e 'puts ERB.new(File.read("test.erb")).result'

To run erb within a webser you need to wrap it somehow.

Here is a gem that does the job:

Serve - A Rapid Prototyping Framework for Web Applications

gem install serve

And then run it on the directory where your scripts are:

serve

The standard address is localhost:4000

like image 20
Guilherme Viebig Avatar answered Oct 02 '22 14:10

Guilherme Viebig