Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SWIFTweb
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
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
SWIFT
SWIFTweb
Commits
4bb03420
Commit
4bb03420
authored
7 years ago
by
Josh Borrow
Browse files
Options
Downloads
Patches
Plain Diff
pep8 compliant
parent
a1f81034
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
about.py
+14
-11
14 additions, 11 deletions
about.py
compiler.py
+7
-7
7 additions, 7 deletions
compiler.py
with
21 additions
and
18 deletions
about.py
+
14
−
11
View file @
4bb03420
...
...
@@ -10,7 +10,9 @@
Created 16-08-2017 by Josh Borrow (joshua.borrow@durham.ac.uk)
"""
import
os
#Disable errors associated with un-overwritten methods in HTMLParser.
#pylint: disable=W0223
from
html.parser
import
HTMLParser
import
pypandoc
...
...
@@ -19,8 +21,8 @@ import yaml
def
open_meta
(
filename
=
"
about_meta.yaml
"
,
data_dir
=
"
../data
"
):
"""
Read the meta file and return the associated data
"""
with
open
(
f
"
{
data_dir
}
/
{
filename
}
"
,
"
r
"
)
as
f
:
return
yaml
.
load
(
f
)
with
open
(
f
"
{
data_dir
}
/
{
filename
}
"
,
"
r
"
)
as
handle
:
return
yaml
.
load
(
handle
)
def
compile_markdown
(
data
,
data_dir
=
"
../data
"
):
...
...
@@ -29,8 +31,8 @@ def compile_markdown(data, data_dir="../data"):
output_text
=
""
for
item
in
data
[
"
files
"
]:
with
open
(
f
"
{
data_dir
}
/
{
item
[
'
name
'
]
}
"
,
"
r
"
)
as
f
:
input_text
=
f
.
read
()
with
open
(
f
"
{
data_dir
}
/
{
item
[
'
name
'
]
}
"
,
"
r
"
)
as
handle
:
input_text
=
handle
.
read
()
compiled_text
=
pypandoc
.
convert_text
(
input_text
,
'
html
'
,
format
=
'
md
'
)
...
...
@@ -39,6 +41,7 @@ def compile_markdown(data, data_dir="../data"):
class
Parser
(
HTMLParser
):
"""
Custom HTML Parser that builds the headings tree
"""
def
__init__
(
self
):
super
(
Parser
,
self
).
__init__
()
...
...
@@ -58,7 +61,7 @@ class Parser(HTMLParser):
self
.
headings
.
append
([
tag
,
this_id
])
self
.
waiting_for_data
=
True
def
handle_endtag
(
self
,
tag
):
pass
...
...
@@ -117,18 +120,18 @@ def compile_to_yaml(in_filename="about_meta.yaml", out_filename="about.yaml", da
"
sidebar
"
:
sidebar
}
with
open
(
f
"
{
data_dir
}
/
{
out_filename
}
"
,
"
w
"
)
as
f
:
yaml
.
dump
(
output_data
,
f
)
with
open
(
f
"
{
data_dir
}
/
{
out_filename
}
"
,
"
w
"
)
as
handle
:
yaml
.
dump
(
output_data
,
handle
)
return
output_data
if
__name__
==
"
__main__
"
:
print
(
"
Running this script directly will only compile the markdown in data.
"
)
print
(
"
If you wish to continue, please enter Y, if not, please enter N.
"
)
choice
=
input
()
if
choice
in
[
'
y
'
,
'
Y
'
]:
CHOICE
=
input
()
if
CHOICE
in
[
'
y
'
,
'
Y
'
]:
compile_to_yaml
()
else
:
exit
(
0
)
This diff is collapsed.
Click to expand it.
compiler.py
+
7
−
7
View file @
4bb03420
"""
Short compilation script from the website
(essentially just stitches together a bunch of jinja templates)
Created 16-08-2017 by Josh Borrow (joshua.borrow@durham.ac.uk)
"""
...
...
@@ -37,8 +37,8 @@ def get_associated_data(template_names, data_dir="../data"):
filename
=
f
"
{
data_dir
}
/
{
stub
}
.yaml
"
try
:
with
open
(
filename
,
"
r
"
)
as
f
:
data
.
append
(
yaml
.
load
(
f
))
with
open
(
filename
,
"
r
"
)
as
handle
:
data
.
append
(
yaml
.
load
(
handle
))
except
FileNotFoundError
:
data
.
append
({})
...
...
@@ -85,8 +85,8 @@ def global_variables(active, data_dir="../data"):
Active is the name of the current page
'
s template and is used in the
production of the processed navbar.
"""
with
open
(
"
{}/global.yaml
"
.
format
(
data_dir
),
"
r
"
)
as
f
:
raw
=
yaml
.
load
(
f
)
# We need to process the navbar.
with
open
(
"
{}/global.yaml
"
.
format
(
data_dir
),
"
r
"
)
as
handle
:
raw
=
yaml
.
load
(
handle
)
# We need to process the navbar.
return
process_navbar
(
raw
,
active
)
...
...
@@ -102,8 +102,8 @@ def render(render_pages, data_dir, template_dir, output_dir):
os
.
makedirs
(
output_dir
)
for
page
,
data
in
zip
(
render_pages
,
output
):
with
open
(
"
{}/{}
"
.
format
(
output_dir
,
page
),
"
w
"
)
as
f
:
f
.
write
(
data
)
with
open
(
"
{}/{}
"
.
format
(
output_dir
,
page
),
"
w
"
)
as
handle
:
handle
.
write
(
data
)
return
...
...
This diff is collapsed.
Click to expand it.
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