
What is Phlex?
Phlex is a Ruby gem that lets you build object-oriented web views in pure Ruby. Instead of mixing Ruby code with template languages, you write everything in Ruby using a clean, intuitive DSL.Why Phlex?
Pure Ruby
No template language to learn. Use Ruby’s full power including classes, modules, and inheritance for your views.
Object-Oriented
Build reusable components with proper encapsulation. Pass data through initializers, not magic variables.
Type-Safe
Leverage Ruby’s type system and tools like Sorbet or RBS. Get autocomplete and type checking in your views.
Lightning Fast
Optimized for performance with attribute caching and efficient buffer management. Faster than ERB or Haml.
Key Features
Component-Based Architecture
Every view is a Ruby class that inherits fromPhlex::HTML, Phlex::SVG, or Phlex::CSV. This gives you:
- Encapsulation: Components manage their own state through instance variables
- Reusability: Compose components together like building blocks
- Testability: Unit test your views like any other Ruby class
Clean Attribute Syntax
Phlex provides an elegant API for HTML attributes with automatic safety features:Phlex automatically converts underscores to dashes in attribute names and provides XSS protection.
Flexible Rendering
Render components in multiple ways:What You Can Build
HTML Views
Full HTML documents with doctype, meta tags, and semantic markup.
SVG Graphics
Scalable vector graphics with the same clean Ruby syntax.
CSV Exports
Generate CSV files with proper escaping and formatting.
Requirements
Phlex has minimal dependencies:zeitwerk(~> 2.7) - For autoloadingrefract(~> 1.0) - For efficient rendering
Next Steps
Installation
Add Phlex to your project and configure your environment
Quick Start
Build your first component in 5 minutes
