assertchris/ellison
Laravel package that helps you build Ellison-style, class-based email templates with reusable components and a clean API. Designed to streamline email markup and keep designs consistent across messages while staying easy to maintain.
Installation:
composer require assertchris/ellison
No additional configuration is required—just autoload the package.
First Use Case: Analyze a sentence for readability and complexity:
use Ellison\Ellison;
$ellison = new Ellison();
$result = $ellison->analyze("The quick brown fox jumps over the lazy dog.");
print_r($result);
Output will include metrics like Flesch-Kincaid readability score, sentence length, and word complexity flags.
Where to Look First:
Ellison class for core methods.analyze() method for default thresholds and return structure.Service Provider Binding (Recommended):
// app/Providers/AppServiceProvider.php
public function register()
{
$this->app->singleton(Ellison::class, function ($app) {
return new Ellison(config('ellison.thresholds'));
});
}
Define thresholds in config/ellison.php:
return [
'max_sentence_length' => 20,
'max_word_complexity' => 3, // Syllables
];
Form Request Validation: Use Ellison to validate user-generated content (e.g., blog posts, emails):
use Ellison\Ellison;
public function rules()
{
return [
'content' => [
'required',
function ($attribute, $value, $fail) {
$ellison = app(Ellison::class);
$result = $ellison->analyze($value);
if ($result['is_complex']) {
$fail('Content is too complex. Aim for simpler sentences.');
}
},
],
];
}
Middleware for API Responses: Auto-analyze API responses before sending:
// app/Http/Middleware/AnalyzeResponse.php
public function handle($request, Closure $next)
{
$response = $next($request);
if ($response->isJson()) {
$content = $response->getContent();
$ellison = app(Ellison::class);
$metrics = $ellison->analyze($content);
$response->setData([
'content' => $content,
'readability' => $metrics,
]);
}
return $response;
}
Command-Line Tooling: Create an Artisan command to audit database records:
// app/Console/Commands/AuditReadability.php
public function handle()
{
$posts = Post::all();
foreach ($posts as $post) {
$metrics = app(Ellison::class)->analyze($post->content);
if ($metrics['is_complex']) {
$this->error("Post ID {$post->id}: Complexity detected.");
}
}
}
False Positives for Technical Writing: Ellison flags long sentences (e.g., legal/technical terms) as "complex." Override thresholds for domain-specific content:
$ellison = new Ellison(['max_sentence_length' => 30]);
Syllable Counting Quirks:
countSyllables() method or pre-process text:$text = preg_replace('/-/', ' ', $text); // Split hyphens
Performance with Large Texts: Avoid analyzing multi-page documents in a single call. Split text into paragraphs:
$paragraphs = explode("\n\n", $longText);
array_map([$ellison, 'analyze'], $paragraphs);
Enable Verbose Output:
Pass true to analyze() for detailed breakdowns:
$ellison->analyze($text, true);
Output includes:
Mocking for Tests: Use dependency injection to mock Ellison:
$this->mock(Ellison::class)->shouldReceive('analyze')
->once()
->andReturn(['is_complex' => false]);
Custom Readability Metrics:
Extend the Ellison class to add metrics (e.g., "passive voice detection"):
class CustomEllison extends Ellison {
public function analyze($text, $verbose = false) {
$result = parent::analyze($text, $verbose);
$result['passive_voice'] = $this->detectPassiveVoice($text);
return $result;
}
}
Language Support:
Override getLanguage() to support non-English text (e.g., Spanish):
$ellison->setLanguage('es');
// Or extend the class to add new language rules.
Database Storage:
Store metrics in a readability_metrics table:
// After analysis
DB::table('readability_metrics')->insert([
'content_id' => $post->id,
'flesch_score' => $result['flesch_score'],
'is_complex' => $result['is_complex'],
'created_at' => now(),
]);
max_sentence_length = 15). Override via constructor:
$ellison = new Ellison(['max_sentence_length' => 25]);
$text = mb_strtolower($text, 'UTF-8');
How can I help you explore Laravel packages today?