Skip to content

Commit 0c60c38

Browse files
author
Forni B
authored
Merge pull request #13 from fabfab1/develop
Develop
2 parents 5f1eebf + f4744fb commit 0c60c38

27 files changed

+1333
-1253
lines changed

EnCAB/EnCAB.py

Lines changed: 147 additions & 97 deletions
Large diffs are not rendered by default.

EnCAB/README.md

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# EnCAB
2-
> Work in progress
3-
4-
Python program to update static website with indexes and algorithms.
52

3+
Python program to update static HTML website with algorithms and index imported from XML data.
64

75

86
## Getting started
@@ -26,26 +24,32 @@ Press ENTER to confirm configuration and update HTML files.
2624

2725
### Built With
2826

29-
Python 3, with Jinja2 (for templating) and BeautifulSoup (for editing HTML).
27+
Python 3, with Jinja2 (for templating), ElementTree (for parsing XML) and BeautifulSoup (for parsing HTML).
3028

3129

3230
## Configuration
3331

34-
Edit config file ("config.py") to change directories and preference.
35-
The program will access the HTML files and the algorithms data.
36-
The algorithms data are XML files for each algorithm.
32+
Edit config file "config.py" to change directories and other preferences.
3733

38-
The website MUST contain the directories named as the different <algorithm_description>,
39-
each containing the different HTML files to be indexed.
34+
The program will read the HTML files and the algorithms data.
35+
It will write the HTML data in *.html files inside ```<section block="algorithm/index" sort="(name)"></section>```.
4036

37+
```block="algorithm" sort="(name)"``` write algorithms data, insert in (name) a SORT_STRINGS (from "config.py") or XML XPath of desired item to sort
4138

42-
## Tests
39+
```block="index" sort="(name)"``` write files index, insert in (name) the folder name of desired files to use for the sorted index
4340

44-
[coming soon]
41+
### Data
4542

46-
```shell
47-
test/test.py
48-
```
43+
Each algorithms must have its own XML file stored in ALGORITHMS_DIR with .xml or .txt extension.
44+
See "- algorithms codes format" for mandatory format of the codes.
45+
46+
### HTML Templates
47+
48+
Templates are written in Jinja2 templating language. The XML ElementTree is passed as argument.
49+
50+
### Errors
51+
52+
The log with the errors found are stored in the file "log.txt".
4953

5054

5155
## Licensing

EnCAB/config.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,11 @@
1717
TEMPLATE_INDEX = "templates/index.html" # default: "templates/index.html"
1818

1919

20-
# Extra options
21-
22-
# List of used tags to check for unknown tags in XML input
23-
KNOWN_TAGS = ["reference", "biblioref", "authorgroup"]
24-
2520
# List of possible sort attributes for <section> with relative XML tag
26-
SORT_STRINGS = {'algorithm_types': 'algorithm_description/algorithm_types',
21+
SORT_STRINGS = {'algorithm_type': 'algorithm_description/algorithm_type',
2722
'position_in_process': 'algorithm_description/position_in_process',
2823
'material': 'algorithm_description/material',
29-
'abbrev': 'reference'}
24+
'abbrev': 'biblioref/abbrev'}
3025

31-
# INDEXES = [..,..] folders
32-
# IGNORE_IF_CONTAIN = "_index" #_files to ignore in index
26+
# String to select files containing it in their filename, those files will be ignored for the index
27+
IGNORE_IF_CONTAIN = "_index" # default: "_index"

EnCAB/requirements.txt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
Jinja2==2.10
2-
MarkupSafe==1.0
3-
beautifulsoup4==4.6.0
4-
#Flask
5-
#Frozen-Flask
1+
Jinja2
2+
MarkupSafe
3+
beautifulsoup4

EnCAB/templates/algorithm.html

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11

2-
{% for b, filename in blocks_data -%}
3-
<a href="#{{ b.find('reference').text }}">{{ b.find('reference').text|replace('_','&nbsp;') }}</a>{% if not loop.last %}&nbsp;- {% endif %}
4-
{% endfor %}
2+
{#- --- INDEX --- #}
3+
{%- set ns = namespace(new_sort = '') %}
4+
{% for b, filename in blocks_data -%}{% if b.find(sort).text.lower() != ns.new_sort.lower() %}{% set ns.new_sort = b.find(sort).text %}
5+
{% if ns.new_sort %}{% if not loop.first %} - {% endif %}<a href="#{{ ns.new_sort.lower() }}">{{ ns.new_sort|replace('_','&nbsp;') }}</a>{% endif %}
6+
{%- endif %}{% endfor %}
7+
{% set ns.new_sort = '' %}
58

69
<br><br><br>
710

811
{% for b, filename in blocks_data %}
12+
{% if b.find(sort).text.lower() != ns.new_sort.lower() %}{% set ns.new_sort = b.find(sort).text %}<a name="{{ ns.new_sort.lower() }}"></a>{% endif %}
913
<a name="{{ b.find('reference').text }}"></a>
1014
<b>{{ b.find('reference').text|replace('_','&nbsp;') }}</b>
1115
<table class="data">
@@ -42,18 +46,18 @@
4246
{% endif %}</td>
4347
</tr>
4448
<tr>
45-
<td>Source info:</td><td>{% if b.find('biblioref/authorgroup/author').text %}<a href="../bibliography/bibliography.html#{{(b.find('biblioref/authorgroup/author/surname').text or '').strip('.,')|replace(' ','')}}{{(b.find('biblioref/authorgroup/author/firstname').text or '').strip('.,')|replace(' ','')}}">{{ b.find('biblioref/abbrev').text|replace('_',' ') }}</a>{% else %}{{ (b.find('biblioref/abbrev').text|replace('_',' ')) or '' }}{% endif %}
49+
<td>Source info:</td><td>{% if b.find('biblioref/authorgroup/author').text %}<a href="../bibliography/bibliography.html#{{(b.find('biblioref/authorgroup/author/surname').text or '').strip('.,')|replace(' ','')}}{{(b.find('biblioref/authorgroup/author/firstname').text or '').strip('.,')|replace(' ','')}}">{{ b.find('biblioref/abbrev').text|replace('_',' ') }}</a>{% else %}{{ (b.find('biblioref/abbrev').text or '')|replace('_',' ') }}{% endif %}
4650
{%- if b.find('biblioref/pagenums').text %}, {{ b.find('biblioref/pagenums').text }}{% endif %}</td>
47-
<td>Also cited in:</td><td>{% if b.find('biblioref/authorgroup/author2').text %}<a href="../bibliography/bibliography.html#{{(b.find('biblioref/authorgroup/author2/surname').text or '').strip('.,')|replace(' ','')}}{{(b.find('biblioref/authorgroup/author2/firstname').text or '').strip('.,')|replace(' ','')}}">{{ b.find('biblioref/abbrev2').text|replace('_',' ') }}</a>{% else %}{{ (b.find('biblioref/abbrev2').text|replace('_',' ')) or '' }}{% endif %}
51+
<td>Also cited in:</td><td>{% if b.find('biblioref/authorgroup/author2').text %}<a href="../bibliography/bibliography.html#{{(b.find('biblioref/authorgroup/author2/surname').text or '').strip('.,')|replace(' ','')}}{{(b.find('biblioref/authorgroup/author2/firstname').text or '').strip('.,')|replace(' ','')}}">{{ b.find('biblioref/abbrev2').text|replace('_',' ') }}</a>{% else %}{{ (b.find('biblioref/abbrev2').text or '')|replace('_',' ') }}{% endif %}
4852
{%- if b.find('biblioref/pagenums2').text %}, {{ b.find('biblioref/pagenums').text }}{% endif %}</td>
4953
</tr>
5054
<tr>
51-
<td>Algorithm type:</td><td>{% if b.find('algorithm_description/algorithm_type').text %}<a href="../algorithm_type/{{b.find('algorithm_description/algorithm_type').text|replace(' ','_')|lower}}.html">{{ b.find('algorithm_description/algorithm_type').text }}</a>{% endif %}</td>
52-
<td>Position in process:</td><td>{% if b.find('algorithm_description/position_in_process').text %}<a href="../position_in_process/{{b.find('algorithm_description/position_in_process').text|replace(' ','_')|lower}}.html">{{ b.find('algorithm_description/position_in_process').text }}</a>{% endif %}</td>
55+
<td>Algorithm type:</td><td>{% if b.find('algorithm_description/algorithm_type').text %}<a href="../algorithm_type/{{b.find('algorithm_description/algorithm_type').text|replace(' ','_')|lower}}.html">{{ b.find('algorithm_description/algorithm_type').text|title }}</a>{% endif %}</td>
56+
<td>Position in process:</td><td>{% if b.find('algorithm_description/position_in_process').text %}<a href="../position_in_process/{{b.find('algorithm_description/position_in_process').text|replace(' ','_')|lower}}.html">{{ b.find('algorithm_description/position_in_process').text|title }}</a>{% endif %}</td>
5357
</tr>
5458
<tr>
55-
<td>Material:</td><td>{% if b.find('algorithm_description/material').text %}<a href="../material/{{b.find('algorithm_description/material').text|replace(' ','_')|lower}}.html">{{ b.find('algorithm_description/material').text }}</a>{% endif %}</td>
56-
<td>Source type:</td><td>{% if b.find('algorithm_description/source_type').text %}<a href="../source_type/{{b.find('algorithm_description/source_type').text|replace(' ','_')|lower}}.html">{{ b.find('algorithm_description/source_type').text }}</a>{% endif %}</td>
59+
<td>Material:</td><td>{% if b.find('algorithm_description/material').text %}<a href="../material/{{b.find('algorithm_description/material').text|replace(' ','_')|lower}}.html">{{ b.find('algorithm_description/material').text|title }}</a>{% endif %}</td>
60+
<td>Source type:</td><td>{% if b.find('algorithm_description/source_type').text %}<a href="../source_type/{{b.find('algorithm_description/source_type').text|replace(' ','_')|lower}}.html">{{ b.find('algorithm_description/source_type').text|title }}</a>{% endif %}</td>
5761
</tr>
5862
<tr>
5963
<td>Source chronology:</td><td>{% if b.find('algorithm_description/source_chronology').text %}<a href="../source_chronology/{{b.find('algorithm_description/source_chronology').text|replace(' ','_')|lower}}.html">{{ b.find('algorithm_description/source_chronology').text }}</a>{% endif %}</td>

EnCAB/to-do programming.txt

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
List of things still to do in EnCAB Program:
2+
--------------------------------------------
23

34

4-
5-
- check Aurence <op>
6-
7-
8-
The HTML files where the algorithms are placed should have links to anchors for the different categories; example, at the top of 'Algorithms by Material' instead of links to the individual algorithms (Abrans 1994_47_1 etc) there should be links to the materials, so 'earth', 'mudbrick', 'pise'', 'plaster' etc. The same for the algorithm_type.html and the algorithm_position_in_process.html. The algorithm_bibliography.html would instead be by author_year, so Abrams 1994.
9-
10-
update Readme file
11-
125
write programming page
136

147
write Bernardo bio page
158

9+
favicon.ico ?
1610

17-
----------
18-
19-
create a CSV data dump from all the input files used (also the ones with errors) with the XML tags as headers. Filename should be "EnCAB_input_xyz.csv" where xyz is the date (year month day format) and time. the seperator should be a tab character (the error trapping should give an error if there is a tab used in the input, and should replace that character with 5 spaces when sending to the CSV file)
2011

12+
CSV data dump from all the input files used (also the ones with errors) with the XML tags as headers. Filename should be "EnCAB_input_xyz.csv" where xyz is the date (year month day format) and time.
13+
the separator should be a tab character (the error trapping should give an error if there is a tab used in the input, and should replace that character with 4 spaces when sending to the CSV file)

docs/algorithm_type/algorithm_type_index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ <h4> Index: </h4>
2727
<a href="tools.html">tools</a> &nbsp;
2828
<a href="transport.html">transport</a> &nbsp;
2929
<a href="wall_building.html">wall&nbsp;building</a> &nbsp;
30-
</section>
30+
</section>
3131
<h4><a name="al_type">Algorithm Type</a></h4>
3232
<p>Algorithm Type</p>
3333
</body>
34-
</html>
34+
</html>

0 commit comments

Comments
 (0)