Empty Block

Hashmap Mode

Beside native string syntax, be it as an literal string argument or external file with *.fncd or *.fncd.phtml extension, Funcdown offers additional flexibility by utilizing PHP multidimensional indexed arrays for generation of valid markup. In other words it means literal translation from PHP array to Funcdown string. So, let get started on how to provide such hashmaps and their indexes and values.

ARRAY KEYS

Array keys in Hashmap mode serve for two purposes. You use them to provide tag names and attributes with their values. This: [ 'p' => 'Lorem ipsum' ] .. will be translated to: p {:>>> Lorem ipsum <<<:} In contrast to native string/file mode, there are no open/close () braces, but single @ AT character, after which is all the same as in native string mode, in order to provide attributes and their respective values. This (note the @ char): [ 'p@# unique-id,. preformatted' => 'Lorem ipsum' ] .. will be translated to: p (# unique-id,. preformatted) {:>>> Lorem ipsum <<<:} .. which will then get translated to: <p id="unique-id" class="preformatted">Lorem ipsum</p> One also doesn't need to escape anything but comma , for attribute values, which is kinda factor of relief.

If there is no key at all, just string value or it is literal NUMERICAL index, translation will result in HTML comment, pretty much like with exclamation character.

Just like with native string mode, DTD tag ('*'), literal string nodes ('~') and HTML comment nodes ('!') CANNOT have attributes attached to them. Also, expect ERROR if You want to assign new array value to those three just mentioned. DTD declaration, STRING node and COMMENT tags are for STRINGS - only - without ARGUMENTS, they do not act as BLOCK tags.


Fragment Injection

One of the unique features of Hashmap mode is the option to easily inject other .fncd files into play by using ` or backtick character. Good example is head tag as its child contents are never the same for any given page, for literally almost any - normal - website, not to mention body tag and its children .. Anyways, this (note the 'H' key (head tag) and its descendants): [ '*' => 5, 'R' => [ 'H' => [ '`' => '/current/head/target/fragment.fncd.phtml' ], 'B' => [ '!' => 'Body tag contents ...' ] ] ] ... .. will replace backtick key and literal string value (which MUST be ABSOLUTE path to funcdown file) with the contents of the given path to funcdown file or fragment in this case. The above 'fragment.fncd.phtml' example: meta (charset utf-8)| title {Current Page Title} meta (name robots,content noacrhive\,noindex\,nofollow)| meta (name description,content Page description)| link (rel stylesheet,type text/css,media all,href /style.css)| script (src application.js, defer){} ... When all of that is translated into funcdown string, we can expect: * {5} R [ H [ meta (charset utf-8)| title {Current Page Title} meta (name robots,content noacrhive\,noindex\,nofollow)| meta (name description,content Page description)| link (rel stylesheet,type text/css,media all,href /style.css)| script (src application.js, defer){} ] B [ ! {:>>> Body tag contents ... <<<:} ] ] ...

The Problem

Every single array in PHP is key => value type. Even if one types just this [ 'a', 'b', 'c' ] it will be exactly the same as [ 0 => 'a', 1 => 'b', 2 => 'c' ]. If no key was found, it is considered to be array_as_list where the interpretter automatically assigns those missing. For human sake, when key is not if integer type it is called 'associative' or 'indexed' array. That being said, any scalar value can be index/key with the exception of NULL as non-scalar - and valid index/key.

We are talking about indexed array here. That means the same indexed keys one after another will result in overwriting the previous by the latter, thus resulting in unwanted outcome. This: [ 'ul' => [ 'li' => 'List item 1', 'li' => 'List item 2', 'li' => 'List item 3', 'li' => 'List item 4', ], ] ... ... will be translated to: ul [ li {:>>> List item 4 <<<:} ] ... ... and it is not something we would like to encounter.

The Solution

Prepending ANYTHING followed by colon before tag name in case that there are no attributes at all, as attributes would make all indexes unique. Kinda. Something like this: [ 'ul' => [ ':li' => 'List item 1', '0:li' => 'List item 2', '1:li' => 'List item 3', 'THIS_WILL_EVAPORATE:li' => 'List item 4', ], ] ... .. will be translated to: ul [ li {:>>> List item 1 <<<:} li {:>>> List item 2 <<<:} li {:>>> List item 3 <<<:} li {:>>> List item 4 <<<:} ] ...

ARRAY VALUES

Array values for Funcdown hashmap mode determine what type of tag it is all about, is there going to be recursion while translation to Funcdown string is underway or whether it is literal string node or it is literal php string Fragment injection. New array as value means that it is BLOCK tag all about and recursion will occur. [ 'div' => [ '!' => '...' ]] ... NULL or BOOLEAN value means that it is SELF-CLOSING tag. All three below ... [ 'M@N author,@ John Doe' => true ] ... [ 'M@N author,@ John Doe' => false ] ... [ 'M@N author,@ John Doe' => null ] ... .. will translate the same: M (N author,@ John Doe)| ... STRING, INTEGER or DOUBLE will provide TAG with DIRECT string node. [ 'span' => '' ] -> span {} -> <span></span> [ 'span' => '123.456' ] -> span {:>>> 123.456 <<<:} -> <span>123.456</span> [ 'span' => 123.456 ] -> span {:>>> 123.456 <<<:} -> <span>123.456</span> [ 'span' => 123456 ] -> span {:>>> 123456 <<<:} -> <span>123456</span> Providing any other TYPE except those mentioned above will result in - nothing. Most probably syntax error of some sort. That includes objects, callables, streams, etc.. So, You definitelly would like to avoid every type that is NOT mentioned with examples. For more additional info and how Hashmap mode works look for private function atos (atos = Array To String) in Funcdown library file.

Keep in mind that providing EMPTY array for Funcdown to parse will result in error with explanatory message on screen. This is because Funcdown is designed for extensive and HUGE data processing. Generating small ammounts of data with Funcdown is literal waste of resources. Don't spare anything but feed the parser properly.

Empty Block
Empty Block
Empty Block
Empty Block