shogun
shogun copied to clipboard
"View full listing" for meta examples
Every meta example on the website should have a tab that says "show full code listing", which allows a user to see all of the example code, not just the snippets
Requires some web-hacking skills... not THAT easy, but not impossible
Start from the sphinx plugin:
For that, you will have to modify the sphinx plugin we wrote to render the meta examples, see https://github.com/shogun-toolbox/shogun/blob/develop/doc/cookbook/extensions/sgexample.py
I would like to do this in my GSoC project, here are my initial ideas:
- Enclose the unclosured initial meta example
.sgcode with#![initial_code]. This work could be done automatically with python. - Modify all
.rstfiles. Add.. sgexample:: something.sg:initial_code. This work could also be done automatically with python. - To show full code, we could add
. sgexample:: something.sgat the end of each.rstfiles, and modifysgexample.pyto make the full code hide initially.
By doing procedures 1 and 2, we can make all cookbook with full content of example code. By doing procedure 3, we can add a “show full list” feature to our cookbook.
I'm currently learning sphinx, so I may have a more detailed idea on how to modify sgexample.py.
Hi thanks for taking this up!
- is not really necessary. We do explicitly extract code in
sgexample.pyso we can just extract all there. - modifying the
.rstfiles is not really a good idea since it requires so many changes. Rather we want to change how the page is generated in the python script mentioned above - same as above
I think the best way to change things is to start playing with the web page template that is used and then take it from there
Hey, any updates or questions here?
Yes, I do have some updates:
- I agree that we'd better modify
.rstfile as few as we could, while I think that the.rstfile may still be modified, for we want to show full code. However.rstfiles haven't contained all of them yet. Such a modification could be easy if we write an automated snippet. We could discuss on how to make the modification less and easy to be done. - I agree that the crucial part is to modify sphinx-related code, and I have checked some of the doc pages generated by
sphinx:- The most famous one is The Python Documentation Tutorials. For each code block, they added a small button at the upper-right corner to toggle interactive prompts like
>>>or.... Here is an Example. We could learn from their design by adding a button withshow full codewritten on it, and once we hit that button, we could see full code. Such a feature is done with a JS snippet, in whichbutton.parent().find('.go, .gp, .gt').hide();hides words in elements with classgo,gpandgt. - Here is another example from SQLAlchemy Tutorial where they have a likewise small SQL button to toggle full code (closer to our demand). Their approach is to contain related code in their
.rstfile, and in this snippet, they wrote a functioninitSQLPopups()to control whether to pop-up or to close an already preparedpopup-sqldiv by modifyingcss.
- The most famous one is The Python Documentation Tutorials. For each code block, they added a small button at the upper-right corner to toggle interactive prompts like
Looking forward to a further discussion!
Yeah exactly this is what we want, the >>>-style button that just shows all of the code in the file
Here's a question: Do we have other code for our sphinx doc pages, or all we have is a python sphinx generator sgexample.py? If the latter is right, what can we do to add js snippets in it?
I am not exactly sure what you mean, but the sgexample.py is pretty much all that generates the cookbook pages along with the .rst and the .py, .cpp, .java, etc
@novate We have some static files and the html template in https://github.com/shogun-toolbox/shogun/tree/develop/doc/cookbook/source
Thanks! I get it. Now I know that we have other code for the cookbook pages, and all static things like js snippets could be placed at here.
Ah yes and it’s bootstrap!
any updates here @novate ?
This is still open