コード例 #1
1
ファイル: Templatr.php プロジェクト: bahulneel/php-templatr
 public function render()
 {
     $m = new \Mustache_Engine();
     $template = $this->template->contents();
     $output = $m->render($template, $this->context);
     $this->output->write($output);
 }
コード例 #2
0
ファイル: mustache.php プロジェクト: nooku/nooku-framework
 /**
  * Render a template
  *
  * @param   string  $source   The template path or content
  * @param   array   $data     An associative array of data to be extracted in local template scope
  * @throws \RuntimeException If the template could not be loaded
  * @return string The rendered template
  */
 public function render($source, array $data = array())
 {
     parent::render($source, $data);
     //Let mustache load the template by proxiing through the load() method.
     $result = $this->_mustache->render($source, $data);
     //Render the debug information
     return $this->renderDebug($result);
 }
コード例 #3
0
 public function renderFile($templateNames, $data)
 {
     $this->ensureLoaded();
     $templatePath = null;
     foreach ($templateNames as $templateName) {
         echo $this->mustache->render($templateName, $data);
     }
 }
コード例 #4
0
ファイル: controller.php プロジェクト: Swapon444/Patrimoine
 /**
  * @param $_pageContent : Contenu à "templater"
  * @param null $_data : Source de données optionnelle
  */
 function renderTemplate($_pageContent, $_data = null)
 {
     // Ajout des constantes de chemin absolu
     $_data["PUBLIC_ABSOLUTE_PATH"] = PUBLIC_ABSOLUTE_PATH;
     $_data["SERVER_ABSOLUTE_PATH"] = SERVER_ABSOLUTE_PATH;
     $mustache = new Mustache_Engine();
     // Favicons
     $_data["favicons"] = $mustache->render(file_get_contents("public/html/favicons.html"), $_data);
     echo $mustache->render($_pageContent, $_data);
 }
コード例 #5
0
ファイル: Mustache.php プロジェクト: nineeshk/incubator
 /**
  * {@inheritdoc}
  *
  * @param string  $path
  * @param array   $params
  * @param boolean $mustClean
  */
 public function render($path, $params, $mustClean = false)
 {
     if (!isset($params['content'])) {
         $params['content'] = $this->_view->getContent();
     }
     $content = $this->mustache->render(file_get_contents($path), $params);
     if ($mustClean) {
         $this->_view->setContent($content);
     } else {
         echo $content;
     }
 }
コード例 #6
0
ファイル: Mustache.php プロジェクト: kathynka/Foundation
 /**
  * {@inheritdoc}
  *
  * @param string  $path
  * @param array   $params
  * @param boolean $mustClean
  */
 public function render($path, $params, $mustClean = false)
 {
     if (!isset($params['content'])) {
         $params['content'] = $this->_view->getContent();
     }
     $tplContent = $this->getCachedTemplate($path);
     $content = $this->mustache->render("{{%FILTERS}}\n" . $tplContent, $params);
     if ($mustClean) {
         $this->_view->setContent($content);
     } else {
         echo $content;
     }
 }
コード例 #7
0
ファイル: Module.php プロジェクト: wasabi-cms/cms
 /**
  * Render the output for this module (out.ctp).
  *
  * @param BasicThemeView $view
  * @return string
  */
 public function render($view)
 {
     if (method_exists($this, 'beforeRender')) {
         $this->beforeRender();
     }
     if (method_exists($this, 'getContext')) {
         $contextClass = $this->getContext();
         $context = new $contextClass($view, $this->data);
         $template = $this->path() . DS . 'out.mustache';
     } else {
         $template = $this->path() . DS . 'out.ctp';
     }
     if (!file_exists($template)) {
         user_error(__d('wasabi_cms', 'Template "{0}" for module {1} not found.', $template, $this->name()));
     }
     if (isset($context)) {
         if (!$this->_mustache) {
             $this->_mustache = new \Mustache_Engine();
         }
         $output = $this->_mustache->render(file_get_contents($template), $context);
     } else {
         $output = $view->element('Wasabi/Cms.module', ['template' => $template, 'data' => $this->data]);
     }
     return $output;
 }
コード例 #8
0
ファイル: layout.php プロジェクト: RomLAURENT/Jar2Fer
 public function render($template, $data=true)
 {   
     $data=$this->createView($data);
     return $this->m->render("{{# render}}$template{{/ render}}",[
         'session'=>[
             'debug'=>DEBUG,
             'hc'=> 
                 $this->api->estAuthentifier()?
                 $this->api->compteConnecte()->contraste:
                 false,
             'pages'=>$this->api->API_pages_lister(),
             'compte'=>$this->api->compteConnecte(),
             'estAuthentifier'=>$this->api->estAuthentifier(),
             'estAdministrateur'=>$this->api->estAdmin(),
             'estDesactive'=>$this->api->estDésactivé(),
             'estLibreService'=>$this->api->estLibreService(),
             'estNouveau'=>$this->api->estNouveau(),
             //'estPanier'=>$this->api->estPanier(),
             //'estPremium'=>$this->api->estPremium(),
             'peutCommander'=>$this->api->peutCommander(),
             'peutModifierCommande'=>function($value){
                 return $this->api->peutModifierCommande($value);
             }
         ],
         'data'=>$data
     ]);
     
 }
コード例 #9
0
 public static function show_news($folder = 'posts', $template = 'templates')
 {
     $m = new Mustache_Engine();
     $files = glob("{$folder}/*.md");
     /** /
         usort($files, function($a, $b) {
             return filemtime($a) < filemtime($b);
         });
         /**/
     $html = '';
     foreach ($files as $file) {
         $route = substr($file, strlen($folder) + 1, -3);
         $page = new FrontMatter($file);
         $title = $page->fetch('title') != '' ? $page->fetch('title') : $route;
         $date = $page->fetch('date');
         $author = $page->fetch('author');
         $description = $page->fetch('description') == '' ? '' : $page->fetch('description');
         $data[] = array('title' => $title, 'route' => $route, 'author' => $author, 'description' => $description, 'date' => $date);
     }
     /**/
     function date_compare($a, $b)
     {
         $t1 = strtotime($a['date']);
         $t2 = strtotime($b['date']);
         return $t1 - $t2;
     }
     usort($data, 'date_compare');
     $data = array_reverse($data);
     /**/
     $template = file_get_contents('templates/show_news.tpl');
     $data['files'] = $data;
     return $m->render($template, $data);
     return $html;
 }
コード例 #10
0
 /**
  * Renders a template using Mustache.php.
  *
  * @see View::render()
  * @param string $template The template name specified in Slim::render()
  * @return string
  */
 public function render($template)
 {
     require_once self::$mustacheDirectory . '/Autoloader.php';
     \Mustache_Autoloader::register(dirname(self::$mustacheDirectory));
     $m = new \Mustache_Engine();
     $contents = file_get_contents($this->getTemplatesDirectory() . '/' . ltrim($template, '/'));
     return $m->render($contents, $this->data);
 }
コード例 #11
0
 /**
  * Generate the objects and factories
  */
 public function generate()
 {
     $this->readyDestinationDirectory();
     $tableSchemas = (new SchemaGenerator($this->connection))->getTableSchemas();
     // @codeCoverageIgnoreStart
     if ($tableSchemas === null || count($tableSchemas) === 0) {
         throw new \Parm\Exception\ErrorException("No tables in database.");
     }
     // @codeCoverageIgnoreEnd
     $globalNamespaceData['tables'] = [];
     $globalNamespaceData['namespace'] = $this->generateToNamespace;
     $globalNamespaceData['escapedNamespace'] = $this->generateToNamespace != "" ? str_replace("\\", "\\\\", $this->generateToNamespace) . "\\\\" : '';
     $globalNamespaceData['namespaceLength'] = strlen($this->generateToNamespace) + 1;
     foreach ((new SchemaGenerator($this->connection))->getTableSchemas() as $tableName => $schema) {
         $globalNamespaceData['tables'][] = ['className' => ucfirst(\Parm\Row::columnToCamelCase($tableName))];
         $data = $this->getTemplatingDataFromSchema($schema);
         $m = new \Mustache_Engine();
         $this->writeContentsToFile(rtrim($this->destinationDirectory, '/') . '/' . $data['className'] . 'Table.php', $m->render(file_get_contents(dirname(__FILE__) . '/templates/table_interface.mustache'), $data));
         $this->writeContentsToFile(rtrim($this->destinationDirectory, '/') . '/' . $data['className'] . 'TableFunctions.php', $m->render(file_get_contents(dirname(__FILE__) . '/templates/table_trait.mustache'), $data));
         $this->writeContentsToFile(rtrim($this->destinationDirectory, '/') . '/' . $data['className'] . 'DaoObject.php', $m->render(file_get_contents(dirname(__FILE__) . '/templates/dao_object.mustache'), $data));
         $this->writeContentsToFile(rtrim($this->destinationDirectory, '/') . '/' . $data['className'] . 'DaoFactory.php', $m->render(file_get_contents(dirname(__FILE__) . '/templates/dao_factory.mustache'), $data));
         // global namespace file
         if ($this->generateToNamespace != "\\" && $this->generateToNamespace != "") {
             $this->writeContentsToFile(rtrim($this->destinationDirectory, '/') . '/alias_all_tables_to_global_namespace.php', $m->render(file_get_contents(dirname(__FILE__) . '/templates/alias_all_tables_to_global_namespace.mustache'), $globalNamespaceData));
             $this->writeContentsToFile(rtrim($this->destinationDirectory, '/') . '/autoload.php', $m->render(file_get_contents(dirname(__FILE__) . '/templates/namespaced_autoload.mustache'), $globalNamespaceData));
         } else {
             $this->writeContentsToFile(rtrim($this->destinationDirectory, '/') . '/autoload.php', $m->render(file_get_contents(dirname(__FILE__) . '/templates/global_autoload.mustache'), $globalNamespaceData));
         }
     }
 }
コード例 #12
0
ファイル: TemplateEngine.php プロジェクト: alex2stf/phpquick
 public static function mustacheRender($template, $values)
 {
     TemplateEngine::getMustacheInstance();
     $m = new Mustache_Engine();
     //
     $response = $m->render($template, $values);
     //        $response = preg_replace('/[\s\t\n\r\s]+/', ' ', $response);
     return $response;
 }
コード例 #13
0
ファイル: MustView.php プロジェクト: adamhesim/karet
 public function render($filename, $tplvars = false, $nodisplay = false)
 {
     $data = $this->mergeData($tplvars);
     $tpl = parent::render($filename, $data);
     if ($nodisplay) {
         return $tpl;
     } else {
         echo $tpl;
     }
 }
コード例 #14
0
ファイル: registration.php プロジェクト: Swapon444/Patrimoine
 function register()
 {
     if ('POST' == $_SERVER['REQUEST_METHOD']) {
         //stocke les valeurs
         $email = strtolower($_POST["txtMail"]);
         $firstName = $_POST["txtFirstName"];
         $lastName = $_POST["txtLastName"];
         $phone = $_POST["txtPhone"];
         $pass = $_POST["txtPassword"];
         $passCheck = $_POST["txtPasswordConfirm"];
         if (!empty($_POST["txtMail"]) and !empty($_POST["txtFirstName"]) and !empty($_POST["txtLastName"]) and !empty($_POST["txtPhone"]) and !empty($_POST["txtPassword"])) {
             //modifier le numéro de téléphone afin de correspondre à la BD
             $phone = self::normalizePhoneNumber($phone);
             //vérifier si informations valides (email + pass)
             if (Users::getUserIdByName($email) == -1 && $pass == $passCheck) {
                 $salt = self::generateSalt();
                 $crypt = crypt($pass, $salt);
                 $userId = Users::addFamilyOwner($email, $phone, $firstName, $lastName, $crypt, $salt);
                 $owner = $userId;
                 $name = "Contenant principal";
                 $parent = null;
                 $value = 0;
                 $initValue = 0;
                 $warranty = "";
                 $infos = "";
                 $summary = "Contenant de départ";
                 $public = 1;
                 $quantity = 1;
                 Objects::addObject($name, $owner, $parent, $value, $initValue, $warranty, $infos, $summary, $public, $quantity);
                 header(CONNECTION_HEADER . '/registration');
                 if (isset($userId)) {
                     $user = Users::getUser($userId);
                     $headers = 'MIME-Version: 1.0' . "\r\n";
                     $headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
                     $to = "";
                     $recipients = Users::getAllAdminMail();
                     foreach ($recipients as $recipient) {
                         $to .= $recipient . ', ';
                     }
                     substr($to, 0, -2);
                     $subject = "Nouvelle demande de patrimoine";
                     $data = array('path' => SERVER_ABSOLUTE_PATH . "/sysadmin", 'user' => $user["UserName"], 'img' => PUBLIC_ABSOLUTE_PATH . "/assets/logo_petit.png");
                     $mustache = new Mustache_Engine();
                     mail($to, $subject, $mustache->render(file_get_contents('public/html/mailtemplateregistration.html'), $data), $headers . "From: " . SENDING_EMAIL);
                 }
             } else {
                 $data = array("SERVER_ABSOLUTE_PATH" => SERVER_ABSOLUTE_PATH, "PUBLIC_ABSOLUTE_PATH" => PUBLIC_ABSOLUTE_PATH, "Error" => true, "ErrorMSG" => Users::getUserIdByName($email) != -1 ? "Adresse courriel déjà en utilisation" : "Vous devez saisir le même mot de passe", "FirstName" => $firstName, "LastName" => $lastName, "Phone" => $phone, "Email" => $email);
                 $this->renderTemplate(file_get_contents(REGISTRATION_PAGE), $data);
             }
         } else {
             $data = array("SERVER_ABSOLUTE_PATH" => SERVER_ABSOLUTE_PATH, "PUBLIC_ABSOLUTE_PATH" => PUBLIC_ABSOLUTE_PATH, "Error" => true, "ErrorMSG" => "Informations manquantes", "FirstName" => $firstName, "LastName" => $lastName, "Phone" => $phone, "Email" => $email);
             $this->renderTemplate(file_get_contents(REGISTRATION_PAGE), $data);
         }
     }
 }
コード例 #15
0
 static function render($view, $data)
 {
     global $aplication;
     global $debugbar;
     $app = $aplication->getApp();
     $path = $app->getViews();
     Mustache_Autoloader::register();
     $options = array('extension' => '.mustache');
     $template = new Mustache_Engine(array('loader' => new Mustache_Loader_FilesystemLoader($path, $options)));
     echo $template->render($view, $data);
 }
コード例 #16
0
ファイル: MustacheTemplate.php プロジェクト: arvici/framework
 /**
  * Render template.
  *
  * @param View $template Template view instance.
  * @param array|DataCollection $data Data.
  *
  * @return string|void
  *
  * @throws ConfigurationException
  * @throws FileNotFoundException
  * @throws RendererException
  */
 public function render(View $template, array $data = array())
 {
     if (!empty($this->data)) {
         $data = array_merge($this->data, $data);
     }
     // Load file into string
     $source = file_get_contents($template->getFullPath());
     if ($source === false) {
         throw new FileNotFoundException("View file '" . $template->getFullPath() . "' is not found!");
         // @codeCoverageIgnore
     }
     return $this->mustache->render($source, $data);
 }
コード例 #17
0
ファイル: Mustache.php プロジェクト: arroyo/erdiko
 /** 
  * Example playing with mustache templates
  * the $string variable would really be a view, but it's good to see here.
  */
 public function getMustache()
 {
     $string = "Hello, {{ planet }}!\n            {{# get_region }}two{{/ get_region }}\n            {{# get_region }}'three'{{/ get_region }}\n            {{# index }}four{{/ index }}\n            {{# getMustacheTest2 }}five{{/ getMustacheTest2 }}\n            ";
     $m = new \Mustache_Engine();
     $data = array('planet' => 'world', 'get_region' => function ($name) {
         return $this->getMustacheTest($name);
     }, 'index' => function () {
         return $this->getMustacheTest2();
     });
     $content = $m->render($string, $data);
     $this->setTitle('Mustache');
     $this->setContent($content);
 }
コード例 #18
0
ファイル: component.php プロジェクト: uklibraries/findingaid
 public function render()
 {
     $m = new Mustache_Engine(array('partials_loader' => new Mustache_Loader_FilesystemLoader(implode(DIRECTORY_SEPARATOR, array(APP, 'views', 'findingaid')))));
     $pieces = explode('_', $this->params['id']);
     $id = $pieces[0];
     $component_id = $pieces[1];
     $model = new ComponentModel($id, $component_id);
     $container_list_template = load_template('findingaid/container_list');
     $component_template = load_template('findingaid/component');
     $container_lists = array();
     foreach ($model->container_lists() as $container_list) {
         $container_list_content = $m->render($container_list_template, $container_list);
         $container_lists[] = array('container_list' => $container_list_content);
     }
     $subcomponents = $model->subcomponents();
     $subcomponent_content = array();
     foreach ($model->subcomponents() as $subcomponent) {
         $subcomponent_content[] = array('subcomponent' => $m->render($component_template, array('label' => fa_brevity($subcomponent->title()), 'collapsible' => true, 'scopecontent' => $subcomponent->scopecontent())));
     }
     $component_content = $m->render($component_template, array('label' => fa_brevity($model->title()), 'collapsible' => true, 'container_lists' => $container_lists, 'scopecontent' => $model->scopecontent(), 'subcomponents' => $subcomponent_content));
     return array($component_content, array('level' => (string) $model->level(), 'metadata' => array('label' => fa_brevity($model->title()), 'id' => 'demo_id')));
 }
コード例 #19
0
ファイル: utils.php プロジェクト: diogok/biodiv-ui
function view($name, $props)
{
    if (isset($_SERVER['HTTP_ACCEPTS']) && $_SERVER['HTTP_ACCEPTS'] == 'application/json') {
        header('Content-Type: application/json');
        foreach ($props as $k => $v) {
            if (preg_match('/json/', $k)) {
                unset($props[$k]);
            } else {
                if (is_object($props[$k]) || is_array($props[$k])) {
                    foreach ($props[$k] as $kk => $vv) {
                        if (preg_match('/json/', $kk)) {
                            unset($props[$k][$kk]);
                        }
                    }
                }
            }
        }
        return json_encode($props);
    }
    $partials = [];
    $iterator = new \DirectoryIterator(__DIR__ . "/../templates");
    foreach ($iterator as $file) {
        if ($file->isFile() && preg_match("/\\.mustache\$/", $file->getFilename())) {
            $partials[substr($file->getFilename(), 0, -9)] = file_get_contents($file->getPath() . "/" . $file->getFilename());
        }
    }
    $base = getenv('BASE');
    if ($base == null) {
        $base = "";
    }
    $props['base'] = $base;
    if (isset($_SESSION['lang'])) {
        $props['strings'] = json_decode(file_get_contents(__DIR__ . '/../lang/' . $_SESSION['lang'] . '.json'));
    } else {
        $props['strings'] = json_decode(file_get_contents(__DIR__ . '/../lang/en.json'));
    }
    $template = file_get_contents(__DIR__ . '/../templates/' . $name . '.mustache');
    $m = new \Mustache_Engine(array('partials' => $partials));
    $m->addHelper('json', function ($v) {
        return json_encode($v);
    });
    $m->addHelper('geojson', function ($v) {
        if ($v != null) {
            return json_encode($v);
        } else {
            return '{"features":[],"type":"FeatureCollection"}';
        }
    });
    $content = $m->render($template, $props);
    return $content;
}
コード例 #20
0
ファイル: Mustache.php プロジェクト: mikejestes/ornamental
 public function renderString($string, $templateData)
 {
     if ($this->settings->partialDir) {
         $partialDir = $this->settings->partialDir;
     } else {
         $partialDir = $this->settings->templateDir . 'partials/';
     }
     $options = array();
     if (is_dir($partialDir)) {
         $options['partials_loader'] = new \Mustache_Loader_FilesystemLoader($partialDir);
     }
     $mustacheEngine = new \Mustache_Engine($options);
     return $mustacheEngine->render($string, $templateData);
 }
コード例 #21
0
ファイル: Generator.php プロジェクト: afosto/api-client
 /**
  * Render the templates and store the files in the model directory
  */
 private function _generateModels()
 {
     $model = file_get_contents($this->_rootDir . '/' . self::TEMPLATE_DIR . '/model.mustache');
     $apiModel = file_get_contents($this->_rootDir . '/' . self::TEMPLATE_DIR . '/api_model.mustache');
     $link = file_get_contents($this->_rootDir . '/' . self::TEMPLATE_DIR . '/link.mustache');
     $baseModel = file_get_contents($this->_rootDir . '/' . self::TEMPLATE_DIR . '/base_model.mustache');
     $baseApiModel = file_get_contents($this->_rootDir . '/' . self::TEMPLATE_DIR . '/base_api_model.mustache');
     $baseLink = file_get_contents($this->_rootDir . '/' . self::TEMPLATE_DIR . '/base_link.mustache');
     $modelDir = $this->_rootDir . '/' . self::TARGET_PATH . '/';
     if (is_dir($modelDir)) {
         shell_exec('rm -rf ' . $modelDir);
     }
     foreach ($this->_definitions as $definition) {
         $dir = $modelDir . $definition->namespace . '/';
         $baseDir = $modelDir . '_Base/' . $definition->namespace . '/';
         $baseFile = 'Base' . $definition->name . '.php';
         $file = $definition->name . '.php';
         $basePath = $baseDir . $baseFile;
         $path = $dir . $file;
         if (!is_dir($dir)) {
             mkdir($dir, 0777, true);
         }
         if (!is_dir($baseDir)) {
             mkdir($baseDir, 0777, true);
         }
         if (file_exists($path)) {
             unlink($path);
         }
         if (file_exists($basePath)) {
             unlink($basePath);
         }
         if (in_array(strtolower($definition->name), $this->_paths)) {
             //ApiModel
             $content = $this->_mustache->render($apiModel, $definition->getArray());
             $baseContent = $this->_mustache->render($baseApiModel, $definition->getArray());
         } else {
             if (substr($definition->name, -3) == 'Rel') {
                 //Link
                 $content = $this->_mustache->render($link, $definition->getArray());
                 $baseContent = $this->_mustache->render($baseLink, $definition->getArray());
             } else {
                 //Model
                 $content = $this->_mustache->render($model, $definition->getArray());
                 $baseContent = $this->_mustache->render($baseModel, $definition->getArray());
             }
         }
         file_put_contents($path, $content);
         file_put_contents($basePath, $baseContent);
     }
 }
コード例 #22
0
ファイル: AjaxExample.php プロジェクト: rajesh28892/erdiko
 /**
  * Get
  */
 public function get($var = null)
 {
     if ($var != null) {
         // load action
         return $this->autoaction($var);
     }
     $m = new \Mustache_Engine();
     $test = $m->render('Hello, {{ planet }}!', array('planet' => 'world'));
     // Hello, world!
     // error_log("mustache = {$test}");
     // error_log("var: ".print_r($var, true));
     $data = array("hello", "world");
     $view = new \erdiko\core\View('examples/helloworld', $data);
     $this->setContent($view);
 }
コード例 #23
0
 /**
  * Generate command class based on $args, $assocParams and $params
  * and put content in Command.php file in global cache wp-cli path.
  *
  * @return void
  */
 public static function generateCommandClass()
 {
     $args = \ViewOne\WPCLIEnvironment\Command::getArguments();
     $assocParams = \ViewOne\WPCLIEnvironment\Command::getAssocParameters();
     $params = \ViewOne\WPCLIEnvironment\Command::getParameters();
     $moutstache = new \Mustache_Engine();
     $dir = self::getCachePath();
     if (!file_exists($dir . '/wp-cli-environment')) {
         mkdir($dir . '/wp-cli-environment', 0777, true);
     }
     $template = file_get_contents(__DIR__ . '/../../../template/command.mustache');
     $variables = array('args' => $args, 'assoc_params' => $assocParams, 'params' => $params);
     $class = $moutstache->render($template, $variables);
     file_put_contents($dir . '/wp-cli-environment/Command.php', $class);
 }
コード例 #24
0
ファイル: Mustacher.php プロジェクト: vanilla/mustacher
 public static function generate($template, $data, $format = self::FORMAT_MUSTACHE)
 {
     if (!$format) {
         $format = self::FORMAT_MUSTACHE;
     }
     switch ($format) {
         case self::FORMAT_MUSTACHE:
             $m = new \Mustache_Engine();
             $result = $m->render($template, $data);
             break;
         case self::FORMAT_MESSAGE:
             $result = static::formatString($template, $data);
             break;
         default:
             throw new \Exception("Invalid format {$format}.", 500);
     }
     return $result;
 }
コード例 #25
0
ファイル: RenderCommand.php プロジェクト: renegare/configen
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $file = $input->getArgument('file');
     $exposedEnv = $input->getOption('env');
     $m = new \Mustache_Engine();
     $data = [];
     foreach ($exposedEnv as $key) {
         $value = '';
         if (preg_match('/^([\\w0-9_]+)=(.*)$/', $key, $matches)) {
             $key = $matches[1];
             $value = $matches[2];
         }
         if (!$value) {
             $value = getenv($key);
         }
         $data[$key] = $value;
     }
     $output->writeln($m->render(file_get_contents($file), $data));
 }
コード例 #26
0
 public function parse_string($template, $data = array(), $return = FALSE, $config = array())
 {
     if (!is_array($config)) {
         $config = array();
     }
     $config = array_merge($this->config, $config);
     if (!is_array($data)) {
         $data = array();
     }
     $ci = $this->ci;
     $is_mx = false;
     if (!$return) {
         list($ci, $is_mx) = $this->detect_mx();
     }
     $parser = new Mustache_Engine($config);
     $parser->setLoader(new Mustache_Loader_StringLoader());
     $template = $parser->render($template, $data);
     return $this->output($template, $return, $ci, $is_mx);
 }
コード例 #27
0
ファイル: Writer.php プロジェクト: bluesnowman/Chimera
 /**
  * This method renders the data for the writer.
  *
  * @access public
  * @return string                                           the data as string
  * @throws \Exception                                       indicates a problem occurred
  *                                                          when generating the template
  */
 public function render()
 {
     $metadata = $this->metadata;
     $declaration = $metadata['declaration'] ? Core\Data\XML::declaration($metadata['encoding'][1], $metadata['standalone']) . $metadata['eol'] : '';
     if (!empty($metadata['template'])) {
         $file = new IO\File($metadata['template']);
         $mustache = new \Mustache_Engine(array('loader' => new \Mustache_Loader_FilesystemLoader($file->getFilePath()), 'escape' => function ($string) use($metadata) {
             $string = Core\Data\Charset::encode($string, $metadata['encoding'][0], $metadata['encoding'][1]);
             $string = Core\Data\XML::entities($string);
             return $string;
         }));
         ob_start();
         try {
             echo $declaration;
             echo $mustache->render($file->getFileName(), $this->data);
         } catch (\Exception $ex) {
             ob_end_clean();
             throw $ex;
         }
         $template = ob_get_clean();
         if (!empty($metadata['minify'])) {
             $template = Minify\XML::minify($template, $metadata['minify']);
         }
         return $template;
     } else {
         ob_start();
         try {
             $document = new \DOMDocument();
             $document->formatOutput = true;
             $this->toXML($document, $document, $this->data);
             echo $declaration;
             echo $document->saveXML();
         } catch (\Exception $ex) {
             ob_end_clean();
             throw $ex;
         }
         $template = ob_get_clean();
         return $template;
     }
 }
コード例 #28
0
ファイル: AutoController.php プロジェクト: subbly/cms
 protected function run()
 {
     $routesMap = Config::get('subbly.frontendUri');
     $currentTheme = Config::get('subbly.theme');
     $themePath = TPL_PUBLIC_PATH . DS . $currentTheme . DS;
     $request = Request::createFromGlobals();
     $routes = new Routing\RouteCollection();
     foreach ($routesMap as $uri => $page) {
         preg_match_all('/\\{(.*?)\\}/', $uri, $matches);
         $optionals = array_map(function ($m) {
             return trim($m, '?');
         }, $matches[1]);
         $uri = preg_replace('/\\{(\\w+?)\\?\\}/', '{$1}', $uri);
         $routes->add($page, new Routing\Route($uri, $optionals));
     }
     unset($page);
     $context = new Routing\RequestContext();
     $context->fromRequest($request);
     $matcher = new Routing\Matcher\UrlMatcher($routes, $context);
     // Tremplates
     $options = array('extension' => '.php');
     $m = new \Mustache_Engine(array('loader' => new \Mustache_Loader_FilesystemLoader($themePath, $options), 'partials_loader' => new \Mustache_Loader_FilesystemLoader($themePath . 'partials', $options)));
     try {
         $routeParams = $matcher->match($request->getPathInfo());
         extract($routeParams, EXTR_SKIP);
         foreach ($routeParams as $key => $value) {
             if (isset($this->params[$key])) {
                 $this->params[$key] = $value;
             }
         }
         $this->params['currentpage'] = $_route;
         // \Debugbar::info( $this->params );
         $content = $m->render($_route);
         return \Response::make($content, 200);
     } catch (Routing\Exception\ResourceNotFoundException $e) {
         App::abort(404, 'Page Not Found');
     } catch (Exception $e) {
         App::abort(500, 'An error occurred');
     }
 }
コード例 #29
0
ファイル: MY_Parser.php プロジェクト: siburny/stats
 public function parse_string($template, $data = array(), $return = FALSE, $options = array())
 {
     if (!is_array($options)) {
         $options = array();
     }
     $options = array_merge($this->config, $options);
     if (!isset($options['charset']) || trim($options['charset']) == '') {
         $options['charset'] = $this->ci->config->item('charset');
     }
     $options['charset'] = strtoupper($options['charset']);
     if (!is_array($data)) {
         $data = array();
     }
     $data = array_merge($this->data, $data);
     $parser = new Mustache_Engine($options);
     $template = $parser->render($template, $data);
     if (!$return) {
         $this->ci->output->append_output($template);
         return "";
     }
     return $template;
 }
コード例 #30
0
ファイル: Writer.php プロジェクト: bluesnowman/Chimera
 /**
  * This method renders the data for the writer.
  *
  * @access public
  * @return string                                           the data as string
  * @throws \Exception                                       indicates a problem occurred
  *                                                          when generating the template
  */
 public function render()
 {
     $declaration = $this->metadata['declaration'] ? '<!DOCTYPE html>' . "\n" : '';
     if (!empty($this->metadata['template'])) {
         $file = new IO\File($this->metadata['template']);
         $mustache = new \Mustache_Engine(array('loader' => new \Mustache_Loader_FilesystemLoader($file->getFilePath()), 'escape' => function ($string) {
             return htmlentities($string);
         }));
         ob_start();
         try {
             echo $declaration;
             echo $mustache->render($file->getFileName(), $this->data);
         } catch (\Exception $ex) {
             ob_end_clean();
             throw $ex;
         }
         $template = ob_get_clean();
         //if (!empty($this->metadata['minify'])) {
         //	$template = Minify\HTML::minify($template, $this->metadata['minify']);
         //}
         return $template;
     }
     return $declaration;
 }