NuriaProject Framework  0.1
The NuriaProject Framework
Public Member Functions | List of all members
Nuria::FileTemplateLoader Class Reference

A template loader which loads templates from files. More...

#include <filetemplateloader.hpp>

Inheritance diagram for Nuria::FileTemplateLoader:
Nuria::TemplateLoader

Public Member Functions

 FileTemplateLoader (QObject *parent=0)
 
 FileTemplateLoader (const QDir &path, QObject *parent=0)
 
 FileTemplateLoader (const QVector< QDir > &paths, QObject *parent=0)
 
 ~FileTemplateLoader () override
 
void addSearchPath (const QDir &path)
 
bool hasTemplate (const QString &name) override
 
bool hasTemplateChanged (const QString &name, const QDateTime &since) override
 
QByteArray load (const QString &name) override
 
QVector< QDir > searchPaths () const
 
void setSearchPaths (const QVector< QDir > &paths) const
 
void setSuffix (const QString &suffix)
 
QString suffix () const
 
- Public Member Functions inherited from Nuria::TemplateLoader
 TemplateLoader (QObject *parent=0)
 
 ~TemplateLoader () override
 

Additional Inherited Members

- Signals inherited from Nuria::TemplateLoader
void allTemplatesChanged ()
 
void templateChanged (const QString &name)
 

Detailed Description

A template loader which loads templates from files.

This template loader tries to load files from one or more paths in the file-system. This includes paths in Qt resources.

Search paths are tried from the one added first to the one added last. You can also define a common file suffix, which is appended to every template name internally. Use this if all your templates have a common suffix, like ".twig", and don't want to write it in the Twig code.

Directory traversal attacks, meaning traversing outside of the given search paths, are not possible.

Note
If template names are case-sensitive or not depends on the platform.

Constructor & Destructor Documentation

Nuria::FileTemplateLoader::FileTemplateLoader ( QObject *  parent = 0)
explicit

Default constructor.

Nuria::FileTemplateLoader::FileTemplateLoader ( const QDir &  path,
QObject *  parent = 0 
)
explicit

Constructor which uses path as search path.

Nuria::FileTemplateLoader::FileTemplateLoader ( const QVector< QDir > &  paths,
QObject *  parent = 0 
)
explicit

Contstructor which uses paths as search paths.

Nuria::FileTemplateLoader::~FileTemplateLoader ( )
override

Destructor.

Member Function Documentation

void Nuria::FileTemplateLoader::addSearchPath ( const QDir &  path)

Adds path to the list of search paths.

bool Nuria::FileTemplateLoader::hasTemplate ( const QString &  name)
overridevirtual

Returns true if a template name is known to the template loader. The default implementation returns true if name is not empty.

Reimplemented from Nuria::TemplateLoader.

bool Nuria::FileTemplateLoader::hasTemplateChanged ( const QString &  name,
const QDateTime &  since 
)
overridevirtual

Returns true if name has been changed since. The default implementation always returns false, which is fine for template loaders making use of the changed signals in this class.

Reimplemented from Nuria::TemplateLoader.

QByteArray Nuria::FileTemplateLoader::load ( const QString &  name)
overridevirtual

Returns the template data of the template called name. The default implementation returns name.

A empty result is treated as failure.

Reimplemented from Nuria::TemplateLoader.

QVector< QDir > Nuria::FileTemplateLoader::searchPaths ( ) const

Returns the current search paths.

void Nuria::FileTemplateLoader::setSearchPaths ( const QVector< QDir > &  paths) const

Replaces the current search path list with paths.

void Nuria::FileTemplateLoader::setSuffix ( const QString &  suffix)

Sets the file suffix, which is appended internally to every template name.

QString Nuria::FileTemplateLoader::suffix ( ) const

Returns the file suffix.


The documentation for this class was generated from the following file: