Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
cvette committed Apr 15, 2017
0 parents commit a78c3f7
Show file tree
Hide file tree
Showing 14 changed files with 1,090 additions and 0 deletions.
40 changes: 40 additions & 0 deletions Classes/DataSources/GeshiLanguagesDataSource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
namespace Vette\CodeBlock\DataSources;

use Neos\ContentRepository\Domain\Model\NodeInterface;
use Neos\Neos\Service\DataSource\AbstractDataSource;

/**
* GeshiLanguages DataSource
*/
class GeshiLanguagesDataSource extends AbstractDataSource
{

/**
* @return string
*/
public static function getIdentifier()
{
return 'geshiLanguages';
}

/**
* @param NodeInterface|null $node
* @param array $arguments
* @return array
*/
public function getData(NodeInterface $node = null, array $arguments)
{
$geshi = new \GeSHi();
$languages = $geshi->get_supported_languages(true);
$data = array();
foreach ($languages as $language => $fullName) {
$data[] = array(
'value' => $language,
'label' => $fullName
);
}

return $data;
}
}
40 changes: 40 additions & 0 deletions Classes/NodeTypes/CodeBlockImplementation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
namespace Vette\CodeBlock\NodeTypes;

use Neos\Fusion\FusionObjects\AbstractFusionObject;

/**
* CodeBlock Implementation
*/
class CodeBlockImplementation extends AbstractFusionObject {

/**
* Evaluate
*
* @return string
*/
public function evaluate()
{
$source = $this->fusionValue('code');
$language = $this->fusionValue('language');
$showLineNumbers = $this->fusionValue('showLineNumbers');
$startLinesAt = $this->fusionValue('startLinesAt');
$highlightLines = $this->fusionValue('highlightLines');
$inlineCss = $this->fusionValue('inlineCss');

$geshi = new \GeSHi($source, $language);
$geshi->start_line_numbers_at($startLinesAt);
$geshi->highlight_lines_extra($highlightLines);
$geshi->set_overall_class('code-block');

if (!$inlineCss) {
$geshi->enable_classes();
}

if ($showLineNumbers) {
$geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);
}

return $geshi->parse_code();
}
}
58 changes: 58 additions & 0 deletions Configuration/NodeTypes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
'Vette.CodeBlock:CodeBlock':
superTypes:
'Neos.Neos:Content': TRUE
ui:
label: i18n
icon: 'icon-code'
group: 'general'
inspector:
groups:
'codeBlock':
label: 'Code Block'
properties:
code:
type: string
ui:
reloadIfChanged: true
label: i18n
inspector:
group: 'codeBlock'
editor: 'Neos.Neos/Inspector/Editors/CodeEditor'
editorOptions:
buttonLabel: 'Edit'
highlightingMode: 'text/plain'
language:
defaultValue: 'text'
type: string
ui:
reloadIfChanged: true
label: i18n
inspector:
group: 'codeBlock'
editor: 'Neos.Neos/Inspector/Editors/SelectBoxEditor'
editorOptions:
dataSourceIdentifier: 'geshiLanguages'

showLineNumbers:
type: boolean
defaultValue: true
ui:
reloadIfChanged: true
label: i18n
inspector:
group: 'codeBlock'
startLinesAt:
type: integer
defaultValue: 1
ui:
reloadIfChanged: true
label: i18n
inspector:
group: 'codeBlock'
highlightLines:
type: string
ui:
reloadIfChanged: true
label: i18n
inspector:
group: 'codeBlock'
9 changes: 9 additions & 0 deletions Configuration/Settings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Neos:
Neos:
fusion:
autoInclude:
'Vette.CodeBlock': TRUE
userInterface:
translation:
autoInclude:
'Vette.CodeBlock': ['NodeTypes/*']
Loading

0 comments on commit a78c3f7

Please sign in to comment.