Tagged: Web RSS Toggle Comment Threads | Keyboard Shortcuts

  • Sasha O 12:53 pm on 2012-01-29 Permalink | Reply
    Tags: , templates, variable substitution, Web   

    Bristle template: when you don’t have time to do your Moustache 

    Usually I generate my pages with Velocity. Recently I had a project where even implementing Velocity was not worth the time. I tried both MessageFormatter and StringTemplates and both had problems with some portion of HTML/Javascript markup.

    So I did what we, engineers always do in this situation: run your own. Good news, it took just over an hour and I ended with a single very small file. It  can only variable substitution but that was enough for me. Here it is:

    http://codebistro.googlecode.com/svn/trunk/misc/src/main/java/org/codebistro/util/BristleTemplate.java

    The best part: it has no dependencies so you can just copy file into your project and template away.

    Of course you can Maven just as well:

        <repositories>
            ...
            <repository>
                <id>codebistro-open</id>
                <name>codebistro-open repo</name>
                <layout>default</layout>
                <url>http://codebistro.googlecode.com/svn/repo/</url&gt;
            </repository>
            ...
        </repositories>
        ...
        <dependencies>
            ...
            <dependency>
                <groupId>org.codebistro.util</groupId>
                <artifactId>misc</artifactId>
                <version>1.0-SNAPSHOT</version>
            </dependency>
         <dependencies>

    Microframeworks are popular these days. This thing doesn’t even qualify to be called micro- or even nano- but I got a feeling I am going to use Bristle template in the future…

     
  • codebistro 5:41 am on 2008-12-23 Permalink | Reply
    Tags: Development, Web   

    The AHAH! Moment 

    By my faith! For more than forty years I have been speaking prose without knowing anything about it, and I am much obliged to you for having taught me that.

    Molière

    We have been doing AHAH for a few months and now I know! The thing definitely makes sense, especially as the app gets more complicated and every bit of code shaved off the client side saves us a bit of our lives.

    The performance still requires investigation. For now I assume that transparent gzip compression can make HTML snippets just about as small as compressed JSON responses.

     
    • Burton 11:56 pm on 2010-03-09 Permalink | Reply

      codeibstro.com, how do you do it?

    • Sasha Ovsankin 10:53 am on 2010-03-11 Permalink | Reply

      Well the main advantage here to avoid duplication (DRY). Imagine a web page which is both rendered by the server (for SEO) as well as dynamically, via AJAX. Something like Twitter. If you do the AJAX rendering the usual way — get the data via JSON and then “dress it up” into HTML, you end up with 2 totally different pieces of rendering code which should be synchronized, a headache.

      Using AHAH, you render both of them using the same code on the server side, transfer the rendered piece via AJAX and then the client-side JavaScript would only stick it at a proper place in DOM. Makes sense?

      However since the time of this post things changed a bit: the HTML has become more “semantic” so the rendering magic shifted to CSS which can be safely reused by both sides. Also, we made some sort of browser-side templates: we put template in HTML with “display:none”, then for rendering we copy it, populate and make it visible. Still a bit of duplication but not really a big problem. So AHAH is not used that much any more.

    • Anton 6:40 pm on 2010-06-28 Permalink | Reply

      wikipedia link got deleted, that one worked fine for me

      http://microformats.org/wiki/rest/ahah

      • codebistro 11:29 pm on 2010-06-28 Permalink | Reply

        Thanks, fixed the enry

c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
shift + esc
cancel
Follow

Get every new post delivered to your Inbox.