0

Hi,

How do you create HTML files using RUBY. I have a requirement where I need to set color and font of the text, and also provide formatting options for tables having different colors for rows and border(on/off).

Can anybody tell how to do this

Thanks,
K

3
Contributors
4
Replies
8
Views
7 Years
Discussion Span
Last Post by skrithikaa
0

There's really nothing special other than just outputting HTML syntax inside of a file named with an htm or html extension.

fileHtml = File.new("fred.html", "w+")
fileHtml.puts "<HTML><BODY BGCOLOR='green'>"
fileHtml.puts "<CENTER>this is neat</CENTER>"
fileHtml.puts "</BODY></HTML>"
fileHtml.close()
0

...here's a more robust example (with sloppy html):

fileHtml = File.new("fred.html", "w+")
fileHtml.puts "<HTML><BODY BGCOLOR='green'>"
fileHtml.puts "<CENTER>this is neat</CENTER><br>"
fileHtml.puts "<CENTER><FONT COLOR='yellow'>this is neat</FONT></CENTER>"

fileHtml.puts "<TABLE BORDER='1' ALIGN='center'>"
fileHtml.puts "<TR><TH>HEADER</TH></TR>"
fileHtml.puts "<TR><TD>Cell in <FONT COLOR='RED'>TableThing</FONT></TD></TR>"
fileHtml.puts "</TABLE>"

fileHtml.puts "<TABLE BORDER='0' ALIGN='center'>"
fileHtml.puts "<TR><TH>HEADER on borderless</TH></TR>"
fileHtml.puts "<TR><TD>Cell in borderless<FONT COLOR='white'>TableThing</FONT></TD></TR>"
fileHtml.puts "</TABLE>"
fileHtml.puts "</BODY></HTML>"
fileHtml.close()

system("start fred.html") #...on windows
0

You also can use a (rather antiquidated, but included) cgi class.
The CGI class would be like

#!/usr/bin/env ruby
# *-ruby-*-
require 'cgi'

# Create an instance of CGI, with HTML 4 output
cgi = CGI.new("html4")

# Send the following to the CGI object's output
cgi.out {
  cgi.html {

# Produce a header
cgi.head { cgi.title { "This is a title" }
} +

# Produce a body
cgi.body {
  cgi.h1 { "This is a headline" } +
    cgi.p { "Hello, world." }
}
  }
}

Docs: http://ruby-doc.org/stdlib/libdoc/cgi/rdoc/index.html
If your looking for templating etc, try looking at haml-lang.org

0

Sub: Create Api to create document and add, edit, delete text and
table(add row, modify and delete row)

Can somebody please tell me how to implement this using inheritence /
composition / patterns ?

Thanks,
skrithikaa Sub: Create Api to create document and add, edit, delete text and
table(add row, modify and delete row)

Can somebody please tell me how to implement this using inheritence /
composition / patterns ?

Thanks,
skrithikaa

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.