Added GeshiBundle to highlight source code
Signed-off-by: Gergely Polonkai (W00d5t0ck) <polesz@w00d5t0ck.info>
This commit is contained in:
parent
4a07b2e120
commit
ea325aab7f
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
require __DIR__ . '/../vendor/easybook/geshi/geshi.php';
|
||||
|
||||
use Symfony\Component\HttpKernel\Kernel;
|
||||
use Symfony\Component\Config\Loader\LoaderInterface;
|
||||
@ -21,6 +22,7 @@ class AppKernel extends Kernel
|
||||
new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(),
|
||||
new Io\TcpdfBundle\IoTcpdfBundle(),
|
||||
new GergelyPolonkai\FrontBundle\GergelyPolonkaiFrontBundle(),
|
||||
new GergelyPolonkai\GeshiBundle\GergelyPolonkaiGeshiBundle(),
|
||||
);
|
||||
|
||||
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
|
||||
|
@ -24,6 +24,7 @@
|
||||
"sensio/generator-bundle": "2.1.*",
|
||||
"jms/security-extra-bundle": "1.2.*",
|
||||
"jms/di-extra-bundle": "1.1.*",
|
||||
"easybook/geshi": "dev-master",
|
||||
"gergelypolonkai/tcpdfbundle": "dev-master"
|
||||
},
|
||||
"scripts": {
|
||||
|
@ -0,0 +1,58 @@
|
||||
/*
|
||||
Document : code
|
||||
Created on : 2012.09.04., 10:05:47
|
||||
Author : polonkai.gergely
|
||||
Description:
|
||||
Purpose of the stylesheet follows.
|
||||
*/
|
||||
|
||||
.code {
|
||||
font-family: monospace;
|
||||
background-color: #333;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
.code * {
|
||||
font-family: monospace;
|
||||
color: #b5b5b5;
|
||||
}
|
||||
|
||||
.code .kw1 {
|
||||
color: #f0e68c;
|
||||
}
|
||||
|
||||
.code .kw2 {
|
||||
color: #cd5c5c;
|
||||
}
|
||||
|
||||
.code .kw3 {
|
||||
color: #f8dead;
|
||||
}
|
||||
|
||||
.code .kw4 {
|
||||
color: #ffa0a0;
|
||||
}
|
||||
|
||||
.code .re0 {
|
||||
color: #98fb98;
|
||||
}
|
||||
|
||||
.code .sy0 {
|
||||
color: #d9d9d9;
|
||||
}
|
||||
|
||||
.code .co4 {
|
||||
color: #87ceeb;
|
||||
}
|
||||
|
||||
.code .br0 {
|
||||
color: #f8d8a9;
|
||||
}
|
||||
|
||||
.code .st_h {
|
||||
color: #ffa0a0;
|
||||
}
|
||||
|
||||
.code .me1 {
|
||||
color: #ffffff;
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace GergelyPolonkai\GeshiBundle\DependencyInjection;
|
||||
|
||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
||||
|
||||
/**
|
||||
* This is the class that validates and merges configuration from your app/config files
|
||||
*
|
||||
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
|
||||
*/
|
||||
class Configuration implements ConfigurationInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getConfigTreeBuilder()
|
||||
{
|
||||
$treeBuilder = new TreeBuilder();
|
||||
$rootNode = $treeBuilder->root('gergely_polonkai_geshi');
|
||||
|
||||
// Here you should define the parameters that are allowed to
|
||||
// configure your bundle. See the documentation linked above for
|
||||
// more information on that topic.
|
||||
|
||||
return $treeBuilder;
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace GergelyPolonkai\GeshiBundle\DependencyInjection;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||
use Symfony\Component\DependencyInjection\Loader;
|
||||
|
||||
/**
|
||||
* This is the class that loads and manages your bundle configuration
|
||||
*
|
||||
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
|
||||
*/
|
||||
class GergelyPolonkaiGeshiExtension extends Extension
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function load(array $configs, ContainerBuilder $container)
|
||||
{
|
||||
$configuration = new Configuration();
|
||||
$config = $this->processConfiguration($configuration, $configs);
|
||||
|
||||
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
$loader->load('services.yml');
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace GergelyPolonkai\GeshiBundle;
|
||||
|
||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
|
||||
class GergelyPolonkaiGeshiBundle extends Bundle
|
||||
{
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
parameters:
|
||||
gergely_polonkai_geshi.geshi_highlighter.class: GergelyPolonkai\GeshiBundle\Twig\GeshiHighlight
|
||||
|
||||
services:
|
||||
gergely_polonkai_geshi.geshi_highlighter:
|
||||
class: %gergely_polonkai_geshi.geshi_highlighter.class%
|
||||
tags:
|
||||
- { name: 'twig.extension' }
|
45
src/GergelyPolonkai/GeshiBundle/Twig/GeshiHighlight.php
Normal file
45
src/GergelyPolonkai/GeshiBundle/Twig/GeshiHighlight.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace GergelyPolonkai\GeshiBundle\Twig;
|
||||
|
||||
use GeSHi;
|
||||
|
||||
/**
|
||||
* Description of GeshiHighlight
|
||||
*
|
||||
* @author polonkai.gergely
|
||||
*/
|
||||
class GeshiHighlight extends \Twig_Extension
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var \GeSHi $geshi
|
||||
*/
|
||||
private $geshi;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->geshi = new GeSHi();
|
||||
}
|
||||
|
||||
public function getFilters()
|
||||
{
|
||||
return array(
|
||||
'geshi_highlight' => new \Twig_Filter_Method($this, 'geshiFilter', array('is_safe' => array('html'))),
|
||||
);
|
||||
}
|
||||
|
||||
public function geshiFilter($code, $lang)
|
||||
{
|
||||
$this->geshi->set_language($lang);
|
||||
$this->geshi->set_source($code);
|
||||
$this->geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
|
||||
$this->geshi->enable_keyword_links(false);
|
||||
$this->geshi->enable_classes();
|
||||
return $this->geshi->parse_code();
|
||||
}
|
||||
|
||||
public function getName() {
|
||||
return 'geshi_highlighter';
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user