Created
July 20, 2012 21:16
-
-
Save kek/3153275 to your computer and use it in GitHub Desktop.
Writing a CGI script with templates. For PHP programmers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'cgi' | |
require 'erb' | |
cgi = CGI.new('html') | |
template = <<TEMPLATE | |
<html> | |
<head> | |
<title>Ruby as PHP</title> | |
</head> | |
<body> | |
<h1>Loop</h1> | |
<ul> | |
<% 1.upto(5).each do |i| %> | |
<li>Number <%= i %></li> | |
<% end %> | |
</ul> | |
</body> | |
TEMPLATE | |
html = ERB.new(template).result(binding) | |
cgi.out { html } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment