<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Latest posts for the topic "MentaOnRuby: Custom tags for RSP"]]></title>
		<link>http://blogs.mentaframework.org/posts/list/2.page</link>
		<description><![CDATA[Latest messages posted in the topic "MentaOnRuby: Custom tags for RSP"]]></description>
		<generator>JForum - http://www.jforum.net</generator>
			<item>
				<title>MentaOnRuby: Custom tags for RSP</title>
				<description><![CDATA[ The version 0.4b was released with some nice improvements. Thanks to Mauricio Linhares for the good tips. Here are the improvements:<br /> <br /> :arrow: Input, Output, Session, Application, Cookies now support the [] and []= methods to work like Ruby hashes.<br /> <br /> So instead of:<br /> [code]<br /> class Hello &lt; Action<br /> <br />     def execute<br />       username = input.get("username")<br />       output.put("hi", "Hello #{username.upcase}")<br />       :SUCCESS<br />     end<br /> <br /> end<br /> [/code]<br /> <br /> You can have:<br /> [code]<br /> <br /> class Hello &lt; Action<br /> <br />     def execute<br />       username = input["username"]<br />       output["hi"] = "Hello #{username.upcase}"<br />       :SUCCESS<br />     end<br /> <br /> end<br /> [/code]<br /> :arrow: In the RSP (ERB file) you can now use the instance methods input, output, session, application, cookies and page.<br /> <br /> Instead of:<br /> [code]<br /> &lt;%= action.output.get("hi") %&gt;<br /> [/code]<br /> You can do:<br /> [code]<br /> &lt;%= output['hi'] %&gt;<br /> [/code]<br /> :arrow: [b][color="blue"]Support for MentaTags (tags that come with MentaOnRuby) and CustomTags (tags that you can code yourself)[/b][/color].<br /> <br /> The first MentaTag:<br /> [code]<br /> &lt;!-- t_out = print a value from the output --&gt;<br /> &lt;%= t_out('hi') %&gt;<br /> [/code]<br /> Let's create our own tag now. Place the following code inside the file HelloMerb/app/controllers/my_tag.rb:<br /> [code]<br /> require 'Mentawai/tag/base_tag'<br /> <br /> include Mentawai::Tag<br /> <br /> class MyTag &lt; BaseTag<br /> <br />   def sayHello(params)<br />     attr1 = params[:attr1]<br />     attr2 = params[:attr2]<br />     attr3 = params[:attr3]<br />     "#{attr1}/#{attr2}/#{attr3}"<br />   end<br /> <br /> end<br /> [/code]<br /> In your application manager, just define your new tag like that:<br /> [code]<br /> require 'Mentawai/core/app_manager'<br /> require 'Mentawai/core/forward'<br /> <br /> require 'my_tag'<br /> <br /> include Mentawai::Core<br /> <br /> class AppManager &lt; ApplicationManager<br /> <br />   def init(appContext)<br />   <br />     action("Hello").on(:SUCCESS =&gt; Forward.new("sayHello"))<br />     <br />     addCustomTag('myTag', :tag =&gt; 'MyTag', :method =&gt; 'sayHello' )<br />   end<br />   <br /> end<br /> [/code]<br /> Now in the HelloMerb/app/views/sayHello.html.erb you can use your tag like a regular Ruby method.<br /> [code]<br /> &lt;%= myTag(:attr1 =&gt; 'Hello', :attr2 =&gt; 'Bye', :attr3 =&gt; 'Tchau' ) %&gt;<br /> [/code]<br /> Mentawai will turn tags into instance methods of the controller, so you are free to call them in your pages.<br /> <br /> You can download the new version from the Mentawai site: http://www.mentaframework.org/ruby/MentaOnRuby-0.4b.zip<br /> <br /> Feel free to share your comments! There is much work to be done yet, but we are moving forward!<br /> <br /> ]]></description>
				<guid isPermaLink="true">http://blogs.mentaframework.org/posts/preList/16/25.page</guid>
				<link>http://blogs.mentaframework.org/posts/preList/16/25.page</link>
				<pubDate><![CDATA[Fri, 29 Feb 2008 16:07:50]]> GMT</pubDate>
				<author><![CDATA[ saoj]]></author>
			</item>
	</channel>
</rss>