From c8d80134c50754e4725c071f604a081d98de3c9d Mon Sep 17 00:00:00 2001
From: Luthaf '),
- (r"\begin{verse}", ' '),
- (r"\beginverse*", ' '),
- (r"\begin{verse*}", ' '),
- (r"\beginchorus", ' '),
- (r"\begin{chorus}", ' '),
- ]
-
-_BLOCKS_PATTERNS += [(r"\endverse", '
\n'.format(node=node.nodeName) + elif node.nodeName == "par" and in_song: + res += '\n
\n' + elif node.nodeName == "chord" and in_song: + res += '' + for subnode in node.allChildNodes: + res += subnode + res += '' + # TODO: get chord text + res += '' + # TODO: advance in the loop + elif node.nodeName == "#text" and in_song: + res += node + res = res.replace('&', "♭") + res = res.replace('#', "♯ ") + return res # TODO: Write all the output to a log file def import_song(repo, filepath): diff --git a/generator/views/songs.py b/generator/views/songs.py index 95a4687..b415149 100644 --- a/generator/views/songs.py +++ b/generator/views/songs.py @@ -60,9 +60,7 @@ def get_context_data(self, **kwargs): def _read_song(song): path = os.path.join(SONGS_LIBRARY_DIR, 'songs', song.file_path) - with open(path, 'r') as song_file: - content = song_file.read() - return parse_song(content) + return parse_song(path) class SongView(CurrentSongbookMixin, DetailView): From 82c7ded7f75ab5830b21185c41447bfb4111c1d3 Mon Sep 17 00:00:00 2001 From: Louis\n".format(node.nodeName.replace('*', '_star')) + res += self.renderNodes(node.childNodes) + res += "
" + return res + + def renderPar(self, node): + # TODO + return "" + + def renderChord(self, node): + # Je ne comprend pas pourquoi la version suivante, bien plus élégante, + # m'introduit des saut de ligne partout... + # return u""" + # + # {} + # + # {} + # + # """.format( + # node.chord.replace('&', u"♭").replace('#', u"♯"), + # "", # TODO + # ) + return ( + u'' + u'' + u'{}' + u'' + u'{}' + u'' + u'' + ).format( + node.chord.replace('&', u"♭").replace('#', u"♯"), + "", # TODO + ) + + def parse_song(filename): + filename = '/home/louis/projets/songbook/core/songbook_core/data/examples/songs/vent_frais.sg' tex = SongParser.parse(filename) - in_song = False - res = "" - - for node in tex.allChildNodes: - if node.nodeName in ["chorus", "verse", "verse*", "bridge"]: - if not in_song: - in_song = True - part_name = node.nodeName - part_name.replace("*", "_star") - res += '\n'.format(node=node.nodeName) - elif node.nodeName == "par" and in_song: - res += '\n
\n' - elif node.nodeName == "chord" and in_song: - res += '' - res += node.chord - res += '' - # TODO: get chord text - res += '' - # TODO: advance in the loop - elif node.nodeName == "#text" and in_song: - res += node - res = res.replace('&', "♭") - res = res.replace('#', "♯ ") - return res + return Renderer(tex).renderNodes(tex.childNodes) + # TODO: Write all the output to a log file def import_song(repo, filepath): From 6f1fac45099bba99a50a1ef5cff6b353f99005ed Mon Sep 17 00:00:00 2001 From: Louis\n".format(node.nodeName.replace('*', '_star')) - res += self.renderNodes(node.childNodes) + res += self.render_nodes(node.childNodes) res += "
" return res - def renderPar(self, node): + @staticmethod + def render_par(__node): + """Render a paragraph.""" # TODO return "" - def renderChord(self, node): - with self.push("_render", {'active::&': self.renderPlainText(u"♭")}): - with self.push("_render_text", {'#': self.renderPlainText(u"♯")}): + def render_chord(self, node): + r"""Render a chord command `\[`.""" + with self.push("_render", {'active::&': self.render_plain_text(u"♭")}): + with self.push("_render_text", {'#': self.render_plain_text(u"♯")}): return u""" {} @@ -104,19 +128,21 @@ def renderChord(self, node): {} """.format( - self.renderNodes(node.childNodes), + self.render_nodes(node.childNodes), "", # TODO ) def parse_song(filename): + """Parse song 'filename', and return the corresponding HTML code.""" + filename = filename.replace("../patacrep/data/examples/songs/", "") tex = SongParser.parse(filename) - return Renderer(tex).renderNodes(tex.childNodes) + return Renderer(tex).render_nodes(tex.childNodes) def import_song(repo, filepath): '''Import a song in the database''' data = parsetex(filepath) - LOGGER.info("Processing " + + LOGGER.info("Processing " + pprint.pformat(data['titles'][0])) artist_name = smart_text(data['args']['by'], 'utf-8') @@ -169,10 +195,11 @@ def import_song(repo, filepath): title=song_title, artist=artist_model, defaults={ - 'title': song_title, - 'language': language_code, - 'file_path': filepath_rel, - 'slug': ('%06x' % random.randrange(16**6)) }) + 'title': song_title, + 'language': language_code, + 'file_path': filepath_rel, + 'slug': ('%06x' % random.randrange(16**6)) + }) if created: if Song.objects.filter(slug=song_slug).exists(): song_slug += '-' + str(song_model.id) From 0e98a787476c27516f455f20b0725d51b92ef8ae Mon Sep 17 00:00:00 2001 From: Louis\n".format(node.nodeName.replace('*', '_star')) + res += "
".format(node.nodeName.replace('*', '_star')) res += self.render_nodes(node.childNodes) res += "
" return res From 48d78587a239f8b5bb261198cf853732cf2a3441 Mon Sep 17 00:00:00 2001 From: Louis".format(node.nodeName.replace('*', '_star')) + res += "
".format(node.nodeName.replace('*', '_star')) res += self.render_nodes(node.childNodes) res += "
" return res From 4f276f7370fc9580bfaf241cc6ab80a15ffd78ee Mon Sep 17 00:00:00 2001 From: Oliverpool".format(node.nodeName.replace('*', '_star')) + res = u"" + res += u"
".format(node.nodeName.replace('*', '_star')) res += self.render_nodes(node.childNodes) - res += "
" + res += u"" return res @staticmethod def render_par(__node): """Render a paragraph.""" # TODO - return "" + return u"" def render_chord(self, node): r"""Render a chord command `\[`.""" @@ -170,13 +170,13 @@ def render_chord(self, node): with self.push("_render_text", {'#': self.render_plain_text(u"♯")}): name = self.render_nodes(node.attributes["name"]) text = self.render_nodes(node.childNodes) - return ('' - '' - '{name}' - '' - '{text}' - '' - '').format(name=name, text=text) + return (u'' + u'' + u'{name}' + u'' + u'{text}' + u'' + u'').format(name=name, text=text) def parse_song(filename): From 9aeff9625d5c304ac55a1578998fbe255505d55e Mon Sep 17 00:00:00 2001 From: Luthaf