KTextTemplate::FileSystemTemplateLoader

Search for usage in LXR

KTextTemplate::FileSystemTemplateLoader Class Reference

#include <templateloader.h>

Inheritance diagram for KTextTemplate::FileSystemTemplateLoader:

Public Member Functions

 FileSystemTemplateLoader (const QSharedPointer< AbstractLocalizer > localizer={})
 
 ~FileSystemTemplateLoader () override
 
bool canLoadTemplate (const QString &name) const override
 
std::pair< QString, QStringgetMediaUri (const QString &fileName) const override
 
Template loadByName (const QString &name, Engine const *engine) const override
 
void setTemplateDirs (const QStringList &dirs)
 
void setTheme (const QString &themeName)
 
QStringList templateDirs () const
 
QString themeName () const
 
- Public Member Functions inherited from KTextTemplate::AbstractTemplateLoader
virtual ~AbstractTemplateLoader ()
 

Detailed Description

The FileSystemTemplateLoader loads Templates from the file system.

This template loader works by traversing a list of directories to find templates. Directories are checked in order, and the first match hit is parsed and returned.

loader->setTemplateDirs({
"/home/user/app/templates",
"/usr/local/share/app/templates"
});
engine->setTemplateLoader( loader );
// This will try /home/user/app/templates/mytemplate.html
// followed by /usr/local/share/app/templates/mytemplate.html
engine->loadByName( "mytemplate.html" );

Additionally, a themeName may be set on the template loader, which will be appended to search paths before the template name.

loader->setTemplateDirs({
"/home/user/app/templates" <<
"/usr/local/share/app/templates"
});
loader->setTheme( "simple_theme" );
engine->setTemplateLoader( loader );
// This will try /home/user/app/templates/simple_theme/mytemplate.html
// followed by /usr/local/share/app/templates/simple_theme/mytemplate.html
engine->loadByName( "mytemplate.html" );

Media URIs may be retrieved for media relative to the directories searched queried for templates.

loader->setTemplateDirs({
"/home/user/app/templates",
"/usr/local/share/app/templates"
});
loader->setTheme( "simple_theme" );
engine->setTemplateLoader( loader );
// This will try /home/user/app/templates/simple_theme/logo.png
// followed by /usr/local/share/app/templates/simple_theme/logo.png
// and return the first one that exists.
engine->mediaUri( "logo.png" );

The template files loaded by a %**FileSystemTemplateLoader** must be UTF-8 encoded.

See also
Deploying Templates

Definition at line 124 of file templateloader.h.

Constructor & Destructor Documentation

◆ FileSystemTemplateLoader()

FileSystemTemplateLoader::FileSystemTemplateLoader ( const QSharedPointer< AbstractLocalizer > localizer = {})

Constructor.

Definition at line 42 of file templateloader.cpp.

◆ ~FileSystemTemplateLoader()

FileSystemTemplateLoader::~FileSystemTemplateLoader ( )
override

Destructor.

Definition at line 48 of file templateloader.cpp.

Member Function Documentation

◆ canLoadTemplate()

bool FileSystemTemplateLoader::canLoadTemplate ( const QString & name) const
overridevirtual

Return true if a Template identified by name exists and can be loaded.

Implements KTextTemplate::AbstractTemplateLoader.

Definition at line 95 of file templateloader.cpp.

◆ getMediaUri()

std::pair< QString, QString > FileSystemTemplateLoader::getMediaUri ( const QString & fileName) const
overridevirtual

Return a complete URI for media identified by fileName.

Implements KTextTemplate::AbstractTemplateLoader.

Definition at line 145 of file templateloader.cpp.

◆ loadByName()

Template FileSystemTemplateLoader::loadByName ( const QString & name,
Engine const * engine ) const
overridevirtual

Load a Template called name.

Return an invalid Template if no content by that name exists.

Implements KTextTemplate::AbstractTemplateLoader.

Definition at line 116 of file templateloader.cpp.

◆ setTemplateDirs()

void FileSystemTemplateLoader::setTemplateDirs ( const QStringList & dirs)

Sets the directories to look for template files to dirs.

Definition at line 78 of file templateloader.cpp.

◆ setTheme()

void FileSystemTemplateLoader::setTheme ( const QString & themeName)

Sets the theme of this loader to themeName.

Definition at line 62 of file templateloader.cpp.

◆ templateDirs()

QStringList FileSystemTemplateLoader::templateDirs ( ) const

The directories this TemplateLoader looks in for template files.

Definition at line 89 of file templateloader.cpp.

◆ themeName()

QString FileSystemTemplateLoader::themeName ( ) const

The themeName of this TemplateLoader.

Definition at line 72 of file templateloader.cpp.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:12:30 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.