An example of how I use XBN-Java and Template Feather: Filling live code samples into blog posts

I’m writing a many-part Python Django tutorial, which is a step-by-step for implementing authentication (create/delete web account, login/logout, change/reset password). Each post has multiple code samples, each of which are live code. I therefore have to manually duplicate the code into the post on each change I make.

Instead, I’ve written the following for each post, which manually reads in the live code files, and inserts them into the proper spots in the post-template. (This is only for code-samples that are of the entire file, not a snippet.)

This is built with XBN-Java and Template Featherweight

  import  com.github.aliteralmind.templatefeather.FeatherTemplate;
   import  com.github.aliteralmind.templatefeather.GapCharConfig;
   import  com.github.aliteralmind.templatefeather.Resettable;
 * cd /home/jeffy/django_files/django_auth_lifecycle/non_django_files/wordpress_posts/build/
 * java -classpath .:/home/jeffy/django_files/django_auth_lifecycle/non_django_files/wordpress_posts/build/dependency_jars/xbnjava- BuildPartThree
public class BuildPartThree  {
   public static final void main(String[] ignored)  {
         String inputRoot = "/home/jeffy/django_files/django_auth_lifecycle/";
         String postRoot = inputRoot + "non_django_files/wordpress_posts/";
         String inputPath = postRoot + "03_main_view.html.html";
         String outputPath = postRoot + "build/output/03_main_view.html__built.html";

         GapCharConfig gapcfg = new GapCharConfig('@', '@',
            "__AT_SIGN_START__", "__AT_SIGN_END__");

      //Read in raw template
         String origText = PlainTextFileUtil.getText(inputPath, "origText");
         FeatherTemplate tmpl = new FeatherTemplate(origText, gapcfg,
            Resettable.NO, System.out);

      //Read in source code, one per gap
         String alRoot = inputRoot + "djauth_root/auth_lifecycle/";

         String viewMainDotPy = PlainTextFileUtil.getText(alRoot + "", "viewMainDotPy").
         String mainPageDotHtml = PlainTextFileUtil.getText(alRoot + "main_page.html", "mainPageDotHtml").
         String testViewMainDotPy = PlainTextFileUtil.getText(alRoot + "", "testViewMainDotPy").
         String alUrlsDotPy = PlainTextFileUtil.getText(alRoot + "", "alUrlsDotPy").

      //Fill in gaps with read-in code

         //Example gap: @view__main_dot_py@

         String rendered = tmpl.
               fill("view__main_dot_py", viewMainDotPy).
               fill("main_page_dot_py", mainPageDotHtml).
               fill("test__view_main_dot_py", testViewMainDotPy).
               fill("al_urls_dot_py", alUrlsDotPy).

      //Global replacement
         rendered = rendered.replace("/home/jeffy/", "/home/myname/");

      //Write out result
         PlainTextFileUtil.openWriteClose(outputPath, "outputPath",
            Overwrite.YES, rendered);

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s