API Documentation for: 1.0.1
Show:

Parser Class

Namespace: Canteen\Parser

Simple string parser and template API to use for doing html substitutions. Located in the namespace Canteen\Parser.

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 String

    The path of the manifest JSON to autoload

addTemplate

(
  • name
  • path
)

Add a single template

Parameters:

  • name String

    The alias name of the template

  • path String

    The full path to the template file

contains

(
  • needle
  • haystack
)
Boolean

Check to see if a string contains a sub tag

Parameters:

  • needle String

    The tag name to look for with out the {{}}

  • haystack String

    The string to search in

Returns:

Boolean:

If the tag is in the string

fixPath

(
  • content
  • basePath
)
String

Replaces any path (href/src) with the base

Parameters:

  • content String

    The content string

  • basePath Dictionary

    The string to prepend all src and href with

Returns:

String:

The content with paths fixed

flush

()

Clear the cache

getContents

(
  • The
  • [cache=true]
)
String

Get a template content

Parameters:

  • The String

    name of the template

  • [cache=true] Boolean optional

    If we should cache the template, good for templates that are requested multiple times.

Returns:

String:

The string contents of the template

getPath

(
  • name
)
String

Get a template by name

Parameters:

  • name String

    The template name

Returns:

String:

The path to the template

lastJsonError

() String private

Get the last JSON error message

Returns:

String:

The json error message

load

(
  • path
  • [asAssociate=true]
)
Array private

Load a JSON file from a path, does the error checking

Parameters:

  • path String

    The path to the .json file

  • [asAssociate=true] Boolean optional

    Return as associative array

Returns:

Array:

The native object or array

parse

(
  • &content
  • substitutions
)
String

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 String

    The content data

  • substitutions Dictionary

    The substitutions key => value replaces in template

Returns:

String:

The parsed template

parseFile

(
  • url
  • substitutions
  • [cache=true]
)
String

Parse a url with substitutions

Parameters:

  • url String

    The path to the template

  • substitutions Dictionary

    The substitutions key => value replaces in template

  • [cache=true] Boolean optional

    If we should cache the template, good for templates that are requested multiple times.

Returns:

String:

The parsed template

removeEmpties

(
  • content
)
String

Remove the empty substitution tags

Parameters:

  • content String

    The content string

Returns:

String:

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

Parameters:

  • name String

    The name of the template as defined in Autoloader

  • [cache=true] Boolean optional

    If we should cache the template, good for templates that are requested multiple times.

  • [substitutions=[] Dictionary optional

    The collection of data to substitute

Properties

_cache

Dictionary

The map of file name to template contents

Default: []

_profiler

Profiler private

The instance of the profiler

_templates

Array private

The list of valid templates

limit

Int

The maximum number of loops to parse before bailing

Default: 10000