Пример #1
0
std::string PageTemplate::get_variable(const ArgumentList& arguments, const ArrayArgument::Item* arrayItem, const std::string& var) const
{
	if (arrayItem != 0)
	{
		ArrayArgument::Item::const_iterator i = arrayItem->find(var);
		if (i != arrayItem->end())
			return i->second;
	}
	ArgumentList::const_iterator i = arguments.find(var);
	return i == arguments.end() ? std::string() : i->second->to_string();
}
Пример #2
0
void PageTemplate::yield_foreach(const ArgumentList& arguments, const TokenPtr& token, std::string& result) const
{
	const ForeachToken* ftoken = static_cast<const ForeachToken*>(token.get());
	ArgumentList::const_iterator i = arguments.find(ftoken->data);
	if (i == arguments.end() || !i->second->is_array())
		return;
	const ArrayArgument* array = static_cast<const ArrayArgument*>(i->second.get());
	for (std::size_t i = 0, n = array->size(); i < n; i++)
	{
		if (i > 0)
			yield_tokens(arguments, 0, ftoken->sep, result);
		yield_tokens(arguments, &array->get(i), ftoken->body, result);
	}
}