Skip to content

[FEATURE] Make csv-table directive work with content #575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 6, 2023

Conversation

linawolf
Copy link
Contributor

@linawolf linawolf commented Sep 3, 2023

No description provided.

Copy link
Member

@jaapio jaapio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels like we would need to introduce some extra layer here, some kind of strategy that can be executed per variant.

I don't know if I'm making things over complex by this but I would like to have your opinion on this.

interface CsvTableFactory {
   public function supports(Directive $directive, BlockContext $blockContext): bool;
   public function create(Directive $directive, BlockContext $blockContext): Node; 
} 
class CsvTableStringFactory implements CsvTableFactory 
{
   public function supports(Directive $directive, BlockContext $blockContext): bool {
      return count($blockContext->getDocumentIterator()->toArray()) > 0
   }
   
   public function create(Directive $directive, BlockContext $blockContext) {
      /*...*/
      
      return new TableNode($rows, array_filter([$header]));
   }
}

This makes the code cleaner to me... and would allow us to be more strict on the combinations of options that are used... for example... when :file: is set, we ignore the content, but also the :header:

@linawolf
Copy link
Contributor Author

linawolf commented Sep 5, 2023

I think my PR is working as is and it is a seldom used directive for us. Right now calling csv directives causes a file not found error. If you want to apply your ideas in a follow up go ahead. There are however much more frequently used directives where we have no check for silently

@jaapio jaapio enabled auto-merge September 6, 2023 19:14
@jaapio jaapio merged commit 1f69ca0 into main Sep 6, 2023
@jaapio jaapio deleted the feature/csv-table branch September 6, 2023 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants