Browse Source

Les variables sont maintenant un bloc spécial dans jinja.

Du coup :
- ce ne sont pas des commentaires
- ils n'apparaissent pas pour autant dans le document final.
pull/22/head
Louis 11 years ago
parent
commit
11add71d84
  1. 21
      songbook_core/data/templates/default.tex
  2. 46
      songbook_core/data/templates/layout.tex
  3. 21
      songbook_core/data/templates/patacrep.tex
  4. 21
      songbook_core/data/templates/songs.tex
  5. 16
      songbook_core/templates.py

21
songbook_core/data/templates/default.tex

@ -1,3 +1,24 @@
(%%) Copyright (C) 2014 The Songbook team (www.patacrep.com)
(%%)
(%%) This program is free software; you can redistribute it and/or
(%%) modify it under the terms of the GNU General Public License
(%%) as published by the Free Software Foundation; either version 2
(%%) of the License, or (at your option) any later version.
(%%)
(%%) This program is distributed in the hope that it will be useful,
(%%) but WITHOUT ANY WARRANTY; without even the implied warranty of
(%%) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
(%%) GNU General Public License for more details.
(%%)
(%%) You should have received a copy of the GNU General Public License
(%%) along with this program; if not, write to the Free Software
(%%) Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
(%%) MA 02110-1301, USA.
(%%)
(%%) The latest version of this program can be obtained from
(%%) https://github.com/patacrep/
(% variables %) (% variables %)
{ {
"title": {"description": {"english": "Title", "french": "Titre"}, "title": {"description": {"english": "Title", "french": "Titre"},

46
songbook_core/data/templates/layout.tex

@ -1,27 +1,30 @@
(%%) Copyright (C) 2014 The Songbook team (www.patacrep.com)
(%%)
(%%) This program is free software; you can redistribute it and/or
(%%) modify it under the terms of the GNU General Public License
(%%) as published by the Free Software Foundation; either version 2
(%%) of the License, or (at your option) any later version.
(%%)
(%%) This program is distributed in the hope that it will be useful,
(%%) but WITHOUT ANY WARRANTY; without even the implied warranty of
(%%) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
(%%) GNU General Public License for more details.
(%%)
(%%) You should have received a copy of the GNU General Public License
(%%) along with this program; if not, write to the Free Software
(%%) Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
(%%) MA 02110-1301, USA.
(%%)
(%%) The latest version of this program can be obtained from
(%%) https://github.com/patacrep/
%% Automaticly generated document. %% Automaticly generated document.
%% You may edit this file but all changes will be overwritten. %% You may edit this file but all changes will be overwritten.
%% If you want to change this document, have a look at %% If you want to change this document, have a look at
%% the templating system. %% the templating system.
%%
% This program is free software; you can redistribute it and/or %% Generated using Songbook <http://www.patacrep.com>
% modify it under the terms of the GNU General Public License
% as published by the Free Software Foundation; either version 2
% of the License, or (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
% MA 02110-1301, USA.
%
% The latest version of this program can be obtained from
% https://github.com/patacrep/
% Copyright (C) 2014 The Songbook team (www.patacrep.com)
(% variables %) (% variables %)
{ {
@ -107,4 +110,5 @@
(* endblock *) (* endblock *)
\end{document} \end{document}
% End of file
(%%) End of file

21
songbook_core/data/templates/patacrep.tex

@ -1,3 +1,24 @@
(%%) Copyright (C) 2014 The Songbook team (www.patacrep.com)
(%%)
(%%) This program is free software; you can redistribute it and/or
(%%) modify it under the terms of the GNU General Public License
(%%) as published by the Free Software Foundation; either version 2
(%%) of the License, or (at your option) any later version.
(%%)
(%%) This program is distributed in the hope that it will be useful,
(%%) but WITHOUT ANY WARRANTY; without even the implied warranty of
(%%) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
(%%) GNU General Public License for more details.
(%%)
(%%) You should have received a copy of the GNU General Public License
(%%) along with this program; if not, write to the Free Software
(%%) Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
(%%) MA 02110-1301, USA.
(%%)
(%%) The latest version of this program can be obtained from
(%%) https://github.com/patacrep/
(% variables %) (% variables %)
{ {
"songnumberbgcolor": {"description": {"english": "Number Shade", "french": "Couleur des numéros"}, "songnumberbgcolor": {"description": {"english": "Number Shade", "french": "Couleur des numéros"},

21
songbook_core/data/templates/songs.tex

@ -1,3 +1,24 @@
(%%) Copyright (C) 2014 The Songbook team (www.patacrep.com)
(%%)
(%%) This program is free software; you can redistribute it and/or
(%%) modify it under the terms of the GNU General Public License
(%%) as published by the Free Software Foundation; either version 2
(%%) of the License, or (at your option) any later version.
(%%)
(%%) This program is distributed in the hope that it will be useful,
(%%) but WITHOUT ANY WARRANTY; without even the implied warranty of
(%%) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
(%%) GNU General Public License for more details.
(%%)
(%%) You should have received a copy of the GNU General Public License
(%%) along with this program; if not, write to the Free Software
(%%) Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
(%%) MA 02110-1301, USA.
(%%)
(%%) The latest version of this program can be obtained from
(%%) https://github.com/patacrep/
(* extends "layout.tex" *) (* extends "layout.tex" *)
(* block songbookpreambule *) (* block songbookpreambule *)

16
songbook_core/templates.py

@ -3,6 +3,7 @@
"""Template for .tex generation settings and utilities""" """Template for .tex generation settings and utilities"""
from jinja2 import Environment, FileSystemLoader, ChoiceLoader, PackageLoader, TemplateNotFound from jinja2 import Environment, FileSystemLoader, ChoiceLoader, PackageLoader, TemplateNotFound
from jinja2.ext import Extension
from jinja2.meta import find_referenced_templates as find_templates from jinja2.meta import find_referenced_templates as find_templates
import os import os
import re import re
@ -19,6 +20,16 @@ _LATEX_SUBS = (
(re.compile(r'\.\.\.+'), r'\\ldots'), (re.compile(r'\.\.\.+'), r'\\ldots'),
) )
class VariablesExtension(Extension):
tags = set(['variables'])
def parse(self, parser):
parser.stream.next()
parser.parse_statements(end_tokens=['name:endvariables'], drop_needle=True)
return nodes.Const("")
def _escape_tex(value): def _escape_tex(value):
'''Escape TeX special characters''' '''Escape TeX special characters'''
@ -50,13 +61,14 @@ class TexRenderer(object):
'songbook_core', os.path.join('data', 'templates') 'songbook_core', os.path.join('data', 'templates')
), ),
]), ]),
extensions=[VariablesExtension],
) )
self.texenv.block_start_string = '(*' self.texenv.block_start_string = '(*'
self.texenv.block_end_string = '*)' self.texenv.block_end_string = '*)'
self.texenv.variable_start_string = '((' self.texenv.variable_start_string = '(('
self.texenv.variable_end_string = '))' self.texenv.variable_end_string = '))'
self.texenv.comment_start_string = '(% variables %)' self.texenv.comment_start_string = '(#'
self.texenv.comment_end_string = '(% endvariables %)' self.texenv.comment_end_string = '#)'
self.texenv.line_comment_prefix = '(%%)' self.texenv.line_comment_prefix = '(%%)'
self.texenv.filters['escape_tex'] = _escape_tex self.texenv.filters['escape_tex'] = _escape_tex
self.texenv.trim_blocks = True self.texenv.trim_blocks = True

Loading…
Cancel
Save