Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
ots-doctools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ots
ots-doctools
Commits
5a765ff9
Commit
5a765ff9
authored
2 years ago
by
James Vasile
Browse files
Options
Downloads
Patches
Plain Diff
Add todo func
parent
5f2b0faa
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
jinja/jinjify.py
+53
-6
53 additions, 6 deletions
jinja/jinjify.py
with
53 additions
and
6 deletions
jinja/jinjify.py
+
53
−
6
View file @
5a765ff9
...
@@ -36,6 +36,9 @@ for r in regex:
...
@@ -36,6 +36,9 @@ for r in regex:
def
run_p
(
text
,
meta
):
def
run_p
(
text
,
meta
):
return
meta
.
get
(
'
legacy
'
,
''
)
!=
"
legacy
"
return
meta
.
get
(
'
legacy
'
,
''
)
!=
"
legacy
"
def
slurp_lines
(
fspec
):
with
open
(
fspec
)
as
fh
:
return
fh
.
read
().
split
(
"
\n
"
)
# We're not using this func right now, but I do want to add markdown
# We're not using this func right now, but I do want to add markdown
# support back in later, once I've figure out how to fit it in
# support back in later, once I've figure out how to fit it in
...
@@ -50,6 +53,36 @@ def md2tex(string):
...
@@ -50,6 +53,36 @@ def md2tex(string):
)
)
return
p
.
communicate
(
input
=
string
.
encode
(
'
UTF-8
'
))[
0
].
decode
(
'
UTF-8
'
)
return
p
.
communicate
(
input
=
string
.
encode
(
'
UTF-8
'
))[
0
].
decode
(
'
UTF-8
'
)
class
TodoManager
():
def
__init__
(
self
,
fname
=
"
todo.txt
"
):
self
.
fname
=
fname
if
os
.
path
.
exists
(
fname
):
self
.
lines
=
slurp_lines
(
fname
)
else
:
self
.
lines
=
[]
# We'll compare against this later to see if our lines changed
self
.
new_lines
=
[]
def
latex
(
self
):
if
not
self
.
lines
:
return
"
No todos
"
ret
=
(
r
"
\notocsection{{\color{red} TODOS}}
"
+
"
\\
begin{itemize}
\n\\
item
"
+
"
\n\\
item
"
.
join
(
self
.
lines
)
+
"
\n\\
end{itemize}
"
)
return
ret
def
write
(
self
):
"""
Write our new todo lines, return True if they
'
ve changed
"""
if
"
\n
"
.
join
(
self
.
lines
)
!=
"
\n
"
.
join
(
self
.
new_lines
):
self
.
lines
=
self
.
new_lines
with
open
(
self
.
fname
,
'
w
'
)
as
fh
:
fh
.
write
(
"
\n
"
.
join
(
self
.
new_lines
))
fh
.
write
(
"
\n
"
)
return
True
return
False
def
run
(
text
,
meta
):
def
run
(
text
,
meta
):
"""
Apply jinja templates to TEXT, using metadata from dict META.
"""
Apply jinja templates to TEXT, using metadata from dict META.
Returns rendered text and unchanged META.
"""
Returns rendered text and unchanged META.
"""
...
@@ -75,10 +108,24 @@ def run(text, meta):
...
@@ -75,10 +108,24 @@ def run(text, meta):
template
=
latex_jinja_env
.
get_template
(
'
jinjify_me.ltx
'
)
template
=
latex_jinja_env
.
get_template
(
'
jinjify_me.ltx
'
)
# Quick example of calling a python func from our template. Evoke with
tman
=
TodoManager
()
# \VAR{testfunc()}
def
todo
(
text
):
#def testfunc():
"""
Record a todo and return approprate latex to display the todo.
# return u'TEST'
#template.globals.update(testfunc=testfunc)
Evoke with \VAR{todo()}
"""
tman
.
new_lines
.
append
(
text
.
replace
(
"
\n
"
,
"
"
))
return
f
'
\\
textbf{{TODO}}:
{
text
}
'
template
.
globals
.
update
(
todo
=
todo
)
# register jinja hook for todo func
# Render repeatedly until we no longer need to rerender
rejinjify
=
False
while
True
:
template
.
globals
.
update
(
todos
=
tman
.
latex
())
rendered
=
template
.
render
(
**
meta
)
rejinjify
=
tman
.
write
()
if
not
rejinjify
:
break
return
template
.
render
(
**
meta
)
,
meta
return
rendered
,
meta
This diff is collapsed.
Click to expand it.
Karl Fogel
@kfogel
mentioned in commit
c6563cc1
·
2 years ago
mentioned in commit
c6563cc1
mentioned in commit c6563cc1f95130a85c12bb3dba5e33f8bc2aebe7
Toggle commit list
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment