Skip to content

Commit

Permalink
Add a way to dump all fixer + better doc
Browse files Browse the repository at this point in the history
  • Loading branch information
lyrixx committed Aug 30, 2021
1 parent 9346ac2 commit af804ee
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion tools/phar/bin/jolitypo
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,49 @@ use Symfony\Component\Finder\Finder;
require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../../../vendor/autoload.php';

$help = <<<EOTXT
JoliTypo is a tool fixing Microtypography glitches inside your HTML content.
# Usages
## Get the list of all available fixers:
<comment>%command.name% --list-rules foo bar</>
## Run the fixer on one file
<comment>%command.name% fr_FR index.html</>
## Run the fixer on one directory
<comment>%command.name% fr_FR directory/</>
## Specify some rules:
<comment>%command.name% fr_FR index.html --rule=FrenchQuotes --rule=Dash</>
EOTXT;

(new SingleCommandApplication('JoliTypo'))
->addArgument('locale', InputArgument::REQUIRED, 'Locale of the content to fix.')
->addArgument('path', InputArgument::REQUIRED, 'Path of file(s) to fix.')
->addOption('rule', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Rules used to fix the content')
->addOption('list-rules', null, InputOption::VALUE_NONE, 'List available rules')
->setHelp($help)
->setCode(function (InputInterface $input, OutputInterface $output): int {
$io = new SymfonyStyle($input, $output);

if ($input->getOption('list-rules')) {
$list = [];
foreach ((new Finder())->in(__DIR__ . '/../../../src/JoliTypo/Fixer')->sortByName()->files() as $file) {
$list[] = $file->getFilenameWithoutExtension();
}
$io->listing($list);

return 0;
}

static $recommendedRulesByLocale = [
'en_GB' => ['Ellipsis', 'Dimension', 'Unit', 'Dash', 'SmartQuotes', 'NoSpaceBeforeComma', 'CurlyQuote', 'Hyphen', 'Trademark'],
'fr_FR' => ['Ellipsis', 'Dimension', 'Unit', 'Dash', 'SmartQuotes', 'FrenchNoBreakSpace', 'NoSpaceBeforeComma', 'CurlyQuote', 'Hyphen', 'Trademark'],
Expand All @@ -37,7 +75,6 @@ require __DIR__ . '/../../../vendor/autoload.php';
$rules = $recommendedRulesByLocale[$locale];
}

$io = new SymfonyStyle($input, $output);

$fixer = new Fixer($rules);
$fixer->setLocale($locale);
Expand Down

0 comments on commit af804ee

Please sign in to comment.