handle package naming style
Option --name can now be set to either raw or prepend-author this controls the derivation of the name of the formatted package from the source file read in.
This commit is contained in:
parent
357144e9f0
commit
315e3647ab
@ -21,7 +21,7 @@ class TexFileToFormat:
|
||||
build_all: bool = False):
|
||||
self.src_path = src_path
|
||||
self.build_path = build_dir
|
||||
self.tex_name = latex_name # Still an identifier on how to name the package when being formatted
|
||||
self.latex_name = latex_name # Still an identifier on how to name the package when being formatted
|
||||
self.current_build_info = current_build_info
|
||||
self.last_build_info = last_build_info
|
||||
self.allow_dirty = allow_dirty
|
||||
@ -80,12 +80,14 @@ class TexFileToFormat:
|
||||
formatter = PackageFormatter(
|
||||
package_name=self.src_path.with_suffix('').name,
|
||||
author=self.current_build_info.author,
|
||||
extra_header=self._header)
|
||||
extra_header=self._header,
|
||||
latex_name=self.latex_name)
|
||||
elif '.pycls' in self.src_path.name:
|
||||
formatter = ClassFormatter(
|
||||
class_name=self.src_path.with_suffix('').name,
|
||||
author=self.current_build_info.author,
|
||||
extra_header=self._header)
|
||||
extra_header=self._header,
|
||||
latex_name=self.latex_name)
|
||||
else:
|
||||
raise Exception('Programming error. Please contact the developer.')
|
||||
pytex_msg('Writing file {}'.format(formatter.file_name))
|
||||
|
@ -4,8 +4,9 @@ import PyTeX.macros
|
||||
|
||||
|
||||
class ClassFormatter(PyTeX.formatter.TexFormatter):
|
||||
def __init__(self, class_name: str, author: str, extra_header: [str] = []):
|
||||
PyTeX.formatter.TexFormatter.__init__(self, class_name, author, extra_header, '.cls')
|
||||
def __init__(self, class_name: str, author: str, extra_header: [str] = [],
|
||||
latex_name: str = 'prepend-author'):
|
||||
PyTeX.formatter.TexFormatter.__init__(self, class_name, author, extra_header, '.cls', latex_name)
|
||||
|
||||
def make_default_macros(self):
|
||||
PyTeX.macros.make_default_macros(self, 'class')
|
||||
|
@ -4,8 +4,9 @@ import PyTeX.macros
|
||||
|
||||
|
||||
class PackageFormatter(PyTeX.formatter.TexFormatter):
|
||||
def __init__(self, package_name: str, author: str, extra_header: [str] = []):
|
||||
PyTeX.formatter.TexFormatter.__init__(self, package_name, author, extra_header, '.sty')
|
||||
def __init__(self, package_name: str, author: str, extra_header: [str] = [],
|
||||
latex_name: str = 'prepend-author'):
|
||||
PyTeX.formatter.TexFormatter.__init__(self, package_name, author, extra_header, '.sty', latex_name)
|
||||
|
||||
def make_default_macros(self):
|
||||
PyTeX.macros.make_default_macros(self, 'package')
|
||||
|
@ -8,14 +8,20 @@ from PyTeX.base import Attributes, Args
|
||||
|
||||
|
||||
class TexFormatter:
|
||||
def __init__(self, name: str, author: str, header: Optional[List[str]], file_extension: str):
|
||||
def __init__(self, name: str, author: str, header: Optional[List[str]], file_extension: str,
|
||||
latex_name: str):
|
||||
self.header = header
|
||||
self.name_raw = name
|
||||
self.author = author
|
||||
self.latex_name = latex_name
|
||||
author_parts = self.author.lower().replace('ß', 'ss').split(' ')
|
||||
self.author_acronym = author_parts[0][0] + author_parts[-1]
|
||||
if self.latex_name == 'prepend-author':
|
||||
self.name_lowercase = r'{prefix}-{name}'.format(prefix=self.author_acronym,
|
||||
name=self.name_raw.lower().strip().replace(' ', '-'))
|
||||
else:
|
||||
self.name_lowercase = self.name_raw.lower().strip().replace(' ', '-')
|
||||
|
||||
self.prefix = self.name_lowercase.replace('-', '@') + '@'
|
||||
self.file_name = self.name_lowercase + file_extension
|
||||
self.date = datetime.now().strftime('%Y/%m/%d')
|
||||
|
Loading…
Reference in New Issue
Block a user