Templating system

I knew when I start­ed this project (which was a while ago, I kin­da cheat­ed on this one) that I didn’t want to write out all the HTML myself, I’m not THAT masochis­tic. What I want­ed to do was basi­cal­ly say “make a text box to write the address in”.

So I start­ed with a gener­ic pre­proces­sor. I’ve use pre­proces­sors such as CPP, TeX and Make so fig­ured I would take a gener­ic pre­proces­sor like M4 and define a few HTML macros… prob­lem solved. Unfor­tu­nate­ly it wasn’t that sim­ple and as I added com­plex­i­ty it got hard­er to keep it all straight, par­tic­u­lar­ly the quot­ing.

The basic text box wasn’t too bad.

dnl TEXT_Q(name, label, [length])
define(TEXT_Q, indir(LAYOUT, $1,
    ‘<label for=”$1_text”>$2</label>’,
    ‘<input id=”$1_text” name=”$1ifelse($3, ‘’, ‘’, ‘size=”$3″’)>’

But when I tried to cre­ate option­al group­ings it start­ed to get messy. This is a snip­pit from TABULAR_OPTIONAL_ROWS and call­ing it.

    dnl Build the head­ing rows
    <tr class=“tabular_optional_rows_heading_row”>
    pushdef(LAYOUT, TABULAR_OPTIONAL_ROWS_HEADING_LAYOUT)
    foreach(‘XXXXX’, (dquote(shift($@))), ‘XXXXX’)
    popdef(LAYOUT)
    </tr>


TABULAR_OPTIONAL_ROWS(3,
    TEXT_Q(salary_abn, Pay­ers Aus­tralian busi­ness num­ber, 11), dnl TODO: Should be Payer’s
    

With TABULAR_OPTIONAL_ROWS I couldn’t fig­ure out how to have a vari­able num­ber of rows and I couldn’t fig­ure out how to pass it’s options with­out quot­ing so I decid­ed to throw in the tow­el and switch to some­thing else.

I had exper­i­ment­ed with Tem­plate Toolk­it at work using it to inject snip­pits of Javascript into HTML doc­u­ments. In the end I stopped using it and had a sta­t­ic HTML page which includ­ed a ful­ly gen­er­at­ed Javascript file but the short expo­sure I had impressed me and I tried it here. I found it much clean­er, the named para­me­ters cut out a lot of com­plex­i­ty and the abil­i­ty to just drop back to Perl if I want­ed to do some­thing real­ly hairy was nice.

This is the def­i­n­i­tion of a text box fol­lowed by the call­ing syn­tax of a radio box that tog­gles the vis­i­bil­i­ty of the text box.


<tr class=“text” id=[% name %]_row” 
    [%- IF hide -%]
        style=“dis­play: none”
    [%- END -%]
>
<td class=“ques­tion”>
    <label for=[% name %]_id”>[% text %]</label>
</td>
<td class=“answer”>
    <input type=“text” name=[% name %] id=[% name %]_id”>
</td>
</tr>


[% INCLUDE tax/radio
    name = “surname_changed”
    text = “Has any part of your name changed since com­plet­ing your last tax return?”
    mod­i­fy = “previous_surname”
    options = [{name => “Yes”, action => “show”}, {name => “No”, action => “hide”}]
%]

[% INCLUDE tax/text
    name = “previous_surname”
    text = “Pre­vi­ous sur­name”
    hide = “true”
%]

The nor­mal syn­tax for options is sim­ply [“Yes”, “No”], the Perl fall­back I men­tioned ear­li­er allows me to have more com­plex syn­tax when I need it but keeps things sim­ple most of the time. I’ve since dis­cov­ered there’s a Tem­plate Toolk­it ver­sion three that’s a nice step for­ward but it’s list­ed as still in devel­op­ment and in a very Alpha state, it also smelt a bit like it was suf­fer­ing from clas­sic sec­ond project woes. I think I’m play­ing with enough new stuff not to add exper­i­men­tal Tem­plate Toolk­it ver­sions to the list.

Goal — Online tax returns

For my first project I am going to make a web based tax return cre­ator for Aus­tralian tax returns.

The Aus­tralian Tax Office (ATO) pro­duces E-Tax, a pro­gram for Win­dows com­put­ers that allows you to pro­duce a tax return and sub­mit it online. Sad­ly it’s very much Win­dows only though they sug­gest explor­ing run­ning Win­dows in a vir­tu­al machine. They are cur­rent­ly “inves­ti­gat­ing” sup­port­ing oth­er plat­forms, but they have been doing this for years now and I’ve seen third hand cor­re­spon­dence that sug­gests the inves­ti­ga­tion isn’t pro­gress­ing par­tic­u­lar­ly quick­ly.

You can also fill in the return by hand on paper, com­plete with explana­to­ry book­lets. In prac­tice the pro­ce­dure for both is basi­cal­ly the same, the advan­tage of doing it dig­i­tal­ly is that it’s eas­i­er to see the cal­cu­la­tions and make cor­rec­tions.

So the goal is to pro­duce a web­site to help enter tax returns. I’ll base it off the paper tax return and as out­put pro­duce a PDF that can be print­ed and post­ed in direct­ly. The ATO actu­al­ly accepts print­outs from E-Tax so I’m fair­ly con­fi­dent that they will accept these.

The sec­ondary goal is to improve my abil­i­ties with Javascript. I have toyed around with Javascript a lit­tle bit, enough to do small tasks for web­pages. In doing this I saw enough to know that Javascript had some fun­da­men­tal dif­fer­ences but not enough to real­ly under­stand or work with them. By doing a sub­stan­tial Javascript project I hope to get over that hur­dle and start to see how to prop­er­ly design with the lan­guage.

By April 4th I’ll have a pro­to­type site com­plete. Not a usable solu­tion, that will prob­a­bly hap­pen some­time after the new tax returns come out in July. The devel­op­ment site can be seen at http://taxreturn.projects.david.tulloh.id.au/

April 4th fea­tures

  • Tem­plat­ing sys­tem
  • Basic lay­out
  • Func­tion­al data entry
  • Javascript data check­ing
  • Server­side stor­age
  • Basic cal­cu­la­tions
  • Inde­pen­dent domain name
  • Pub­lic source repos­i­to­ry

Maybe fea­tures

  • Client side encryp­tion
  • User login sys­tem
  • Basic per­son­al tax pack cov­ered
  • Client side PDF gen­er­a­tion

Lat­er fea­tures

  • Gen­er­al pack­age refac­tor
  • Com­plete core tax pack cov­ered
  • Com­plete sup­ple­men­tary tax pack cov­ered
  • Retrieve pre­fill infor­ma­tion from ATO
  • Elec­tron­ic sub­mis­sion to ATO
  • Inte­grate with account­ing soft­ware
Return top