Separation and abstraction

Once having the template freed from logic, new risks appear. Template code and technical issues of the output format might enter the logic site. This reduces the value of the separation, even it not fully destroys it. Especially re-usability is hurt. Though, a strong abstraction layer should be used to empower the separation.

Snippetory ships with a powerful and extensible abstraction layer. A central element is the encoding. The encoding is designed to handle technical issues of a specific output format when different encodings are integrated within each other. If we take HTML as base an URL might be integrated as is, plain text needs some characters to be escaped, and wiki will need some complicated thing…

Let’s look at some examples to get an idea how this works. Once I implemented a date picker based on jQuery. First I simply initialized it by putting a formatted and localized date into the input field like

<input type="text" name="start" value="{v:start date='medium'}" />

This worked fine for German and English, however Italian failed because java makes quiet different assumptions how the preferred format in the different languages look like, while jQuery thinks another way. Though, I needed a language agnostic way to hand over the parameter:

$( ".selector" ).datepicker({ defaultDate: {v:preset date='JS_JS' });

Though, we can see, that formatting is sometimes in the responsibility of the template, though it should be possible to handle it there. However, it is part of the interface to the controller, which has to parse it. Though, the responsibility is not clear and has to be clarified wisely.

See you on jproggy.org

About these ads