Skip to content

interface for adding extra template context #3483

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

Closed
davidism opened this issue Jan 5, 2018 · 14 comments
Closed

interface for adding extra template context #3483

davidism opened this issue Jan 5, 2018 · 14 comments
Labels
Improvement Minor improvement to code Needed: design decision A core team decision is required Needed: patch A pull request is required

Comments

@davidism
Copy link

davidism commented Jan 5, 2018

I've been working on porting Flask's docs to be built on RTD instead of our custom builder. Our builder has a separate JSON file with metadata about versions, and inserts it into html_context by combining each project's Sphinx config with a standard config. html_context can also be set on the command line with -A key=value flags. RTD's interface doesn't allow doing this yet.

While that version information is already available from RTD and just needs to be documented (#3482), it would still be nice to be able to specify additional template context using the web interface. One option is a text box that users can paste JSON in, then add html_context.update({{ extra_html_context|tojson }}) after RTD's default html_context.

@davidism
Copy link
Author

davidism commented Jan 5, 2018

@ericholscher mentioned this could be accomplished with a Sphinx plugin. However, this would require us to maintain a separate public package, make a new release of it with new context, and trigger RTD builds for all versions every time we wanted to change the global context, which is not very convenient. RTD directly supporting extra global context would be much nicer.

@ericholscher
Copy link
Member

We currently support a user having a defined html_context in their conf.py. This can be generated with Python code, and doesn't require an extension. An example here: https://github.com/writethedocs/www/blob/master/docs/conf.py#L111-L114 -- I believe this is what you want?

@ericholscher
Copy link
Member

We already call update on the existing html_context here: https://github.com/rtfd/readthedocs.org/blob/master/readthedocs/doc_builder/templates/doc_builder/conf.py.tmpl#L130

I guess we could add additiona_html_context in YAML, but I'm not sure how this would be better than just having it defined in the conf.py?

@davidism
Copy link
Author

davidism commented Jan 8, 2018

The problem with it being in the code is that it's now tied to the version being built. The useful thing about the context is that it can be modified externally at build time.

@ericholscher
Copy link
Member

I'm not sure I follow. Can you explain the exact use case?

@davidism
Copy link
Author

davidism commented Jan 8, 2018

Let's say we want to display the docs for Flask 0.10, 0.11, 0.12, and 1.0. If we want to display some standard information in the sidebar for each build, like links to each version, we don't want to have to go back to the 0.10 branch and update it so it knows that 1.0 was released. We want to inject the current list of versions as we build each one. The specific example with versions is already handled by RTD's context, but it demonstrates the idea.

@ericholscher
Copy link
Member

Yea, this is actually a different problem on our side. We solve this in JavaScript by sending the data via the footer response. That is "v2" of #3482, where we give users access to that "realtime" project data in JS, so you don't have to rebuild all docs every time one version changes.

@ericholscher
Copy link
Member

but I believe #3482 has what you want (a list of all active versions injected in template context on build)

@davidism
Copy link
Author

davidism commented Jan 8, 2018

Yes, for the versions use case, I've already got the information I need. This was a more general request for specifying global context at build time.

@ericholscher
Copy link
Member

ericholscher commented Jan 8, 2018

Gotcha. 👍

@ericholscher ericholscher added Improvement Minor improvement to code Needed: design decision A core team decision is required Needed: patch A pull request is required labels Jan 8, 2018
@humitos
Copy link
Member

humitos commented Apr 2, 2018

@davidism Hi! I'm about to start working on this issue and I would like to have some more feedback from your side to know if by implementing the design proposed in #3490 will fit your needings or there is something else missing from our side to achieve this issue.

@davidism
Copy link
Author

davidism commented Apr 2, 2018

That appears to be documenting RTD's internal context. It mentions adding context to conf.py, but the problem with that is discussed above. This issue is about adding a field to the RTD admin form to provide context that is independent of the version being built. The version information was an example, but this could apply to arbitrary context a project wants to add.

@davidfischer
Copy link
Contributor

You primarily need this in order to get versions of particular projects correct? I believe this can be handled through the API like so:

https://readthedocs.org/api/v2/version/?project__slug=flask

That will get you all the versions and you can grab just the active ones if you want to. The active ones can be administered in the dashboard.

Let me know if this gets you were you need to be on this issue.

@davidism
Copy link
Author

davidism commented Aug 1, 2018

I don't need this anymore, although it may be useful to others. Perhaps it's more appropriate (or already present) in the YAML config?

You can close it if you'd like.

@davidism davidism closed this as completed Dec 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Improvement Minor improvement to code Needed: design decision A core team decision is required Needed: patch A pull request is required
Projects
None yet
Development

No branches or pull requests

4 participants