8000 trinketbook.sh outputs new nunjucks format · StudyCourse/pythonlearn@ea97be8 · GitHub
[go: up one dir, main page]

Skip to content

Commit ea97be8

Browse files
committed
trinketbook.sh outputs new nunjucks format
1 parent ad76dbe commit ea97be8

24 files changed

+511
-56
lines changed

book/10-tuples.mkd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ dictionary sorted by the *value* stored in each key-value pair.
386386

387387
To do this, we first make a list of tuples where each tuple is
388388
`(value, key)`. The `items` method would give us a
389-
list of `(key, value)` tuplesbut this time we want to sort
389+
list of `(key, value)` tuples-but this time we want to sort
390390
by value, not key. Once we have constructed the list with the value-key
391391
tuples, it is a simple matter to sort the list in reverse order and
392392
print out the new, sorted list.
@@ -493,7 +493,7 @@ tuples. It assigns the elements of each tuple to `last` and
493493
`first`, then prints the name and corresponding telephone
494494
number.
495495

496-
Sequences: strings, lists, and tuplesOh My!
496+
Sequences: strings, lists, and tuples-Oh My!
497497
--------------------------------------------
498498

499499
\index{sequence}

book/trinket/buildtoc.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from __future__ import print_function
2+
42D7 import sys
3+
from pyquery import PyQuery
4+
import re
5+
6+
filename = sys.argv[1]
7+
8+
print("Processing TOC for " + filename + "...")
9+
10+
with open(filename, 'r+') as f:
11+
text = f.read()
12+
13+
with open(filename, 'w') as f:
14+
f.write('{% extends "books/pfe.html" %}\n\n')
15+
pattern = re.compile(r"{% block toc %}(.*){% endblock %}", re.DOTALL)
16+
matches = re.findall(pattern, text)
17+
d = PyQuery(matches[0])
18+
# first ul gets 'right'
19+
d('ul').eq(0).addClass('right')
20+
# first li gets dropdown
21+
d('li').eq(0).addClass('has-dropdown')
22+
# second ul is dropdown
23+
d('ul').eq(1).addClass('dropdown')
24+
25+
toc = "{% block toc %}\n" + str(d.html()) + "\n{% endblock %}"
26+
newtext = re.sub(pattern, toc, text)
27+
f.write(newtext)

book/trinket/nunjucks.html

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1-
{% block content %}
2-
<div class="content">
1+
{% block chaptercontent %}
2+
<div class="row">
3+
<div class="columns small-12">
34
$if(title)$
45
<div id="$idprefix$header">
5-
<h1 class="title">$title$</h1>
6+
<h2 class="title">$title$</h2>
67
$if(subtitle)$
7-
<h1 class="subtitle">$subtitle$</h1>
8+
<h3 class="subtitle">$subtitle$</h3>
89
$endif$
910
$for(author)$
10-
<h2 class="author">$author$</h2>
11+
<h4 class="author">$author$</h4>
42D7
1112
$endfor$
12-
$if(date)$
13-
<h3 class="date">$date$</h3>
14-
$endif$
1513
</div>
1614
$endif$
1715

1816
$body$
1917
</div>
18+
19+
</div>
20+
{% endblock %}
21+
22+
{% block toc %}
23+
$toc$
2024
{% endblock %}

book/trinket/pfe/01-intro.html

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
{% block content %}
2-
<div class="content">
1+
{% extends "books/pfe.html" %}
2+
3+
{% block chaptercontent %}
4+
<div class="row">
5+
<div class="columns small-12">
36
<div id="header">
4-
<h1 class="title">Python 3.0 For Informatics : Exploring Information</h1>
5-
<h2 class="author">Charles Severance</h2>
6-
<h3 class="date">This book is being converted from Python 2.0 to Python 3.0. If you want to help see http://www.pythonlearn.com/book/</h3>
7+
<h2 class="title">Python 3.0 For Informatics : Exploring Information</h2>
8+
<h4 class="author">Charles Severance</h4>
79
</div>
810

911
<h1 id="why-should-you-learn-to-write-programs">Why should you learn to write programs?</h1>
@@ -409,4 +411,26 @@ <h2 id="exercises">Exercises</h2>
409411
</ol>
410412
</div>
411413
</div>
414+
415+
</div>
416+
{% endblock %}
417+
418+
{% block toc %}
419+
420+
<li class="has-dropdown"><a href="#why-should-you-learn-to-write-programs">Why should you learn to write programs?</a><ul class="dropdown">
421+
<li><a href="#creativity-and-motivation">Creativity and motivation</a></li>
422+
<li><a href="#computer-hardware-architecture">Computer hardware architecture</a></li>
423+
<li><a href="#understanding-programming">Understanding programming</a></li>
424+
<li><a href="#words-and-sentences">Words and sentences</a></li>
425+
<li><a href="#conversing-with-python">Conversing with Python</a></li>
426+
<li><a href="#terminology-interpreter-and-compiler">Terminology: interpreter and compiler</a></li>
427+
<li><a href="#writing-a-program">Writing a program</a></li>
428+
<li><a href="#what-is-a-program">What is a program?</a></li>
429+
<li><a href="#the-building-blocks-of-programs">The building blocks of programs</a></li>
430+
<li><a href="#what-could-possibly-go-wrong">What could possibly go wrong?</a></li>
431+
<li><a href="#the-learning-journey">The learning journey</a></li>
432+
<li><a href="#glossary">Glossary</a></li>
433+
<li><a href="#exercises">Exercises</a></li>
434+
</ul></li>
435+
412436
{% endblock %}

book/trinket/pfe/02-variables.html

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
{% block content %}
2-
<div class="content">
1+
{% extends "books/pfe.html" %}
2+
3+
{% block chaptercontent %}
4+
<div class="row">
5+
<div class="columns small-12">
36

47
<h1 id="variables-expressions-and-statements">Variables, expressions, and statements</h1>
58
<h2 id="values-and-types">Values and types</h2>
@@ -390,4 +393,28 @@ <h2 id="exercises">Exercises</h2>
390393
</ol>
391394
</div>
392395
</div>
396+
397+
</div>
398+
{% endblock %}
399+
400+
{% block toc %}
401+
402+
<li class="has-dropdown"><a href="#variables-expressions-and-statements">Variables, expressions, and statements</a><ul class="dropdown">
403+
<li><a href="#values-and-types">Values and types</a></li>
404+
<li><a href="#variables">Variables</a></li>
405+
<li><a href="#variable-names-and-keywords">Variable names and keywords</a></li>
406+
<li><a href="#statements">Statements</a></li>
407+
<li><a href="#operators-and-operands">Operators and operands</a></li>
408+
<li><a href="#expressions">Expressions</a></li>
409+
<li><a href="#order-of-operations">Order of operations</a></li>
410+
<li><a href="#modulus-operator">Modulus operator</a></li>
411+
<li><a href="#string-operations">String operations</a></li>
412+
<li><a href="#asking-the-user-for-input">Asking the user for input</a></li>
413+
<li><a href="#comments">Comments</a></li>
414+
<li><a href="#choosing-mnemonic-variable-names">Choosing mnemonic variable names</a></li>
415+
<li><a href="#debugging">Debugging</a></li>
416+
<li><a href="#glossary">Glossary</a></li>
417+
<li><a href="#exercises">Exercises</a></li>
418+
</ul></li>
419+
393420
{% endblock %}

book/trinket/pfe/03-conditional.html

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
{% block content %}
2-
<div class="content">
1+
{% extends "books/pfe.html" %}
2+
3+
{% block chaptercontent %}
4+
<div class="row">
5+
<div class="columns small-12">
36

47
<h1 id="conditional-execution">Conditional execution</h1>
58
<h2 id="boolean-expressions">Boolean expressions</h2>
@@ -316,4 +319,24 @@ <h2 id="exercises">Exercises</h2>
316319
</ol>
317320
</div>
318321
</div>
322+
323+
</div>
324+
{% endblock %}
325+
326+
{% block toc %}
327+
328+
<li class="has-dropdown"><a href="#conditional-execution">Conditional execution</a><ul class="dropdown">
329+
<li><a href="#boolean-expressions">Boolean expressions</a></li>
330+
<li><a href="#logical-operators">Logical operators</a></li>
331+
<li><a href="#conditional-execution-conditional-execution">Conditional execution {#conditional execution}</a></li>
332+
<li><a href="#alternative-execution-alternative-execution">Alternative execution {#alternative execution}</a></li>
333+
<li><a href="#chained-conditionals">Chained conditionals</a></li>
334+
<li><a href="#nested-conditionals">Nested conditionals</a></li>
335+
<li><a href="#catch1">Catching exceptions using try and except</a></li>
336+
<li><a href="#short-circuit-evaluation-of-logical-expressions">Short-circuit evaluation of logical expressions</a></li>
337+
<li><a href="#whitespace">Debugging</a></li>
338+
<li><a href="#glossary">Glossary</a></li>
339+
<li><a href="#exercises">Exercises</a></li>
340+
</ul></li>
341+
319342
{% endblock %}

book/trinket/pfe/04-functions.html

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
{% block content %}
2-
<div class="content">
1+
{% extends "books/pfe.html" %}
2+
3+
{% block chaptercontent %}
4+
<div class="row">
5+
<div class="columns small-12">
36

47
<h1 id="funcchap">Functions</h1>
58
<h2 id="functionchap">Function calls</h2>
@@ -390,4 +393,27 @@ <h2 id="exercises">Exercises</h2>
390393
F</code></pre>
391394
<p>Run the program repeatedly to test the various different values for input.</p>
392395
</div>
396+
397+
</div>
398+
{% endblock %}
399+
400+
{% block toc %}
401+
402+
<li class="has-dropdown"><a href="#funcchap">Functions</a><ul class="dropdown">
403+
<li><a href="#functionchap">Function calls</a></li>
404+
<li><a href="#built-in-functions">Built-in functions</a></li>
405+
<li><a href="#type-conversion-functions">Type conversion functions</a></li>
406+
<li><a href="#random-numbers">Random numbers</a></li>
407+
<li><a href="#math-functions">Math functions</a></li>
408+
<li><a href="#adding-new-functions">Adding new functions</a></li>
409+
<li><a href="#definitions-and-uses">Definitions and uses</a></li>
410+
<li><a href="#flow-of-execution">Flow of execution</a></li>
411+
<li><a href="#parameters">Parameters and arguments</a></li>
412+
<li><a href="#fruitful-functions-and-void-functions">Fruitful functions and void functions</a></li>
413+
<li><a href="#why-functions">Why functions?</a></li>
414+
<li><a href="#editor">Debugging</a></li>
415+
<li><a href="#glossary">Glossary</a></li>
416+
<li><a href="#exercises">Exercises</a></li>
417+
</ul></li>
418+
393419
{% endblock %}

book/trinket/pfe/05-iterations.html

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
{% block content %}
2-
<div class="content">
1+
{% extends "books/pfe.html" %}
2+
3+
{% block chaptercontent %}
4+
<div class="row">
5+
<div class="columns small-12">
36

47
<h1 id="iteration">Iteration</h1>
58
<p></p>
@@ -241,4 +244,26 @@ <h2 id="exercises">Exercises</h2>
241244
</ol>
242245
</div>
243246
</div>
247+
248+
</div>
249+
{% endblock %}
250+
251+
{% block toc %}
252+
253+
<li class="has-dropdown"><a href="#iteration">Iteration</a><ul class="dropdown">
254+
<li><a href="#update">Updating variables</a></li>
255+
<li><a href="#the-while-statement">The <code>while</code> statement</a></li>
256+
<li><a href="#infinite-loops">Infinite loops</a></li>
257+
<li><a href="#infinite-loops-and-break">"Infinite loops" and <code>break</code></a></li>
258+
<li><a href="#finishing-iterations-with-continue">Finishing iterations with <code>continue</code></a></li>
259+
<li><a href="#definite-loops-using-for">Definite loops using <code>for</code></a></li>
260+
<li><a href="#loop-patterns">Loop patterns</a><ul>
261+
<li><a href="#counting-and-summing-loops">Counting and summing loops</a></li>
262+
<li><a href="#maximum-and-minimum-loops">Maximum and minimum loops</a></li>
263+
</ul></li>
264+
<li><a href="#debugging">Debugging</a></li>
265+
<li><a href="#glossary">Glossary</a></li>
266+
<li><a href="#exercises">Exercises</a></li>
267+
</ul></li>
268+
244269
{% endblock %}

book/trinket/pfe/06-strings.html

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
{% block content %}
2-
<div class="content">
1+
{% extends "books/pfe.html" %}
2+
3+
{% block chaptercontent %}
4+
<div class="row">
5+
<div class="columns small-12">
36

47
<h1 id="strings">Strings</h1>
58
<h2 id="a-string-is-a-sequence">A string is a sequence</h2>
@@ -353,4 +356,27 @@ <h2 id="exercises">Exercises</h2>
353356
</ol>
354357
</div>
355358
</div>
359+
360+
</div>
361+
{% endblock %}
362+
363+
{% block toc %}
364+
365+
<li class="has-dropdown"><a href="#strings">Strings</a><ul class="dropdown">
366+
<li><a href="#a-string-is-a-sequence">A string is a sequence</a></li>
367+
<li><a href="#getting-the-length-of-a-string-using-len">Getting the length of a string using <code>len</code></a></li>
368+
<li><a href="#for">Traversal through a string with a loop</a></li>
369+
<li><a href="#slice">String slices</a></li>
370+
<li><a href="#strings-are-immutable">Strings are immutable</a></li>
371+
<li><a href="#counter">Looping and counting</a></li>
372+
<li><a href="#inboth">The <code>in</code> operator</a></li>
373+
<li><a href="#string-comparison">String comparison</a></li>
374+
<li><a href="#string-methods"><code>string</code> methods</a></li>
375+
<li><a href="#parsing-strings">Parsing strings</a></li>
376+
<li><a href="#format-operator">Format operator</a></li>
377+
<li><a href="#debugging">Debugging</a></li>
378+
<li><a href="#glossary">Glossary</a></li>
379+
<li><a href="#exercises">Exercises</a></li 9E0D >
380+
</ul></li>
381+
356382
{% endblock %}

book/trinket/pfe/07-files.html

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
{% block content %}
2-
<div class="content">
1+
{% extends "books/pfe.html" %}
2+
3+
{% block chaptercontent %}
4+
<div class="row">
5+
<div class="columns small-12">
36

47
<h1 id="files">Files</h1>
58
<p> </p>
@@ -13725,4 +13728,24 @@ <h2 id="exercises">Exercises</h2>
1372513728
NA NA BOO BOO TO YOU - You have been punk'd!</code></pre>
1372613729
<p>We are not encouraging you to put Easter Eggs in your programs—this is just an exercise.</p>
1372713730
</div>
13731+
13732+
</div>
13733+
{% endblock %}
13734+
13735+
{% block toc %}
13736+
13737+
<li class="has-dropdown"><a href="#files">Files</a><ul class="dropdown">
13738+
<li><a href="#persistence">Persistence</a></li>
13739+
<li><a href="#opening-files">Opening files</a></li>
13740+
<li><a href="#text-files-and-lines">Text files and lines</a></li>
13741+
<li><a href="#reading-files">Reading files</a></li>
13742+
<li><a href="#searching-through-a-file">Searching through a file</a></li>
13743+
<li><a href="#letting-the-user-choose-the-file-name">Letting the user choose the file name</a></li>
13744+
<li><a href="#using-try-except-and-open">Using <code>try, except,</code> and <code>open</code></a></li>
13745+
<li><a href="#writing-files">Writing files</a></li>
13746+
<li><a href="#debugging">Debugging</a></li>
13747+
<li><a href="#glossary">Glossary</a></li>
13748+
<li><a href="#exercises">Exercises</a></li>
13749+
</ul></li>
13750+
1372813751
{% endblock %}

0 commit comments

Comments
 (0)
0