Skip to content

Commit

Permalink
Merge pull request #67 from alexander-nitsche/task-update-readme-inst…
Browse files Browse the repository at this point in the history
…allation-section

Update the "Quick Start" section in README.md.
  • Loading branch information
vanderlee authored Apr 21, 2023
2 parents 47936d9 + 9f350c1 commit e6b723a
Show file tree
Hide file tree
Showing 4 changed files with 247 additions and 235 deletions.
77 changes: 45 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,56 @@ Supports PHP 5.6 and up, so you can use it on older servers.

Quick start
-----------
Just include phpSyllable in your project, set up the autoloader to the classes
directory and instantiate yourself a Syllable class.

Install phpSyllable via Composer

```
composer require vanderlee/syllable
```

or simply add phpSyllable to your project and set up the project's
autoloader for phpSyllable's src/ directory.

Then instantiate a Syllable object and start hyphenation.

Minimal example:

```php
$syllable = new Syllable('en-us');
$syllable = new \Vanderlee\Syllable\Syllable('en-us');
echo $syllable->hyphenateText('Provide a plethora of paragraphs');
```

Extended example:

```php
use Vanderlee\Syllable\Syllable;
use Vanderlee\Syllable\Hyphen;

// Globally set the directory where Syllable can store cache files.
Syllable::setCacheDir(__DIR__ . '/cache');

// Globally set the directory where the .tex files are stored.
// By default, this is the languages/ folder of this package and
// usually does not need to be adapted.
Syllable::setLanguageDir(__DIR__ . '/languages');

// Create a new instance for the language.
$syllable = new Syllable('en-us');

// Set the style of the hyphen. In this case it is the "-" character.
// By default, it is the soft hyphen "­".
$syllable->setHyphen(new Hyphen\Dash());

// Set the minimum word length required for hyphenation.
// By default, all words are hyphenated.
$syllable->setMinWordLength(5);

// Output hyphenated text.
echo $syllable->hyphenateText('Provide your own paragraphs...');
```

See the [demo.php](demo.php) file for a working example.

`Syllable` class reference
--------------------------
The following is an incomplete list, containing only the most common methods.
Expand Down Expand Up @@ -162,35 +204,6 @@ Count the number of syllables in the text.

Count the number of polysyllables in the text.

Example
-------
See the [demo.php](demo.php) file for a working example.

```php
// Setup the autoloader (if needed)
require_once dirname(__FILE__) . '/classes/autoloader.php';
use Vanderlee\Syllable\Syllable;

// Create a new instance for the language
$syllable = new Syllable('en-us');

// Set the directory where the .tex files are stored
$syllable->getSource()->setPath(__DIR__ . '/languages');

// Set the directory where Syllable can store cache files
$syllable->getCache()->setPath(__DIR__ . '/cache');

// Set the hyphen style. In this case, the ­ HTML entity
// for HTML (falls back to '-' for text)
$syllable->setHyphen(new Syllable_Hyphen_Soft);

// Set the treshold (sensitivity)
$syllable->setTreshold(Syllable::TRESHOLD_MOST);

// Output hyphenated text
echo $syllable->hyphenateText('Provide your own paragraphs...');
```

Development
-----------

Expand Down
4 changes: 2 additions & 2 deletions build/classes/DocumentationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ protected function updateReadme()

$readme = file_get_contents($this->readmeFile);
$apiDocumentationStart = strpos($readme, '###', strpos($readme, "`Syllable` class reference\n--------------------------"));
$apiDocumentationEnd = strpos($readme, "Example\n-------", $apiDocumentationStart);
$apiDocumentationEnd = strpos($readme, "Development\n-----------", $apiDocumentationStart);
$apiDocumentationLength = $apiDocumentationEnd - $apiDocumentationStart;
$apiDocumentationOld = '';
$readmeState = 0;
Expand All @@ -164,7 +164,7 @@ protected function updateReadme()

if ($readmeState < 1) {
if (!($readmeState & 1)) {
$errors[] = 'Missing headlines "`Syllable` class reference" and "Example" to locate API documentation.';
$errors[] = 'Missing headlines "`Syllable` class reference" and "Development" to locate API documentation.';
}
if (isset($errors)) {
throw new Exception(sprintf(
Expand Down
Loading

0 comments on commit e6b723a

Please sign in to comment.