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
4 changed files with 20 additions and 10 deletions
|
@ -21,7 +21,7 @@ class TexFileToFormat:
|
||||||
build_all: bool = False):
|
build_all: bool = False):
|
||||||
self.src_path = src_path
|
self.src_path = src_path
|
||||||
self.build_path = build_dir
|
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.current_build_info = current_build_info
|
||||||
self.last_build_info = last_build_info
|
self.last_build_info = last_build_info
|
||||||
self.allow_dirty = allow_dirty
|
self.allow_dirty = allow_dirty
|
||||||
|
@ -80,12 +80,14 @@ class TexFileToFormat:
|
||||||
formatter = PackageFormatter(
|
formatter = PackageFormatter(
|
||||||
package_name=self.src_path.with_suffix('').name,
|
package_name=self.src_path.with_suffix('').name,
|
||||||
author=self.current_build_info.author,
|
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:
|
elif '.pycls' in self.src_path.name:
|
||||||
formatter = ClassFormatter(
|
formatter = ClassFormatter(
|
||||||
class_name=self.src_path.with_suffix('').name,
|
class_name=self.src_path.with_suffix('').name,
|
||||||
author=self.current_build_info.author,
|
author=self.current_build_info.author,
|
||||||
extra_header=self._header)
|
extra_header=self._header,
|
||||||
|
latex_name=self.latex_name)
|
||||||
else:
|
else:
|
||||||
raise Exception('Programming error. Please contact the developer.')
|
raise Exception('Programming error. Please contact the developer.')
|
||||||
pytex_msg('Writing file {}'.format(formatter.file_name))
|
pytex_msg('Writing file {}'.format(formatter.file_name))
|
||||||
|
|
|
@ -4,8 +4,9 @@ import PyTeX.macros
|
||||||
|
|
||||||
|
|
||||||
class ClassFormatter(PyTeX.formatter.TexFormatter):
|
class ClassFormatter(PyTeX.formatter.TexFormatter):
|
||||||
def __init__(self, class_name: str, author: str, extra_header: [str] = []):
|
def __init__(self, class_name: str, author: str, extra_header: [str] = [],
|
||||||
PyTeX.formatter.TexFormatter.__init__(self, class_name, author, extra_header, '.cls')
|
latex_name: str = 'prepend-author'):
|
||||||
|
PyTeX.formatter.TexFormatter.__init__(self, class_name, author, extra_header, '.cls', latex_name)
|
||||||
|
|
||||||
def make_default_macros(self):
|
def make_default_macros(self):
|
||||||
PyTeX.macros.make_default_macros(self, 'class')
|
PyTeX.macros.make_default_macros(self, 'class')
|
||||||
|
|
|
@ -4,8 +4,9 @@ import PyTeX.macros
|
||||||
|
|
||||||
|
|
||||||
class PackageFormatter(PyTeX.formatter.TexFormatter):
|
class PackageFormatter(PyTeX.formatter.TexFormatter):
|
||||||
def __init__(self, package_name: str, author: str, extra_header: [str] = []):
|
def __init__(self, package_name: str, author: str, extra_header: [str] = [],
|
||||||
PyTeX.formatter.TexFormatter.__init__(self, package_name, author, extra_header, '.sty')
|
latex_name: str = 'prepend-author'):
|
||||||
|
PyTeX.formatter.TexFormatter.__init__(self, package_name, author, extra_header, '.sty', latex_name)
|
||||||
|
|
||||||
def make_default_macros(self):
|
def make_default_macros(self):
|
||||||
PyTeX.macros.make_default_macros(self, 'package')
|
PyTeX.macros.make_default_macros(self, 'package')
|
||||||
|
|
|
@ -8,14 +8,20 @@ from PyTeX.base import Attributes, Args
|
||||||
|
|
||||||
|
|
||||||
class TexFormatter:
|
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.header = header
|
||||||
self.name_raw = name
|
self.name_raw = name
|
||||||
self.author = author
|
self.author = author
|
||||||
|
self.latex_name = latex_name
|
||||||
author_parts = self.author.lower().replace('ß', 'ss').split(' ')
|
author_parts = self.author.lower().replace('ß', 'ss').split(' ')
|
||||||
self.author_acronym = author_parts[0][0] + author_parts[-1]
|
self.author_acronym = author_parts[0][0] + author_parts[-1]
|
||||||
self.name_lowercase = r'{prefix}-{name}'.format(prefix=self.author_acronym,
|
if self.latex_name == 'prepend-author':
|
||||||
name=self.name_raw.lower().strip().replace(' ', '-'))
|
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.prefix = self.name_lowercase.replace('-', '@') + '@'
|
||||||
self.file_name = self.name_lowercase + file_extension
|
self.file_name = self.name_lowercase + file_extension
|
||||||
self.date = datetime.now().strftime('%Y/%m/%d')
|
self.date = datetime.now().strftime('%Y/%m/%d')
|
||||||
|
|
Loading…
Reference in a new issue