File indexing completed on 2024-04-21 03:49:59

0001 // SPDX-FileCopyrightText: 2012 Illya Kovalevskyy <illya.kovalevskyy@gmail.com>
0002 //
0003 // SPDX-License-Identifier: LGPL-2.1-or-later
0004 
0005 #ifndef MARBLE_TEMPLATEDOCUMENT_H
0006 #define MARBLE_TEMPLATEDOCUMENT_H
0007 
0008 #include <QtGlobal>
0009 
0010 class QString;
0011 
0012 namespace Marble
0013 {
0014 
0015 class TemplateDocumentPrivate;
0016 
0017 /**
0018  * @brief The Template Document
0019  *
0020  * The class represents a template engine for
0021  * Marble HTML/plain text. It allows to template big
0022  * documents with variables like %variable_name% or
0023  * to make includes like %!{include_name}%
0024  *
0025  * "Include" is a special type of template variables which
0026  * allows to include extra already templated text into the
0027  * template. E.g. %!{bootstrap}% will include bootstrap CSS
0028  * files into html file, where this include is called
0029  *
0030  * @see TemplateDocument()
0031  *
0032  */
0033 class TemplateDocument
0034 {
0035 public:
0036     TemplateDocument();
0037     explicit TemplateDocument(const QString &templateText);
0038     ~TemplateDocument();
0039 
0040     /**
0041      * @brief Returns the current template value of @p key
0042      * @param key template key (\<here\>)
0043      * @return value of the template
0044      */
0045     QString value(const QString &key) const;
0046 
0047     /**
0048      * @brief Change set template value into new one
0049      * @param key template key
0050      * @param value template value
0051      */
0052     void setValue(const QString &key, const QString &value);
0053 
0054     /**
0055      * @brief Set template text
0056      * @param newTemplateText new template text
0057      */
0058     void setTemplate(const QString &newTemplateText);
0059 
0060     /**
0061      * @brief Indexator for template values
0062      * @param key template value's index
0063      * @return reference for the item
0064      */
0065     QString& operator[](const QString &key);
0066 
0067     /**
0068      * @brief Final proceed text
0069      *
0070      * @return ready text with all variables and includes processed
0071      */
0072     QString finalText() const;
0073 
0074 private:
0075     Q_DISABLE_COPY(TemplateDocument)
0076     TemplateDocumentPrivate *d;
0077 };
0078 
0079 } // namespace Marble
0080 
0081 #endif // MARBLE_TEMPLATEDOCUMENT_H