943,946 Members | Top Members by Rank

Ad:
  • Ruby Discussion Thread
  • Unsolved
  • Views: 4238
  • Ruby RSS
Nov 4th, 2009
0

Create HTML files using RUBY

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
skrithikaa is offline Offline
4 posts
since Oct 2009
Nov 8th, 2009
0
Re: Create HTML files using RUBY
There's really nothing special other than just outputting HTML syntax inside of a file named with an htm or html extension.

Ruby Syntax (Toggle Plain Text)
  1. fileHtml = File.new("fred.html", "w+")
  2. fileHtml.puts "<HTML><BODY BGCOLOR='green'>"
  3. fileHtml.puts "<CENTER>this is neat</CENTER>"
  4. fileHtml.puts "</BODY></HTML>"
  5. fileHtml.close()
Featured Poster
Reputation Points: 290
Solved Threads: 277
Posting Virtuoso
thines01 is offline Offline
1,686 posts
since Oct 2009
Nov 8th, 2009
0
Re: Create HTML files using RUBY
...here's a more robust example (with sloppy html):
Ruby Syntax (Toggle Plain Text)
  1.  
  2. fileHtml = File.new("fred.html", "w+")
  3. fileHtml.puts "<HTML><BODY BGCOLOR='green'>"
  4. fileHtml.puts "<CENTER>this is neat</CENTER><br>"
  5. fileHtml.puts "<CENTER><FONT COLOR='yellow'>this is neat</FONT></CENTER>"
  6.  
  7. fileHtml.puts "<TABLE BORDER='1' ALIGN='center'>"
  8. fileHtml.puts "<TR><TH>HEADER</TH></TR>"
  9. fileHtml.puts "<TR><TD>Cell in <FONT COLOR='RED'>TableThing</FONT></TD></TR>"
  10. fileHtml.puts "</TABLE>"
  11.  
  12. fileHtml.puts "<TABLE BORDER='0' ALIGN='center'>"
  13. fileHtml.puts "<TR><TH>HEADER on borderless</TH></TR>"
  14. fileHtml.puts "<TR><TD>Cell in borderless<FONT COLOR='white'>TableThing</FONT></TD></TR>"
  15. fileHtml.puts "</TABLE>"
  16. fileHtml.puts "</BODY></HTML>"
  17. fileHtml.close()
  18.  
  19. system("start fred.html") #...on windows
Featured Poster
Reputation Points: 290
Solved Threads: 277
Posting Virtuoso
thines01 is offline Offline
1,686 posts
since Oct 2009
Nov 12th, 2009
0
Re: Create HTML files using RUBY
You also can use a (rather antiquidated, but included) cgi class.
The CGI class would be like
ruby Syntax (Toggle Plain Text)
  1. #!/usr/bin/env ruby
  2. # *-ruby-*-
  3. require 'cgi'
  4.  
  5. # Create an instance of CGI, with HTML 4 output
  6. cgi = CGI.new("html4")
  7.  
  8. # Send the following to the CGI object's output
  9. cgi.out {
  10. cgi.html {
  11.  
  12. # Produce a header
  13. cgi.head { cgi.title { "This is a title" }
  14. } +
  15.  
  16. # Produce a body
  17. cgi.body {
  18. cgi.h1 { "This is a headline" } +
  19. cgi.p { "Hello, world." }
  20. }
  21. }
  22. }
Docs: http://ruby-doc.org/stdlib/libdoc/cgi/rdoc/index.html
If your looking for templating etc, try looking at haml-lang.org
Reputation Points: 18
Solved Threads: 21
Junior Poster
codejoust is offline Offline
180 posts
since Jul 2009
Nov 13th, 2009
0

Create Api to create document and add, edit, delete text

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
skrithikaa is offline Offline
4 posts
since Oct 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Ruby Forum Timeline: (Installed Ruby 1.9.1) gem isn't working
Next Thread in Ruby Forum Timeline: Meaning of '!(...' EG: "myObject.parse!(argv)" ..?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC