Skip to content

Commit

Permalink
Merge pull request #13 from fabfab1/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Forni B authored Mar 26, 2018
2 parents 5f1eebf + f4744fb commit 0c60c38
Show file tree
Hide file tree
Showing 27 changed files with 1,333 additions and 1,253 deletions.
244 changes: 147 additions & 97 deletions EnCAB/EnCAB.py

Large diffs are not rendered by default.

32 changes: 18 additions & 14 deletions EnCAB/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# EnCAB
> Work in progress
Python program to update static website with indexes and algorithms.

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


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

### Built With

Python 3, with Jinja2 (for templating) and BeautifulSoup (for editing HTML).
Python 3, with Jinja2 (for templating), ElementTree (for parsing XML) and BeautifulSoup (for parsing HTML).


## Configuration

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

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

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

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

[coming soon]
### Data

```shell
test/test.py
```
Each algorithms must have its own XML file stored in ALGORITHMS_DIR with .xml or .txt extension.
See "- algorithms codes format" for mandatory format of the codes.

### HTML Templates

Templates are written in Jinja2 templating language. The XML ElementTree is passed as argument.

### Errors

The log with the errors found are stored in the file "log.txt".


## Licensing
Expand Down
13 changes: 4 additions & 9 deletions EnCAB/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,11 @@
TEMPLATE_INDEX = "templates/index.html" # default: "templates/index.html"


# Extra options

# List of used tags to check for unknown tags in XML input
KNOWN_TAGS = ["reference", "biblioref", "authorgroup"]

# List of possible sort attributes for <section> with relative XML tag
SORT_STRINGS = {'algorithm_types': 'algorithm_description/algorithm_types',
SORT_STRINGS = {'algorithm_type': 'algorithm_description/algorithm_type',
'position_in_process': 'algorithm_description/position_in_process',
'material': 'algorithm_description/material',
'abbrev': 'reference'}
'abbrev': 'biblioref/abbrev'}

# INDEXES = [..,..] folders
# IGNORE_IF_CONTAIN = "_index" #_files to ignore in index
# String to select files containing it in their filename, those files will be ignored for the index
IGNORE_IF_CONTAIN = "_index" # default: "_index"
8 changes: 3 additions & 5 deletions EnCAB/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
Jinja2==2.10
MarkupSafe==1.0
beautifulsoup4==4.6.0
#Flask
#Frozen-Flask
Jinja2
MarkupSafe
beautifulsoup4
22 changes: 13 additions & 9 deletions EnCAB/templates/algorithm.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@

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

<br><br><br>

{% for b, filename in blocks_data %}
{% 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 %}
<a name="{{ b.find('reference').text }}"></a>
<b>{{ b.find('reference').text|replace('_','&nbsp;') }}</b>
<table class="data">
Expand Down Expand Up @@ -42,18 +46,18 @@
{% endif %}</td>
</tr>
<tr>
<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 %}
<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 %}
{%- if b.find('biblioref/pagenums').text %}, {{ b.find('biblioref/pagenums').text }}{% endif %}</td>
<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 %}
<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 %}
{%- if b.find('biblioref/pagenums2').text %}, {{ b.find('biblioref/pagenums').text }}{% endif %}</td>
</tr>
<tr>
<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>
<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>
<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>
<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>
</tr>
<tr>
<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>
<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>
<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>
<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>
</tr>
<tr>
<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>
Expand Down
15 changes: 4 additions & 11 deletions EnCAB/to-do programming.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
List of things still to do in EnCAB Program:
--------------------------------------------



- check Aurence <op>


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.

update Readme file

write programming page

write Bernardo bio page

favicon.ico ?

----------

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)

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 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)
4 changes: 2 additions & 2 deletions docs/algorithm_type/algorithm_type_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ <h4> Index: </h4>
<a href="tools.html">tools</a> &nbsp;
<a href="transport.html">transport</a> &nbsp;
<a href="wall_building.html">wall&nbsp;building</a> &nbsp;
</section>
</section>
<h4><a name="al_type">Algorithm Type</a></h4>
<p>Algorithm Type</p>
</body>
</html>
</html>
Loading

0 comments on commit 0c60c38

Please sign in to comment.