Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
max-line-length = 88
8 changes: 6 additions & 2 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ indent-after-paren=4
indent-string=' '

# Maximum number of characters on a single line.
max-line-length=100
max-line-length=88

# Maximum number of lines in a module.
max-module-lines=1000
Expand Down Expand Up @@ -430,7 +430,11 @@ disable=raw-checker-failed,
deprecated-pragma,
use-symbolic-message-instead,
use-implicit-booleaness-not-comparison-to-string,
use-implicit-booleaness-not-comparison-to-zero
use-implicit-booleaness-not-comparison-to-zero,
missing-module-docstring,
attribute-defined-outside-init,
too-few-public-methods,
import-error

# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
Expand Down
12 changes: 12 additions & 0 deletions pyloremgen/generator/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from .lorem_pdf import PDFGenerator
from .lorem_text import LoremIpsum, LoremIpsumError
from .pdf_utils.cover_page_template import CoverPageBuilder
from .pdf_utils.pdf_page_settings import PagesConfigPDF

__all__ = [
"LoremIpsum",
"PDFGenerator",
"LoremIpsumError",
"PagesConfigPDF",
"CoverPageBuilder",
]
40 changes: 35 additions & 5 deletions pyloremgen/generator/lorem_pdf.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,47 @@
from typing import Optional

from reportlab.lib.styles import getSampleStyleSheet
from reportlab.platypus import PageBreak, Paragraph

from pyloremgen.generator.lorem_text import LoremIpsum
from pyloremgen.generator.pdf_utils.cover_page_template import CoverPageBuilder
from pyloremgen.generator.pdf_utils.pdf_page_settings import PagesConfigPDF
from .lorem_text import LoremIpsum
from .pdf_utils.cover_page_template import CoverPageBuilder
from .pdf_utils.pdf_page_settings import PagesConfigPDF


class PDFGenerator:
def __init__(self, pages_config=None):
"""
PDFGenerator class for creating PDF documents with Lorem Ipsum content.

This class provides functionality to generate
PDF files filled with Lorem Ipsum text,
with options for customizing page settings and including cover pages.

Attributes:
pages_config (PagesConfigPDF): Configuration for PDF page settings.
lorem (LoremIpsum): Instance of LoremIpsum for generating text content.

Methods:
generate_pdf(filename: str, num_pages: int = 1,
cover_page_count: bool = True) -> None:
Generates a PDF document with the specified number of pages.
"""

def __init__(self, pages_config: Optional[PagesConfigPDF] = None) -> None:
self.pages_config = pages_config or PagesConfigPDF()
self.lorem = LoremIpsum()

def generate_pdf(self, filename, num_pages=1, cover_page_count=True):
def generate_pdf(
self, filename: str, num_pages: int = 1, cover_page_count: bool = True
) -> None:
"""
Generate a PDF document with Lorem Ipsum content.

Args:
filename (str): The name of the output PDF file.
num_pages (int, optional): The number of pages to generate. Defaults to 1.
cover_page_count (bool, optional):
Whether to include a cover page. Defaults to True.
"""
self.num_pages = num_pages
doc = self.pages_config.create_document(filename)
content = []
Expand Down
24 changes: 12 additions & 12 deletions pyloremgen/generator/lorem_text.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import random

from pyloremgen.utilities.file_helper import get_data_json
from ..utilities.file_helper import get_data_json


class LoremIpsumError(Exception):
Expand All @@ -17,7 +17,7 @@ class LoremIpsum:
LoremIpsum class

This class generates lorem ipsum text.
It provides methods for generating paragraphs, words, and a shopping list of random items.
It provides methods for generating paragraphs, words, and shopping lists.

Methods:
__init__():
Expand Down Expand Up @@ -63,8 +63,8 @@ def __init__(self) -> None:
- `paragraph_lorem`: A list to store lorem ipsum paragraphs.
- `words_lorem`: A list to store lorem ipsum words.
- `items_lorem`: A list to store lorem ipsum items.
- `paragraphs_words`: A variable to store the number of words in each paragraph.
- `start_with_lorem_ipsum`: A string that represents the start of a lorem ipsum text.
- `paragraphs_words`: Number of words in each paragraph.
- `start_with_lorem_ipsum`: Start lorem ipsum string.

Parameters:
None
Expand Down Expand Up @@ -126,10 +126,10 @@ def paragraphs(

Parameters:
paragraphs_numbers (int): The number of paragraphs to generate.
size (str, optional): The size of the paragraphs. Can be "small", "medium", or "large". Defaults to "medium".
start_with_lorem_ipsum (bool, optional):
start_with_lorem_ipsum (bool, optional):
Whether to start with a "Lorem ipsum" paragraph. Defaults to False.
size (str, optional): Size of paragraphs
("small", "medium", "large"). Default "medium".
start_with_lorem_ipsum (bool, optional): Start with
"Lorem ipsum" paragraph. Default True.

Returns:
str: The generated paragraphs joined by newline characters.
Expand Down Expand Up @@ -180,7 +180,7 @@ def shopping_list(self, items_count: int = None) -> str:
Returns:
str: The shopping list as a string, with each item on a new line.
Raises:
LoremIpsumError: If an error occurs during the generation of the shopping list.
LoremIpsumError: If an error occurs.
"""
items_count = random.randint(5, 100) if items_count is None else items_count
try:
Expand All @@ -194,8 +194,8 @@ def shopping_list(self, items_count: int = None) -> str:
items = random.choices(repeated_data, k=items_count)
else:
items = random.choices(data_json, k=items_count)
self.items_lorem.append("Shopping List:")
self.items_lorem.extend(items)
return "\n".join(self.items_lorem)
self.items_lorem.append("Shopping List:")
self.items_lorem.extend(items)
return "\n".join(self.items_lorem)
except Exception as e:
raise LoremIpsumError(f"Error generating shopping list: {str(e)}") from e
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.black]
line-length = 100
line-length = 88
target-version = ['py38']
skip-string-normalization = true


[tool.isort]
profile = "black"
line_length = 100
line_length = 88

[tool.flake8]
max-line-length = 88
Loading