- Revision
- 585
- Author
- paul
- Date
- 2008-02-06 23:47:31 -0600 (Wed, 06 Feb 2008)
Log Message
reformat
Modified Paths
- trunk/waffle-distribution/src/site/content/accessing-java-from-ruby.html
- trunk/waffle-distribution/src/site/content/ruby-controllers.html
- trunk/waffle.ipr
Diff
Modified: trunk/waffle-distribution/src/site/content/accessing-java-from-ruby.html (584 => 585)
--- trunk/waffle-distribution/src/site/content/accessing-java-from-ruby.html 2008-02-06 21:08:32 UTC (rev 584) +++ trunk/waffle-distribution/src/site/content/accessing-java-from-ruby.html 2008-02-07 05:47:31 UTC (rev 585) @@ -1,23 +1,22 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html><head><meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type" /> <title>Accessing Java from Ruby</title></head> - <body> Waffle: How to access your Java components from your Ruby Actions.<br /><br />In my last post I gave an overview of how you can easily integrate JRuby with Waffle. Now we will examine Ruby based controller in a bit more depth. Lets assume we have the following Waffle Registrar for our -application:<br /><br />public class MyRegistrar extends AbstractRubyAwareRegistrar {<br /><br /> public MyRegistrar(Registrar delegate) {<br /> super(delegate);<br /> }<br /><br /> @Override<br /> public void application() {<br /> register("the_dao", PersonDAOImpl.class);<br /><br /> registerRubyScript("person", "PersonController");<br /> }<br />}<br /><br />A +application:<br /><pre>public class MyRegistrar extends AbstractRubyAwareRegistrar {<br /> public MyRegistrar(Registrar delegate) {<br /> super(delegate);<br /> }</pre><pre><br /> @Override<br /> public void application() {<br /> register("the_dao", PersonDAOImpl.class);<br /> registerRubyScript("person", "PersonController");<br /> }<br />}</pre>A DAO, PersonDAOImpl, is registered under the name "the_dao" and we have one Ruby based controller available. Now its probably safe to assume that this Ruby PersonController will need access to the DAO. Gaining access to this DAO from the controller is easy in Waffle, just call the -locate method:<br />class PersonController<br /><br /> def index<br /> @person_dao = locate(example.PersonDAO)<br /><br /> @people = @person_dao.findAll<br /> render 'person.rhtml'<br /> end<br /><br />end<br /><br />Notice +locate method:<br /><pre>class PersonController<br /> def index<br /> @person_dao = locate(example.PersonDAO)<br /> @people = @person_dao.findAll<br /> render 'person.rhtml'<br /> end<br />end</pre>Notice that we were able to retrieve the DAO by its interface. Additionally, since this DAO was registered with a key you can use a convention to retrieve the component. The convention is "locate_<component -key>", here is the same controller using the locate_ convention:<br />class PersonController<br /><br /> def index<br /> @person_dao = locate_the_dao<br /><br /> @people = @person_dao.findAll<br /> render 'person.rhtml'<br /> end<br /><br />end<br /><br />As +key>", here is the same controller using the locate_ convention:<br /><pre>class PersonController<br /> def index<br /> @person_dao = locate_the_dao<br /> @people = @person_dao.findAll<br /> render 'person.rhtml'<br /> end<br />end</pre>As you can see this makes writing Ruby based Controllers/Actions with Waffle really easy. In my next post I'll detail how to access request parameter and context attributes with ease.
Modified: trunk/waffle-distribution/src/site/content/ruby-controllers.html (584 => 585)
--- trunk/waffle-distribution/src/site/content/ruby-controllers.html 2008-02-06 21:08:32 UTC (rev 584) +++ trunk/waffle-distribution/src/site/content/ruby-controllers.html 2008-02-07 05:47:31 UTC (rev 585) @@ -1,7 +1,6 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html><head> <title>Ruby Controllers</title></head> - <body>Ever wish you could utilize Ruby from your Java based web applications?<br /><br />Waffle, a Java based Web Framework, now provides built in support for JRuby. This will allow you to easily write your Controllers in Ruby. The @@ -20,16 +19,16 @@ pluggability. The following three context-param nodes need to be added to your applications web.xml. This alerts Waffle that a few of its foundational components should be replaced with alternate -implementations.<br /><br /><context-param><br /> <param-name>org.codehaus.waffle.context.ContextContainerFactory</param-name><br /> <param-value>org.codehaus.waffle.context.pico.RubyAwarePicoContextContainerFactory</param-value><br /></context-param><br /><context-param><br /> <param-name>org.codehaus.waffle.bind.DataBinder</param-name><br /> <param-value>org.codehaus.waffle.bind.RubyDataBinder</param-value><br /></context-param><br /><context-param><br /> <param-name>org.codehaus.waffle.controller.ControllerDefinitionFactory</param-name><br /> <param-value>org.codehaus.waffle.controller.RubyControll erDefinitionFactory</param-value><br /></context-param><br /><br />Step +implementations.<br /><pre><context-param><br /> <param-name>org.codehaus.waffle.context.ContextContainerFactory</param-name><br /> <param-value>org.codehaus.waffle.context.pico.RubyAwarePicoContextContainerFactory</param-value><br /></context-param></pre><pre><context-param><br /> <param-name>org.codehaus.waffle.bind.DataBinder</param-name><br /> <param-value>org.codehaus.waffle.bind.RubyDataBinder</param-value><br /></context-param></pre><pre><context-param><br /> <param-name>org.codehaus.waffle.controller.ControllerDefinitionFactory</param-name><br /> <param-value>org.codehaus.waffle.co ntroller.RubyControllerDefinitionFactory</param-value><br /></context-param></pre>Step 2 - Your application's Registrar should extended AbstractRubyAwareRegistrar. This exposes a new registration method to use within your Registrar ... registerRubyScript(String key, String -className). See the example below: <br />public class MyRegistrar extends AbstractRubyAwareRegistrar {<br /><br /> public MyRegistrar(Registrar delegate) {<br /> super(delegate);<br /> }<br /> <br /> @Override<br /> public void application() {<br /> registerRubyScript("foobar", "FooBar");<br /> }<br /> ...<br />}<br /><br />In +className). See the example below: <br /><pre>public class MyRegistrar extends AbstractRubyAwareRegistrar {<br /> public MyRegistrar(Registrar delegate) {<br /> super(delegate);<br /> } </pre><pre> @Override<br /> public void application() {<br /> registerRubyScript("foobar", "FooBar");<br /> }<br /> ...<br />}</pre>In this example the Ruby class named 'FooBar' will be exposed as a Controller under the name 'foobar' (e.g. http://localhost:8080/jruby/foobar.waffle).<br /><br />Step 3 - Write your Ruby Controller class. Notice in the following example that your -class does not need to extend or include anything.<br />class FooBar<br /><br /> def index # This is the default action<br /> "<h1>Hello World</h1>"<br /> end<br /> <br />end<br /><br />And +class does not need to extend or include anything.<br /><pre>class FooBar<br /> def index # This is the default action<br /> "<h1>Hello World</h1>"<br /> end <br />end</pre>And that is all the steps required to integrate JRuby within your Waffle Applications. In my next post I will uncover details on how to access registered components from your Ruby based controllers as well as
Modified: trunk/waffle.ipr (584 => 585)
--- trunk/waffle.ipr 2008-02-06 21:08:32 UTC (rev 584) +++ trunk/waffle.ipr 2008-02-07 05:47:31 UTC (rev 585) @@ -406,8 +406,5 @@ <component name="com.intellij.profile.ui.ErrorOptionsConfigurable" proportions="" version="1"> <option name="myLastEditedConfigurable" /> </component> - <UsedPathMacros> - <macro name="M2_REPOSITORY" /> - </UsedPathMacros> </project>
To unsubscribe from this list please visit:
