Chat with us on Skype:

Chat Offline

Golgi Application

It is nice to avoid writing duplicate code for obvious reasons, but many methods for dealing with it are inefficient on another ground (file system access, extra database queries, and excessively large scripts particularly in interpreted languages). In many cases, with manual labor being the most expensive of the components driving software, the tradeoff is well worth it.

However, when scaling, these tradeoffs can add up quickly. Imagine when hosting many different websites on a shared server, if you could completely eliminate the need for a server-side language on sites with predominantly static content.

We created Golgi Application as a painless way to do upfront some of the unnecessary processing that sometimes goes on continually as a result of optimizing code reuse during development. It is similar to the C preprocessor, but works for almost any language and can even handle includes cross-languages (while that's not very useful for code, it is for certain tentatively-static data or content that otherwise requires database or filesystem access to syndicate).

Golgi Application is named after the Golgi apparatus, an organelle found in eukaryotic cells that is responsible for modifying and packaging proteins to be sent around the cell. While we try to avoid too many biology references for fear that a project will outgrow the analogy (let's not forget that computers are supposed to work like computers, not necessarily real-world things), this one was too good a fit to pass up. We also like to strut our biology knowledge occasionally for our clients in health care and related industries.


Documentation

Golgi Application is XML-based. You can view the syntax and examples below.


Contents


↑ Contents

Tag List/Directives

register

Declares (optionally initializes) vars and contains data elements.


data

Contains source information.

AttributeRequiredValueDescription
idrequiredstringIdentifier, unique per file.

var

Declares a variable in register elements. Inner content, if present, defines value (default value if in register element). Variables without values are initialized to empty strings. The "variable name" is blindly replaced by its value. Note that variables are processed in the reverse order of declaration in the register element (order within prepare does not matter), but this actually gives the more intuitive effect of vars needing to be declared prior to use when embedding variable names within variable values.

AttributeRequiredValueDescription
namerequiredstringVariable name/placeholder.

operation

Contains instructions for a "Golgi operation": find + replace, repeat + set × N, or exec. Note that in prepare tags target tags will be processed after operation tags. So effectively Golgi code could write itself, but to modify the result in a target tag, prepare tags would have to be nested (they are processed in reverse order).


find

Specifies a string to find and replace with value in a matching replace tag within containing data tag (or containing operation tag if in a prepare tag).


replace

Specifies a string with which to replace occurrances of string specified in matching find.


repeat

Specifies a template string with placeholders to be repeated N-times where N is determined by the greatest number of values contained in matching set tag(s). Repeated string will replace this tag in place when processed.


set

Specifies the values to be used in repititions of string template in matching repeat tag. There can be many set tags to the single repeat tag. For each iteration, the first value in each set tag will be used to replace placeholders, and then the next and so on. If a set contains fewer values than other sets, the repeat operation will proceed using an empty string for the deficient placeholder.

AttributeRequiredValueDescription
labeloptionalstringCooresponding placeholder within repeat string. Defaults to \N where N is in order of set tag occurrance.
sepoptionalstringDelimiter of values within set tag. Defaults to comma.

conditional

Evaluates a var for equivelance (or inequivelance) with a value (note that since variables are replaced blindly, variables can effectively be compared) and if specified condition is NOT true removes the contents within the conditional tag. This tag is processed at a precedence such that operation tags may be contained within it and executed conditionally. Conditional tags may be nested.

AttributeRequiredValueDescription
varrequiredvar nameVariable to evaluate.
eq|nerequiredstringMust be one or the other, eq meaning the value in var equals value within chosen attribute and ne meaning not equal.

exec

Executes a shell command and replaces tag in place with the output. The user will be prompted for confirmation before commands are executed.


prepare

Defines vars specified in registers. Contains operations (processed first) and targets (processed next). Processed in reverse order, so can effectively be nested.


target

Specifies a repository file to process and replace contents with.

AttributeRequiredValueDescription
repooptionalshared|appSpecifies repository to retrieve file from. If omitted, first looks in app repository and falls back on shared.
filerequiredfile pathFile to retrieve from repository.
datarequireddata idIdentifier to specify a data element to retrieve content from.

↑ Contents

Repository Files

Structure

Samples

Continuing example A
<golgi:register> <golgi:var name="current_page" /> <golgi:var name="file_type" /> <golgi:data id="navlinks"> <golgi:conditional var="file_type" eq="php">*/ echo '</golgi:conditional> <div class="nav"> <golgi:operation> <!-- build the navigation with a repeat --> <golgi:repeat><a href="/{uri}">\2</a></golgi:repeat> <golgi:set label="{uri}">,bears.html,something/</golgi:set> <golgi:set sep="|">Home|Bears|Something Else</golgi:set> </golgi:operation> </div> <!-- the conditional will prevent setting the current page for the homepage --> <!-- no reason other than to demonstrate that operations can be enclosed in conditional tags --> <golgi:conditional var="current_page" ne="/"> <golgi:operation> <!-- set the current page via a find/replace operation --> <golgi:find>href="/current_page"</golgi:find> <golgi:replace>href="/current_page" class="current"</golgi:replace> </golgi:operation> </golgi:conditional> <golgi:conditional var="file_type" eq="php">'; /**</golgi:conditional> </golgi:data> </golgi:register>
Continuing example B
-- <golgi:register> -- <golgi:var name="{prefix}" /> -- <golgi:data id="bears"> CREATE TABLE {prefix}bears ( id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, name VARCHAR(255) NOT NULL, color ENUM('brown', 'black', 'white') DEFAULT NULL, PRIMARY KEY (id), KEY name (name) ); -- </golgi:data> -- <golgi:data id="bears-accessories"> CREATE TABLE {prefix}accessories ( id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, name VARCHAR(255) NOT NULL, `type` ENUM('clothing', 'weapon') NOT NULL, PRIMARY KEY (id), KEY name (name) ); CREATE TABLE {prefix}bears_accessories ( id_bears INT(11) UNSIGNED NOT NULL, id_accessories INT(11) UNSIGNED NOT NULL, UNIQUE KEY id_bears_accessories (id_bears, id_accessories), KEY id_accessories (id_accessories) ); -- </golgi:data> -- </golgi:register>

↑ Contents

Target Files

Structure

Samples

Continuing example A
<?php /** <golgi:prepare> <golgi:target repo="shared" file="Ev_Example.php" data="example"> */ require EV_SHARED . 'Ev_Example.php'; /** </golgi:target> <golgi:target file="Example.php" data="example"> */ require EV_APP . 'Example.php'; /** </golgi:target> </golgi:prepare> */ $Example = new Example; //probably do some stuff /** <golgi:prepare> <golgi:var name="current_page">/</golgi:var> <golgi:var name="file_type">php</golgi:var> <golgi:target file="navigation.html" data="navlinks"> */ echo '<div class="nav"></div>'; /** </golgi:target> </golgi:prepare> */ ?>
Continuing example B
-- <golgi:prepare> -- <golgi:var name="{prefix}">wildlife_</golgi:var> ALTER DATABASE sample_db CHARACTER SET utf8; USE sample_db; SET storage_engine=MYISAM; CREATE TABLE wildlife_users ( id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, name VARCHAR(255) NOT NULL, passwd TEXT NOT NULL, passwdsalt VARCHAR(255) NOT NULL, active ENUM('0', '1') DEFAULT '1', PRIMARY KEY (id), UNIQUE name (name) ); -- <golgi:target repo="shared" file="bears.sql" data="bears"> -- </golgi:target> -- <golgi:target repo="shared" file="bears.sql" data="bears-accessories"> -- </golgi:target> -- </golgi:prepare>

↑ Contents

Copyright © 2011 Evolutrix, Inc.