-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Abstract the template engine #47
Comments
Related: #69. |
I like the idea. Basically, a theme would have a dependency with its template engine, but SassDoc wouldn't force any. This comes handy with the idea of theme inheritance. The var theme = require('sassdoc-theme-dark');
theme.render({
// Usual SassDoc view variables here
...
// Any other theme-specific variables
layout: theme.LAYOUT_TWO_COLUMNS,
}); I don't know if this should return an HTML string (can take a lot of memory if the project is big), or if we need to pass it a destination file path to write in, or maybe a destination directory to allow a theme to create multiple files (other than the conventional |
After some reflection, the templating module can be abstracted at a point it's not bound to SassDoc in any way. I think it can live in its own repo and Node module. And while I'm thinking about it, I just saw something similar yesterday; Json Resume is a project where you have a JSON input (like SassDoc's main object passed to the view), with a theming system that looks exactly like what we need.
|
I like that.
I like that even better. |
Oh yeah, JSON resume is a great example. Like that project. |
I took a look at Json Resume's theme manager, I think there's not enough abstraction for our needs. It's still really interesting to see how it works for inspiration, but I have some doubts:
I'll create a new project for the theming engine tonight. |
I started to work on this in this repository https://github.com/valeriangalliat/themeleon-test. I'm not sure about the name though, but this is not my priority. My ideas are in the readme, and I've provided a simple implementation using this test theme. The code is actually dead simple. The
... and returns a Promise/A+ compliant instance. Any program that wants to use the theme can If you ask me, I choosed to place the destination directory before the context so it can easily be currified. I mean that you could have a Like I say in the readme, I'm planning to create an helper package for the themes, so they don't need to take care of the promises stuff, and "low-level" filesystem calls. |
How far are we on this? |
I didn't have a lot of time to work on it this week, but I've managed to do this yesterday: https://github.com/valeriangalliat/themeleon. There's no actual example other than the one in the readme, but I plan to do it this week-end. At first, only Swig will be supported as template engine plugin, but it will be easy to support any other template engine. |
We should not make any assumptions about the template engine. |
Yes, I'm just adding Swig at first for testing purpose, but the template engine is a dependency of the final theme, not of the theme engine. |
Moving this to 1.2. Val and I are on fire. |
I just want to make something clear. The only thing SassDoc should expect from a template is that it exports a function like this: module.exports = function(dest, context, options){
} Everything else should be an implementation detail of the template. What you are doing with Themeleon sounds way to complicated. Just let the author of the template choose how he wants to implement it. |
On the other hand, Themeleon is kind of a framework to build themes, so perhaps it's a good idea. I really don't know guys, I'll leave this up to you. |
Yeah, if an author wants to use Themeleon he can. But don't make it the only way to create themes for SassDoc |
Themeleon only hides the "low-level" filesystem operations from the theme creator, leaving him with only simple functions like Themeleon is actually very lightweight (86 SLOC including But it's not at all a requirement. The only interface needed is: /**
* @param {string} dest Directory to render theme in.
* @param {object} ctx Variables to pass to the theme.
* @return {promise} A Promises/A+ implementation.
*/
module.exports = function (dest, ctx) {}; Themeleon is built around this interface, and make it trivial to build a theme, but anything implementing this interface will work. And to make it clear, Themeleon is not a dependency of |
Okay. We should document it exactly like this. |
Nice! I'll merge |
The `view` directory and all templating logic is removed from SassDoc, and this is now deletated to `sassdoc-theme-default`. The only interface needed for a theme is the one described here <#47 (comment)>. Conflicts: view/assets/css/main.css view/assets/js/main.js view/scss/base/_base.scss view/scss/partials/_footer.scss view/scss/partials/_header.scss view/scss/partials/_item.scss view/scss/partials/_main.scss view/scss/partials/_sidebar.scss view/scss/utils/_functions.scss view/templates/includes/annotations/requires.html.swig view/templates/includes/items/item.html.swig view/templates/includes/items/variable.html.swig view/templates/includes/partials/sidebar.html.swig
Awesome! |
Possibly not forcing Swig. In any case, making the view more configurable.
The text was updated successfully, but these errors were encountered: