madebymany/sir-trevor-js

Render data as blog post

CptMaumau opened this issue · 12 comments

Hi,

Maybe it's only me but I couldn't find any example of rendering the data stored with Sir Trevor.

Once you have finish writing your post and want to publish it, do you need to do a custom method or is there something already implemented to render the data ?

@CptMaumau are you submitting the data with a form submission or javascript?

@raffij I submit the data with a form submission and store it in a mongo DB.

@CptMaumau sir-trevor will bind to the form submit function. Place the json in the textarea and then submit the form.

Are you seeing something different?

@raffij storing the data is fine. What I want is render the data in a view so it looks like a blog post.

Maybe there's a read-only version of Sir Trevor?

Sorry if my question was not understandable.

@CptMaumau Sir Trevor does not handle rendering, only an editing interface.

In my opinion Sir Trevor already handles rendering since it transforms the data object into html tags for editing.
A method that only does that without the editing part would be useful.

@CptMaumau you are partially correct. A little bit of history for you.

Sir Trevor is built to be display agnostic. Attempting to totally detach the editing / storage and display of the data. However we need a language to store text formatting.

Originally we used markdown as it's easy to parse and widely adopted. However working with markdown became troublesome so we moved to simple formatted HTML as you find today. So you should think of the HTML as a storage solution rather than necessarily the display language.

For rendering sirtrevor content you'll want to write your own logic. We have a rails gem which you can take inspiration from. There will be others you can find on GitHub to help you in your language of choice. For instance I once did a Wordpress renderer, not public. Basically what you'll be doing is parsing the Json and outputing each block to a template file.

The rendering is not part of sir-Trevor and never will be, but we will endeavour to add further rendering plugins as links to the repo as and when we create them and would encourage others to do the same.

If you find any then let us know and we'll add them.

If you have problems please create a new issue as I think this is a good one to archive for others.

Thank you for taking the time to answer me. I will follow your advice and create my own rendering logic.

What language are you using?

@CptMaumau: The implementations links in the readme might be a good place to seek inspiration/solutions. There are implementations for Rails, Umbraco, Django and several PHP CMSs.

@raffij Server side is Node JS/Express with Vash for view engine

It's not that hard to understand the rendering logic, you just need to have something to digest the JSON and format it as you please.

For me, once I receive the JSON I convert it directly into HTML (for use with bootstrap) so that I don't have to compile the HTML each time the page is loaded. It gives you alot of flexibility to implement your front end however you like.