
namespace KTextTemplate
{
/**
  @page using_and_deploying Using %KTextTemplate in your application

  Using %KTextTemplate in %Qt applications will often not require much code.

  @code
    auto engine = getEngine();
    auto t = engine->loadByName( "mytemplate.html" );
    Context c;
    c.insert( "some_input", some_value );
    browser.setHtml( t->render( c ) );
  @endcode

  Error handling etc is omitted for clarity. In order for the above to work as expected, it is necessary to configure the build system to find %KTextTemplate, and to configure %KTextTemplate to find templates and plugins.

  @section finding_with_cmake Finding KTextTemplate with CMake

  %KTextTemplate uses the <a href="http://www.cmake.org/">CMake</a> cross platform build system, and installs a cmake file called <tt>KF6TextTemplateConfig.cmake</tt>. This config file is automatically searched for by CMake and contains the information needed for other CMake based applications to find headers and link against %KTextTemplate libraries. See https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html for more.

  When creating an application using CMake that depends on %KTextTemplate, first issue the <tt>find_package</tt> command, and then use the CMake <tt>target_link_libraries</tt> command link to and use the libraries.

  @code
    project(my_application)

    cmake_minimum_required(VERSION 2.8.11)

    set(CMAKE_AUTOMOC ON)
    set(CMAKE_INCLUDE_CURRENT_DIR ON)

    find_package(KF6TextTemplate REQUIRED)

    # ... Application sources etc.

    target_link_libraries(my_application
      PRIVATE
        Qt5::Widgets
        KF6::TextTemplate
    )
  @endcode

  @section deploying_templates Deploying Templates

  %Template files can be installed by your application and must later be found by %KTextTemplate so they can be used. If the files are installed on the filesystem, the path they were installed to can be specified when creating a AbstractTemplateLoader instance.

  @code
    Engine* getEngine()
    {
      auto engine = new Engine( this );

      auto loader = QSharedPointer<FileSystemTemplateLoader>::create();
      loader->setTemplateDirs( QStringList{ path_to_installed_templates } );

      engine->addTemplateLoader( loader );
      return engine;
    }
  @endcode

  It is also possible to compile the templates into a <a href="https://doc.qt.io/qt-5/resources.html">Qt Resource</a> file and set the resource URL on the AbstractTemplateLoader instance.

  my_app_templates.qrc:
  @code
    <!DOCTYPE RCC><RCC version="1.0">
    <qresource>
        <file>mybasetemplate.html</file>
        <file>mytemplate.html</file>
        <file>myothertemplate.html</file>
    </qresource>
    </RCC>
  @endcode


  CMake code:
  @code
    set (_rcc_file "my_app_templates.qrc")
    qt5_add_resources(_template_rcc_src ${_rcc_file} OPTIONS -root "/templates/" )

    add_executable(my_app, ${my_app_srcs} ${_template_rcc_src})
  @endcode

  Application code:

  @code
    auto loader = QSharedPointer<FileSystemTemplateLoader>::create();
    loader->setTemplateDirs( QStringList{ ":/templates/" } );

    engine->addTemplateLoader( loader );
  @endcode

  The <tt>-root</tt> option passed to <tt>rcc</tt> in CMake causes the templates to be in the virtual filesystem location &quot;<tt>:/templates/mytemplate.html</tt>&quot; etc. This name spacing helps keep independent data in the virtual filesystem separate.

  @section finding_user_templates Finding user defined templates

  If users are able to define their own templates in an application that uses %KTextTemplate for theming for example, the path to the location of such potential templates must also be set through the AbstractTemplateLoader instance. Paths to user defined templates should be defined before default/installed templates so that the user templates are found first. If there is a reason to disallow user overriding of certain templates, they can be specified in a separate AbstractTemplateLoader instance.

  @code
    auto no_override_loader = QSharedPointer<FileSystemTemplateLoader>::create();
    no_override_loader->setTemplateDirs(
        QStringList{ path_to_non_overridable_templates }
        );

    engine->addTemplateLoader( no_override_loader );

    auto override_loader = QSharedPointer<FileSystemTemplateLoader>::create();
    override_loader->setTemplateDirs(
        QStringList{ path_to_user_templates, path_to_default_templates }
        );

    engine->addTemplateLoader( override_loader );
  @endcode

  Additionally, the <a href="https://doc.qt.io/qt-5/resources.html#external-binary-resources">External binary resources</a> feature could be used to allow savvy users to share themes/templates in a package, or to deploy updated templates easily to existing deployed applications.

  @section finding_plugins Finding tags and filters

  %KTextTemplate looks for plugins in the paths from the Engine::pluginPaths property. It does so
  in the same order they appear there.

  The property defaults to the following directories
    - The default plugin directory of your %Qt installation (<tt>qmake -query QT_INSTALL_PLUGINS</tt>).
    - The directories specified in the environment variable <tt>QT_PLUGIN_DIR</tt>.
    - The default plugin directory of your %KTextTemplate installation.

  Each path has <tt>&quot;kf6/ktexttemplate&quot;</tt> appended to it, and the resulting
  directory is searched for plugins. For example, if
  QCoreApplication::libraryPaths() contains <tt>&quot;/usr/lib/plugins/&quot;</tt>, the directory
  <tt>&quot;/usr/lib/plugins/kf6/ktexttemplate&quot;</tt> would be searched for plugins. The search
  stops when a plugin matching a particular name is found.

  The paths used to search for plugins can be overriden by using Engine::setPluginPaths. If you
  just want to add some additional paths use Engine::addPluginPath. The added path will be
  prepended to the list of search paths.

  @section deploying_custom_plugins Deploying custom tags and filters

  Custom tags and filters can be defined in C++ code or in Javascript.

  To create a custom C++ plugin it must be built as part of a library and installed in a location known to the application.

  @code
    # CMake code

    add_library(my_custom_plugin MODULE
      custom_plugin_library.cpp
    )

    install(TARGETS my_custom_plugin
            RUNTIME DESTINATION ${PLUGIN_INSTALL_DIR}
            LIBRARY DESTINATION ${PLUGIN_INSTALL_DIR}
            ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
            COMPONENT Devel
    )
  @endcode

  In this case, <tt>my_custom_plugin</tt> is a name used for the plugin in the CMake environment. It is used to install the custom library in the CMake <tt>install</tt> command.

  <tt>custom_plugin_library.cpp</tt> is the C++ file where you implement the KTextTemplate::TagLibraryInterface to return custom tags and filters.

  Note that the <tt>PLUGIN_INSTALL_DIR</tt> given to the install command should point to the subdir specific
  for the %KTextTemplate plugins. For example, <tt>/usr/share/my_app/plugins/kf6/ktexttemplate/</tt>.

  In C++ code, it is necessary to either instruct the KTextTemplate::Engine about the location of the plugins or to configure your QCoreApplication::libraryPaths by another standard method. Note that it is possible to define custom versions of built in tags and filters by putting your own plugin library in the path before the path to the default %KTextTemplate plugins.

  For example, if your custom plugin library contained a custom implementation of the @gr_tag{for} tag:
  @code
    auto engine = new Engine( this );
    engine->setPluginPaths(
        QStringList{ path_to_custom_plugins, path_to_ktexttemplate_defaults }
        );
  @endcode

  Custom tags and filters implemented in Javascript can also be deployed on the file system, or, like template files, can also be deployed in %Qt Resource files. In that case, the plugin subdir should be specified in the -root argument in CMake.

  @code
    # CMake code:
    set (_rcc_file "my_qtscript_library.qrc")
    qt5_add_resources(_scripted_rcc_src
        ${_rcc_file}
        OPTIONS -root "/plugins/kf6/ktexttemplate"
    )

    add_executable(my_app, ${my_app_srcs} ${_scripted_rcc_src})

    # C++ code:
    engine->setPluginPaths( QStringList{ ":/plugins/" } );
  @endcode

  Note again that when specifying the path in the virtual filesystem, the subdir is omitted. User defined filter written in Javascript can also be located similiarly to templates from either the filesystem or the %Qt Resource virtual filesystem.

  @section building_ktexttemplate Building KTextTemplate

  It is possible to build only parts of %KTextTemplate if your application is a QCoreApplication that depends only on QtCore

  The appropriate options may be specified in the cmake gui, or on the command line using the <tt>BUILD_TEXTDOCUMENT</tt> or <tt>BUILD_TEMPLATES</tt> CMake options.

  @code
    mkdir build && cd build
    cmake .. -DBUILD_TEXTDOCUMENT=OFF -DBUILD_TESTING=OFF
  @endcode

  Similarly, it is possible to build only the core of the %KTextTemplate Template library without the plugins. This may be useful for specialized applications, but as the unit tests depend on the plugins, the tests would need to be deactivated in this case too:

  @code
    mkdir build && cd build
    cmake .. -DBUILD_TEXTDOCUMENT=OFF -DBUILD_TESTING=OFF -DBUILD_MAIN_PLUGINS=OFF
  @endcode

  By default, %KTextTemplate depends on the QtQml library in order to implement Javascript support. This support is only enabled if the QtQml library is found.

*/
}
