aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/docs
diff options
context:
space:
mode:
authorHsiangNianian <i@jyunko.cn>2025-03-13 01:01:20 +0800
committerHsiangNianian <i@jyunko.cn>2025-03-13 01:01:20 +0800
commit80b74f79dfbfa9afb845172a5ea84110d75f1bc8 (patch)
tree361dcb055de78b50d82619646fde28fa618f9507 /docs
parentdd873e954a92d0e3209fe98b034570b47c859589 (diff)
downloadconventional_role_play-80b74f79dfbfa9afb845172a5ea84110d75f1bc8.tar.gz
conventional_role_play-80b74f79dfbfa9afb845172a5ea84110d75f1bc8.zip
refactor(project)!: first implementation of the Conventional Role Play SDK with core components, renderers, extractors, and example usage.
Diffstat (limited to 'docs')
-rw-r--r--docs/source/api.md94
-rw-r--r--docs/source/usage.md58
2 files changed, 152 insertions, 0 deletions
diff --git a/docs/source/api.md b/docs/source/api.md
new file mode 100644
index 0000000..d1c381b
--- /dev/null
+++ b/docs/source/api.md
@@ -0,0 +1,94 @@
+# API Documentation for TRPG Log Processor
+
+## Overview
+
+The TRPG Log Processor SDK provides a structured way to parse, extract, and render logs from tabletop role-playing games (TRPGs). This document outlines the key components of the SDK, including classes, methods, and their functionalities.
+
+## Core Components
+
+### Parser
+
+- **Class**: `Parser`
+- **Module**: `src/conventionalrp/core/parser.py`
+- **Methods**:
+ - `parse_log(log: str) -> List[Token]`: Parses a TRPG log string and returns a list of tokens.
+ - `load_rules(rules_file: str) -> None`: Loads parsing rules from a specified file.
+
+### Processor
+
+- **Class**: `Processor`
+- **Module**: `src/conventionalrp/core/processor.py`
+- **Methods**:
+ - `process_tokens(tokens: List[Token]) -> None`: Processes a list of tokens.
+ - `generate_output(format: str) -> str`: Generates output in the specified format (e.g., HTML, Markdown, JSON).
+
+## Extractors
+
+### BaseExtractor
+
+- **Class**: `BaseExtractor`
+- **Module**: `src/conventionalrp/extractors/base.py`
+- **Methods**:
+ - `extract(data: Any) -> Any`: Extracts relevant data based on defined rules.
+ - `load_rules(rules_file: str) -> None`: Loads extraction rules from a specified file.
+
+### RuleExtractor
+
+- **Class**: `RuleExtractor`
+- **Module**: `src/conventionalrp/extractors/rule_extractor.py`
+- **Methods**:
+ - `extract(data: Any) -> List[Rule]`: Extracts rules from JSON configuration files.
+
+## Renderers
+
+### BaseRenderer
+
+- **Class**: `BaseRenderer`
+- **Module**: `src/conventionalrp/renderers/base.py`
+- **Methods**:
+ - `render(data: Any) -> str`: Renders data into a specific format.
+ - `set_style(style: str) -> None`: Sets the rendering style.
+
+### HTMLRenderer
+
+- **Class**: `HTMLRenderer`
+- **Module**: `src/conventionalrp/renderers/html_renderer.py`
+- **Methods**:
+ - `render(data: Any) -> str`: Renders data into HTML format.
+
+### MarkdownRenderer
+
+- **Class**: `MarkdownRenderer`
+- **Module**: `src/conventionalrp/renderers/markdown_renderer.py`
+- **Methods**:
+ - `render(data: Any) -> str`: Renders data into Markdown format.
+
+### JSONRenderer
+
+- **Class**: `JSONRenderer`
+- **Module**: `src/conventionalrp/renderers/json_renderer.py`
+- **Methods**:
+ - `render(data: Any) -> str`: Renders data into JSON format.
+
+## Plugins
+
+### PluginManager
+
+- **Class**: `PluginManager`
+- **Module**: `src/conventionalrp/plugins/plugin_manager.py`
+- **Methods**:
+ - `load_plugins() -> None`: Loads available plugins.
+ - `execute_plugin(name: str, data: Any) -> Any`: Executes a specified plugin with the provided data.
+
+## Utilities
+
+### Text Processing
+
+- **Module**: `src/conventionalrp/utils/text_processing.py`
+- **Functions**:
+ - `tokenize(text: str) -> List[str]`: Tokenizes input text into a list of tokens.
+ - `match_regex(pattern: str, text: str) -> List[str]`: Matches a regex pattern against the input text.
+
+## Conclusion
+
+This API documentation provides a comprehensive overview of the TRPG Log Processor SDK. For detailed usage instructions and examples, please refer to the `usage.md` file in the `docs` directory.
diff --git a/docs/source/usage.md b/docs/source/usage.md
new file mode 100644
index 0000000..33481ca
--- /dev/null
+++ b/docs/source/usage.md
@@ -0,0 +1,58 @@
+# Usage Instructions for TRPG Log Processor
+
+## Overview
+
+The TRPG Log Processor is a Python SDK designed for structured processing of tabletop role-playing game (TRPG) logs. It provides functionalities for parsing logs, extracting rules, and rendering outputs in multiple formats.
+
+## Installation
+
+To install the TRPG Log Processor, you can use pip:
+
+```bash
+pip install conventionalrp
+```
+
+## Basic Usage
+
+Here is a simple example of how to use the TRPG Log Processor:
+
+```python
+from conventionalrp.core.parser import Parser
+from conventionalrp.core.processor import Processor
+from conventionalrp.extractors.rule_extractor import RuleExtractor
+from conventionalrp.renderers.html_renderer import HTMLRenderer
+
+# Step 1: Load rules
+rule_extractor = RuleExtractor()
+rules = rule_extractor.load_rules('path/to/rules.json')
+
+# Step 2: Parse the log
+parser = Parser(rules)
+parsed_log = parser.parse_log('path/to/log.txt')
+
+# Step 3: Process the parsed tokens
+processor = Processor()
+output = processor.process_tokens(parsed_log)
+
+# Step 4: Render the output
+renderer = HTMLRenderer()
+html_output = renderer.render(output)
+
+# Save or display the output
+with open('output.html', 'w') as f:
+ f.write(html_output)
+```
+
+## Features
+
+- **Rule Extraction**: Easily extract rules from JSON configuration files using the `RuleExtractor`.
+- **Multi-format Rendering**: Render outputs in various formats such as HTML, Markdown, and JSON using the respective renderer classes.
+- **Extensibility**: Create custom plugins to extend the functionality of the SDK.
+
+## Custom Plugins
+
+To create a custom plugin, you can follow the example provided in `examples/custom_plugin.py`. This allows you to add additional processing or rendering capabilities tailored to your needs.
+
+## Documentation
+
+For more detailed information on the API and available classes, please refer to the [API documentation](api.md).