Skip to content

Commit

Permalink
Closes #23: solutions cells hidden by default
Browse files Browse the repository at this point in the history
- adopted this solution: spatialaudio/nbsphinx#305 (comment)
- introduced JupmanPreprocessor
- now you have to run jupman_tools.init(jm) in setup
- removed some cell hiding kruft in jupman.js
- bumping version to 3.2
  • Loading branch information
DavidLeoni committed Oct 16, 2020
1 parent 2bcdab9 commit 2722651
Show file tree
Hide file tree
Showing 38 changed files with 505 additions and 280 deletions.
36 changes: 35 additions & 1 deletion _static/css/jupman-web.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

/** ONLY AVAILABLE IN THE WEBSITE */


/* Makes visible the '+' boxes in menu
https://github.com/DavidLeoni/jupman/issues/38
Expand Down Expand Up @@ -41,4 +43,36 @@ img {
*/
.jupman-inline-img {
display: inline;
}
}

.jupman-sol {
margin-top: -10px
}

.jupman-sol-question {
margin-bottom: 20px
}

.jupman-sol-label {
background-color:#f3faff /* lighter than admonition */;

padding: 7px;

border-style: solid;
border-color: #ede4f4;
}

.jupman-sol-content {
background-color:#f3faff;
padding-right:7px;
border-style: solid;
border-color: #ede4f4;
}

.jupman-sol-hidden {
display: 'none';
}

.jupman-sol-visible {
display: block;
}
16 changes: 2 additions & 14 deletions _static/css/jupman.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

/** ONLY AVAILABLE IN JUPYTER **/

#jupman-nav {
position: fixed;
top: 10px;
Expand Down Expand Up @@ -113,17 +115,3 @@
#jupman-toc .toc-active {
background: rgba(168, 254, 255, 0.32);
}

.jupman-solution {
padding:1px;
}

.jupman-solution-header {
display:none;
color: blue;
text-decoration: underline;
cursor: pointer;
}



25 changes: 25 additions & 0 deletions _static/css/softpython-theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,28 @@ div.nbinput.container div.prompt, div.nboutput.container div.prompt{
width:5px !important;
}

.jupman-sol {
margin-top: -10px
}

.jupman-sol-question {
margin-bottom: 20px
}


.jupman-sol-label {
background-color:#ebf3ed; /* lighter than admonition */

padding: 7px;

border-style: solid;
border-color: #d3dfd6;
}


.jupman-sol-content {
background-color:#ebf3ed;
padding-right:7px;
border-style: solid;
border-color: #d3dfd6;
}
93 changes: 46 additions & 47 deletions _static/js/jupman.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@

/*
/**
* JUPYTER MANAGER JavaScript https://github.com/DavidLeoni/jupman
*
*/


/**
* @deprecated use jupman.toggleVisibility instead
* @param {string} what
*/
function toggleVisibility(what){
var e = document.getElementById(what);
if(e.style.display == 'block')
e.style.display = 'none';
else
e.style.display = 'block';
};

console.warn("global toggleVisibility is deprecated, use jupman.toggleVisibility instead");
jupman.toggleVisibility(what);
};

function showthis(url) {
window.open(url, "pres", "toolbar=yes,scrollbars=yes,resizable=yes,top=10,left=400,width=500,height=500");
Expand Down Expand Up @@ -103,42 +104,49 @@ var jupman = {
}
}).parents('div .cell ').hide();
},

/**
* NOTE: ONLY WORKS ON THE WEBSITE
*
* @param {@string} solId i.e. jupman-sol-7
* @since 3.2
*/
toggleSolution : function(solId){

let sol = $('#' + solId);

button = sol.children(':first');

content = sol.children(':nth-child(2)');

if (content.css('display') === 'none'){
button.val(button.data('jupman-hide'));
} else {
button.val(button.data('jupman-show'));
}
content.slideToggle();
},

toggleVisibility: function(what){
/**
* Simple vanilla way to toggle an element
* @param {string} what i.e. someid (no # prefix)
*/
toggleVisibility : function (what){

var e = document.getElementById(what);
if(e.style.display == 'block')
e.style.display = 'none';
else
e.style.display = 'block';
if(e.style.display == 'block') {
e.style.display = 'none';
} else {
e.style.display = 'block';
}
},

/**
* Code common to both jupman in jupyter and Website
*/
initCommon : function(){

$(".jupman-solution-header").remove();
span = $('<div>');
span.addClass('jupman-solution-header');
span.text('Show/hide solution');

span.insertBefore(".jupman-solution");


$(".jupman-solution").hide();
$(".jupman-solution-header").show();

$('.jupman-solution-header')
.off('click')
.click(function(){

var uls = $(this).nextAll(".jupman-solution");
var sibling = uls.eq(0);

sibling.slideToggle();
ev.preventDefault();
ev.stopPropagation();
});
console.log('Jupman initCommon')

},

Expand All @@ -157,16 +165,7 @@ var jupman = {
// **************************** WARNING ********************************
// THIS HIDE STUFF DOES NOT WORK IN SPHINX, ONLY WORKS WHEN YOU MANUALLY EXPORT TO HTML
// ******************************************************************************
jupman.hideCell("%%HTML");
jupman.hideCell("import jupman");

// TODO this is a bit too hacky
jupman.hideCell(/from exercise(.+)_solution import \*/)

jupman.hideCellAll(/.*jupman_init.*/);
jupman.hideCell("jupman_show_run(");
jupman.hideCell("nxpd.draw(");
jupman.hideCellAll("jupman_run(");

if (jupman.hasToc()){
if ($("#jupman-toc").length === 0){
Expand Down Expand Up @@ -200,7 +199,7 @@ var jupman = {
} else {
$("#jupman-toc").hide();
}

$
/* if ($("#jupman-toc").is(":visible")){
if (jupman.hoverToc()) {
} else {
Expand Down Expand Up @@ -285,7 +284,7 @@ var jupman = {

jupman.initCommon();

if (typeof JUPMAN_IN_JUPYTER === "undefined" || !JUPMAN_IN_JUPYTER ){
if (typeof JUPMAN_IN_JUPYTER === "undefined" || !JUPMAN_IN_JUPYTER ){
jupman.initWebsite();
} else {
jupman.initJupyter();
Expand Down
6 changes: 3 additions & 3 deletions _test/jupman_tools_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ def test_setup(tconf):
mockapp = MockSphinx()

tconf.setup(mockapp)
assert os.path.isfile(os.path.join(tconf.jm.generated, 'jupyter-intro.zip'))
assert os.path.isfile(os.path.join(tconf.jm.generated, 'python-intro.zip'))
assert os.path.isfile(os.path.join(tconf.jm.generated, 'tools-intro.zip'))
assert os.path.isfile(os.path.join(tconf.jm.generated, 'jupyter-example.zip'))
assert os.path.isfile(os.path.join(tconf.jm.generated, 'python-example.zip'))
assert os.path.isfile(os.path.join(tconf.jm.generated, 'jup-and-py-example.zip'))

def test_ignore_spaces():

Expand Down
13 changes: 12 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@

Jupman Jupyter Manager

https://jupman.softpython.org
[jupman.softpython.org](https://jupman.softpython.org)


## October 16 2020 - 3.2

- added optional build on Github Actions
- solutions are finally hidden on the website, with a click to show button!
- moved to jupman.softpython.org
- updated nbsphinx to 0.7.1
- updated sphinx_rtd_theme to 0.4.3
- updated sphinx to 2.3.1
- updated pygments to2.7.1

## January 16th 2020 - 3.1

Expand Down
21 changes: 16 additions & 5 deletions conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3# -*- coding: utf-8 -*-


# This is the configuration file of Sphynx, edit it as needed.

import recommonmark
Expand All @@ -12,6 +13,7 @@
import sys
sys.path.append('.') # for rtd
import jupman_tools as jmt
import jupman_tools


on_rtd = os.environ.get('READTHEDOCS') == 'True'
Expand Down Expand Up @@ -48,7 +50,13 @@
jm.chapter_patterns = ['*/']
jm.chapter_exclude_patterns = ['[^_]*/','exams/', 'project/']

# words used in ipynb files - you might want to translate these in your language. Use plural.
# words used in ipynb files - you might want to translate these in your language.
# Use singular
jm.ipynb_show_solution = "Show solution"
jm.ipynb_hide_solution = "Hide"
jm.ipynb_show_answer = "Show answer"
jm.ipynb_hide_answer = "Hide"
# Use plural
jm.ipynb_solutions = "SOLUTIONS"
jm.ipynb_exercises = "EXERCISES"

Expand Down Expand Up @@ -424,7 +432,9 @@
# Background images fitting mode
pdf_fit_background_mode = 'scale'


def setup(app):
jmt.init(jm)

app.add_config_value( 'recommonmark_config', {
'auto_toc_tree_section': 'Contents',
Expand All @@ -445,12 +455,13 @@ def sub(x):
return x

jm.zip_paths(['project', 'requirements.txt'],
'_static/generated/project-template',
patterns = sub)

'_static/generated/project-template',
patterns = sub)

source_suffix = {
'.rst': 'restructuredtext',
'.txt': 'markdown',
'.md': 'markdown'
}
}


19 changes: 12 additions & 7 deletions index.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -534,13 +534,13 @@
"\n",
"- Based on [NBSphinx](http://nbsphinx.readthedocs.io/) which produces website made of static files\n",
"- Supports build with ReadTheDocs or [Github Actions](https://github.com/DavidLeoni/readthedocs-to-actions) (or local Docker emulating ReadTheDocs)\n",
"- decent PDF layout\n",
"- builds exercises from solution templates (both .ipynb and .py)\n",
"- builds chapter zips\n",
"- supports sharing code among chapters\n",
"- Python Tutor integration (can work offline, doesn't need to install dependencies)\n",
"- includes a exam management system (script and grades spreadsheet)\n",
"- configuration clearly separated from code\n",
"- decent PDF layout\n",
"- made for Python 3\n",
"- comes with [documentation](usage.ipynb)\n",
"- Open source code [on Github](https://github.com/DavidLeoni/jupman)\n",
Expand All @@ -553,8 +553,9 @@
"\n",
"**Used by:**\n",
"\n",
"- [Scientific Programming Lab at University of Trento, Data Science Master](http://datasciprolab.readthedocs.io/) (English)\n",
"- [SoftPython book](http://softpython.readthedocs.io/) (Italian)"
"- [SoftPython book (english)](https://en.softpython.org/)\n",
"- [SoftPython book (italian)](https://it.softpython.org/)\n",
"- [Scientific Programming Lab at University of Trento, Data Science Master](http://datasciprolab.readthedocs.io/) (English)"
]
},
{
Expand All @@ -576,13 +577,17 @@
"source": [
"## Revisions\n",
"\n",
"* **16 October 2020**: Released v3.2\n",
"\n",
"* **16 January 2020**: Released v3.1\n",
"\n",
"* **29 December 2019**: Released v3.0\n",
"\n",
"* **24 September 2018**: Released v2.0\n",
"\n",
"* **3 August 2018**: Released v0.8\n",
"\n",
"* [Change log](changelog.ipynb)\n"
"* [Change log](changelog.md)"
]
},
{
Expand All @@ -605,9 +610,9 @@
"\n",
"1. [JUPMAN USAGE](usage.ipynb)\n",
"1. Chapter examples\n",
" 1. [Python introduction](python-intro.ipynb)\n",
" 1. [Jupyter introduction](jupyter-intro.ipynb)\n",
" 1. [Tools](tools-intro.ipynb)\n",
" 1. [Python example](python-example/python-example.ipynb)\n",
" 1. [Jupyter example](jupyter-example/jupyter-example-sol.ipynb)\n",
" 1. [Jupyter and python example](jup-and-py-example/jup-and-py-example-sol.ipynb)\n",
"1. Templates\n",
" 1. [Past exams](past-exams.ipynb)\n",
" 1. [Changelog](changelog.md)"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 2722651

Please sign in to comment.