1 # This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
 
   2 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
 
   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"
 
  53     default_license_description = {
 
  55             "Wszystkie zasoby Wolnych Lektur możesz swobodnie wykorzystywać, "
 
  56             "publikować i rozpowszechniać pod warunkiem zachowania warunków "
 
  57             "licencji i zgodnie z Zasadami wykorzystania Wolnych Lektur.\n"
 
  58             "Ten utwór jest w domenie publicznej.\n"
 
  59             "Wszystkie materiały dodatkowe (przypisy, motywy literackie) są "
 
  60             "udostępnione na Licencji Wolnej Sztuki 1.3: "
 
  61             "https://artlibre.org/licence/lal/pl/\n"
 
  62             "Fundacja Wolne Lektury zastrzega sobie prawa do wydania "
 
  63             "krytycznego zgodnie z art. Art.99(2) Ustawy o prawach autorskich "
 
  64             "i prawach pokrewnych.\nWykorzystując zasoby z Wolnych Lektur, "
 
  65             "należy pamiętać o zapisach licencji oraz zasadach, które "
 
  66             "spisaliśmy w Zasadach wykorzystania Wolnych Lektur: "
 
  67             "https://wolnelektury.pl/info/zasady-wykorzystania/\nZapoznaj "
 
  68             "się z nimi, zanim udostępnisz dalej nasze książki."
 
  71     license_description = {
 
  73             #"Ten utwór jest udostępniony na licencji {meta.license_description}: \n{meta.license}",
 
  74             "Wszystkie zasoby Wolnych Lektur możesz swobodnie wykorzystywać, "
 
  75             "publikować i rozpowszechniać pod warunkiem zachowania warunków "
 
  76             "licencji i zgodnie z Zasadami wykorzystania Wolnych Lektur.\n"
 
  77             "Ten utwór jest jest udostępniony na licencji {meta.license_description} ({meta.license}). "
 
  78             "Wszystkie materiały dodatkowe (przypisy, motywy literackie) są "
 
  79             "udostępnione na Licencji Wolnej Sztuki 1.3: "
 
  80             "https://artlibre.org/licence/lal/pl/\n"
 
  81             "Fundacja Wolne Lektury zastrzega sobie prawa do wydania "
 
  82             "krytycznego zgodnie z art. Art.99(2) Ustawy o prawach autorskich "
 
  83             "i prawach pokrewnych.\nWykorzystując zasoby z Wolnych Lektur, "
 
  84             "należy pamiętać o zapisach licencji oraz zasadach, które "
 
  85             "spisaliśmy w Zasadach wykorzystania Wolnych Lektur: "
 
  86             "https://wolnelektury.pl/info/zasady-wykorzystania/\nZapoznaj "
 
  87             "się z nimi, zanim udostępnisz dalej nasze książki."
 
  91     def __init__(self, base_url=None):
 
  94             'header': TxtFragment()
 
  96         self.current_fragments = [self.fragments[None]]
 
  98     def enter_fragment(self, fragment):
 
  99         self.current_fragments.append(self.fragments[fragment])
 
 101     def exit_fragment(self):
 
 102         self.current_fragments.pop()
 
 104     def push_text(self, text, prepared=False):
 
 105         self.current_fragments[-1].push_text(text, prepared=prepared)
 
 107     def push_margin(self, margin):
 
 108         self.current_fragments[-1].push_margin(margin)
 
 110     def push_legacy_margin(self, margin, where=None):
 
 111         self.current_fragments[-1].push_legacy_margin(margin)
 
 113     def build(self, document, raw_text=False, **kwargs):
 
 114         document.tree.getroot().txt_build(self)
 
 117         self.enter_fragment('header')
 
 119             self.push_text("tłum. ")
 
 122                     translator.readable()
 
 123                     for translator in meta.translators
 
 126             #builder.push_margin(2)
 
 127             self.push_legacy_margin(1)
 
 130             #builder.push_margin(2)
 
 131             self.push_legacy_margin(1)
 
 133             if isbn.startswith(('ISBN-' , 'ISBN ')):
 
 135             self.push_text('ISBN {isbn}'.format(isbn=isbn))
 
 136             #builder.push_margin(5)
 
 138         #builder.push_margin(4)
 
 139         self.push_legacy_margin(1)
 
 142         text = ''.join(self.fragments['header'].pieces) +  ''.join(self.fragments[None].pieces)
 
 148                 license_description = self.license_description['pol'].format(meta=meta)
 
 150                 license_description = self.default_license_description['pol']
 
 153                 source = "\n\nTekst opracowany na podstawie: " + meta.source_name
 
 157             contributors = ', '.join(
 
 159                 for person in sorted(set(
 
 161                         meta.technical_editors + meta.editors
 
 166                     "\n\nOpracowanie redakcyjne i przypisy: %s."
 
 170             funders = ', '.join(meta.funders)
 
 172                 funders = "\n\nPublikację wsparli i wsparły: %s." % funders
 
 174             isbn = getattr(meta, 'isbn_txt', None)
 
 180             result = TEMPLATE % {
 
 182                 "description": meta.description,
 
 184                 "license_description": license_description,
 
 186                 "contributors": contributors,
 
 188                 "publisher":  '\n\nWydawca: ' + ', '.join(meta.publisher),
 
 192         result = '\r\n'.join(result.splitlines()) + '\r\n'
 
 193         return OutputFile.from_bytes(result.encode('utf-8'))