Parser Class
Simple string parser and template API to use for doing html substitutions. Located in the namespace Canteen\Parser.
Item Index
Methods
Properties
Methods
addManifest
-
manifestPath
Register a JSON manfest which is an array that contains template files the templates paths should be relative to the location of the manifest file.
Parameters:
-
manifestPath
StringThe path of the manifest JSON to autoload
addTemplate
-
name
-
path
Add a single template
contains
-
needle
-
haystack
Check to see if a string contains a sub tag
Parameters:
Returns:
If the tag is in the string
fixPath
-
content
-
basePath
Replaces any path (href/src) with the base
Parameters:
-
content
StringThe content string
-
basePath
DictionaryThe string to prepend all src and href with
Returns:
The content with paths fixed
flush
()
Clear the cache
getContents
-
The
-
[cache=true]
Get a template content
Parameters:
Returns:
The string contents of the template
getPath
-
name
Get a template by name
Parameters:
-
name
StringThe template name
Returns:
The path to the template
lastJsonError
()
String
private
Get the last JSON error message
Returns:
The json error message
load
-
path
-
[asAssociate=true]
Load a JSON file from a path, does the error checking
Parameters:
Returns:
The native object or array
parse
-
&content
-
substitutions
Prepare the site content to be displayed This does all of the data substitutions and url fixes. The order of operations is to do the templates, loops, if blocks, then individual substitutions.
Parameters:
-
&content
StringThe content data
-
substitutions
DictionaryThe substitutions key => value replaces in template
Returns:
The parsed template
parseFile
-
url
-
substitutions
-
[cache=true]
Parse a url with substitutions
Parameters:
Returns:
The parsed template
removeEmpties
-
content
Remove the empty substitution tags
Parameters:
-
content
StringThe content string
Returns:
The content string
setProfiler
-
profiler
Attach an optional Profiler to the parser for debugging purposes
Parameters:
-
profiler
Profiler
template
-
name
-
[cache=true]
-
[substitutions=[]
Get the template by form name
Properties
_cache
Dictionary
The map of file name to template contents
Default: []
_profiler
Profiler
private
The instance of the profiler
limit
Int
The maximum number of loops to parse before bailing
Default: 10000