Skip to content

Commit

Permalink
Fix typo in "listeners" (#58)
Browse files Browse the repository at this point in the history
* Replace "listenere" with "listener" in comments

* Replace "listenere" with "listener" in local variable

* Replace "listenere" with "listener" in methods

Since methods may be exposed to other classes, use an alias for the listenere

* Update Lexer.php

Co-authored-by: Basil <[email protected]>
  • Loading branch information
florisluiten and nadar authored Apr 5, 2022
1 parent cd105b7 commit 56abc51
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 34 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ This would render the following HTML:

## Extend the Parser

In order to extend the Parser by adding your own listeneres (this can be the case if you are using quill plugins which generates custom delta code), you have to decide whether it's an:
In order to extend the Parser by adding your own listeners (this can be the case if you are using quill plugins which generates custom delta code), you have to decide whether it's an:

+ inline element: Replaces content with new parsed content, this is mostly the case when working with quill extensions.
+ block element: Block elements which encloses the whole input with a tag, for example heading.
Expand All @@ -98,7 +98,7 @@ class Mention extends InlineListener
}
```

Now register the listenere:
Now register the listener:

```php
$lexer = new Lexer($json);
Expand Down
2 changes: 1 addition & 1 deletion src/BlockListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Block Listener
*
* Block listeneres writes from $line->input into the $line->output.
* Block listener writes from $line->input into the $line->output.
*
* @author Basil Suter <[email protected]>
* @since 1.0.0
Expand Down
4 changes: 2 additions & 2 deletions src/InlineListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
use Exception;

/**
* Inline Listenere.
* Inline listener.
*
* Inline listeneres changes the $line->input value!
* Inline listeners changes the $line->input value!
*
* @author Basil Suter <[email protected]>
* @since 1.0.0
Expand Down
68 changes: 43 additions & 25 deletions src/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,36 @@
*
* The lexer class represents the main thread in how delta input is processed and rendered.
*
* Basically Listeneres can watch every line of delta and interact with the line, which means
* reading input and writting to output and mark this line as done, so other listeneres won't
* Basically listeners can watch every line of delta and interact with the line, which means
* reading input and writting to output and mark this line as done, so other listeners won't
* take care of this line as well.
*
* ## Basic concept
*
* Listeneres are grouped in 2 types:
* Listeners are grouped in 2 types:
*
* + inline: For elements which are only inline applied, like writing bold or italic
* + block: Used when the line represents a full html element like heading or lists
*
* Inside this group types there are 2 prioirities:
*
* + early bird: This is default value, the early bird catches the worm...
* + garbage collector: This is mainly used for the text listenere which generates the paragraphs and can only be done at the very end of the process.
* + garbage collector: This is mainly used for the text listener which generates the paragraphs and can only be done at the very end of the process.
*
* Every listenere has two methods a process() and render():
* Every listener has two methods a process() and render():
*
* + process: is triggered by every line, so the listenere can choose whether he wants to pick this line, interact or not.
* + render: after all lines are processed, every listenered triggers the render() method once, so the picked line from process can be "further" processed and rendered.
* + process: is triggered by every line, so the listener can choose whether he wants to pick this line, interact or not.
* + render: after all lines are processed, every listener triggers the render() method once, so the picked line from process can be "further" processed and rendered.
*
* ## Lifecycle
*
* 1. lines will be generated
* 2. lines foreached and inline early bird listeners run process() method.
* 3. lines foreached and inline garbage collector listeneres run process() method.
* 4. lines foreached and block early bird listeneres run process() method.
* 5. lines foreached and block garbage collector listenere run process() method.
* 6. inline listeneres foreach and run render() method.
* 7. block listeneres foreach and run render() method.
* 3. lines foreached and inline garbage collector listeners run process() method.
* 4. lines foreached and block early bird listeners run process() method.
* 5. lines foreached and block garbage collector listener run process() method.
* 6. inline listeners foreach and run render() method.
* 7. block listeners foreach and run render() method.
*
* @author Basil Suter <[email protected]>
* @since 1.0.0
Expand Down Expand Up @@ -104,7 +104,7 @@ class Lexer
protected $json;

/**
* @var array The listeneres grouped by type and priority.
* @var array The listeners grouped by type and priority.
*/
protected $listeners = [
Listener::TYPE_INLINE => [
Expand All @@ -121,21 +121,21 @@ class Lexer
* Initializer
*
* @param string|array $json The delta ops json as string or as already parsed array.
* @param boolean $loadBuiltinListeneres Whether the built in listeneres should be loaded or not.
* @param boolean $loadBuiltinlisteners Whether the built in listeners should be loaded or not.
*/
public function __construct($json, $loadBuiltinListeneres = true)
public function __construct($json, $loadBuiltinListeners = true)
{
$this->json = $json;

if ($loadBuiltinListeneres) {
$this->loadBuiltinListeneres();
if ($loadBuiltinListeners) {
$this->loadBuiltinListeners();
}
}

/**
* Loads the library built in listeneres.
* Loads the library built in listeners.
*/
public function loadBuiltinListeneres()
public function loadBuiltinListeners()
{
$this->registerListener(new Image);
$this->registerListener(new Bold);
Expand All @@ -156,7 +156,16 @@ public function loadBuiltinListeneres()
}

/**
* Register a new listenere.
* Alias for loadBuiltinListeners() for compatibility
* @deprecated will be removed in 3.0
*/
public function loadBuiltinListeneres()
{
return $this->loadBuiltinListeners();
}

/**
* Register a new listener.
*
* @param Listener $listener
*/
Expand All @@ -169,15 +178,15 @@ public function registerListener(Listener $listener)
* Overrite an existing listener with a new object
*
* An example could when you like to provide more options or access other elements which are not covered by the base class
* so you can extend from the built in listeneres and overrite them. This keeps also the hyrarchical level of the elements.
* so you can extend from the built in listeners and overrite them. This keeps also the hyrarchical level of the elements.
*
* ```php
* $lexer->overwriteListener(new Image, new MyOwnImage);
* ```
*
* As the `new Image` listener is already registered, it will just replace the object with `new MyOwnImage`.
*
* @param Listener $listener The already registered listenere object
* @param Listener $listener The already registered listener object
* @param Listener $new The new listener object
* @see https://github.com/nadar/quill-delta-parser/issues/55
* @since 2.8.0
Expand Down Expand Up @@ -353,7 +362,7 @@ protected function processListeners(Line $line, $type)
* @param [type] $type
* @return void
*/
protected function renderListeneres($type)
protected function renderListeners($type)
{
foreach ($this->listeners[$type] as $prios) {
foreach ($prios as $listener) {
Expand All @@ -362,6 +371,15 @@ protected function renderListeneres($type)
}
}

/**
* Alias for renderListeners() for compatibility
* @deprecated will be removed in 3.0
*/
protected function renderListeneres($type)
{
return $this->renderListeners($type);
}

/**
* Renders the current delta into a html string.
*
Expand All @@ -376,8 +394,8 @@ public function render()
$this->processListeners($line, Listener::TYPE_BLOCK);
}

$this->renderListeneres(Listener::TYPE_INLINE);
$this->renderListeneres(Listener::TYPE_BLOCK);
$this->renderListeners(Listener::TYPE_INLINE);
$this->renderListeners(Listener::TYPE_BLOCK);

$buff = null;
foreach ($this->_lines as $line) {
Expand Down
4 changes: 2 additions & 2 deletions src/Line.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ class Line
const STATUS_CLEAN = 1;

/**
* @var integer The status of the line if its picked by a listenere.
* @var integer The status of the line if its picked by a listener
*/
const STATUS_PICKED = 2;

/**
* @var integer The status of the line if some of the listeneres marked this line as done.
* @var integer The status of the line if some of the listener marked this line as done.
*/
const STATUS_DONE = 3;

Expand Down
4 changes: 2 additions & 2 deletions src/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Listener Object.
*
* Every type of element is a listenere. Listeneres are "listening" to every line of delta code and can
* Every type of element is a listener. Listeners are "listening" to every line of delta code and can
* pick and process this line.
*
* @author Basil Suter <[email protected]>
Expand All @@ -30,7 +30,7 @@ abstract class Listener

/**
* @var integer Second priority listener within the given type. This is currently only used
* for TEXT listeneres - as they need to be the very last entry.
* for TEXT listeners - as they need to be the very last entry.
*/
const PRIORITY_GARBAGE_COLLECTOR = 2;

Expand Down

0 comments on commit 56abc51

Please sign in to comment.