Table of Contents Code Kata

I was looking through some code the other day that generated web based documentation for a framework. They, of course, list everything in a table of contents layout with those being links to the actual files.

In order to achieve this, they break out each section into a file. So the first section is located in the file named “1. Introduction.txt”, and the 2.3.5.1 section is located in the file named “2.3.5.1 Section Name.txt” - simple enough?

They do not use another file to specify how to order these files, there is already a convention. They just execute a directory listing, then sort this list.

As an example, given this as input:

[
  '2.2 Next Agenda Item.txt',
  '2.1.1 Baby Step.txt',
  '1. Introduction.txt',
  '2.1 Moving Forward.txt',
  '2. Getting Started.txt'
]

Should result in:

[
  '1. Introduction.txt',
  '2. Getting Started.txt',
  '2.1 Moving Forward.txt',
  '2.1.1 Baby Step.txt',
  '2.2 Next Agenda Item.txt'
]

I wouldn’t worry about actually making the files. Just have a list of file names, then sort them to match up with how they are actually suppose to be sorted.

So I’m curious, do you think this is code kata? It is much shorter than other ones I have seen, but I think we do need variations of katas.

Related Posts