User Guide / Components

Using with Phlex

Phlex is “a framework for building fast, reusable, testable views in pure Ruby”.

Whilst Phlex does not have a concept of a ‘component’ as such but its views can effectively be used to fulfill the same role in an application.

Lookbook enables you to preview Phlex views in isolation for development and testing.

See the Phlex docs for setup and usage instructions: https://phlex.fun

Locating views

Lookbook assumes that Phlex view files will be stored in the app/views directory.

If that is not the case, you will need to add your Phlex view path to the component_paths config option:

config.lookbook.component_paths << "path/to/phlex/views"

Rendering in previews

Phlex components are rendered in preview classes using the render method:

# test/components/previews/article_view_preview.rb
class ArticleViewPreview < Lookbook::Preview
  def default
    render Views::Article.new
  end

  def with_args
    render Views::Article.new(title: "This is a title") do
      "This is the body"
    end
  end
end

User Guide

Extending Lookbook

API

Elsewhere