Skip to content

Commit

Permalink
added comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jgniecki committed Jun 13, 2024
1 parent f5c5f00 commit 5072e81
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ composer require dev-lancer/minecraft-motd-parser
## Parsing

### Usage TextParser
To parse a text-based MOTD using custom formatting and colors:
```php
$formatCollection = \DevLancer\MinecraftMotdParser\FormatCollection::generate();
$colorCollection = \DevLancer\MinecraftMotdParser\ColorCollection::generate();
Expand All @@ -24,6 +25,7 @@ $motdItemCollection = $parser->parse($motd, new \DevLancer\MinecraftMotdParser\M
```

### Usage ArrayParser
To parse a structured array-based MOTD:
```php
$colorCollection = \DevLancer\MinecraftMotdParser\ColorCollection::generate();
$parser = new \DevLancer\MinecraftMotdParser\Parser\ArrayParser($colorCollection);
Expand Down Expand Up @@ -53,41 +55,51 @@ $motdItemCollection = $parser->parse($motd, new \DevLancer\MinecraftMotdParser\M
## Generation

### MotdItemCollection
Example of creating a MotdItemCollection:
```php
$parser = new \DevLancer\MinecraftMotdParser\Parser\TextParser();
$motd = "A &l&fMine&4craft &rServer";
$motdItemCollection = $parser->parse($motd, new \DevLancer\MinecraftMotdParser\MotdItemCollection());
```

### Usage HtmlGenerator
To generate HTML from a parsed MOTD:
```php
$generator = new \DevLancer\MinecraftMotdParser\Generator\HtmlGenerator();

// Generate HTML from the MOTD item collection
echo $generator->generate($motdItemCollection);
```

#### Output
The output will be:
```html
A <span style="font-weight: bold; color: #FFFFFF;">Mine</span>
<span style="font-weight: bold; color: #AA0000;">craft </span> Server
```

### Usage RawGenerator
To generate raw text from a parsed MOTD:
```php
$generator = new \DevLancer\MinecraftMotdParser\Generator\RawGenerator("&");
$generator = new \DevLancer\MinecraftMotdParser\Generator\RawGenerator("§");
// Generate raw text from the MOTD item collection
echo $generator->generate($motdItemCollection);
//output: A &f&lMine&4craft &rServer
//output: A §f§lMine§4craft §rServer
```

### Usage TextGenerator
To generate plain text from a parsed MOTD:
```php
$generator = new \DevLancer\MinecraftMotdParser\Generator\TextGenerator();
// Generate plain text from the MOTD item collection
echo $generator->generate($motdItemCollection);
//output: A Minecraft Server
```

## Custom formatter

### Define new class formatter
Example of creating a custom bold formatter:
```php
class CustomBoldFormatter implements FormatterInterface
{
Expand All @@ -109,26 +121,33 @@ class CustomBoldFormatter implements FormatterInterface
```

### Usage
To use the custom formatter:
```php
$formatCollection = new \DevLancer\MinecraftMotdParser\FormatCollection();
// Create a new format collection
$formatCollection = \DevLancer\MinecraftMotdParser\FormatCollection::generate();

// and override the default formatter for bold
$formatCollection->add(new CustomBoldFormatter());

// Create a new MOTD item
$motdItem = new \DevLancer\MinecraftMotdParser\MotdItem();
$motdItem->setBold(true);
$motdItem->setText("Hello World");

// Create a new MOTD item collection and add the MOTD item
$motdItemCollection = new \DevLancer\MinecraftMotdParser\MotdItemCollection();
$motdItemCollection->add($motdItem);

// Generate HTML using the custom formatter
$generator = new \DevLancer\MinecraftMotdParser\Generator\HtmlGenerator($formatCollection);
echo $generator->generate($motdItemCollection);
```

### Output
The output will be:
```html
<b class="CustomBoldFormatter">Hello World</b>
```

## License

[MIT](LICENSE)
This library is licensed under the [MIT](LICENSE) License.

0 comments on commit 5072e81

Please sign in to comment.