datafoodconsortium / connector-codegen

An Acceleo project to generate the source code of the DFC connector into all the supported programming languages.
MIT License
3 stars 3 forks source link

Allow output context to be configured #8

Closed mkllnk closed 9 months ago

mkllnk commented 9 months ago

The API of the serializer advertised this option already but ignored it later on. Now we use it instead of repeating the context URL. This allows software to call the serialiser with their own context:

tomato = DataFoodConsortium::Connector::SuppliedProduct.new("https://myplatform.com/tomato")

inputContext = DataFoodConsortium::Connector::Context.inputContext
outputContext = "https://www.datafoodconsortium.org/wp-content/plugins/wordpress-context-jsonld/context.jsonld"
exporter = DataFoodConsortium::Connector::JsonLdSerializer.new(outputContext, inputContext)

exporter.process(tomato)

I also simplified some Ruby code along the way.