<?xml version="1.0"?>
<rss version="2.0">
<channel>
  <title>Spikes Of Nothingness - stringtemplate tag</title>
  <link>http://weblog.flop.ca/tags/stringtemplate/</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>
  
  <item>
    <title>StringTemplate for JPublish</title>
    <link>http://weblog.flop.ca/2007/08/23/1187872320000.html</link>
    
      
        <description>
          &lt;br /&gt;
A couple of weeks ago I stumbled on a few articles about the StringTemplate framework and then, digging further, I started to be attracted by the idea of using &lt;a href=&#034;http://www.stringtemplate.org/&#034;&gt;StringTemplate&lt;/a&gt; for rendering pages in JPublish.&lt;br /&gt;
&lt;br /&gt;
I also needed to be able to learn to use StringTemplate and this is how I found few more very good blog articles at &lt;a href=&#034;http://hardlikesoftware.com/weblog&#034;&gt;Hardlikesoftware&lt;/a&gt;. &lt;br /&gt;
&lt;br /&gt;
In order to learn something, you need to start using it, or at least this is the principle that guides me, and this is how the StringTemplateViewRenderer was born :)&lt;br /&gt;
&lt;br /&gt;
Now you can use StringTemplate to design your web site with JPublish. Is very simple, and to convince you, below are few hints to get you started.&lt;br /&gt;
&lt;br /&gt;
- get &lt;a href=&#034;http://code.google.com/p/jpublish/&#034;&gt;JPublish&lt;/a&gt; (optional but good to have it handy)&lt;br /&gt;
- download a very simple StringTemplate based JPublish web demo application from &lt;a href=&#034;http://jpublish.googlecode.com/files/stdemo.war.zip&#034;&gt;here&lt;/a&gt;.&lt;br /&gt;
- in your jpublish.xml of the application you downloaded before you&#039;ll find the definition for the the StringTemplateViewRenderer:&lt;br /&gt;
&lt;blockquote&gt;&amp;lt;!--StringTemplate Viewer--&amp;gt;&lt;br /&gt;
&amp;lt;view-renderer classname=&amp;quot;org.jpublish.view.stringtemplate.StringTemplateViewRenderer&amp;quot;&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!--&amp;lt;lexer class=&amp;quot;org.antlr.stringtemplate.language.AngleBracketTemplateLexer&amp;quot;/&amp;gt;--&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;lexer class=&amp;quot;org.antlr.stringtemplate.language.DefaultTemplateLexer&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!-- todo: &amp;lt;error-listener class=&amp;quot;&amp;quot;/&amp;gt;--&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;refresh-interval&amp;gt;15&amp;lt;/refresh-interval&amp;gt;&lt;br /&gt;
&amp;lt;/view-renderer&amp;gt;&lt;br /&gt;
&lt;/blockquote&gt; For integrating ST with JPublish I am using the Repository objects in JPublish which represent an abstract layer above the file system. Then for every Repository you define in jpublish.xml I am creating a new StringTemplateGroup with the name of the repository and the template root directory being that one of the Repository.&lt;br /&gt;
&lt;br /&gt;
So for example, for every JPublish repositories defined, let&#039;s say you define the &lt;strong&gt;fs_repository&lt;/strong&gt; like this:&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt; &amp;lt;repository name=&amp;quot;fs_repository&amp;quot; classname=&amp;quot;org.jpublish.repository.filesystem.FileSystemRepository&amp;quot;&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;root&amp;gt;content&amp;lt;/root&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;cache&amp;gt;default&amp;lt;/cache&amp;gt;&lt;br /&gt;
&amp;lt;/repository&amp;gt;&lt;br /&gt;
&lt;/blockquote&gt; when the StringTemplateViewRenderer is initialized, a StringTemplateGroup will be defined for every repository:&lt;br /&gt;
&lt;blockquote&gt; ...&lt;br /&gt;
stg = new StringTemplateGroup(repository.getName(),&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;&amp;nbsp; repository.pathToFile(EMPTY_STRING).getAbsolutePath(), lexer);&lt;br /&gt;
...&lt;br /&gt;
&lt;/blockquote&gt; For the repository defined above, a new StringTemplateGroup called &amp;quot;fs_repository&amp;quot; will be created as having the template root to the folder &#039;content&#039; in your web application and the lexer defined earlier in jpublish.xml; &lt;strong&gt;org.antlr.stringtemplate.language.DefaultTemplateLexer &lt;/strong&gt;respectively.&lt;br /&gt;
&lt;br /&gt;
Then for every page requested from JPublish, a StringTemplateGroup will be asked to return a StringTemplate instance of the page your want.&lt;br /&gt;
&lt;br /&gt;
Exciting enough to get you interested in learning/using StringTemplate for web development? For me sure is, and I just started to learn ST :)&lt;br /&gt;
&lt;br /&gt;
Have fun!&lt;br /&gt;
-florin
        </description>
      
      
    
    
    
    <category>Java</category>
    
    <comments>http://weblog.flop.ca/2007/08/23/1187872320000.html#comments</comments>
    <guid isPermaLink="true">http://weblog.flop.ca/2007/08/23/1187872320000.html</guid>
    <pubDate>Thu, 23 Aug 2007 12:32:00 GMT</pubDate>
  </item>
  
  </channel>
</rss>

