2 from __future__ import unicode_literals
5 from librarian import OutputFile, get_resource
8 with io.open(get_resource("res/text/template.txt")) as f:
15 self.current_margin = 0
16 self.starting_block = True
18 def push_legacy_margin(self, margin):
21 self.pieces[-1] = self.pieces[-1].rstrip(' ')
22 self.pieces.append('\r\n' * margin)
23 self.current_margin += margin
24 self.starting_block = True
26 def push_margin(self, margin):
29 self.pieces[-1] = self.pieces[-1].rstrip(' ')
30 if margin > self.current_margin:
31 self.pieces.append('\r\n' * (margin - self.current_margin))
32 self.current_margin = margin
33 self.starting_block = True
35 def push_text(self, text, prepared=False):
37 if self.starting_block and not prepared:
39 self.pieces.append(text)
40 self.current_margin = 0
42 self.starting_block = False
48 file_extension = "txt"
51 default_license_description = {
53 "Ten utwór nie jest objęty majątkowym prawem autorskim "
54 "i znajduje się w domenie publicznej, co oznacza że "
55 "możesz go swobodnie wykorzystywać, publikować "
56 "i rozpowszechniać. Jeśli utwór opatrzony jest "
57 "dodatkowymi materiałami (przypisy, motywy literackie "
58 "etc.), które podlegają prawu autorskiemu, to te "
59 "dodatkowe materiały udostępnione są na licencji "
60 "Creative Commons Uznanie Autorstwa – Na Tych Samych "
62 "(http://creativecommons.org/licenses/by-sa/3.0/)"
65 license_description = {
66 "pol": "Ten utwór jest udostępniony na licencji {meta.license_description}: \n{meta.license}",
72 'header': TxtFragment()
74 self.current_fragments = [self.fragments[None]]
76 def enter_fragment(self, fragment):
77 self.current_fragments.append(self.fragments[fragment])
79 def exit_fragment(self):
80 self.current_fragments.pop()
82 def push_text(self, text, prepared=False):
83 self.current_fragments[-1].push_text(text, prepared=prepared)
85 def push_margin(self, margin):
86 self.current_fragments[-1].push_margin(margin)
88 def push_legacy_margin(self, margin, where=None):
89 self.current_fragments[-1].push_legacy_margin(margin)
91 def build(self, document, raw_text=False):
92 document.tree.getroot().txt_build(self)
95 self.enter_fragment('header')
97 self.push_text("tłum. ", 'header')
98 for translator in meta.translators:
99 self.push_text(translator.readable())
100 #builder.push_margin(2)
101 self.push_legacy_margin(1)
104 #builder.push_margin(2)
105 self.push_legacy_margin(1)
107 if isbn.startswith(('ISBN-' , 'ISBN ')):
109 self.push_text('ISBN {isbn}'.format(isbn=isbn))
110 #builder.push_margin(5)
112 #builder.push_margin(4)
113 self.push_legacy_margin(1)
116 text = ''.join(self.fragments['header'].pieces) + ''.join(self.fragments[None].pieces)
122 license_description = self.license_description['pol'].format(meta=meta)
124 license_description = self.default_license_description['pol']
127 source = "\n\nTekst opracowany na podstawie: " + meta.source_name
131 contributors = ', '.join(
133 for person in sorted(set(
135 meta.technical_editors + meta.editors
140 "\n\nOpracowanie redakcyjne i przypisy: %s."
144 funders = ', '.join(meta.funders)
146 funders = u"\n\nPublikację wsparli i wsparły: %s." % funders
148 isbn = getattr(meta, 'isbn_txt', None)
154 result = TEMPLATE % {
156 "description": meta.description,
158 "license_description": license_description,
160 "contributors": contributors,
162 "publisher": '\n\nWydawca: ' + ', '.join(meta.publisher),
166 result = '\r\n'.join(result.splitlines()) + '\r\n'
167 return OutputFile.from_bytes(result.encode('utf-8'))