MQTTSuite
Loading...
Searching...
No Matches
inja Namespace Reference

Namespaces

namespace  string_view

Classes

class  FunctionStorage
 Class for builtin functions and user-defined callbacks. More...
struct  SourceLocation
struct  InjaError
struct  ParserError
struct  RenderError
struct  FileError
struct  DataError
class  NodeVisitor
class  AstNode
 Base node class for the abstract syntax tree (AST). More...
class  BlockNode
class  TextNode
class  ExpressionNode
class  LiteralNode
class  DataNode
class  FunctionNode
class  ExpressionListNode
class  StatementNode
class  ForStatementNode
class  ForArrayStatementNode
class  ForObjectStatementNode
class  IfStatementNode
class  IncludeStatementNode
class  ExtendsStatementNode
class  BlockStatementNode
class  SetStatementNode
class  StatisticsVisitor
 A class for counting statistics on a Template. More...
struct  Template
 The main inja Template. More...
struct  LexerConfig
 Class for lexer configuration. More...
struct  ParserConfig
 Class for parser configuration. More...
struct  RenderConfig
 Class for render configuration. More...
struct  Token
 Helper-class for the inja Lexer. More...
class  Lexer
 Class for lexing an inja Template. More...
class  Parser
 Class for parsing an inja Template. More...
class  Renderer
 Class for rendering a Template with data. More...
class  Environment
 Class for changing the configuration. More...

Typedefs

using Arguments = std::vector<const nlohmann::json*>
using json = nlohmann::json
using CallbackFunction = std::function<json(Arguments& args)>
using VoidCallbackFunction = std::function<void(Arguments& args)>
using TemplateStorage = std::map<std::string, Template>

Functions

SourceLocation get_source_location (std::string_view content, size_t pos)
void replace_substring (std::string &s, const std::string &f, const std::string &t)
std::string render (std::string_view input, const json &data)
 render with default settings to a string
void render_to (std::ostream &os, std::string_view input, const json &data)
 render with default settings to the given output stream

Typedef Documentation

◆ Arguments

typedef std::vector< const json * > inja::Arguments = std::vector<const nlohmann::json*>

Definition at line 57 of file MqttMapperPlugin.h.

◆ CallbackFunction

using inja::CallbackFunction = std::function<json(Arguments& args)>

Definition at line 99 of file inja.hpp.

◆ json

using inja::json = nlohmann::json

Definition at line 58 of file MqttMapperPlugin.h.

◆ TemplateStorage

using inja::TemplateStorage = std::map<std::string, Template>

Definition at line 905 of file inja.hpp.

◆ VoidCallbackFunction

using inja::VoidCallbackFunction = std::function<void(Arguments& args)>

Definition at line 100 of file inja.hpp.

Function Documentation

◆ get_source_location()

SourceLocation inja::get_source_location ( std::string_view content,
size_t pos )
inline

Definition at line 330 of file inja.hpp.

330 {
331 // Get line and offset position (starts at 1:1)
332 auto sliced = string_view::slice(content, 0, pos);
333 std::size_t last_newline = sliced.rfind("\n");
334
335 if (last_newline == std::string_view::npos) {
336 return {1, sliced.length() + 1};
337 }
338
339 // Count newlines
340 size_t count_lines = 0;
341 size_t search_start = 0;
342 while (search_start <= sliced.size()) {
343 search_start = sliced.find("\n", search_start) + 1;
344 if (search_start == 0) {
345 break;
346 }
347 count_lines += 1;
348 }
349
350 return {count_lines + 1, sliced.length() - last_newline};
351 }
static void content(const std::string &contentEncoding, const std::string &contentMediaType, const json &instance)
std::string_view slice(std::string_view view, size_t start, size_t end)
Definition inja.hpp:311

References inja::string_view::slice().

Referenced by inja::Lexer::current_position(), and inja::Renderer::throw_renderer_error().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ render()

std::string inja::render ( std::string_view input,
const json & data )
inline

render with default settings to a string

Definition at line 3059 of file inja.hpp.

3059 {
3060 return Environment().render(input, data);
3061 }
Class for changing the configuration.
Definition inja.hpp:2851
std::string render(std::string_view input, const json &data)
Definition inja.hpp:2948

References inja::Environment::Environment().

Here is the call graph for this function:

◆ render_to()

void inja::render_to ( std::ostream & os,
std::string_view input,
const json & data )
inline

render with default settings to the given output stream

Definition at line 3066 of file inja.hpp.

3066 {
3067 Environment env;
3068 env.render_to(os, env.parse(input), data);
3069 }
std::ostream & render_to(std::ostream &os, const Template &tmpl, const json &data)
Definition inja.hpp:2989
Template parse(std::string_view input)
Definition inja.hpp:2932

References inja::Environment::parse().

Here is the call graph for this function:

◆ replace_substring()

void inja::replace_substring ( std::string & s,
const std::string & f,
const std::string & t )
inline

Definition at line 353 of file inja.hpp.

353 {
354 if (f.empty()) {
355 return;
356 }
357 for (auto pos = s.find(f); // find first occurrence of f
358 pos != std::string::npos; // make sure f was found
359 s.replace(pos, f.size(), t), // replace with t, and
360 pos = s.find(f, pos + t.size())) // find next occurrence of f
361 {
362 }
363 }

Referenced by inja::Renderer::visit().

Here is the caller graph for this function: