']
5 | if filename:
6 | html.append('
' + filename + '
')
7 |
8 | a = a.splitlines() if a != '' else []
9 | b = b.splitlines() if b != '' else []
10 |
11 | html.append('
')
12 | for i in range(0, max(len(a), len(b))):
13 | line_a = a[i] if i < len(a) else ''
14 | line_b = b[i] if i < len(b) else ''
15 | s = difflib.SequenceMatcher(a=line_a, b=line_b)
16 | ops = s.get_opcodes()
17 | changed = False
18 | for op in ops:
19 | if op[0] == 'equal':
20 | html.append('' + line_a[op[1]:op[2]] + '')
21 | elif op[0] == 'delete':
22 | html.append(
23 | ''
24 | + line_a[op[1]:op[2]] + line_b[op[3]:op[4]]
25 | + ''
26 | )
27 | changed = True
28 | elif op[0] == 'insert':
29 | html.append(
30 | ''
31 | + line_a[op[1]:op[2]] + line_b[op[3]:op[4]]
32 | + ''
33 | )
34 | changed = True
35 | elif op[0] == 'replace':
36 | html.append(
37 | ''
38 | + line_a[op[1]:op[2]]
39 | + ''
40 | )
41 | html.append(
42 | ''
43 | + line_b[op[3]:op[4]]
44 | + ''
45 | )
46 | changed = True
47 | # html.append(tag + content + '')
48 | html.append('
')
49 | html.append('
')
50 | return ''.join(html)#.encode('utf-8')
51 |
--------------------------------------------------------------------------------
/sedlex/template/__init__.py:
--------------------------------------------------------------------------------
1 | import jinja2
2 | import os
3 | import shutil
4 |
5 | _ROOT = os.path.abspath(os.path.dirname(__file__))
6 |
7 | def template_string(template, values):
8 | template = os.path.join(_ROOT, template)
9 | f = open(template, 'r')
10 | e = jinja2.Environment(
11 | loader=jinja2.FileSystemLoader(os.path.dirname(template))
12 | )
13 | t = e.from_string(f.read().decode('utf-8'))
14 | f.close()
15 |
16 | return t.render(values)
17 |
18 | def template_file(template, values, out):
19 | template = os.path.join(_ROOT, template)
20 | r = template_string(template, values)
21 |
22 | path = os.path.dirname(out)
23 | if not os.path.exists(path):
24 | os.makedirs(path)
25 | f = open(out, 'w')
26 | f.write(r.encode('utf-8') + "\n")
27 | f.truncate()
28 | f.close()
29 |
30 | def template_dir(dir, values, out):
31 | dir = os.path.join(_ROOT, dir)
32 | templated_files = []
33 | for root, dirs, files in os.walk(dir):
34 | for name in files:
35 | path = os.path.join(root, name)
36 | out_path = out + path.replace(dir, '')
37 | out_dir = os.path.dirname(out_path)
38 | if not os.path.exists(out_dir):
39 | os.makedirs(out_dir)
40 | if name.endswith(".j2"):
41 | out_path = out_path.replace('.j2', '')
42 | template_file(path, values, out_path)
43 | else:
44 | if os.path.exists(out_path):
45 | os.remove(out_path)
46 | shutil.copy(path, out_path)
47 | templated_files.append(out_path)
48 | return templated_files
49 |
--------------------------------------------------------------------------------
/sedlex/template/git/.travis.yml:
--------------------------------------------------------------------------------
1 | sudo: required
2 | dist: trusty
3 | language: python
4 |
5 | install:
6 | - pip install ansible
7 | - ansible-galaxy install -r requirements.yml
8 |
9 | script:
10 | - ansible-playbook -i "localhost," -c local provision.yml
11 |
--------------------------------------------------------------------------------
/sedlex/template/git/provisioning/provision.yml.j2:
--------------------------------------------------------------------------------
1 | ---
2 |
3 | - hosts: localhost
4 | vars:
5 | duralex_project_url: "{{ url }}"
6 | project_repository: "{{ '{{' }} playbook_dir | dirname {{ '}}' }}"
7 | roles:
8 | - { role: geerlingguy.git }
9 | - { role: bobbyrenwick.pip }
10 | - { role: geerlingguy.nodejs, nodejs_version: "7.x", nodejs_npm_global_packages: gitbook-cli }
11 | - { role: duralex-sedlex }
12 | - { role: pages }
13 |
--------------------------------------------------------------------------------
/sedlex/template/git/provisioning/requirements.yml:
--------------------------------------------------------------------------------
1 | ---
2 |
3 | - src: geerlingguy.git
4 | version: 1.4.0
5 |
6 | - src: bobbyrenwick.pip
7 | version: v2.1.1
8 |
9 | - src: geerlingguy.nodejs
10 | version: 4.1.1
11 |
--------------------------------------------------------------------------------
/sedlex/template/git/provisioning/roles/duralex-sedlex/tasks/main.yml:
--------------------------------------------------------------------------------
1 | ---
2 |
3 | - name: Install DuraLex.
4 | pip:
5 | name: git+git://github.com/Legilibre/DuraLex.git#egg=duralex
6 | state: present
7 |
8 | - name: Install SedLex.
9 | pip:
10 | name: git+git://github.com/Legilibre/SedLex.git#egg=sedlex
11 | state: present
12 |
13 | - name: Fetch DuraLex data.
14 | shell: duralex --url "{{ duralex_project_url }}" > /tmp/duralex.json
15 |
--------------------------------------------------------------------------------
/sedlex/template/git/provisioning/roles/pages/tasks/main.yml:
--------------------------------------------------------------------------------
1 | ---
2 |
3 | - name: Generate HTML pages.
4 | shell: cat /tmp/duralex.json | sedlex --gitbook --gitbook-format html --repository {{ project_repository }}
5 |
--------------------------------------------------------------------------------
/sedlex/template/gitbook/README.md.j2:
--------------------------------------------------------------------------------
1 | {%- import 'html.j2' as html -%}
2 |
3 | # {{ html.icon('university" aria-hidden="true') }} {{ title | title }}
4 |
5 | {{ description[0].upper() }}{{ description[1:] }}.
6 |
7 | [{{ html.icon('external-link" aria-hidden="true') }} Texte original]({{ url }})
8 |
9 | ## {{ html.icon('bookmark-o') }} Articles
10 |
11 | {% if type == 'law-proposal' %}
12 | La proposition de loi est constituée des articles suivants :
13 | {% elif type == 'law-project' %}
14 | Le projet de loi est constituée des articles suivants :
15 | {% endif %}
16 |
17 | {% for article in articles %}
18 | * [Article {{ article.order }}](article-{{ article.order }}.md)
19 | {%- endfor %}
20 |
21 | {% if amendments | length > 0 %}
22 | et des amendements suivants :
23 |
24 | {% for amendment in amendments %}
25 | * [Amendement {{ amendment.id }}](amendment-{{ amendment.id }}.md)
26 | {%- endfor %}
27 |
28 | {% endif %}
29 |
30 | {% if modified is defined and modified | length > 0 %}
31 | ## {{ html.icon('file-text-o') }} Textes modifiés
32 |
33 | {% if type == 'law-proposal' %}
34 | La proposition de loi modifie les textes suivants :
35 | {% elif type == 'law-project' %}
36 | Le projet de loi modifie les textes suivants :
37 | {% endif %}
38 |
39 | {% for m in modified %}
40 | * [Loi N°{{ m.law }}]({{ m.law }}.md)
41 | {%- for article in m.articles %}
42 | * [Article {{ article.id }}]({{ m.law }}-{{ article.id }}.md)
43 | {%- endfor %}
44 | {%- endfor %}
45 |
46 | {%- endif %}
47 |
48 | {% if cocorico_vote is defined %}
49 | ## Vote
50 |
51 | * [Voter](https://cocorico.cc/embed/vote-widget/{{ cocorico_vote }})
52 | * [Résultats du vote](https://cocorico.cc/ballot-box/{{ cocorico_vote }})
53 | {% endif %}
54 |
--------------------------------------------------------------------------------
/sedlex/template/gitbook/SUMMARY.md.j2:
--------------------------------------------------------------------------------
1 | # Summary
2 |
3 | {% if type == 'law-proposal' %}
4 | ## Proposition de loi
5 | {% elif type == 'law-project' %}
6 | ## Projet de loi
7 | {% endif %}
8 | {% for article in articles %}
9 | * [Article {{ article.order }}](article-{{ article.order }}.md)
10 | {%- endfor %}
11 |
12 | {% for amendment in amendments %}
13 | ## Amendements
14 | * [Amendement {{ amendment.id }}](amendment-{{ amendment.id }}.md)
15 | {%- endfor %}
16 |
17 | {% if modified is defined and modified | length > 0 %}
18 | ## Textes modifiés
19 | {% for m in modified %}
20 | * [Loi N°{{ m.law }}]({{ m.law }}.md)
21 | {%- for article in m.articles %}
22 | * [Article {{ article.id }}]({{ m.law }}-{{ article.id }}.md)
23 | {%- endfor %}
24 | {%- endfor %}
25 |
26 | {%- endif %}
27 |
28 | {% if cocorico_vote is defined %}
29 | ## Vote
30 |
31 | * [Voter](https://cocorico.cc/embed/vote-widget/{{ cocorico_vote }})
32 | * [Résultats du vote](https://cocorico.cc/ballot-box/{{ cocorico_vote }})
33 | {% endif %}
34 |
--------------------------------------------------------------------------------
/sedlex/template/gitbook/amendment.md.j2:
--------------------------------------------------------------------------------
1 | {%- import 'html.j2' as html -%}
2 |
3 | # {{ html.icon('bookmark-o') }} {{ title | title }}, Amendement {{ amendments[current_amendment].id }}
4 |
5 | ## {{ html.icon('lightbulb-o') }} Exposé
6 |
7 | {{ amendments[current_amendment].description }}
8 |
9 | ## {{ html.icon('file-text-o') }} Texte
10 |
11 | {{ amendments[current_amendment].content.replace('\n', '\n\n') }}
12 |
13 | ## {{ html.icon('users') }} Signataires
14 |
15 | {% for signatory in amendments[current_amendment].signatories -%}
16 | * {{ signatory.name }}
17 | {% endfor %}
18 |
19 | {% if amendments[current_amendment].commits | length %}
20 | ## {{ html.icon('pencil-square-o') }} Suivi des modifications
21 |
22 | L'amendement {{ amendments[current_amendment].order }} apporte les modifications suivantes :
23 |
24 | {% for commit in amendments[current_amendment].commits %}
25 | ### {{ commit.title }}
26 |
27 | {{ commit.description | default('') }}
28 |
29 | {{ commit.diff }}
30 | {% endfor %}
31 |
32 | {% endif %}
33 |
--------------------------------------------------------------------------------
/sedlex/template/gitbook/article.md.j2:
--------------------------------------------------------------------------------
1 | {%- import 'html.j2' as html -%}
2 |
3 | # {{ html.icon('bookmark-o') }} {{ title | title }}, Article {{ articles[current_article].order }}
4 |
5 | ## {{ html.icon('file-text-o') }} Texte
6 |
7 | {{ articles[current_article].content.replace('\n', '\n\n') }}
8 |
9 | ## {{ html.icon('pencil-square-o') }} Suivi des modifications
10 |
11 | {% if articles[current_article].gitlabIssue %}
12 | [{{ html.icon('code-fork') }} Voir dans le système de gestion de versions (expert)]({{ articles[current_article].gitlabIssue }})
13 | {% elif articles[current_article].githubIssue %}
14 | [{{ html.icon('code-fork') }} Voir dans le système de gestion de versions (expert)]({{ articles[current_article].githubIssue }})
15 | {% endif %}
16 |
17 | {% if type == 'law-proposal' %}
18 | L'article {{ articles[current_article].order }} de la proposition de loi apporte les modifications suivantes :
19 | {% elif type == 'law-project' %}
20 | L'article {{ articles[current_article].order }} du projet de loi apporte les modifications suivantes :
21 | {% endif %}
22 |
23 | {% for commit in articles[current_article].commits %}
24 | ### {{ commit.title }}
25 |
26 | {{ commit.description | default('') }}
27 |
28 | {{ commit.diff }}
29 | {% endfor %}
30 |
--------------------------------------------------------------------------------
/sedlex/template/gitbook/book.json.j2:
--------------------------------------------------------------------------------
1 | {
2 | "language": "fr",
3 | "plugins": [
4 | "heading-anchors"
5 | ],
6 | "title": "{{ title }}"
7 | }
8 |
--------------------------------------------------------------------------------
/sedlex/template/gitbook/html.j2:
--------------------------------------------------------------------------------
1 | {%- macro icon(name) -%}
2 |