Skip to content
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

let the backend serve the template metadata #76

Open
bwl21 opened this issue Dec 6, 2015 · 8 comments
Open

let the backend serve the template metadata #76

bwl21 opened this issue Dec 6, 2015 · 8 comments

Comments

@bwl21
Copy link
Contributor

bwl21 commented Dec 6, 2015

I would like to modify backend.js and index.html such that it retrieves the templates from the backend. This would allow to install templates simply by copying the same to the template folder. The hardcoded templates in the ViewModel would then be a fallback.

It would be easy but the template does not know its description as

    templates: [{
      name: 'versafix-1', desc: 'The versatile template'
    },{
      name: 'tedc15', desc: 'The TEDC15 template'
    }]

one option would be that in the folder for a template I add a file called manifest.json which would be:

    {
      name: 'versafix-1', desc: 'The versatile template'
    }

based on this, a get-request for /templates would yield the

   [{
      name: 'versafix-1', desc: 'The versatile template'
    },{
      name: 'tedc15', desc: 'The TEDC15 template'
    }]

Any opinion on this?

@bago
Copy link
Member

bago commented Dec 7, 2015

I thought about this, but I didn't implement it because I didn't want people to think this was needed in a generic backend in order to use mosaico. Mosaico library simply use the link to a single template and doesn't know anything about "list of master templates" (this is something part of the "demo" index.html+editor.html+localstorage).

If we change index to rely to a similar backend call then we probably have to change any sample backend to do this (we have the bundled nodejs, the opensource php backend and I know one user developed a .NET backend and another is working on a ruby backend..).

I don't think people uses "index.html" in their production environment for mosaico embedded.

So, I'm not sure this change, alone, is a step forward: maybe combined with other stuff (like loading/saving the contents to the backend) this can belong to an "extension" that enhance mosaico to do that, but in the mean time it sounds easier to ask people to change the index.html to list the templates they want to use.

Any other user out there have comments about this?

@bwl21
Copy link
Contributor Author

bwl21 commented Dec 7, 2015

For the time being, this is my problem, that I do not want to go for my "own" index.html now, but want to add tutorial without changing index.html.

So for people playing around it would be easier if they can simply add their template. And if the backend does not support "/templates" it would yield a 404 which could be captured by index.html and fall back.

But the the bundled nodejs could provide this. You are right, if we could go that step that bundled nodejs also support to save to backend, it would be much easier to see how a production environment could be built.

@bago
Copy link
Member

bago commented Dec 7, 2015

If this is only about development then this could be done in grunt task during build time: you could write a grunt task that scan the template folder and create the json you say and then the index could include that static json from the "dist" folder (or maybe index.html could be changed and copied to dist with the full computed json)...

@bago
Copy link
Member

bago commented Dec 7, 2015

You can even try to run "editor.html#pathtoyourtemplate" instead of using a key... it should load your template by using the path in the hashtag (that's how I was used to run mosaico in my dev-days before I implemented the localstorage demo).

@bago
Copy link
Member

bago commented Dec 7, 2015

One thing that may not be "clear" is that mosaico is able to use templates from any url.
You could run your mosaico editor on http://www.example.com and let it load a template from http://www.example2.com ... the template loader simply does an ajax request and parse relative paths correctly. That's also why I don't "push" the idea that the templates folder should be special in any way.

@bwl21
Copy link
Contributor Author

bwl21 commented Dec 7, 2015

I tried it. Editor comes up but no save / test / download buttons.

I will try further ... Nevertheless, I understand now why you do not want the minimal backend to serve the templates.

@bago
Copy link
Member

bago commented Dec 7, 2015

that's because of current localstorage plugin that depends on the key to save/load things: this could be changed so that when it detect an url it automatically create a new entry in the localstorage and then redirect to it.. but it currently doesn't do this...

BTW template has been added to the index.

@bwl21
Copy link
Contributor Author

bwl21 commented Dec 7, 2015

Thank you, just came home and saw this.

the entire plugin thing is a book with 7 seals to me. I find src/js/ext/localstorage.js. it is referenced in build/mosaico.js. Isn't this compiled in the mosaico dist. So how can I replace it without changing mosaico?

What makes a plugin a plugin? is it the location of a js file, is it a particular api?
Is the mosaico - plugin approach specific to mosaico or is it a plugin pattern provided by knockout, jquery, js (then I can research there how it works).

To be honest my JS skills are more or less not existing :-) I can read code but am not aware of the patterns. I come from Ruby-Land (btw. Sooner or later I will use Opalrb to embed mosaico in production).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants