Class: VariablesFromFirstPost

VariablesFromFirstPost

new VariablesFromFirstPost()

variables loaded from the first post in a thread

Extends

Methods

inherited check(namespace, names, forum_id, thread_id)

check if a variable exists

Name Type Description
namespace string namespace to find the variable in
names string | Array.<string> name(s) of variable within the namespace
forum_id Number optional ID of forum to instantiate for
thread_id Number optional ID of thread to instantiate for
boolean

inherited escape(text){string}

escape a string for use in .parse()

.parse() recursively parses keys passed to it. If you want to include a key that includes literal text {{between two curly brackets}}, you will need to escape it.
Name Type Description
text string string to escape
Returns:
Type Description
string escaped output

inherited get(namespace, names, forum_id, thread_id){Object}

get a variable

Variables need to follow some fairly specific rules to produce useful results: Variables are defined per-language, then the language is decided based on the forum, thread, and default language. Names are defined with sections split up by colons (e.g. "greeting message: newbie", "greeting message: old hand"). We always try to return the most specific name for the language, but can default to less-specific ones Variables can be set to special values to override normal handling: "OVERRIDE: pretend this variable exists but has no contents" treats a variable as an empty string. Use this when you want to define a variable as an empty string. Some WYSIWYG editors will delete empty [quote] blocks - this is the recommended way to avoid those weird errors. "OVERRIDE: pretend this variable doesn't exist" treats a variable as if it didn't exist. Use this when you want to define a general variable, then un-define it again in a more specific variable. "NO OVERRIDE: ..." treats a variable as if the initial "NO OVERRIDE: " didn't exist. Use this to include the above strings literally in a variable. The return object contains 'text' and 'error', one null and one non-null. If there is an error, the object will also contain 'resolutions'. See the source of .resolve() for an example of how to use this output.
Name Type Description
namespace string namespace to find the variable in
names string | Array.<string> name(s) of variable within the namespace
forum_id Number optional ID of forum to instantiate for
thread_id Number optional ID of thread to instantiate for
Returns:
Type Description
Object variable (if found) or error information (otherwise)

inherited get_language(thread_id, forum_id)

get the target language

thread language overrides forum language, which overrides user language, EXCEPT when the user language is a specialism of the other language. So a user language 'en-GB' overrides a thread language 'en', but a user language 'en-GB' is overridden by a thread language 'fr'.
Name Type Description
thread_id Number thread ID
forum_id Number forum ID

inherited parse(text, keys, parser, forum_id, thread_id){string|Array|Object}

parse the contents of a variable

Parse a string as a variable. Keys should either be strings or arrays of strings. Arrays are automatically converted to sentences, e.g. [1,2,3] becomes "1, 2 and 3". All parsers treat text {{between two curly brackets}} specially. They're converted either to one of the keys passed in, or alternatively to another matching variable. Curly bracket blocks can be nested (e.g. {{variable for: {{key}}}}), and references within referenced variables are themselves parsed for references. To include a literal that resembles a variable, put brackets between the key {{(like this)}}. See get() for special override values variables can have. The "string" parser returns plain string output, the "array of items" parser expects the variable to be a BBCode [list], and the "hash of arrays" parser expects the variable to be a BBCode [list] with a single [post], [thread] or [url] element per list item.
Name Type Description
text string string to parse
keys Object.<string, *> optional keys used to instantiate the variable
parser string optional parser used for the variable ('string', 'array of items' or 'hash of arrays', default: 'string')
forum_id Number optional ID of forum to instantiate for
thread_id Number optional ID of thread to instantiate for
Returns:
Type Description
string | Array | Object parsed output
Example
v.parse( 'Hello {{username}}', { username: 'some user' }, 'string', 12, 345 );

inherited abstractrefresh(args){jQuery.Promise}

Reload the cached values
Name Type Description
args Object cacheable arguments (as passed to Cacheable())
Returns:
Type Description
jQuery.Promise promise that will return when the cache has been refreshed

inherited resolve(namespace, names, keys, parser, forum_id, thread_id)

get() and parse() a variable

Name Type Description
namespace string namespace to find the variable in
names string | Array.<string> name(s) of variable within the namespace
keys Object.<string, *> optional keys used to instantiate the variable
parser string optional parser used for the variable ('string', 'array of items' or 'hash of arrays', default: 'string')
forum_id Number optional ID of forum to instantiate for
thread_id Number optional ID of thread to instantiate for
Example
v.resolve( 'policy', [ 'greeting message', 'newbie' ], { name: username }, 'string', 12, 345 );

inherited set_namespaces(){Array.<Object>}

update the complete list of variables, grouped by namespace

Returns:
Type Description
Array.<Object>
Update this.cache using the passed cache_updater() callback