picocms / Pico

Pico is a stupidly simple, blazing fast, flat file CMS.
http://picocms.org/
MIT License
3.83k stars 617 forks source link

YAML for plugin config #439

Closed bricebou closed 6 years ago

bricebou commented 6 years ago

Hi again,

I'm planning to upgrade my SyntaxHighlighter plugin (https://github.com/bricebou/pico_SyntaxHighlighter) for Pico 2.

In the old version, the configuration took place in the root config.php:

// Select the theme for SyntaxHighlighter, from the syntaxhighlighter/styles folder :
// Default, Django, Eclipse, Emacs, FadeToGrey, MDUltra, Midnight, RDark
$config['synhigh']['theme'] = 'Emacs';
// If "true", load the Autoloader script that dynamically load the brushes
// without having to load them all on the same page
// If true, you have to define the brushes you use on your pages
$config['synhigh']['autoloader'] = true;
// If you use the autoloader, you have to define the brushes you use on your pages
// or all of them. The brushes can be found in the syntaxhighlighter/scripts folder. 
// You can specify your own aliases for the brushes.
$config['synhigh']['autobrush'] = array(
    'bash shell' => 'Bash',
    'txt plain text' => 'Plain',
    'js jscript javascript' => 'JScript',
    'tex latex' => 'Latex',
    'perl' => 'Perl',
    'python' => 'Python',
    'ruby' => 'Ruby',
    'php' => 'Php',
    'xml xhtml xslt html' => 'Xml',
    'yaml' => 'Yaml'
);
// If you don't use the autoloader function, you have to declare here all the brushes you use
// on your pages ; all brushes declared here will be loaded on each page of your site.
// See the syntaxhighlighter/scripts folder
// $config['synhigh']['brush'] = array(
//  'Bash',
//  'Plain',
//  'JScript',
//  'Latex',
//  'Php',
//  'Xml'
// );
// Don't load SyntaxHighlighter on certain pages based on __*single*__ meta tags,
// i.e. meta tags that take only one value, like title, template, category...
// Use the pipe | as separator, without space ; case-sensitive.
$config['synhigh']['exclude'] = array(
    'template' => 'category',
    'title' => 'GCweb, qu\'est-ce que c\'est ?|CV',
    'category' => 'Maîtrise Sciences du langage|Master recherche Sciences du langage|Master professionnel Édition'
);

I would like to use your new YAML config system but I was wondering where to store the config file (a synhigh_conf.yml into the root config folder or a config file inside the plugin directory ?) and how to access it (just withpublic function onConfigLoaded(array &$config) {}` ?).

Thanks in advance !

PhrozenByte commented 6 years ago

Just place it in config/synhigh_conf.yml (or config/config.yml if you prefer a single config file) and use onConfigLoaded(&$array) as before

bricebou commented 6 years ago

Ok, thanks for the precision :-)

Is there a documentation about the changes, so I can make my plugin fully compatible without the need of PicoDeprecated plugin ? Is there a way to test if I call function that are no longer in use ?

PhrozenByte commented 6 years ago

Sure, just refer to http://phrozenbyte.github.io/Pico/in-depth/upgrade-pico-20/ for changes that mostly affect users, and https://github.com/picocms/Pico/blob/pico-1.1/CHANGELOG.md for the full changelog, including all changes relevant for developers. You can disable Pico's PicoDeprecated plugin by adding PicoDeprecated.enabled: false to your config/config.yml.

bricebou commented 6 years ago

Ok, thanks for this. I've just looked to this old development and I was wondering if I'm right. Two questions:

Thanks again !

PhrozenByte commented 6 years ago
synhigh:
  theme: Emacs
  autoloader: true
  autobrush:
    "bash shell": Bash
    "txt plain text": Plain
    "js jscript javascript": JScript
    "tex latex": Latex
    "php": Php
    "xml xhtml xslt html": Xml
bricebou commented 6 years ago

Thanks !

But, I still have an issue... with this part:

$config['synhigh']['brush'] = array(
    'Bash',
    'Plain',
    'JScript',
    'Latex',
    'Php',
    'Xml'
);
synhigh:
  brush:
    "Bash"
    "Plain"
    "JScript"
    "Latex"
    "Php"
    "Xml"

with or without quotes, I have a PHP Fatal error..

PHP Fatal error:  Uncaught Symfony\\Component\\Yaml\\Exception\\ParseException: Unable to parse at line 42 (near ""Bash""). in /home/bbrice/webdev/www-dev/vendor/symfony/yaml/Parser.php:288\nStack trace:\n#0 /home/bbrice/webdev/www-dev/vendor/symfony/yaml/Parser.php(320): Symfony\\Component\\Yaml\\Parser->doParse('"Bash"\\n"Plain"\\n...', false, false, false)\n#1 /home/bbrice/webdev/www-dev/vendor/symfony/yaml/Parser.php(246): Symfony\\Component\\Yaml\\Parser->parseBlock(29, '"Bash"\\n"Plain"\\n...', false, false, false)\n#2 /home/bbrice/webdev/www-dev/vendor/symfony/yaml/Parser.php(320): Symfony\\Component\\Yaml\\Parser->doParse(Array, false, false, false)\n#3 /home/bbrice/webdev/www-dev/vendor/symfony/yaml/Parser.php(246): Symfony\\Component\\Yaml\\Parser->parseBlock(9, 'theme: Emacs\\nau...', false, false, false)\n#4 /home/bbrice/webdev/www-dev/vendor/symfony/yaml/Parser.php(78): Symfony\\Component\\Yaml\\Parser->doParse('synhigh:\\n  them...', false, false, false)\n#5 /home/bbrice/webdev/www-dev/vendor/picocms/pico/lib/Pico.php(884): Symfony\\Component\\Ya in /home/bbrice/webdev/www-dev/vendor/symfony/yaml/Parser.php on line 288, referer: http://dev.localhost/parcours/M2pro/

Beside of that and beside of plugin filename, it seems that this plugin is version 2 compatible ! :-)

PhrozenByte commented 6 years ago

Forgive me for being so straightforward, but please try to find a solution yourself (especially by reading the docs) before asking such basic questions. It's a simple YAML list.

synhigh:
  brush:
    - Bash
    - Plain
    - JScript
    - Latex
    - Php
    - Xml
bricebou commented 6 years ago

You are forgiven... I'm sorry, but I'm just a hobbyist coder and it's been a while I touched this code, and I didn't know what to look for exactly. I'm going to open a new thread however regarding another plugin...

So, I made it work and the PicoSyntaxHighlighter is ready (it seems to me) for Pico CMS version 2. The code is here: https://github.com/bricebou/PicoSyntaxHighlighter Again, sorry and many thanks !