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, **kwargs):
92 document.tree.getroot().txt_build(self)
95 self.enter_fragment('header')
97 self.push_text("tłum. ")
100 translator.readable()
101 for translator in meta.translators
104 #builder.push_margin(2)
105 self.push_legacy_margin(1)
108 #builder.push_margin(2)
109 self.push_legacy_margin(1)
111 if isbn.startswith(('ISBN-' , 'ISBN ')):
113 self.push_text('ISBN {isbn}'.format(isbn=isbn))
114 #builder.push_margin(5)
116 #builder.push_margin(4)
117 self.push_legacy_margin(1)
120 text = ''.join(self.fragments['header'].pieces) + ''.join(self.fragments[None].pieces)
126 license_description = self.license_description['pol'].format(meta=meta)
128 license_description = self.default_license_description['pol']
131 source = "\n\nTekst opracowany na podstawie: " + meta.source_name
135 contributors = ', '.join(
137 for person in sorted(set(
139 meta.technical_editors + meta.editors
144 "\n\nOpracowanie redakcyjne i przypisy: %s."
148 funders = ', '.join(meta.funders)
150 funders = u"\n\nPublikację wsparli i wsparły: %s." % funders
152 isbn = getattr(meta, 'isbn_txt', None)
158 result = TEMPLATE % {
160 "description": meta.description,
162 "license_description": license_description,
164 "contributors": contributors,
166 "publisher": '\n\nWydawca: ' + ', '.join(meta.publisher),
170 result = '\r\n'.join(result.splitlines()) + '\r\n'
171 return OutputFile.from_bytes(result.encode('utf-8'))