developer.jelix.org is not used any more and exists only for history. Post new tickets on the Github account.
developer.jelix.org n'est plus utilisée, et existe uniquement pour son historique. Postez les nouveaux tickets sur le compte github.

Opened 12 years ago

Closed 8 years ago

#624 closed new feature (fixed)

Block template de compression JS

Reported by: hadrien Owned by: laurentj
Priority: low Milestone: Jelix 1.2.7
Component: jelix:plugins:tpl Version:
Severity: minor Keywords:
Cc: Blocked By:
Blocking: Documentation needed: no
Hosting Provider: Php version:

Description

Voici un plugin de template de type block permettant de compresser du JS dans un template :

<?php
/**
 * Compress JS in templates
 * @package    jelix
 * @subpackage jtpl_block
 * @version    1
 * @author      Hadrien Lanneau <contact at hadrien dot eu>
 * @copyright  2008 Hadrien.eu
 */

/**
 * jscompress : formate a js block code by removing spaces, tabs and returns.
 * Example:  {jscompress}var foo = bar;{/jscompress}
 * @return string
 */
function jtpl_block_common_jscompress(
        $compiler,
        $begin,
        $params = array())
{
        if ($begin)
        {
                $content = ' ob_start();';
        }
        else
        {
                $content = '
                $buffer = preg_replace(
                        array(
                                "/\/\/.*\n/",
                                "/[\t\n]+/",
                                "/\/\*.*?\*\//"
                        ),
                        array(
                                " ",
                                " ",
                                " "
                        ),
                        ob_get_contents()
                ) . "\n";
                ob_end_clean();
                print $buffer;';
        }
        return $content;
}

?>

Ça fonctionne comme ça :

{jscompress}
var lol = function()
{
	var kikoo = 'lol';
	return kikoo;
}
{/jscompress}

Et ça retourne :

var lol = function() { var kikoo = 'lol'; return kikoo; }

Pensez à bien mettre des point virgules en fin de lignes ;)

Change History (5)

comment:1 Changed 12 years ago by laurentj

  • Component changed from jelix to jelix:plugins
  • Priority changed from normal to low
  • Severity changed from normal to minor
  • Type changed from bug to new feature
  • Version 1.0.4 deleted

comment:2 Changed 10 years ago by laurentj

  • Component changed from jelix:plugins to jelix:plugins:tpl

comment:3 Changed 8 years ago by laurentj

  • Owner set to laurentj
  • Status changed from new to reviewing

comment:4 Changed 8 years ago by laurentj

  • Milestone set to Jelix 1.2.7
  • Status changed from reviewing to reviewed

comment:5 Changed 8 years ago by laurentj

  • Resolution set to fixed
  • Status changed from reviewed to closed
Note: See TracTickets for help on using tickets.