<?xml version="1.0"?>
<rss version="2.0">
<channel>
  <title>Spikes Of Nothingness - template tag</title>
  <link>http://weblog.flop.ca/tags/template/</link>
  <description>Florin T.PATRASCU&#039;s blog</description>
  <language>en</language>
  <copyright>Florin T.PATRASCU</copyright>
  <lastBuildDate>Sat, 12 May 2012 02:12:08 GMT</lastBuildDate>
  <generator>Pebble (http://pebble.sourceforge.net)</generator>
  <docs>http://backend.userland.com/rss</docs>
  
  
  <item>
    <title>5 minutes of fun: JRuby and StringTemplate</title>
    <link>http://weblog.flop.ca/2009/11/04/1257357667790.html</link>
    
      
        <description>
          &lt;p&gt; If you like to explore some stuff on templating, and I highly recommend &lt;a href=&#034;http://www.stringtemplate.org/&#034;&gt;StringTemplate&lt;/a&gt;, this is how you can do it from &lt;a href=&#034;http://jruby.org/&#034;&gt;JRuby&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;/p&gt;
&lt;blockquote&gt;
&lt;h1&gt;jrst.rb&lt;/h1&gt;
&lt;pre&gt;&lt;em&gt;&lt;font color=&#034;#b22222&#034;&gt;# A simple JRuby StringTemplate integration demo &lt;br /&gt;&lt;/font&gt;&lt;/em&gt;&lt;em&gt;&lt;font color=&#034;#b22222&#034;&gt;# Notes: &lt;br /&gt;&lt;/font&gt;&lt;/em&gt;&lt;em&gt;&lt;font color=&#034;#b22222&#034;&gt;# - save this script as &#039;jrst.rb&#039;.&lt;br /&gt;&lt;/font&gt;&lt;/em&gt;&lt;em&gt;&lt;font color=&#034;#b22222&#034;&gt;# - in the folder from where you&#039;re executing this simple script, you&#039;ll&lt;br /&gt;&lt;/font&gt;&lt;/em&gt;&lt;em&gt;&lt;font color=&#034;#b22222&#034;&gt;#  have a subfolder: &#039;lib&#039;, containing the StringTemplate libraries:&lt;br /&gt;&lt;/font&gt;&lt;/em&gt;&lt;em&gt;&lt;font color=&#034;#b22222&#034;&gt;#    lib/antlr-2.7.7.jar&lt;br /&gt;&lt;/font&gt;&lt;/em&gt;&lt;em&gt;&lt;font color=&#034;#b22222&#034;&gt;#    lib/stringtemplate-3.2.1.jar&lt;br /&gt;&lt;/font&gt;&lt;/em&gt;&lt;em&gt;&lt;font color=&#034;#b22222&#034;&gt;# run the script&lt;br /&gt;&lt;/font&gt;&lt;/em&gt;&lt;em&gt;&lt;font color=&#034;#b22222&#034;&gt;# $ jruby jrst.rb World&lt;br /&gt;&lt;/font&gt;&lt;/em&gt;&lt;em&gt;&lt;font color=&#034;#b22222&#034;&gt;#&lt;br /&gt;&lt;/font&gt;&lt;/em&gt;&lt;em&gt;&lt;font color=&#034;#b22222&#034;&gt;# You&#039;ll see: Hello World!&lt;br /&gt;&lt;/font&gt;&lt;/em&gt;&lt;em&gt;&lt;font color=&#034;#b22222&#034;&gt;# ----------- &lt;br /&gt;&lt;/font&gt;&lt;/em&gt;&lt;strong&gt;&lt;font color=&#034;#5f9ea0&#034;&gt;require&lt;/font&gt;&lt;/strong&gt; &lt;strong&gt;&lt;font color=&#034;#bc8f8f&#034;&gt;&#039;java&#039;&lt;/font&gt;&lt;/strong&gt;   &lt;br /&gt;&lt;br /&gt;Dir[&lt;strong&gt;&lt;font color=&#034;#bc8f8f&#034;&gt;&amp;quot;lib/*.jar&amp;quot;&lt;/font&gt;&lt;/strong&gt;].each { |jar| &lt;strong&gt;&lt;font color=&#034;#5f9ea0&#034;&gt;require&lt;/font&gt;&lt;/strong&gt; jar }&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;font color=&#034;#a020f0&#034;&gt;class&lt;/font&gt;&lt;/strong&gt; JRubySringTemplate&lt;br /&gt;  include_class &lt;strong&gt;&lt;font color=&#034;#bc8f8f&#034;&gt;&#039;java.io.StringWriter&#039;&lt;/font&gt;&lt;/strong&gt;   &lt;br /&gt;  include_class &lt;strong&gt;&lt;font color=&#034;#bc8f8f&#034;&gt;&#039;org.antlr.stringtemplate.StringTemplate&#039;&lt;/font&gt;&lt;/strong&gt;    &lt;br /&gt;&lt;br /&gt;  &lt;strong&gt;&lt;font color=&#034;#a020f0&#034;&gt;def&lt;/font&gt;&lt;/strong&gt; &lt;strong&gt;&lt;font color=&#034;#0000ff&#034;&gt;render &lt;/font&gt;&lt;/strong&gt;( arg)                         &lt;br /&gt;    st = StringTemplate.new(&lt;strong&gt;&lt;font color=&#034;#bc8f8f&#034;&gt;&amp;quot;Hello $name$!&amp;quot;&lt;/font&gt;&lt;/strong&gt;)&lt;br /&gt;    st.set_attributes( {&lt;strong&gt;&lt;font color=&#034;#bc8f8f&#034;&gt;&#039;name&#039;&lt;/font&gt;&lt;/strong&gt; =&amp;gt; arg});&lt;br /&gt;    writer = StringWriter.new   &lt;br /&gt;    writer.write( st.toString)&lt;br /&gt;    &lt;strong&gt;&lt;font color=&#034;#a020f0&#034;&gt;return&lt;/font&gt;&lt;/strong&gt; writer.getBuffer&lt;br /&gt;  &lt;strong&gt;&lt;font color=&#034;#a020f0&#034;&gt;end&lt;/font&gt;&lt;/strong&gt; &lt;strong&gt;&lt;font color=&#034;#a020f0&#034;&gt;&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;&lt;/font&gt;&lt;/strong&gt;puts JRubySringTemplate.new().render( ARGV[0]) &lt;/pre&gt;
&lt;/blockquote&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt; My 5 minutes of fun in a lunch break. Next time I&#039;ll show you how to use Velocity in the same way :)&lt;br /&gt;
&lt;br /&gt;
Have fun! &lt;/p&gt;
        </description>
      
      
    
    
    
    <category>Ruby</category>
    
    <category>Java</category>
    
    <comments>http://weblog.flop.ca/2009/11/04/1257357667790.html#comments</comments>
    <guid isPermaLink="true">http://weblog.flop.ca/2009/11/04/1257357667790.html</guid>
    <pubDate>Wed, 04 Nov 2009 18:01:07 GMT</pubDate>
  </item>
  
  <item>
    <title>StringTemplate Renderer for JPublish, a Component this time ;)  </title>
    <link>http://weblog.flop.ca/2007/09/01/1188678524233.html</link>
    
      
        <description>
          &lt;p&gt;  &lt;/p&gt;
Hi there,&lt;br /&gt;
&lt;br /&gt;
For those of you maintaining JPublish sites developed with Velocity or FreeMarker, using the newly added StringTemplate renderer is not an easy option, especially if those sites are in production. So what can you do if you want to use ST? &lt;br /&gt;
&lt;br /&gt;
Don&#039;t worry, you can render StringTemplate syntax in Velocity/FreeMarker driven pages by using the StringTemplate component that I just added to the JPublish component family.&lt;br /&gt;
&lt;br /&gt;
Using it is very simple. &lt;br /&gt;
&lt;br /&gt;
Build the ST Component from &lt;a href=&#034;http://jpublish.googlecode.com/svn/trunk/components/jpStringTemplate/&#034;&gt;SVN&lt;/a&gt;&amp;nbsp; and load it in jpublish.xml:&lt;br /&gt;
&lt;blockquote&gt;&amp;lt;component-manager&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;components&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;component id=&amp;quot;JPST&amp;quot; classname=&amp;quot;ca.flop.jpublish.components.JPSTComponent&amp;quot;&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;stringtemplate-groups&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;group name=&amp;quot;default&amp;quot; relative-root-dir=&amp;quot;/st_content&amp;quot; refresh-interval=&amp;quot;15&amp;quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lexer=&amp;quot;org.antlr.stringtemplate.language.DefaultTemplateLexer&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;group name=&amp;quot;menus&amp;quot; relative-root-dir=&amp;quot;/st_menus&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/stringtemplate-groups&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/components&amp;gt;&lt;br /&gt;
&amp;lt;/component-manager&amp;gt;&lt;br /&gt;
&lt;/blockquote&gt;&lt;br /&gt;
and then use the ST component wherever ST is required, for example in a Velocity page:&lt;br /&gt;
&lt;strong&gt;&lt;font color=&#034;#333399&#034;&gt; $components.JPST.renderPath(&amp;quot;menus:main_menu&amp;quot;)&lt;/font&gt;&lt;/strong&gt;, the contents of the &lt;strong&gt;main_menu.st&lt;/strong&gt; file will be immediately rendered in-line.&lt;br /&gt;
&lt;br /&gt;
I will add more details in the &lt;a href=&#034;http://code.google.com/p/jpublish/wiki/JPublishUserGuide&#034;&gt;JPublish Wiki&lt;/a&gt;, meanwhile you can find the code and a &lt;a href=&#034;http://jpublish.googlecode.com/svn/trunk/components/jpStringTemplate/web/&#034;&gt;demo web application&lt;/a&gt; in our SVN.&lt;br /&gt;
&lt;br /&gt;
Have fun!&lt;br /&gt;
-florin
        </description>
      
      
    
    
    
    <category>Java</category>
    
    <comments>http://weblog.flop.ca/2007/09/01/1188678524233.html#comments</comments>
    <guid isPermaLink="true">http://weblog.flop.ca/2007/09/01/1188678524233.html</guid>
    <pubDate>Sat, 01 Sep 2007 20:28:44 GMT</pubDate>
  </item>
  
  </channel>
</rss>

