зеркало из https://github.com/nextcloud/cookbook.git
Fix the filter to allow Instruction sections
Signed-off-by: Christian Wolf <github@christianwolf.email>
This commit is contained in:
Родитель
9ac1eefabd
Коммит
ca595700aa
|
@ -94,7 +94,13 @@ class FixInstructionsFilter extends AbstractJSONFilter {
|
|||
}
|
||||
|
||||
if ($this->jsonService->isSchemaObject($value, 'HowToStep', false)) {
|
||||
$instructions[$key] = [$value['text']];
|
||||
$instructions[$key] = [$this->extractHowToStep($value)];
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($this->jsonService->isSchemaObject($value, 'HowToSection', false)) {
|
||||
$newInstructions = $this->flattenHowToSection($value);
|
||||
$instructions[$key] = $newInstructions;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -146,6 +152,11 @@ class FixInstructionsFilter extends AbstractJSONFilter {
|
|||
continue;
|
||||
}
|
||||
|
||||
if ($this->jsonService->isSchemaObject($element, 'HowToStep', false)) {
|
||||
$newElements[$key] = [$this->extractHowToStep($element)];
|
||||
continue;
|
||||
}
|
||||
|
||||
throw new InvalidRecipeException($this->l->t('Cannot parse recipe: Unknown object found during flattening of instructions.'));
|
||||
}
|
||||
|
||||
|
@ -197,4 +208,24 @@ class FixInstructionsFilter extends AbstractJSONFilter {
|
|||
$pieces = array_filter($pieces);
|
||||
return $pieces;
|
||||
}
|
||||
|
||||
private function flattenHowToSection($item): array {
|
||||
if ($item['name'] && is_string($item['name'])) {
|
||||
$ret = ['## ' . $item['name']];
|
||||
} else {
|
||||
$ret = ['## HowToSection'];
|
||||
}
|
||||
|
||||
$items = $this->flattenItemList($item);
|
||||
|
||||
return array_merge($ret, $items);
|
||||
}
|
||||
|
||||
private function extractHowToStep($item) {
|
||||
if (! $this->jsonService->isSchemaObject($item, 'HowToStep', false)) {
|
||||
throw new InvalidRecipeException($this->l->t('Cannot parse recipe: Unknown object found during flattening of instructions.'));
|
||||
}
|
||||
|
||||
return $item['text'];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -239,6 +239,8 @@ class FixInstructionsFilterTest extends TestCase {
|
|||
$original = json_decode($originalRaw, true);
|
||||
$expected = json_decode($expectedRaw, true);
|
||||
|
||||
$this->textCleanupHelper->method('cleanUp')->willReturnArgument(0);
|
||||
|
||||
$ret = $this->dut->apply($original);
|
||||
|
||||
$this->assertEquals($expected, $original);
|
||||
|
|
Загрузка…
Ссылка в новой задаче