Project

insular

0.0
No release in over 3 years
Self-contained JSX Components in Rails applications. Server-side render TypeScript components via Deno, cache via Solid Cache, hydrate selectively in the browser if needed.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 5.0
~> 13.0
~> 1.3

Runtime

 Project Readme

Insular

Insular is a Ruby gem that enables rendering JSX components in Ruby applications through the Deno runtime. It provides a bridge between Ruby and JavaScript/JSX, allowing you to render Preact components on the server side while writing your application logic in Ruby.

How It Works

Insular runs a Deno-based server that handles JSX rendering. Your Ruby application sends component information (path, name, and props) to this server, which:

  1. Dynamically imports the requested JSX component
  2. Renders it to an HTML string using Preact
  3. Returns the rendered HTML to your Ruby application

This architecture allows you to:

  • Write UI components in JSX/Preact
  • Use them seamlessly within Ruby applications
  • Take advantage of the Deno runtime's module caching and performance

Installation

Add this gem to your application's Gemfile:

bundle add insular

Or install it directly:

gem install insular

Usage

Starting the Rendering Server

Before rendering components, you need to start the Insular Deno server:

bundle exec insular server

The server accepts the following environment variables:

  • INSULAR_SERVER_HOST - Server host (default: localhost)
  • INSULAR_SERVER_PORT - Server port (default: 3001)

Alternatively, pass flags directly:

bundle exec insular server --host 0.0.0.0 --port 3001

Rendering Components

Use the HTTPRenderer to render JSX components from your Ruby application:

require 'insular'

# Render a component with props
html = Insular::HTTPRenderer.render(
  './tmp/components',  # Path to components directory
  'Name',               # Component name (without .tsx)
  { value: 'World' }   # Props to pass to the component
)

puts html
# => <span class="ok">Hello World</span>

Component File Structure

Place your JSX components in a directory accessible to the Deno server. Components should export a function:

// tmp/components/Name.tsx
export function Name({ value }: { value: string }) {
  return (
    <span class="ok">
      Hello {value}
    </span>
  )
}

Using the Embedded Renderer

For more direct control, you can use the embedded renderer which integrates the Deno runtime directly:

require 'insular'

html = Insular::EmbeddedRenderer.render(
  './tmp/components',
  'Name',
  { value: 'World' }
)

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/insular/insular.

License

The gem is available as open source under the terms of the MIT License.