mirror of
https://github.com/opdavies/gmail-filter-builder.git
synced 2025-11-12 13:28:44 +00:00
Generated filters can be expanded
This commit is contained in:
parent
b123dcf079
commit
4c00155956
4 changed files with 34 additions and 9 deletions
|
|
@ -40,7 +40,7 @@ class GenerateCommand extends Command
|
|||
|
||||
try {
|
||||
// TODO: Inject this.
|
||||
new Builder($this->filters($input), $outputFile = $this->outputFile($input));
|
||||
new Builder($this->filters($input), $outputFile = $this->outputFile($input), true, $input->getOption('expanded'));
|
||||
|
||||
$io->success(sprintf('%s file generated.', $outputFile));
|
||||
} catch (IOException $e) {
|
||||
|
|
@ -61,6 +61,6 @@ class GenerateCommand extends Command
|
|||
throw new \RuntimeException('No input file found.');
|
||||
}
|
||||
|
||||
return require_once $inputFile;
|
||||
return require $inputFile;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,12 +29,16 @@ class Builder
|
|||
*/
|
||||
private $xml;
|
||||
|
||||
public function __construct(array $filters, $outputFile = 'filters.xml', $writeFile = true)
|
||||
/** @var bool */
|
||||
private $expanded;
|
||||
|
||||
public function __construct(array $filters, $outputFile = 'filters.xml', $writeFile = true, $expanded = false)
|
||||
{
|
||||
$this->filesystem = new Filesystem();
|
||||
$this->filters = $filters;
|
||||
$this->outputFile = $outputFile;
|
||||
$this->writeFile = $writeFile;
|
||||
$this->expanded = $expanded;
|
||||
|
||||
$this->build();
|
||||
}
|
||||
|
|
@ -61,14 +65,14 @@ class Builder
|
|||
*/
|
||||
private function build(): void
|
||||
{
|
||||
$prefix = "<?xml version='1.0' encoding='UTF-8'?>" . PHP_EOL . "<feed xmlns='http://www.w3.org/2005/Atom' xmlns:apps='http://schemas.google.com/apps/2006'>";
|
||||
$prefix = "<?xml version='1.0' encoding='UTF-8'?>" . $this->glue() . "<feed xmlns='http://www.w3.org/2005/Atom' xmlns:apps='http://schemas.google.com/apps/2006'>";
|
||||
$suffix = '</feed>';
|
||||
|
||||
$xml = collect($this->filters)->map(function ($items) {
|
||||
return $this->buildEntry($items);
|
||||
})->implode(PHP_EOL);
|
||||
})->implode($this->glue());
|
||||
|
||||
$this->xml = collect([$prefix, $xml, $suffix])->implode(PHP_EOL);
|
||||
$this->xml = collect([$prefix, $xml, $suffix])->implode($this->glue());
|
||||
|
||||
if ($this->writeFile) {
|
||||
$this->filesystem->dumpFile($this->outputFile, $this->xml);
|
||||
|
|
@ -88,9 +92,9 @@ class Builder
|
|||
->map(function ($value, $key): string {
|
||||
return $this->buildProperty($value, $key);
|
||||
})
|
||||
->implode(PHP_EOL);
|
||||
->implode($this->glue());
|
||||
|
||||
return collect(['<entry>', $entry, '</entry>'])->implode(PHP_EOL);
|
||||
return collect(['<entry>', $entry, '</entry>'])->implode($this->glue());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -128,4 +132,9 @@ class Builder
|
|||
|
||||
return sprintf('(%s)', collect($value)->implode($separator));
|
||||
}
|
||||
|
||||
private function glue()
|
||||
{
|
||||
return $this->expanded ? PHP_EOL : null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue