ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> ruby-talk
ruby-talk
Re: Create HTML files using RUBY
by Ehsanul Hoque other posts by this author
Nov 4 2009 9:25PM messages near this date
Re: Create HTML files using RUBY | Re: Create HTML files using RUBY
>  If I was going to write this myself I'd try something like:
>  
>  def h1
>     print "<H1>"
>     yield
>     print "</H1>"
>  end
>  
>  h1 do
>     print "I'm a heading!"
>  end
>  
>  => <H1>I'm a heading!</h1>
>  
>  
>  By yielding to the block you allow yourself to nest other tags
>  inside of tags which is something you often have to do when writing
>  html.
>  
>  Good luck.


That's nice. I suggest that if the OP wants to use your suggested method, maybe do it this w
ay:


class MyHtml
  def self.generate(&block)
    "<html> \n" +
    self.new.instance_eval(&block) +
    "\n</html> "
    end
  def body

    
"<body> \n#{ yield }\n</body>"
  end

  def h1
    
"<h1> #{ yield }</h1>"

  end
end

MyHtml.generate do
  body do
    h1 { "This heading was generated by pure ruby" }
  end
end


Or just use builder or something :P (though it seems like that just might not be allowed for
 the OP, as I suspect whoever is assigning this work expects a real html generator implement
ation.

- Ehsan
 		 	   		  
_________________________________________________________________
Hotmail: Trusted email with powerful SPAM protection.
http://clk.atdmt.com/GBL/go/177141665/direct/01/
Thread:
Krithika San
Greg Barozzi
David
Ehsanul Hoque
Ken Bloom
Gregory Brown
Ehsanul Hoque
Marnen Laibow-Koser
William Manire
Marnen Laibow-Koser
Krithika San
Marnen Laibow-Koser
Krithika San
Justin Collins
Krithika San
Marnen Laibow-Koser
Krithika San
Brian Candler
Marnen Laibow-Koser
Marc Heiler
William Manire
Gregory Brown
Gregory Brown

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved