Templating system

I knew when I star­ted this pro­ject (which was a while ago, I kinda cheated on this one) that I didn’t want to write out all the HTML myself, I’m not THAT mas­ochistic. What I wanted to do was basic­ally say “make a text box to write the address in”.

So I star­ted with a gen­eric pre­pro­cessor. I’ve use pre­pro­cessors such as CPP, TeX and Make so figured I would take a gen­eric pre­pro­cessor like M4 and define a few HTML mac­ros… prob­lem solved. Unfor­tu­nately it wasn’t that simple and as I added com­plex­ity it got harder to keep it all straight, par­tic­u­larly the quoting.

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 optional group­ings it star­ted 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”>
foreach(‘XXXXX’, (dquote(shift($@))), ‘XXXXX’)

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 without quot­ing so I decided to throw in the towel and switch to some­thing else.

I had exper­i­mented with Tem­plate Toolkit at work using it to inject snip­pits of Javas­cript into HTML doc­u­ments. In the end I stopped using it and had a static HTML page which included a fully gen­er­ated Javas­cript file but the short expos­ure I had impressed me and I tried it here. I found it much cleaner, the named para­met­ers cut out a lot of com­plex­ity and the abil­ity to just drop back to Perl if I wanted to do some­thing really hairy was nice.

This is the defin­i­tion of a text box fol­lowed by the call­ing syn­tax of a radio box that toggles the vis­ib­il­ity 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 class=“answer”>
<input type=“text” name=[% name %] id=[% name %]_id”>

[% INCLUDE tax/radio
name = “surname_changed“
text = “Has any part of your name changed since com­plet­ing your last tax return?“
modify = “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 simply [“Yes”, “No”], the Perl fall­back I men­tioned earlier allows me to have more com­plex syn­tax when I need it but keeps things simple most of the time. I’ve since dis­covered there’s a Tem­plate Toolkit ver­sion three that’s a nice step for­ward but it’s lis­ted 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 second pro­ject woes. I think I’m play­ing with enough new stuff not to add exper­i­mental Tem­plate Toolkit ver­sions to the list.

Goal — Online tax returns

For my first pro­ject 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­puters that allows you to pro­duce a tax return and sub­mit it online. Sadly it’s very much Win­dows only though they sug­gest explor­ing run­ning Win­dows in a vir­tual machine. They are cur­rently “invest­ig­at­ing” sup­port­ing other plat­forms, but they have been doing this for years now and I’ve seen third hand cor­res­pond­ence that sug­gests the invest­ig­a­tion isn’t pro­gress­ing par­tic­u­larly quickly.

You can also fill in the return by hand on paper, com­plete with explan­at­ory book­lets. In prac­tice the pro­ced­ure for both is basic­ally the same, the advant­age of doing it digit­ally is that it’s easier to see the cal­cu­la­tions and make corrections.

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 prin­ted and pos­ted in dir­ectly. The ATO actu­ally accepts prin­touts from E-Tax so I’m fairly con­fid­ent that they will accept these.

The sec­ond­ary goal is to improve my abil­it­ies with Javas­cript. I have toyed around with Javas­cript a little bit, enough to do small tasks for webpages. In doing this I saw enough to know that Javas­cript had some fun­da­mental dif­fer­ences but not enough to really under­stand or work with them. By doing a sub­stan­tial Javas­cript pro­ject I hope to get over that hurdle and start to see how to prop­erly design with the language.

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

April 4th features

  • Tem­plat­ing system
  • Basic lay­out
  • Func­tional data entry
  • Javas­cript data checking
  • Server­side storage
  • Basic cal­cu­la­tions
  • Inde­pend­ent domain name
  • Pub­lic source repository

Maybe fea­tures

  • Cli­ent side encryption
  • User login system
  • Basic per­sonal tax pack covered
  • Cli­ent side PDF generation

Later fea­tures

  • Gen­eral pack­age refactor
  • Com­plete core tax pack covered
  • Com­plete sup­ple­ment­ary tax pack covered
  • Retrieve pre­fill inform­a­tion from ATO
  • Elec­tronic sub­mis­sion to ATO
  • Integ­rate with account­ing software
Return top