2017 © Pedro Peláez
 

library temgen

Template generator

image

bezirovoviku/temgen

Template generator

  • Sunday, January 3, 2016
  • by SkaceKamen
  • Repository
  • 1 Watchers
  • 0 Stars
  • 9 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Template generator

This is simple template system for document files. It uses text replacement, allows cyclical replacements and basic filters., (*1)

Installation

You can install this library using composer, (*2)

composer require bezirovoviku/temgen

Requirements

LibreOffice (2+) - only for OPDF converter, (*3)

PhantomJS - only for PPDF converter, (*4)

Usage

First you will need to include the generator class, (*5)

use Temgen\Generator;

then use generator class as follows, (*6)

//Creates generator
$generator = new Generator();
//Adds basic filters
$generator->addFilters();
//Sets temporary folder used to store documents
$generator->setTmp('/tmp');
//Sets path to template file
$generator->setTemplate(new Document('template.html'));
//Generates zip archive from specified data
$generator->generateArchive(json_decode($this->data, true), 'archive.zip');

Creating custom filters

To create custom filter, you will need to implement \Temgen\Generator\Filter interace, (*7)

class MyFilter implements \Temgen\Generator\Filter
{
    /**
     * Returns tag used to identify filter
     *
     * @return string tag identifing filter
     */
    public function getTag() {
      return 'myfilter';
    }

    /**
     * Filter given arguments and return result
     *
     * @param \Temgen\Generator $generator generator calling this filter
     * @param array           $context   replacing context
     * @param array           $arguments arguments passed to filter
     * @param string|null     $input     pipe input (if present)
     * @return string result
     */
    public function filter($generator, $context, $arguments, $input) {
      return strtoupper($input);
    }
}

then you will need to add instance of this filter to generator instance, like so:, (*8)

$generator = new Generator();
$generator->addFilter(new MyFilter());

now, in this generator instance, filter MyFilter will be accessible by {myfilter} syntax, (*9)

Exporting pdf

This requires libreoffice installed, (*10)

//Creates docx generator
$generator = new Generator\Docx();
//PDF converter
$converter = new Converter\OPDF();
//Adds basic filters
$generator->addFilters();
//Sets temporary folder used to store documents
$generator->setTmp('/tmp');
//Sets path to template file
$generator->setTemplate(new Document\Docx('template.docx'));
//Generates zip archive from specified data, converts using converter
$generator->generateArchive(json_decode($this->data, true), 'archive.zip', $converter);

The Versions

03/01 2016

dev-master

9999999-dev

Template generator

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bezirovoviku

template document docx