lanthaler / HydraBundle

HydraBundle is a Symfony2 bundle which shows how easily Hydra can be integrated in modern Web frameworks. It acts as a proof of concept to show how Hydra can simplify the implementation of interoperable and evolvable RESTful APIs.
http://www.markus-lanthaler.com/hydra/
MIT License
59 stars 12 forks source link

RDFa generation #1

Open lsmith77 opened 11 years ago

lsmith77 commented 11 years ago

as you are aware we are using JSON-LD in the SymfonyCmfCreateBundle to receive data from the frontend. I think it would be interesting to also have the ability to return JSON-LD data. however right now we generate RDFa on the server using createphp. I wonder if this Bundle could also generate RDFa optionally.

Right now we are using mapping files like the following to define how the RDFa should be generated from a model instance: https://github.com/symfony-cmf/ContentBundle/blob/master/Resources/rdf-mappings/Symfony.Cmf.Bundle.ContentBundle.Document.MultilangStaticContent.xml

/cc @dbu

dbu commented 11 years ago

for generating the RDFa HTML, we use a twig extension to render the content of a model much like you render forms. conceptually thats quite different from JSON-LD which is a pure semantic format, whereas RDFa is embedded into the HTML code.

@lsmith77 you are aware that the CreateBundle uses the FOS\RestBundle viewhandler to return json-ld to the frontend?

lsmith77 commented 11 years ago

ah right .. i forgot that a json-ld request from the frontends leads to the backend responding with json-ld. with the mapping in this bundle we do have the semantics .. what we lack is "just" the optional name of an html tag.

lanthaler commented 11 years ago

I have to admit I didn’t look at the source code in detail. So I don’t know much about the internals.

If I understand your question and the XML file correctly, all that would be needed is to add an (optional) HTML tag to the annotations (otherwise div is assumed) and to serialize to HTML fragments instead of JSON-LD documents. If that’s correct, I think it would be quite a quite trivial extension.

lsmith77 commented 11 years ago

yes that is what i am thinking ..

lsmith77 commented 11 years ago

btw you might want to have a look at https://github.com/schmittjoh/metadata it could allow you to also support xml/yml mapping which would make it easier to override mappings.

lanthaler commented 11 years ago

Sorry for the late reply. I have been traveling and heaps of mails piled up in the meantime.

Anyway. I would like to explore that idea. What’s the simplest way to test it in your opinion? I started to look at the code but I’m a bit lost as to how to integrate it.

lsmith77 commented 11 years ago

Maybe get the CMF SE (https://github.com/symfony-cmf/symfony-cmf-standard) up and running. You will find f.e. content like this:

<div xmlns:sioc="http://rdfs.org/sioc/ns#" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:skos="http://www.w3.org/2004/02/skos/core#" typeof="sioc:Post" about="/cms/simple">    <h1 property="dcterms:title">Welcome to the CMF Standard Edition</h1>
<div property="sioc:content">This is should get you started with the Symfony CMF.</div>
<ul rel="skos:related" rev=""></ul>

The relevant document classes for the content are here: https://github.com/symfony-cmf/SimpleCmsBundle/tree/master/Document

They are using these createphp mapping files: https://github.com/symfony-cmf/SimpleCmsBundle/tree/master/Resources/rdf-mappings

Finally the template that renders the output is here: https://github.com/symfony-cmf/symfony-cmf-standard/blob/master/app/Resources/CmfSimpleCmsBundle/views/Page/index.html.twig

So essentially that template needs to be changed to use some other twig function that figures out the RDFa to generate from mapping information in the documents.

lanthaler commented 11 years ago

OK, thanks. I’ll build a simple proof of concept. I don’t have much spare time at the moment so it will probably take some time.

lsmith77 commented 11 years ago

OK cool.