doc:oobdtemple
Differences
This shows you the differences between two versions of the page.
doc:oobdtemple [2012/06/03 08:03] – created admin | doc:oobdtemple [2014/03/02 08:05] (current) – removed admin | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== OOBDTemple - The OOBD Source Code Template Tool ====== | ||
- | |||
- | ===== Why another template tool? ===== | ||
- | There are virtual dozens of template tools available, but they all take a template and some data and create the output out of it. | ||
- | |||
- | We were looking for something instead with which we can write and test source code as usual, then identify the pieces of the code inside one source file, which could be used also in similar cases. These common parts we want to extract as a template and import and update them into other source files. | ||
- | |||
- | |||
- | ===== The Princible ===== | ||
- | Image, you have a source code: | ||
- | |||
- | < | ||
- | |||
- | overall initialization | ||
- | |||
- | some specific variable initialization | ||
- | |||
- | a generic doTo loop: | ||
- | |||
- | for (i=0 ... | ||
- | |||
- | some specific tasks in here | ||
- | } | ||
- | |||
- | specific shutdown | ||
- | |||
- | generic shutdown | ||
- | |||
- | |||
- | </ | ||
- | |||
- | Now image you put some markers into that source, which tells, which parts of the code are generic. The specific parts of the code stays unmarked. | ||
- | |||
- | < | ||
- | |||
- | //>>>> | ||
- | |||
- | overall initialization | ||
- | |||
- | //<<<< | ||
- | |||
- | some specific variable initialization | ||
- | |||
- | //>>>> | ||
- | |||
- | a generic doTo loop: | ||
- | |||
- | for (i=0 ... | ||
- | |||
- | //<<<< | ||
- | |||
- | some specific tasks in here | ||
- | |||
- | //>>>> | ||
- | |||
- | } | ||
- | |||
- | //<<<< | ||
- | |||
- | specific shutdown | ||
- | |||
- | //>>>> | ||
- | |||
- | generic shutdown | ||
- | |||
- | //<<<< | ||
- | </ | ||
- | |||
- | As you can see, the generic parts are enclosed into an >>>> | ||
- | |||
- | But to allow nested template code, the markers needs to have a identifier, to which template they belong to. | ||
- | |||
- | Now the markers belongs all to the template called base: | ||
- | |||
- | < | ||
- | |||
- | //>>>> | ||
- | |||
- | overall initialization | ||
- | |||
- | //<<<< | ||
- | |||
- | some specific variable initialization | ||
- | |||
- | //>>>> | ||
- | |||
- | a generic doTo loop: | ||
- | |||
- | for (i=0 ... | ||
- | |||
- | //<<<< | ||
- | |||
- | some specific tasks in here | ||
- | |||
- | //>>>> | ||
- | |||
- | } | ||
- | |||
- | //<<<< | ||
- | |||
- | specific shutdown | ||
- | |||
- | //>>>> | ||
- | |||
- | generic shutdown | ||
- | |||
- | //<<<< | ||
- | </ | ||
- | |||
- | |||
- | That would already work so far, but it might become complicated, | ||
- | |||
- | |||
- | < | ||
- | |||
- | //>>>> | ||
- | |||
- | overall initialization | ||
- | |||
- | //<<<< | ||
- | |||
- | some specific variable initialization | ||
- | |||
- | //>>>> | ||
- | |||
- | a generic doTo loop: | ||
- | |||
- | for (i=0 ... | ||
- | |||
- | //<<<< | ||
- | |||
- | some specific tasks in here | ||
- | |||
- | //>>>> | ||
- | |||
- | } | ||
- | |||
- | //<<<< | ||
- | |||
- | specific shutdown | ||
- | |||
- | //>>>> | ||
- | |||
- | generic shutdown | ||
- | |||
- | //<<<< | ||
- | </ | ||
- | |||
- | |||
- | |||
- | ===== The oobdtemple Commands ===== | ||
- | Above we've seen how a source code amended with markers looks like. Now lets see how oobdtemple deals with that: | ||
- | |||
- | First we take something simple | ||
- | |||
- | ==== oobdtemple --struct : Show template structure ==== | ||
- | |||
- | oobdtemple template_name --struct file | ||
- | |||
- | Prints the actual template struct in < | ||
- | |||
- | |||
- | ==== oobdtemple --extract : Extract template ==== | ||
- | |||
- | | ||
- | |||
- | Prints the actual template content in < | ||
- | |||
- | ---- | ||
- | |||
- | Now we start to copying templates in and out of files: | ||
- | |||
- | |||
- | |||
- | ==== oobdtemple --update : Update source file ==== | ||
- | |||
- | oobdtemple template_name --update sourcefile templatefile | ||
- | |||
- | Updates the actual template content of < | ||
- | |||
- | |||
- | ==== oobdtemple --writetemplate : Update template file ==== | ||
- | |||
- | oobdtemple template_name --writetemplate sourcefile templatefile | ||
- | |||
- | Saves actual template content of < | ||
- | |||
- | ---- | ||
- | |||
- | This were the commands for evaluate or modifying files. The next two commands should be placed into the make process to make sure that the template fits to the content of the source file to work with. | ||
- | |||
- | |||
- | ==== oobdtemple --check : Check source code and template file consistency ==== | ||
- | |||
- | oobdtemple template_name --check sourcefile templatefile | ||
- | |||
- | Checks, if the template of < | ||
- | |||
- | |||
- | But as an inconsistency between source code and template can easily happen during the development phase, there' | ||
- | |||
- | ==== oobdtemple --develop : Warns for source code and template file consistency ==== | ||
- | |||
- | oobdtemple template_name --develop sourcefile templatefile | ||
- | |||
- | Same as --check, but just writes warnings to stderr and exit with 0 to not stop a make process | ||
- | |||
- | |||
- | ===== The oobdtemple Structure checks ===== | ||
- | |||
- | As it obviously can create a lot of damage in the source codes, when you try to merge a template structure into a source, which has a complete different template structure, oobdtemple does a few checks first before merging files. If one of these tests fails, the operation stops and the files remains untouched: | ||
- | |||
- | * On file level oobdtemple checks | ||
- | * if all opening tags have their closing tags | ||
- | * if the optional name given to the opening tag equals to the closing tag | ||
- | * between source file and template file oobdtemple checks | ||
- | * if the number of tags are equal | ||
- | * if the optional names of the tags are equal between source and template | ||
doc/oobdtemple.1338703388.txt.gz · Last modified: 2012/06/03 08:03 (external edit)